Skip to content

Commit 7b8c789

Browse files
authored
Merge pull request #786 from SciML/use_mtk_default_t_and_D
Use MTK's default `t` and `D` throughout repository
2 parents 2671197 + a774087 commit 7b8c789

35 files changed

+112
-158
lines changed

docs/src/api/catalyst_api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ models, and stochastic chemical kinetics jump process models.
3636

3737
```@example ex1
3838
using Catalyst, DifferentialEquations, Plots
39+
t = default_t()
3940
@parameters β γ
40-
@variables t
4141
@species S(t) I(t) R(t)
4242
4343
rxs = [Reaction(β, [S,I], [I], [1,1], [2])

docs/src/catalyst_applications/simulation_structure_interfacing.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ Finally, we note that we cannot change the values of solution unknowns or parame
104104
Catalyst is built on an *intermediary representation* implemented by (ModelingToolkit.jl)[https://github.com/SciML/ModelingToolkit.jl]. ModelingToolkit is a modelling framework where one first declares a set of symbolic variables and parameters using e.g.
105105
```@example ex2
106106
using ModelingToolkit
107+
t = default_t()
107108
@parameters σ ρ β
108-
@variables t x(t) y(t) z(t)
109+
@variables x(t) y(t) z(t)
109110
nothing # hide
110111
```
111112
and then uses these to build systems of equations. Here, these symbolic variables (`x`, `y`, and `z`) and parameters (`σ`, `ρ`, and `β`) can be used to interface a `problem`, `integrator`, and `solution` object (like we did previously, but using Symbols, e.g. `:X`). Since Catalyst models are built on ModelingToolkit, these models also contain similar symbolic variables and parameters.

docs/src/catalyst_functionality/chemistry_related_functionality.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ While Catalyst has primarily been designed around the modelling of biological sy
1010
We will first show how to create compound species through [programmatic model construction](@ref programmatic_CRN_construction), and then demonstrate using the DSL. To create a compound species, use the `@compound` macro, first designating the compound, followed by its components (and their stoichiometries). In this example, we will create a CO₂ molecule, consisting of one C atom and two O atoms. First, we create species corresponding to the components:
1111
```@example chem1
1212
using Catalyst
13-
@variables t
13+
t = default_t()
1414
@species C(t) O(t)
1515
```
1616
Next, we create the `CO2` compound species:
@@ -97,7 +97,8 @@ In all of these cases, the side to the left of the `~` must be enclosed within `
9797
### Compounds with multiple independent variables
9898
While we generally do not need to specify independent variables for compound, if the components (together) have more than one independent variable, this have to be done:
9999
```@example chem1
100-
@variables t s
100+
t = default_t()
101+
@variables s
101102
@species N(s) O(t)
102103
@compound NO2(t,s) ~ N + 2O
103104
```
@@ -117,7 +118,7 @@ which correctly finds the (rather trivial) solution `C + 2O --> CO2`. Here we no
117118
Let us consider a more elaborate example, the reaction between ammonia (NH₃) and oxygen (O₂) to form nitrogen monoxide (NO) and water (H₂O). Let us first create the components and the unbalanced reaction:
118119
```@example chem2
119120
using Catalyst # hide
120-
@variables t
121+
t = default_t()
121122
@species N(t) H(t) O(t)
122123
@compounds begin
123124
NH3 ~ N + 3H

docs/src/catalyst_functionality/compositional_modeling.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ plot(TreePlot(rn), method=:tree, fontsize=12, nodeshape=:ellipse)
5151
We could also have directly constructed `rn` using the same reaction as in
5252
`basern` as
5353
```@example ex1
54+
t = default_t()
5455
@parameters k
55-
@variables t
5656
@species A(t), B(t), C(t)
5757
rxs = [Reaction(k, [A,B], [C])]
5858
@named rn = ReactionSystem(rxs, t; systems = [newrn, newestrn])
@@ -114,7 +114,7 @@ ability to substitute the value of these variables into the DSL (see
114114
[Interpolation of Julia Variables](@ref dsl_description_interpolation_of_variables)). To make the repressilator we now make
115115
three genes, and then compose them together
116116
```@example ex1
117-
@variables t
117+
t = default_t()
118118
@species G3₊P(t)
119119
@named G1 = repressed_gene(; R=ParentScope(G3₊P))
120120
@named G2 = repressed_gene(; R=ParentScope(G1.P))
@@ -130,7 +130,7 @@ plot(TreePlot(repressilator), method=:tree, fontsize=12, nodeshape=:ellipse)
130130
In building the repressilator we needed to use two new features. First, we
131131
needed to create a symbolic variable that corresponds to the protein produced by
132132
the third gene before we created the corresponding system. We did this via
133-
`@variables t, G3₊P(t)`. We also needed to set the scope where each repressor
133+
`@variables G3₊P(t)`. We also needed to set the scope where each repressor
134134
lived. Here `ParentScope(G3₊P)`, `ParentScope(G1.P)`, and `ParentScope(G2.P)`
135135
signal Catalyst that these variables will come from parallel systems in the tree
136136
that have the same parent as the system being constructed (in this case the

docs/src/catalyst_functionality/constraint_equations.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,22 @@ There are several ways we can create our Catalyst model with the two reactions
2323
and ODE for $V(t)$. One approach is to use compositional modeling, create
2424
separate `ReactionSystem`s and `ODESystem`s with their respective components,
2525
and then extend the `ReactionSystem` with the `ODESystem`. Let's begin by
26-
creating these two systems:
26+
creating these two systems.
27+
28+
Here, to create differentials with respect to time (for our differential equations), we must import the time differential operator from Catalyst. We do this through `D = default_time_deriv()`. Here, `D(V)` denotes the differential of the variable `V` with respect to time.
2729

2830
```@example ceq1
2931
using Catalyst, DifferentialEquations, Plots
32+
t = default_t()
33+
D = default_time_deriv()
3034
3135
# set the growth rate to 1.0
3236
@parameters λ = 1.0
3337
3438
# set the initial volume to 1.0
35-
@variables t V(t) = 1.0
39+
@variables V(t) = 1.0
3640
3741
# build the ODESystem for dV/dt
38-
D = Differential(t)
3942
eq = [D(V) ~ λ * V]
4043
@named osys = ODESystem(eq, t)
4144
@@ -70,10 +73,11 @@ As an alternative to the previous approach, we could have constructed our
7073
`ReactionSystem` all at once by directly using the symbolic interface:
7174
```@example ceq2
7275
using Catalyst, DifferentialEquations, Plots
76+
t = default_t()
77+
D = default_time_deriv()
7378
7479
@parameters λ = 1.0
75-
@variables t V(t) = 1.0
76-
D = Differential(t)
80+
@variables V(t) = 1.0
7781
eq = D(V) ~ λ * V
7882
rx1 = @reaction $V, 0 --> P
7983
rx2 = @reaction 1.0, P --> 0
@@ -102,11 +106,12 @@ advanced_simulations) tutorial.
102106
Let's first create our equations and unknowns/species again
103107
```@example ceq3
104108
using Catalyst, DifferentialEquations, Plots
109+
t = default_t()
110+
D = default_time_deriv()
105111
106112
@parameters λ = 1.0
107-
@variables t V(t) = 1.0
113+
@variables V(t) = 1.0
108114
@species P(t) = 0.0
109-
D = Differential(t)
110115
eq = D(V) ~ λ * V
111116
rx1 = @reaction $V, 0 --> $P
112117
rx2 = @reaction 1.0, $P --> 0
@@ -126,8 +131,8 @@ plot(sol; plotdensity = 1000)
126131
```
127132
We can also model discrete events. Similar to our example with continuous events, we start by creating reaction equations, parameters, variables, and unknowns.
128133
```@example ceq3
134+
t = default_t()
129135
@parameters k_on switch_time k_off
130-
@variables t
131136
@species A(t) B(t)
132137
133138
rxs = [(@reaction k_on, A --> B), (@reaction k_off, B --> A)]

