Skip to content

Commit

Permalink
Merge d8028aa into 940861e
Browse files Browse the repository at this point in the history
  • Loading branch information
TorkelE committed Jun 4, 2024
2 parents 940861e + d8028aa commit 0775d8a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/pages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ pages = Any[
# # Contributor's guide.
# # Repository structure.
# ],
#"FAQs" => "faqs.md",
"FAQs" => "faqs.md",
"API" => "api.md"
]
18 changes: 11 additions & 7 deletions docs/src/faqs.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ One can directly use symbolic variables to index into SciML solution objects.
Moreover, observables can also be evaluated in this way. For example,
consider the system
```@example faq1
using Catalyst, DifferentialEquations, Plots
using Catalyst, OrdinaryDiffEq, Plots
rn = @reaction_network ABtoC begin
(k₊,k₋), A + B <--> C
end
# initial condition and parameter values
setdefaults!(rn, [:A => 1.0, :B => 2.0, :C => 0.0, :k₊ => 1.0, :k₋ => 1.0])
nothing # hide
```
Let's convert it to a system of ODEs, using the conservation laws of the system
to eliminate two of the species:
```@example faq1
osys = convert(ODESystem, rn; remove_conserved = true)
osys = complete(osys)
```
Notice the resulting ODE system has just one ODE, while algebraic observables
have been added for the two removed species (in terms of the conservation law
Expand All @@ -28,7 +26,9 @@ observed(osys)
Let's solve the system and see how to index the solution using our symbolic
variables
```@example faq1
oprob = ODEProblem(osys, [], (0.0, 10.0), [])
u0 = [rn.A => 1.0, rn.B => 2.0, rn.C => 0.0]
ps = [rn.k₊ => 1.0, rn.k₋ => 1.0]
oprob = ODEProblem(osys, u0, (0.0, 10.0), ps)
sol = solve(oprob, Tsit5())
```
Suppose we want to plot just species `C`, without having to know its integer
Expand Down Expand Up @@ -65,7 +65,7 @@ constant, giving `k*X^2/2` instead of `k*X^2` for ODEs and `k*X*(X-1)/2` instead
of `k*X*(X-1)` for jumps. This can be disabled when directly `convert`ing a
[`ReactionSystem`](@ref). If `rn` is a generated [`ReactionSystem`](@ref), we can
do
```julia
```@example faq1
osys = convert(ODESystem, rn; combinatoric_ratelaws=false)
```
Disabling these rescalings should work for all conversions of `ReactionSystem`s
Expand All @@ -88,6 +88,7 @@ rx2 = Reaction(2*k, [B], [D], [1], [2.5])
rx3 = Reaction(2*k, [B], [D], [2.5], [2])
@named mixedsys = ReactionSystem([rx1, rx2, rx3], t, [A, B, C, D], [k, b])
osys = convert(ODESystem, mixedsys; combinatoric_ratelaws = false)
osys = complete(osys)
```
Note, when using `convert(ODESystem, mixedsys; combinatoric_ratelaws=false)` the
`combinatoric_ratelaws=false` parameter must be passed. This is also true when
Expand Down Expand Up @@ -127,6 +128,7 @@ t = default_t()
rx1 = Reaction(β, [S, I], [I], [1,1], [2])
rx2 = Reaction(ν, [I], [R])
@named sir = ReactionSystem([rx1, rx2], t)
sir = complete(sir)
oprob = ODEProblem(sir, [], (0.0, 250.0))
sol = solve(oprob, Tsit5())
plot(sol)
Expand Down Expand Up @@ -162,7 +164,7 @@ Julia `Symbol`s corresponding to each variable/parameter to their values, or
from ModelingToolkit symbolic variables/parameters to their values. Using
`Symbol`s we have
```@example faq4
using Catalyst, DifferentialEquations
using Catalyst, OrdinaryDiffEq
rn = @reaction_network begin
α, S + I --> 2I
β, I --> R
Expand Down Expand Up @@ -199,6 +201,7 @@ the second example, or one can use the `symmap_to_varmap` function to convert th
`Symbol` mapping to a symbolic mapping. I.e. this works
```@example faq4
osys = convert(ODESystem, rn)
osys = complete(osys)
# this works
u0 = symmap_to_varmap(rn, [:S => 999.0, :I => 1.0, :R => 0.0])
Expand All @@ -221,6 +224,7 @@ rx1 = @reaction k, A --> 0
rx2 = @reaction $f, 0 --> A
eq = f ~ (1 + sin(t))
@named rs = ReactionSystem([rx1, rx2, eq], t)
rs = complete(rs)
osys = convert(ODESystem, rs)
```
In the final ODE model, `f` can be eliminated by using
Expand Down

0 comments on commit 0775d8a

Please sign in to comment.