Skip to content

Commit a140f53

Browse files
authored
Merge pull request #940 from isaacsas/fix_parametric_stoich_tutorial
Fix parametric stoich tutorial
2 parents a20bf5b + c4f18d6 commit a140f53

File tree

5 files changed

+37
-31
lines changed

5 files changed

+37
-31
lines changed

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ makedocs(sitename = "Catalyst.jl",
4141
clean = true,
4242
pages = pages,
4343
pagesonly = true,
44-
warnonly = [:missing_docs])
44+
warnonly = true)
4545

4646
deploydocs(repo = "github.com/SciML/Catalyst.jl.git";
4747
push_preview = true)

docs/src/assets/Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ IncompleteLU = "0.2"
5151
JumpProcesses = "9.11"
5252
Latexify = "0.16"
5353
LinearSolve = "2.30"
54-
ModelingToolkit = "9.15"
54+
ModelingToolkit = "9.16.0"
5555
NonlinearSolve = "3.12"
5656
Optim = "1.9"
5757
Optimization = "3.25"
@@ -68,5 +68,5 @@ SpecialFunctions = "2.4"
6868
StaticArrays = "1.9"
6969
SteadyStateDiffEq = "2.2"
7070
StochasticDiffEq = "6.65"
71-
StructuralIdentifiability = "0.5.7"
72-
Symbolics = "5.28"
71+
StructuralIdentifiability = "0.5.8"
72+
Symbolics = "5.30.1"

docs/src/introduction_to_catalyst/introduction_to_catalyst.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ Gillespie's `Direct` method, and then solve it to generate one realization of
182182
the jump process:
183183