docs/src/catalyst_functionality/dsl_description.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ the model. We do this by creating a mapping from each symbolic variable
5454
representing a chemical species to its initial value
5555
```@example tut2
5656
# define the symbolic variables
57-
@variables t
57+
t = default_t()
5858
@species X(t) Y(t) Z(t) XY(t) Z1(t) Z2(t)
5959
6060
# create the mapping
@@ -610,8 +610,8 @@ parameters outside of the macro, which can then be used within expressions in
610610
the DSL (see the [Programmatic Construction of Symbolic Reaction Systems](@ref programmatic_CRN_construction)
611611
tutorial for details on the lower-level symbolic interface). For example,
612612
```@example tut2
613+
t = default_t()
613614
@parameters k α
614-
@variables t
615615
@species A(t)
616616
spec = A
617617
par = α

docs/src/catalyst_functionality/example_networks/hodgkin_huxley_equation.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ We begin by importing some necessary packages.
1515
using ModelingToolkit, Catalyst, NonlinearSolve
1616
using DifferentialEquations, Symbolics
1717
using Plots
18+
t = default_t()
19+
D = default_time_deriv()
1820
```
1921

2022
We'll build a simple Hodgkin-Huxley model for a single neuron, with the voltage,
@@ -51,7 +53,7 @@ We now declare the symbolic variable, `V(t)`, that will represent the
5153
transmembrane potential
5254

5355
```@example hh1
54-
@variables t V(t)
56+
@variables V(t)
5557
nothing # hide
5658
```
5759

@@ -75,7 +77,6 @@ I = I₀ * sin(2*pi*t/30)^2
7577
# get the gating variables to use in the equation for dV/dt
7678
@unpack m,n,h = hhrn
7779
78-
Dₜ = Differential(t)
7980
eqs = [Dₜ(V) ~ -1/C * (ḡK*n^4*(V-EK) + ḡNa*m^3*h*(V-ENa) + ḡL*(V-EL)) + I/C]
8081
@named voltageode = ODESystem(eqs, t)
8182
nothing # hide

docs/src/catalyst_functionality/example_networks/smoluchowski_coagulation_equation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ end
5252
We'll store the reaction rates in `pars` as `Pair`s, and set the initial condition that only monomers are present at ``t=0`` in `u₀map`.
5353
```julia
5454
# unknown variables are X, pars stores rate parameters for each rx
55-
@variables t
55+
t = default_t()
5656
@species k[1:nr] (X(t))[1:N]
5757
pars = Pair.(collect(k), kv)
5858

