- Notifications
You must be signed in to change notification settings - Fork1
A lightweight tool for modeling and simulation of Stochastic Petri Nets (SPNs).
License
jo-chr/pyspn
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A lightweight tool for modeling and simulation of Stochastic Petri Nets (SPNs).
ℹ️Tested with Python 3.11
git clone https://github.com/jo-chr/pyspn.git# 1. Clone repositorypip install -r requirements.txt# 2. Install requirementspython3 examples/one_server.py# 3. Run single-server queue example
Formally, the class of SPNs that can be modeled usingPySPN is defined as:
where:
$P = {P_1,P_2,..,P_m}$ is the set of places, drawn as circles;$T = {T_1,T_2,..,T_n}$ is the set of transitions along with their distribution functions or weights, drawn as bars;$A = A^I \cup A^O \cup A^H$ is the set of arcs, where$A^O$ is the set of output arcs,$A^I$ is the set of input arcs and$A^H$ is the set of inhibitor arcs and each of the arcs has a multiplicity assigned to it;$G = {g_1,g_2,..,g_r}$ is the set of guard functions which are associated with different transitions;- and
$m_0$ is the initial marking, defining the distribution of tokens in the places.
Each transition is represented as
Find sample SPNs underexamples/
. Currently, places, timed transitions (t_type = "T"), immediate transitions (t_type = "I"), output arcs, input arcs, inhibitor arcs, guard functions, and memory policies are supported.
A place with its required arguments is defined like so:
p1 = Place(label="Place 1", n_tokens=0)
A timed transition with its required arguments and a sample distribution function is defined like so:
t1 = Transition(label="Transition 1", t_type="T")t1.set_distribution(distribution="expon", a=0.0, b=1.0/1.0)
An immediate transition with its required arguments and a sample weight is defined like so:
t2 = Transition(label="Transition 2", t_type="I")t2.set_weight(weight=0.8)
For timed transitions, some of the supported distributions are:
Distribution | Parameter |
---|---|
Deterministic ("det") | a (fixed delay) |
Exponential ("expon") | a ,b |
Normal ("norm") | a ,b |
Lognormal ("lognorm") | a ,b ,c |
Uniform ("uniform") | a ,b |
Triangular ("triang") | a ,b ,c |
Weibull ("weibull_min") | a ,b ,c |
More distributions can be easily implemented inRNGFactory.py
. SeeScipy's documentation for details regarding the distributions and their parameters.
Guard functions are defined like so:
defguard_t1():if len(p1.n_tokens)>= 2:return True else:return Falset1.set_guard_function(guard_t1)
The default setting is Race Enable ("ENABLE").
The memory policy can be set during instantiation
t1 = Transition(label="Transition_1",t_type="T",memory_policy="AGE")
or by using a function call
t1.set_memory_policy("AGE")
To configure a transition that joins two or more input places, set the "Join" parameter to True.This indicates that the transition will act upon the confluence of tokens from multiple places.
t1 = Transition(label="", t_type="", Join=True)
Similarly, to set up a transition that splits its output to multiple places, utilize the "Fork" parameter.Setting split to True designates that the transition's output will be distributed to several output places.
t1 = Transition(label="", t_type="", Fork=True)
Export and import SPNs aspickle files using theexport_spn()
andimport_spn()
functions ofspn_io
module.
Simulate a SPN like so:
simulate(spn, max_time = 100, verbosity = 2, protocol = True)
For the verbosity there are 3 levels of what is printed in the terminal:
- 0: No information;
- 1: Only final simulation statistics;
- 2: Initial markings, firing of transitions, and final statistics;
- 3: Initial markings, firing of transitions and the resulting marking and state, and final statistics.
The simulation protocol capturing the markings throughtout the simulation can be found underoutput/protocol/
.
Visualize a SPN like so:
draw_spn(spn, show=False, file="sample_spn", rankdir="LR")
The graph can be found underoutput/graphs/
.
Output graph example for the example "two_server_with_guard&multiplicity.py"
If you are using the tool for a scientific project please consider citing our publications:
# SAGE Publications Sage 2025 (Journal Paper)@article{friederich2025pyspn, title={PySPN: a Python library for stochastic Petri net modeling, simulation, and event log generation}, author={Friederich, Jonas and Khodadadi, Atieh and Lazarova-Molnar, Sanja}, journal={SIMULATION}, pages={00375497251343625}, year={2025}, publisher={SAGE Publications Sage UK: London, England}}# EAI SIMUtools 2023 - 15th EAI International Conference on Simulation Tools and Techniques (preprint, accepted for presentation)@misc{friederich_2023, doi = {10.13140/RG.2.2.25334.16967}, url = {https://www.researchgate.net/publication/375758652_PySPN_An_Extendable_Python_Library_for_Modeling_Simulation_of_Stochastic_Petri_Nets}, year = 2023, month = {Nov}, author = {Friederich, Jonas and Lazarova-Molnar, Sanja}, title = {{PySPN}: An Extendable Python Library for Modeling & Simulation of Stochastic Petri Nets}, conference = {EAI SIMUtools 2023 - 15th EAI International Conference on Simulation Tools and Techniques}, note = {preprint}}
For questions/feedback feel free to contact me:jofr@mmmi.sdu.dk.
About
A lightweight tool for modeling and simulation of Stochastic Petri Nets (SPNs).
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.