184184
```@example tut1
185-
# imports the JumpProcesses packages
185+
# imports the JumpProcesses packages
186186
using JumpProcesses
187187
188188
# redefine the initial condition to be integer valued
@@ -361,4 +361,4 @@ and the ODE model
361361

362362
---
363363
## References
364-
[^1]: [Torkel E. Loman, Yingbo Ma, Vasily Ilin, Shashi Gowda, Niklas Korsbo, Nikhil Yewale, Chris Rackauckas, Samuel A. Isaacson, *Catalyst: Fast and flexible modeling of reaction networks*, PLOS Computational Biology (2023).](https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1011530)
364+
1. [Torkel E. Loman, Yingbo Ma, Vasily Ilin, Shashi Gowda, Niklas Korsbo, Nikhil Yewale, Chris Rackauckas, Samuel A. Isaacson, *Catalyst: Fast and flexible modeling of reaction networks*, PLOS Computational Biology (2023).](https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1011530)

docs/src/model_creation/examples/smoluchowski_coagulation_equation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,6 @@ plot!(ϕ, sol[3,:] / Nₒ, line = (:dot, 4, :purple), label = "Analytical sol--X
147147

148148
---
149149
## References
150-
[^1]: [https://en.wikipedia.org/wiki/Smoluchowski\_coagulation\_equation](https://en.wikipedia.org/wiki/Smoluchowski_coagulation_equation)
151-
[^2]: Scott, W. T. (1968). Analytic Studies of Cloud Droplet Coalescence I, Journal of Atmospheric Sciences, 25(1), 54-65. Retrieved Feb 18, 2021, from https://journals.ametsoc.org/view/journals/atsc/25/1/1520-0469\_1968\_025\_0054\_asocdc\_2\_0\_co\_2.xml
152-
[^3]: Ian J. Laurenzi, John D. Bartels, Scott L. Diamond, A General Algorithm for Exact Simulation of Multicomponent Aggregation Processes, Journal of Computational Physics, Volume 177, Issue 2, 2002, Pages 418-449, ISSN 0021-9991, https://doi.org/10.1006/jcph.2002.7017.
150+
1. [https://en.wikipedia.org/wiki/Smoluchowski\_coagulation\_equation](https://en.wikipedia.org/wiki/Smoluchowski_coagulation_equation)
151+
2. Scott, W. T. (1968). Analytic Studies of Cloud Droplet Coalescence I, Journal of Atmospheric Sciences, 25(1), 54-65. Retrieved Feb 18, 2021, from https://journals.ametsoc.org/view/journals/atsc/25/1/1520-0469\_1968\_025\_0054\_asocdc\_2\_0\_co\_2.xml
152+
3. Ian J. Laurenzi, John D. Bartels, Scott L. Diamond, A General Algorithm for Exact Simulation of Multicomponent Aggregation Processes, Journal of Computational Physics, Volume 177, Issue 2, 2002, Pages 418-449, ISSN 0021-9991, https://doi.org/10.1006/jcph.2002.7017.

docs/src/model_creation/parametric_stoichiometry.md

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@ is a parameter, and the number of products is the product of two parameters.
99
```@example s1
1010
using Catalyst, Latexify, OrdinaryDiffEq, ModelingToolkit, Plots
1111
revsys = @reaction_network revsys begin
12+
@parameters m::Int64 n::Int64
1213
k₊, m*A --> (m*n)*B
1314
k₋, B --> A
1415
end
1516
reactions(revsys)
1617
```
17-
Note, as always the `@reaction_network` macro defaults to setting all symbols
18+
Notice, as described in the [Reaction rate laws used in simulations](@ref introduction_to_catalyst_ratelaws)
19+
section, the default rate laws involve factorials in the stoichiometric
20+
coefficients. For this reason we explicitly specify `m` and `n` as integers (as
21+
otherwise ModelingToolkit will implicitly assume they are floating point).
22+
23+
As always the `@reaction_network` macro defaults to setting all symbols
1824
neither used as a reaction substrate nor a product to be parameters. Hence, in
1925
this example we have two species (`A` and `B`) and four parameters (`k₊`, `k₋`,
2026
`m`, and `n`). In addition, the stoichiometry is applied to the rightmost symbol
@@ -36,21 +42,21 @@ We could have equivalently specified our systems directly via the Catalyst
3642
API. For example, for `revsys` we would could use
3743
```@example s1
3844
t = default_t()
39-
@parameters k₊, k₋, m, n
45+
@parameters k₊ k₋ m::Int n::Int
4046
@species A(t), B(t)
4147
rxs = [Reaction(k₊, [A], [B], [m], [m*n]),
4248
Reaction(k₋, [B], [A])]
4349
revsys2 = ReactionSystem(rxs,t; name=:revsys)
4450
revsys2 == revsys
4551
```
46-
which can be simplified using the `@reaction` macro to
52+
or
4753
```@example s1
48-
rxs2 = [(@reaction k₊, m*A --> (m*n)*B),
54+
rxs2 = [(@reaction k₊, $m*A --> ($m*$n)*B),
4955
(@reaction k₋, B --> A)]
5056
revsys3 = ReactionSystem(rxs2,t; name=:revsys)
5157
revsys3 == revsys
5258
```
53-
Note, the `@reaction` macro again assumes all symbols are parameters except the
59+
Here we interpolate in the pre-declared `m` and `n` symbolic variables using `$m` and `$n` to ensure the parameter is known to be integer-valued. The `@reaction` macro again assumes all symbols are parameters except the
5460
substrates or reactants (i.e. `A` and `B`). For example, in
5561
`@reaction k, F*A + 2(H*G+B) --> D`, the substrates are `(A,G,B)` with
5662
stoichiometries `(F,2*H,2)`.
@@ -62,41 +68,41 @@ osys = complete(osys)
6268
equations(osys)
6369
show(stdout, MIME"text/plain"(), equations(osys)) # hide
6470
```
65-
Notice, as described in the [Reaction rate laws used in simulations](@ref)
66-
section, the default rate laws involve factorials in the stoichiometric
67-
coefficients. For this reason we must specify `m` and `n` as integers, and hence
68-
*use a tuple for the parameter mapping*
71+
Specifying the parameter and initial condition values,
6972
```@example s1
70-
p = (k₊ => 1.0, k₋ => 1.0, m => 2, n => 2)
71-
u₀ = [A => 1.0, B => 1.0]
73+
p = (revsys.k₊ => 1.0, revsys.k₋ => 1.0, revsys.m => 2, revsys.n => 2)
74+
u₀ = [revsys.A => 1.0, revsys.B => 1.0]
7275
oprob = ODEProblem(osys, u₀, (0.0, 1.0), p)
7376
nothing # hide
7477
```
75-
We can now solve and plot the system
76-
```@julia
78+
we can now solve and plot the system
79+
```@example s1
7780
sol = solve(oprob, Tsit5())
7881
plot(sol)
7982
```
80-
*If we had used a vector to store parameters, `m` and `n` would be converted to
81-
floating point giving an error when solving the system.* **Note, currently a [bug](https://github.com/SciML/ModelingToolkit.jl/issues/2296) in ModelingToolkit has broken this example by converting to floating point when using tuple parameters, see the alternative approach below for a workaround.**
8283

8384
An alternative approach to avoid the issues of using mixed floating point and
8485
integer variables is to disable the rescaling of rate laws as described in
85-
[Reaction rate laws used in simulations](@ref) section. This requires passing
86-
the `combinatoric_ratelaws=false` keyword to `convert` or to `ODEProblem` (if
87-
directly building the problem from a `ReactionSystem` instead of first
88-
converting to an `ODESystem`). For the previous example this gives the following
89-
(different) system of ODEs
86+
[Reaction rate laws used in simulations](@ref introduction_to_catalyst_ratelaws)
87+
section. This requires passing the `combinatoric_ratelaws=false` keyword to
88+
`convert` or to `ODEProblem` (if directly building the problem from a
89+
`ReactionSystem` instead of first converting to an `ODESystem`). For the
90+
previous example this gives the following (different) system of ODEs where we
91+
now let `m` and `n` be floating point valued parameters (the default):
9092
```@example s1
93+
revsys = @reaction_network revsys begin
94+
k₊, m*A --> (m*n)*B
95+
k₋, B --> A
96+
end
9197
osys = convert(ODESystem, revsys; combinatoric_ratelaws = false)
9298
osys = complete(osys)
9399
equations(osys)
94100
show(stdout, MIME"text/plain"(), equations(osys)) # hide
95101
```
96102
Since we no longer have factorial functions appearing, our example will now run
97-
even with floating point values for `m` and `n`:
103+
with `m` and `n` treated as floating point parameters:
98104
```@example s1
99-
p = (k₊ => 1.0, k₋ => 1.0, m => 2.0, n => 2.0)
105+
p = (revsys.k₊ => 1.0, revsys.k₋ => 1.0, revsys.m => 2.0, revsys.n => 2.0)
100106
oprob = ODEProblem(osys, u₀, (0.0, 1.0), p)
101107
sol = solve(oprob, Tsit5())
102108
plot(sol)

0 commit comments

Comments
 (0)