docs/src/catalyst_functionality/parametric_stoichiometry.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ rx.substrates[1],rx.substoich[1]
3535
We could have equivalently specified our systems directly via the Catalyst
3636
API. For example, for `revsys` we would could use
3737
```@example s1
38+
t = default_t()
3839
@parameters k₊, k₋, m, n
39-
@variables t
4040
@species A(t), B(t)
4141
rxs = [Reaction(k₊, [A], [B], [m], [m*n]),
4242
Reaction(k₋, [B], [A])]
@@ -177,9 +177,10 @@ calculate and plot the average amount of protein (which is also plotted in the
177177
MomentClosure.jl
178178
[tutorial](https://augustinas1.github.io/MomentClosure.jl/dev/tutorials/geometric_reactions+conditional_closures/)).
179179
```@example s1
180+
t = default_t()
180181
function getmean(jprob, Nsims, tv)
181182
Pmean = zeros(length(tv))
182-
@variables t, P(t)
183+
@variables P(t)
183184
for n in 1:Nsims
184185
sol = solve(jprob, SSAStepper())
185186
Pmean .+= sol(tv, idxs=P)

docs/src/catalyst_functionality/programmatic_CRN_construction.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ and then define symbolic variables for each parameter and species in the system
1515
(the latter corresponding to a `variable` or `unknown` in ModelingToolkit
1616
terminology)
1717
```@example ex
18+
t = default_t()
1819
@parameters α K n δ γ β μ
19-
@variables t
2020
@species m₁(t) m₂(t) m₃(t) P₁(t) P₂(t) P₃(t)
2121
nothing # hide
2222
```
23-
*Note, each species is declared as a function of time!*
23+
Note: each species is declared as a function of time. Here, we first import the *time independent variable*, and stores it in `t`, using `t = default_t()`, and then use it to declare out species.
2424

2525
!!! note
2626
For users familiar with ModelingToolkit, chemical species must be declared
@@ -117,8 +117,8 @@ Reaction(rate, nothing, [P₁,...,Pₙ], nothing, [β₁,...,βₙ])
117117
Finally, we note that the rate constant, `rate` above, does not need to be a
118118
constant or fixed function, but can be a general symbolic expression:
119119
```julia
120+
t = default_t()
120121
@parameters α, β
121-
@variables t
122122
@species A(t), B(t)
123123
rx = Reaction+ β*t*A, [A], [B])
124124
```
@@ -133,7 +133,7 @@ reactions using the [`@reaction`](@ref) macro.
133133

134134
For example, the repressilator reactions could also have been constructed like
135135
```julia
136-
@variables t
136+
t = default_t()
137137
@species P₁(t) P₂(t) P₃(t)
138138
rxs = [(@reaction hillr($P₃,α,K,n), ∅ --> m₁),
139139
(@reaction hillr($P₁,α,K,n), ∅ --> m₂),
@@ -162,8 +162,9 @@ rx = @reaction hillr(P,α,K,n), A --> B
162162
```
163163
is equivalent to
164164
```julia
165+
t = default_t()
165166
@parameters P α K n
166-
@variables t A(t) B(t)
167+
@variables A(t) B(t)
167168
rx = Reaction(hillr(P,α,K,n), [A], [B])
168169
```
169170
Here `(P,α,K,n)` are parameters and `(A,B)` are species.

0 commit comments

Comments
 (0)