Skip to content

Commit 05af1f9

Browse files
committed
Merge branch 'master' into fix_broken_doc_references
2 parents f763f91 + a140f53 commit 05af1f9

File tree

5 files changed

+65
-56
lines changed

5 files changed

+65
-56
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/introduction_to_catalyst/introduction_to_catalyst.md

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

183183
```@example tut1
184-
# imports the JumpProcesses packages
184+
# imports the JumpProcesses packages
185185
using JumpProcesses
186186
187187
# redefine the initial condition to be integer valued
@@ -360,4 +360,4 @@ and the ODE model
360360

361361
---
362362
## References
363-
[^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)
363+
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)

test/reactionsystem_core/reactionsystem.jl

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ end
159159

160160
# Test with JumpSystem.
161161
let
162-
p = rand(rng, length(k))
163162
@species A(t) B(t) C(t) D(t) E(t) F(t)
164163
rxs = [Reaction(k[1], nothing, [A]), # 0 -> A
165164
Reaction(k[2], [B], nothing), # B -> 0
@@ -193,27 +192,29 @@ let
193192
@test all(map(i -> typeof(equations(js)[i]) <: JumpProcesses.ConstantRateJump, cidxs))
194193
@test all(map(i -> typeof(equations(js)[i]) <: JumpProcesses.VariableRateJump, vidxs))
195194

196-
pars = rand(rng, length(k))
195+
p = rand(rng, length(k))
196+
pmap = parameters(js) .=> p
197197
u0 = rand(rng, 2:10, 6)
198+
u0map = unknowns(js) .=> u0
198199
ttt = rand(rng)
199200
jumps = Vector{Union{ConstantRateJump, MassActionJump, VariableRateJump}}(undef,
200201
length(rxs))
201202

202-
jumps[1] = MassActionJump(pars[1], Vector{Pair{Int, Int}}(), [1 => 1])
203-
jumps[2] = MassActionJump(pars[2], [2 => 1], [2 => -1])
204-
jumps[3] = MassActionJump(pars[3], [1 => 1], [1 => -1, 3 => 1])
205-
jumps[4] = MassActionJump(pars[4], [3 => 1], [1 => 1, 2 => 1, 3 => -1])
206-
jumps[5] = MassActionJump(pars[5], [3 => 1], [1 => 2, 3 => -1])
207-
jumps[6] = MassActionJump(pars[6], [1 => 1, 2 => 1], [1 => -1, 2 => -1, 3 => 1])
208-
jumps[7] = MassActionJump(pars[7], [2 => 2], [1 => 1, 2 => -2])
209-
jumps[8] = MassActionJump(pars[8], [1 => 1, 2 => 1], [2 => -1, 3 => 1])
210-
jumps[9] = MassActionJump(pars[9], [1 => 1, 2 => 1], [1 => -1, 2 => -1, 3 => 1, 4 => 1])
211-
jumps[10] = MassActionJump(pars[10], [1 => 2], [1 => -2, 3 => 1, 4 => 1])
212-
jumps[11] = MassActionJump(pars[11], [1 => 2], [1 => -1, 2 => 1])
213-
jumps[12] = MassActionJump(pars[12], [1 => 1, 2 => 3, 3 => 4],
203+
jumps[1] = MassActionJump(p[1], Vector{Pair{Int, Int}}(), [1 => 1])
204+
jumps[2] = MassActionJump(p[2], [2 => 1], [2 => -1])
205+
jumps[3] = MassActionJump(p[3], [1 => 1], [1 => -1, 3 => 1])
206+
jumps[4] = MassActionJump(p[4], [3 => 1], [1 => 1, 2 => 1, 3 => -1])
207+
jumps[5] = MassActionJump(p[5], [3 => 1], [1 => 2, 3 => -1])
208+
jumps[6] = MassActionJump(p[6], [1 => 1, 2 => 1], [1 => -1, 2 => -1, 3 => 1])
209+
jumps[7] = MassActionJump(p[7], [2 => 2], [1 => 1, 2 => -2])
210+
jumps[8] = MassActionJump(p[8], [1 => 1, 2 => 1], [2 => -1, 3 => 1])
211+
jumps[9] = MassActionJump(p[9], [1 => 1, 2 => 1], [1 => -1, 2 => -1, 3 => 1, 4 => 1])
212+
jumps[10] = MassActionJump(p[10], [1 => 2], [1 => -2, 3 => 1, 4 => 1])
213+
jumps[11] = MassActionJump(p[11], [1 => 2], [1 => -1, 2 => 1])
214+
jumps[12] = MassActionJump(p[12], [1 => 1, 2 => 3, 3 => 4],
214215
[1 => -1, 2 => -3, 3 => -2, 4 => 3])
215-
jumps[13] = MassActionJump(pars[13], [1 => 3, 2 => 1], [1 => -3, 2 => -1])
216-
jumps[14] = MassActionJump(pars[14], Vector{Pair{Int, Int}}(), [1 => 2])
216+
jumps[13] = MassActionJump(p[13], [1 => 3, 2 => 1], [1 => -3, 2 => -1])
217+
jumps[14] = MassActionJump(p[14], Vector{Pair{Int, Int}}(), [1 => 2])
217218

218219
jumps[15] = ConstantRateJump((u, p, t) -> p[15] * u[1] / (2 + u[1]),
219220
integrator -> (integrator.u[1] -= 1))
@@ -230,32 +231,34 @@ let
230231
integrator -> (integrator.u[4] -= 2; integrator.u[5] -= 1; integrator.u[6] += 2))
231232

232233
unknownoid = Dict(unknown => i for (i, unknown) in enumerate(unknowns(js)))
233-
jspmapper = ModelingToolkit.JumpSysMajParamMapper(js, pars)
234+
dprob = DiscreteProblem(js, u0map, (0.0, 10.0), pmap)
235+
mtkpars = dprob.p
236+
jspmapper = ModelingToolkit.JumpSysMajParamMapper(js, mtkpars)
234237
symmaj = ModelingToolkit.assemble_maj(equations(js).x[1], unknownoid, jspmapper)
235-
maj = MassActionJump(symmaj.param_mapper(pars), symmaj.reactant_stoch, symmaj.net_stoch,
238+
maj = MassActionJump(symmaj.param_mapper(mtkpars), symmaj.reactant_stoch, symmaj.net_stoch,
236239
symmaj.param_mapper, scale_rates = false)
237240
for i in midxs
238-
@test_broken abs(jumps[i].scaled_rates - maj.scaled_rates[i]) < 100 * eps()
241+
@test abs(jumps[i].scaled_rates - maj.scaled_rates[i]) < 100 * eps()
239242
@test jumps[i].reactant_stoch == maj.reactant_stoch[i]
240243
@test jumps[i].net_stoch == maj.net_stoch[i]
241244
end
242245
for i in cidxs
243246
crj = ModelingToolkit.assemble_crj(js, equations(js)[i], unknownoid)
244-
@test_broken isapprox(crj.rate(u0, p, ttt), jumps[i].rate(u0, p, ttt))
245-
fake_integrator1 = (u = zeros(6), p = p, t = 0.0)
246-
fake_integrator2 = deepcopy(fake_integrator1)
247+
@test isapprox(crj.rate(u0, mtkpars, ttt), jumps[i].rate(u0, p, ttt))
248+
fake_integrator1 = (u = zeros(6), p = mtkpars, t = 0.0)
249+
fake_integrator2 = (u = zeros(6), p, t = 0.0)
247250
crj.affect!(fake_integrator1)
248251
jumps[i].affect!(fake_integrator2)
249-
@test fake_integrator1 == fake_integrator2
252+
@test fake_integrator1.u == fake_integrator2.u
250253
end
251254
for i in vidxs
252255
crj = ModelingToolkit.assemble_vrj(js, equations(js)[i], unknownoid)
253-
@test_broken isapprox(crj.rate(u0, p, ttt), jumps[i].rate(u0, p, ttt))
254-
fake_integrator1 = (u = zeros(6), p = p, t = 0.0)
255-
fake_integrator2 = deepcopy(fake_integrator1)
256+
@test isapprox(crj.rate(u0, mtkpars, ttt), jumps[i].rate(u0, p, ttt))
257+
fake_integrator1 = (u = zeros(6), p = mtkpars, t = 0.0)
258+
fake_integrator2 = (u = zeros(6), p, t = 0.0)
256259
crj.affect!(fake_integrator1)
257260
jumps[i].affect!(fake_integrator2)
258-
@test fake_integrator1 == fake_integrator2
261+
@test fake_integrator1.u == fake_integrator2.u
259262
end
260263
end
261264

@@ -439,7 +442,7 @@ let
439442
umean += sol(10.0, idxs = [B1, B2, B3, C])
440443
end
441444
umean /= Nsims
442-
@test isapprox(umean[1], umean[2]; rtol = 1e-2)
445+
@test isapprox(umean[1], umean[2]; rtol = 1e-2)
443446
@test isapprox(umean[1], umean[3]; rtol = 1e-2)
444447
@test umean[4] == 10
445448
end

0 commit comments

Comments
 (0)