Skip to content

Commit

Permalink
DOC: show AlgebraicPetri SciML integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfairbanks committed Jul 1, 2024
1 parent f8681f9 commit 1d0024e
Showing 1 changed file with 48 additions and 7 deletions.
55 changes: 48 additions & 7 deletions docs/src/AlgebraicPetri.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
````@meta
Draft=false
````
# AlgebraicPetri.jl Integration

You can construct a [`ContinuousResourceSharer`](@ref) from an Open Petri Net for any kind of network supported by [AlgebraicPetri.jl](https://algebraicjulia.github.io/AlgebraicPetri.jl/dev/) including:
Expand All @@ -13,6 +10,40 @@ You can construct a [`ContinuousResourceSharer`](@ref) from an Open Petri Net fo
using AlgebraicPetri
using AlgebraicDynamics
using Catlab.Graphics
Brusselator = PetriNet(6,
(1 => (5, 1)),
((5, 5, 6) => (5, 5, 5)),
((2, 5) => (6, 3, 2)),
(5 => 4)
)
to_graphviz(Brusselator)
````
You just call the constructor for ContinuousResourceSharer on an Open Petri Net.
The constructor knows where to use labels or integers for the state variables.
It also knows to get parameters from the ReactionNet and enclose them into the dynamics.


````@example AlgPetri
open_bruss = Open([1, 3], Brusselator, [1, 2])
rs = ContinuousResourceSharer{Float64}(open_bruss)
````

For the PetriNet case, you supply the state and parameters with regular arrays.

````@example AlgPetri
using OrdinaryDiffEq
using Plots
tspan = (0.0,100.0)
params = [1.0, 1., 1., 1.0]
u0 = [1,3.7,0.0,0.0,1,1]
prob = ODEProblem(rs, u0, tspan, params)
soln = solve(prob, Tsit5())
plot(soln, idxs=[5,6])
````

For the LabelledPetriNet case, you supply the state and parameters with `LArray`.

````@example AlgPetri
Brusselator = LabelledPetriNet([:A, :B, :D, :E, :X, :Y],
:t1 => (:A => (:X, :A)),
:t2 => ((:X, :X, :Y) => (:X, :X, :X)),
Expand All @@ -22,11 +53,21 @@ Brusselator = LabelledPetriNet([:A, :B, :D, :E, :X, :Y],
to_graphviz(Brusselator)
````

You just call the constructor for ContinuousResourceSharer on an Open Petri Net.
The constructor knows where to use labels or integers for the state variables.
It also knows to get parameters from the ReactionNet and enclose them into the dynamics.

````@example AlgPetri
open_bruss = Open([:A, :D], Brusselator, [:A, :B])
rs = ContinuousResourceSharer{Float64}(open_bruss)
````

!!! note
@example AlgPetri
SciML integration for LabelledArrays is broken due to this [issue](https://github.com/SciML/LabelledArrays.jl/issues/162) on LabelledArrays.jl. Once that issue is closed, you should be able to solve LabelledPetriNets with SciML Solvers.

````julia
using LabelledArrays
tspan = (0.0,100.0)
params = LVector(t1=1.0, t2=1.2, t3=3.14, t4=0.1)
u0 = LVector(A=1.0, B=3.17, D=0.0, E=0.0, X=1.0, Y=1.9)
prob = ODEProblem((u,p,t) -> eval_dynamics(rs, u, p, t), u0, tspan, params)
sol = solve(prob, Tsit5())
plot(sol, idxs=[:X, :Y])
````

0 comments on commit 1d0024e

Please sign in to comment.