You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/model_creation/parametric_stoichiometry.md
+15-11Lines changed: 15 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,12 @@ revsys = @reaction_network revsys begin
15
15
end
16
16
reactions(revsys)
17
17
```
18
-
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)
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
19
24
neither used as a reaction substrate nor a product to be parameters. Hence, in
20
25
this example we have two species (`A` and `B`) and four parameters (`k₊`, `k₋`,
21
26
`m`, and `n`). In addition, the stoichiometry is applied to the rightmost symbol
@@ -37,21 +42,21 @@ We could have equivalently specified our systems directly via the Catalyst
37
42
API. For example, for `revsys` we would could use
38
43
```@example s1
39
44
t = default_t()
40
-
@parameters k₊ k₋ m::Int n
45
+
@parameters k₊ k₋ m::Int n::Int
41
46
@species A(t), B(t)
42
47
rxs = [Reaction(k₊, [A], [B], [m], [m*n]),
43
48
Reaction(k₋, [B], [A])]
44
49
revsys2 = ReactionSystem(rxs,t; name=:revsys)
45
50
revsys2 == revsys
46
51
```
47
-
which can be simplified using the `@reaction` macro to
52
+
or
48
53
```@example s1
49
-
rxs2 = [(@reaction k₊, m*A --> (m*n)*B),
54
+
rxs2 = [(@reaction k₊, $m*A --> ($m*$n)*B),
50
55
(@reaction k₋, B --> A)]
51
56
revsys3 = ReactionSystem(rxs2,t; name=:revsys)
52
57
revsys3 == revsys
53
58
```
54
-
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
55
60
substrates or reactants (i.e. `A` and `B`). For example, in
56
61
`@reaction k, F*A + 2(H*G+B) --> D`, the substrates are `(A,G,B)` with
Notice, as described in the [Reaction rate laws used in simulations](@ref)
67
-
section, the default rate laws involve factorials in the stoichiometric
68
-
coefficients. For this reason we must specify `m` and `n` as integers, and hence
69
-
*use a tuple for the parameter mapping*
70
71
```@example s1
71
72
p = (k₊ => 1.0, k₋ => 1.0, m => 2, n => 2)
72
73
u₀ = [A => 1.0, B => 1.0]
@@ -78,8 +79,6 @@ We can now solve and plot the system
78
79
sol = solve(oprob, Tsit5())
79
80
plot(sol)
80
81
```
81
-
*If we had used a vector to store parameters, `m` and `n` would be converted to
82
-
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.**
83
82
84
83
An alternative approach to avoid the issues of using mixed floating point and
85
84
integer variables is to disable the rescaling of rate laws as described in
@@ -89,6 +88,11 @@ directly building the problem from a `ReactionSystem` instead of first
89
88
converting to an `ODESystem`). For the previous example this gives the following
0 commit comments