Skip to content

Commit ae6cf0a

Browse files
authored
Merge pull request #874 from SciML/proposed_faw_remake
Proposed FAq doc updates
2 parents 50acd56 + 78f44ea commit ae6cf0a

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

docs/pages.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ pages = Any[
6666
# # Contributor's guide.
6767
# # Repository structure.
6868
# ],
69-
#"FAQs" => "faqs.md",
69+
"FAQs" => "faqs.md",
7070
"API" => "api.md"
7171
]

docs/src/faqs.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@ One can directly use symbolic variables to index into SciML solution objects.
55
Moreover, observables can also be evaluated in this way. For example,
66
consider the system
77
```@example faq1
8-
using Catalyst, DifferentialEquations, Plots
8+
using Catalyst, OrdinaryDiffEq, Plots
99
rn = @reaction_network ABtoC begin
1010
(k₊,k₋), A + B <--> C
1111
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])
1512
nothing # hide
1613
```
1714
Let's convert it to a system of ODEs, using the conservation laws of the system
1815
to eliminate two of the species:
1916
```@example faq1
2017
osys = convert(ODESystem, rn; remove_conserved = true)
18+
osys = complete(osys)
2119
```
2220
Notice the resulting ODE system has just one ODE, while algebraic observables
2321
have been added for the two removed species (in terms of the conservation law
@@ -28,7 +26,9 @@ observed(osys)
2826
Let's solve the system and see how to index the solution using our symbolic
2927
variables
3028
```@example faq1
31-
oprob = ODEProblem(osys, [], (0.0, 10.0), [])
29+
u0 = [osys.A => 1.0, osys.B => 2.0, osys.C => 0.0]
30+
ps = [osys.k₊ => 1.0, osys.k₋ => 1.0]
31+
oprob = ODEProblem(osys, u0, (0.0, 10.0), ps)
3232
sol = solve(oprob, Tsit5())
3333
```
3434
Suppose we want to plot just species `C`, without having to know its integer
@@ -44,8 +44,8 @@ sol[C]
4444
```
4545
To evaluate `C` at specific times and plot it we can just do
4646
```@example faq1
47-
t = range(0.0, 10.0, length=101)
48-
plot(t, sol(t, idxs = C), label = "C(t)", xlabel = "t")
47+
t = range(0.0, 10.0, length = 101)
48+
plot(sol(t, idxs = C), label = "C(t)", xlabel = "t")
4949
```
5050
If we want to get multiple variables we can just do
5151
```@example faq1
@@ -65,7 +65,7 @@ constant, giving `k*X^2/2` instead of `k*X^2` for ODEs and `k*X*(X-1)/2` instead
6565
of `k*X*(X-1)` for jumps. This can be disabled when directly `convert`ing a
6666
[`ReactionSystem`](@ref). If `rn` is a generated [`ReactionSystem`](@ref), we can
6767
do
68-
```julia
68+
```@example faq1
6969
osys = convert(ODESystem, rn; combinatoric_ratelaws=false)
7070
```
7171
Disabling these rescalings should work for all conversions of `ReactionSystem`s
@@ -87,7 +87,9 @@ rx1 = Reaction(k,[B,C],[B,D], [2.5,1],[3.5, 2.5])
8787
rx2 = Reaction(2*k, [B], [D], [1], [2.5])
8888
rx3 = Reaction(2*k, [B], [D], [2.5], [2])
8989
@named mixedsys = ReactionSystem([rx1, rx2, rx3], t, [A, B, C, D], [k, b])
90+
mixedsys = complete(mixedsys)
9091
osys = convert(ODESystem, mixedsys; combinatoric_ratelaws = false)
92+
osys = complete(osys)
9193
```
9294
Note, when using `convert(ODESystem, mixedsys; combinatoric_ratelaws=false)` the
9395
`combinatoric_ratelaws=false` parameter must be passed. This is also true when
@@ -127,6 +129,7 @@ t = default_t()
127129
rx1 = Reaction(β, [S, I], [I], [1,1], [2])
128130
rx2 = Reaction(ν, [I], [R])
129131
@named sir = ReactionSystem([rx1, rx2], t)
132+
sir = complete(sir)
130133
oprob = ODEProblem(sir, [], (0.0, 250.0))
131134
sol = solve(oprob, Tsit5())
132135
plot(sol)
@@ -162,7 +165,7 @@ Julia `Symbol`s corresponding to each variable/parameter to their values, or
162165
from ModelingToolkit symbolic variables/parameters to their values. Using
163166
`Symbol`s we have
164167
```@example faq4
165-
using Catalyst, DifferentialEquations
168+
using Catalyst, OrdinaryDiffEq
166169
rn = @reaction_network begin
167170
α, S + I --> 2I
168171
β, I --> R
@@ -199,6 +202,7 @@ the second example, or one can use the `symmap_to_varmap` function to convert th
199202
`Symbol` mapping to a symbolic mapping. I.e. this works
200203
```@example faq4
201204
osys = convert(ODESystem, rn)
205+
osys = complete(osys)
202206
203207
# this works
204208
u0 = symmap_to_varmap(rn, [:S => 999.0, :I => 1.0, :R => 0.0])
@@ -221,6 +225,7 @@ rx1 = @reaction k, A --> 0
221225
rx2 = @reaction $f, 0 --> A
222226
eq = f ~ (1 + sin(t))
223227
@named rs = ReactionSystem([rx1, rx2, eq], t)
228+
rs = complete(rs)
224229
osys = convert(ODESystem, rs)
225230
```
226231
In the final ODE model, `f` can be eliminated by using

0 commit comments

Comments
 (0)