A Petri net modeling framework for the Julia programming language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Micah Halter 504aa0f91d
added DOI
3 weeks ago
.github/workflows Fixed documentation generation 1 month ago
docs Petri v0.3.0: Added labelled arrays support (#18) 1 month ago
examples Petri v0.3.0: Added labelled arrays support (#18) 1 month ago
src Petri v0.3.0: Added labelled arrays support (#18) 1 month ago
test Petri v0.3.0: Added labelled arrays support (#18) 1 month ago
.gitignore Petri.jl v0.2.0: DSL Clean Up and Dependency Removal (#17) 1 month ago
LICENSE Updated compatibility and version bump (#10) 6 months ago
Project.toml Petri v0.3.0: Added labelled arrays support (#18) 1 month ago
README.md added DOI 3 weeks ago
REQUIRE Petri.jl v0.2.0: DSL Clean Up and Dependency Removal (#17) 1 month ago

README.md

Petri.jl

Documentation Tests DOI

Petri.jl is a Petri net modeling framework for the Julia programming language.

Examples

We need to include our dependencies. Petri is the only requirement to build the models. OrdinaryDiffEq is required for simulating the network with and ordinary differential equation. Plots can be used to plot the solutions generated by OrdinaryDiffEq. LabelledArrays can be used to make things more readable, but is not necessary. Lastly, Catlab is required for visualizing the models as graphviz diagrams.

using Petri
using LabelledArrays
using OrdinaryDiffEq
using Plots
using Catlab.Graphics.Graphiz
import Catlab.Graphics.Graphviz: Graph

The SIR model represents the epidemiological dynamics of an infectious disease that causes immunity in its victims. There are three states: Suceptible ,Infected, Recovered. These states interact through two transitions. Infection has the form S+I -> 2I where a susceptible person meets an infected person and results in two infected people. The second transition is recovery I -> R where an infected person recovers spontaneously.

The SIR model system shown as a Petri net with ODE formulas

# define the structure of the model
sir = Petri.Model([:S,:I,:R],LVector(
                                inf=(LVector(S=1,I=1), LVector(I=2)),
                                rec=(LVector(I=1),     LVector(R=1))))

# define the initial conditions
u0 = LVector(S=100.0, I=1, R=0)

# define the parameters of the model, each rate corresponds to a transition
p = LVector(inf=0.05, rec=0.35)

# evaluate the expression to create a runnable function
f = toODE(sir)

# this is regular OrdinaryDiffEq problem setup
prob = ODEProblem(f,u0,(0.0,365.0),p)
sol = OrdinaryDiffEq.solve(prob,Tsit5())

# generate a graphviz visualization of the model
graph = Graph(sir)

# visualize the solution
plt = plot(sol)

A solution to the SIR model system

Petri Nets are a simple language for describing reaction networks, you can make increasingly complex diseases. For example the SEIR model has an Exposed phase where people have the disease, but are not infectious yet.

The SEIR model system shown as a Petri net

seir = Petri.Model([:S,:E,:I,:R],LVector(
                                    exp=(LVector(S=1,I=1), LVector(I=1,E=1)),
                                    inf=(LVector(E=1),     LVector(I=1)),
                                    rec=(LVector(I=1),     LVector(R=1))))
u0 = LVector(S=100.0, E=1, I=0, R=0)
p = (exp=0.35, inf=0.05, rec=0.05)
f = toODE(seir)
prob = ODEProblem(f,u0,(0.0,365.0),p)
sol = OrdinaryDiffEq.solve(prob,Tsit5())
plt = plot(sol)

A solution to the SEIR model system

The previous models have transitory behavior, the infection spreads and then terminates as you end up with no infected people in the population. The following SEIRS model has a non-trivial steady state, because recovered people lose their immunity and become susceptible again.

The SEIRS model system shown as a Petri net

seirs = Petri.Model([:S,:E,:I,:R],LVector(
                                    exp=(LVector(S=1,I=1), LVector(I=1,E=1)),
                                    inf=(LVector(E=1),     LVector(I=1)),
                                    rec=(LVector(I=1),     LVector(R=1)),
                                    deg=(LVector(R=1),     LVector(S=1))))
u0 = LVector(S=100.0, E=1, I=0, R=0)
p = LVector(exp=0.35, inf=0.05, rec=0.07, deg=0.3)
f = toODE(seirs)
prob = ODEProblem(f,u0,(0.0,365.0),p)
sol = OrdinaryDiffEq.solve(prob,Tsit5())
plt = plot(sol)

A solution to the SEIRS model system

Goals

Petri makes it easy to build complex reaction networks using a simple DSL. This is related to theDiffeqBiological Reaction DSL, but takes a different implementation approach. Instead of building our framework around symbolic algebra and standard chemical notion, we are working off the Applied Category Theory approach to reaction networks [Baez Pollard, 2017].

There are operations that are easy to do on the Petri.Model like “add a transition from R to S” that require simultaneously changing multiple parts of the algebraic formulation. Applied Category Theory gives a sound theoretical framework for manipulating Petri Nets as a model of chemical reactions. Petri is a Julia package primarily intended to investigate how we can operationalize this theory into practical scientific software.

See SemanticModels for tools that work with Petri net models and manipulating them with higher level APIs based on ACT.