@@ -5,13 +5,10 @@ One can directly use symbolic variables to index into SciML solution objects.
5
5
Moreover, observables can also be evaluated in this way. For example,
6
6
consider the system
7
7
``` @example faq1
8
- using Catalyst, DifferentialEquations , Plots
8
+ using Catalyst, OrdinaryDiffEq , Plots
9
9
rn = @reaction_network ABtoC begin
10
10
(k₊,k₋), A + B <--> C
11
11
end
12
-
13
- # initial condition and parameter values
14
- setdefaults!(rn, [:A => 1.0, :B => 2.0, :C => 0.0, :k₊ => 1.0, :k₋ => 1.0])
15
12
nothing # hide
16
13
```
17
14
Let's convert it to a system of ODEs, using the conservation laws of the system
@@ -29,33 +26,35 @@ observed(osys)
29
26
Let's solve the system and see how to index the solution using our symbolic
30
27
variables
31
28
``` @example faq1
29
+ u0 = [rn.A => 1.0, rn.B => 2.0, rn.C => 0.0]
30
+ ps = [rn.k₊ => 1.0, rn.k₋ => 1.0]
32
31
oprob = ODEProblem(osys, [], (0.0, 10.0), [])
33
32
sol = solve(oprob, Tsit5())
34
33
```
35
34
Suppose we want to plot just species ` C ` , without having to know its integer
36
35
index in the unknown vector. We can do this using the symbolic variable ` C ` , which
37
36
we can get at in several ways
38
- ``` @example faq1
37
+ ``` julia
39
38
sol[osys. C]
40
39
```
41
40
or
42
- ``` @example faq1
41
+ ``` julia
43
42
@unpack C = osys
44
43
sol[C]
45
44
```
46
45
To evaluate ` C ` at specific times and plot it we can just do
47
- ``` @example faq1
46
+ ``` julia
48
47
t = range (0.0 , 10.0 , length= 101 )
49
48
plot (t, sol (t, idxs = C), label = " C(t)" , xlabel = " t" )
50
49
```
51
50
If we want to get multiple variables we can just do
52
- ``` @example faq1
51
+ ``` julia
53
52
@unpack A, B = osys
54
53
sol (t, idxs = [A, B])
55
54
```
56
55
Plotting multiple variables using the SciML plot recipe can be achieved
57
56
like
58
- ``` @example faq1
57
+ ``` julia
59
58
plot (sol; idxs = [A, B])
60
59
```
61
60
@@ -66,7 +65,7 @@ constant, giving `k*X^2/2` instead of `k*X^2` for ODEs and `k*X*(X-1)/2` instead
66
65
of ` k*X*(X-1) ` for jumps. This can be disabled when directly ` convert ` ing a
67
66
[ ` ReactionSystem ` ] ( @ref ) . If ` rn ` is a generated [ ` ReactionSystem ` ] ( @ref ) , we can
68
67
do
69
- ``` julia
68
+ ``` @example faq1
70
69
osys = convert(ODESystem, rn; combinatoric_ratelaws=false)
71
70
```
72
71
Disabling these rescalings should work for all conversions of ` ReactionSystem ` s
@@ -89,6 +88,7 @@ rx2 = Reaction(2*k, [B], [D], [1], [2.5])
89
88
rx3 = Reaction(2*k, [B], [D], [2.5], [2])
90
89
@named mixedsys = ReactionSystem([rx1, rx2, rx3], t, [A, B, C, D], [k, b])
91
90
osys = convert(ODESystem, mixedsys; combinatoric_ratelaws = false)
91
+ osys = complete(osys)
92
92
```
93
93
Note, when using ` convert(ODESystem, mixedsys; combinatoric_ratelaws=false) ` the
94
94
` combinatoric_ratelaws=false ` parameter must be passed. This is also true when
@@ -128,6 +128,7 @@ t = default_t()
128
128
rx1 = Reaction(β, [S, I], [I], [1,1], [2])
129
129
rx2 = Reaction(ν, [I], [R])
130
130
@named sir = ReactionSystem([rx1, rx2], t)
131
+ sir = complete(sir)
131
132
oprob = ODEProblem(sir, [], (0.0, 250.0))
132
133
sol = solve(oprob, Tsit5())
133
134
plot(sol)
@@ -163,7 +164,7 @@ Julia `Symbol`s corresponding to each variable/parameter to their values, or
163
164
from ModelingToolkit symbolic variables/parameters to their values. Using
164
165
` Symbol ` s we have
165
166
``` @example faq4
166
- using Catalyst, DifferentialEquations
167
+ using Catalyst, OrdinaryDiffEq
167
168
rn = @reaction_network begin
168
169
α, S + I --> 2I
169
170
β, I --> R
@@ -200,6 +201,7 @@ the second example, or one can use the `symmap_to_varmap` function to convert th
200
201
` Symbol ` mapping to a symbolic mapping. I.e. this works
201
202
``` @example faq4
202
203
osys = convert(ODESystem, rn)
204
+ osys = complete(osys)
203
205
204
206
# this works
205
207
u0 = symmap_to_varmap(rn, [:S => 999.0, :I => 1.0, :R => 0.0])
0 commit comments