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
While programmatically created models can also have their parameters and species designated using `Symbol`s, the reverse is not possible for DSL-created models. Here, the symbolic variables are never explicitly declared, and thus not available for designating their values. Symbolic designation can be enabled for DSL-created models [by using `@unpack`](@refprogrammatic_CRN_construction_symbolic_representation_unpack).
152
+
While programmatically created models can also have their parameters and species designated using `Symbol`s, the reverse is not possible for DSL-created models. Here, the symbolic variables are never explicitly declared, and thus not available for designating their values. Symbolic designation can be enabled for DSL-created models [by using `@unpack`](@refprogrammatic_CRN_construction_symbolics_and_DSL_unpack).
153
153
154
154
Elsewhere, we also describe how e.g. `ODEProblem`s and [simulations solutions can be queried for the values of model quantities](@ref simulation_structure_interfacing). There, we use use `Symbol`s to represent model quantities, however, symbolic variables (when available) can again be used. E.g. we can use
155
155
```@example programmatic_2
156
156
sol[X1]
157
157
```
158
158
to retrieve $X$'s value across the simulation.
159
159
160
-
### [Using `@unpack` to extract symbolic variables from `ReactionSystem`s](@id programmatic_CRN_construction_symbolic_representation_unpack)
161
-
Let us consider a simple birth-death model created using the DSL:
162
-
```@example programmatic_3
163
-
using Catalyst # hide
164
-
bd_model = @reaction_network begin
165
-
(p,d), 0 <--> X
166
-
end
167
-
nothing # hide
168
-
```
169
-
Since we have not explicitly declared `p`, `d`, and `X` using `@parameters` and `@species`, we cannot represent these symbolically (only using `Symbol`s). If we wish to do so, however, we can fetch these into our current scope using the `@unpack` macro:
170
-
```@example programmatic_3
171
-
@unpack p, d, X = bd_model
172
-
nothing # hide
173
-
```
174
-
This lists first the quantities we wish to fetch (does not need to be the model's full set of parameters and species), then `=`, followed by the model name. `p`, `d` and `X` are now symbolic variables in the current scope, just as if they had been declared using `@parameters` or `@species`. We can confirm this:
175
-
```@example programmatic_3
176
-
X
177
-
```
178
-
Next, we can now use these to e.g. designate initial conditions and parameter values for model simulations:
179
-
```@example programmatic_3
180
-
using OrdinaryDiffEq, Plots # hide
181
-
u0 = [X => 0.1]
182
-
tspan = (0.0, 10.0)
183
-
ps = [p => 1.0, d => 0.2]
184
-
oprob = ODEProblem(bd_model, u0, tspan, ps)
185
-
sol = solve(oprob)
186
-
plot(sol)
187
-
```
188
-
189
-
!!! warn
190
-
Just like [when using `@parameters` and `@species`](@ref programmatic_CRN_construction_symbolic_variables), `@unpack` will overwrite any variables in the current scope which shares name with the imported quantities.
191
-
192
160
## [Additional options for declaration of symbolic variables](@id programmatic_CRN_construction_symbolic_variables_options)
193
161
The declaration of symbolic variables for programmatic Catalyst modelling uses identical syntax as when [parameters/species are explicitly declared within the DSL](@ref ref), or as used within [ModelingToolkit.jl](https://github.com/SciML/ModelingToolkit.jl). Here we will provide a brief summary iterating the same information.
194
162
@@ -233,7 +201,7 @@ nothing # hide
233
201
234
202
If a parameter have a type, a metadata, and a default value, they are designated in the following order:
235
203
```@example programmatic_4
236
-
TODO: @parameters n(t)::Int64
204
+
@parameters n(t)::Int64 = 2 ["Parameter n, which is an integer and defaults to the value 2."]
Sometimes, one wish to declare a large number of similar symbolic variables. E.g. if we have a system with ten species, each being produced at different rates, we could declare ten separate production parameters:
233
+
```@example programmatic_5
234
+
using Catalyst # hide
235
+
@parameters p1 p2 p3 p4 p5 p6 p7 p8 p9 p10
236
+
```
237
+
However, it is also possible to *declare a vector parameter* with ten different values:
238
+
```@example programmatic_5
239
+
@parameters p[1:10]
240
+
```
241
+
242
+
We can use this to create our two-state model, but instead of declaring `X1`, `X2`, `k1`, and `k2` as separate entities, we create them as two length-two vectors:
243
+
```@example programmatic_5
244
+
t = default_t()
245
+
@species X[1:2](t)
246
+
@parameters k[1:2]
247
+
nothing # hide
248
+
```
249
+
Next, we can designate the individual parameters using e.g. `X[1]`
250
+
```@example programmatic_5
251
+
rxs = [
252
+
Reaction(k[1], [X[1]], [X[2]]),
253
+
Reaction(k[2], [X[2]], [X[1]]),
254
+
]
255
+
@named two_state_model = ReactionSystem(rxs, t)
256
+
```
257
+
Now, while we still can provide individual values to `X[1]`, `X[2]`, `k[1]`, and `k[2]`, we can also declare their values directly as vectors:
## [Additional options for declaration of `Reaction`s](@id programmatic_CRN_construction_reactions_options)
270
+
When describing the DSL, we also describe a range of [options for declaring various types of reactions](@ref ref). Each type of reaction that can be created using the DSL can also be created programmatically. Below, we briefly describe each case.
271
+
272
+
### [Reactions with ](@id programmatic_CRN_construction_reactions_options_)
## [Additional options for declaration of `Reaction`s](@id programmatic_CRN_construction_reactions_options)
265
281
266
-
## [Creation of `Reaction`s using the`@reaction`](@id programmatic_CRN_construction_reaction_macro)
282
+
283
+
## [Creation of `Reaction`s using the `@reaction`](@id programmatic_CRN_construction_reaction_macro)
284
+
285
+
## [Working with symbolic variables and the DSL](@id programmatic_CRN_construction_symbolics_and_DSL)
286
+
The `@reaction` macro allowed us to use some of DSL-based modellings advantage (easy declaration of reactions) in programmatic modelling. Similarity, there are also ways to utilise concepts from programmatic modelling (like the declaration and use of symbolic variables) in DSL-based modelling. Below we briefly describe two of these.
287
+
288
+
### [Using `@unpack` to extract symbolic variables from `ReactionSystem`s](@id programmatic_CRN_construction_symbolics_and_DSL_unpack)
289
+
Let us consider a simple birth-death model created using the DSL:
290
+
```@example programmatic_3
291
+
using Catalyst # hide
292
+
bd_model = @reaction_network begin
293
+
(p,d), 0 <--> X
294
+
end
295
+
nothing # hide
296
+
```
297
+
Since we have not explicitly declared `p`, `d`, and `X` using `@parameters` and `@species`, we cannot represent these symbolically (only using `Symbol`s). If we wish to do so, however, we can fetch these into our current scope using the `@unpack` macro:
298
+
```@example programmatic_3
299
+
@unpack p, d, X = bd_model
300
+
nothing # hide
301
+
```
302
+
This lists first the quantities we wish to fetch (does not need to be the model's full set of parameters and species), then `=`, followed by the model name. `p`, `d` and `X` are now symbolic variables in the current scope, just as if they had been declared using `@parameters` or `@species`. We can confirm this:
303
+
```@example programmatic_3
304
+
X
305
+
```
306
+
Next, we can now use these to e.g. designate initial conditions and parameter values for model simulations:
307
+
```@example programmatic_3
308
+
using OrdinaryDiffEq, Plots # hide
309
+
u0 = [X => 0.1]
310
+
tspan = (0.0, 10.0)
311
+
ps = [p => 1.0, d => 0.2]
312
+
oprob = ODEProblem(bd_model, u0, tspan, ps)
313
+
sol = solve(oprob)
314
+
plot(sol)
315
+
```
316
+
317
+
!!! warn
318
+
Just like [when using `@parameters` and `@species`](@ref programmatic_CRN_construction_symbolic_variables), `@unpack` will overwrite any variables in the current scope which shares name with the imported quantities.
319
+
320
+
### [Interpolating variables into the DSL](@id advanced_intro_to_catalyst_interpolation)
321
+
322
+
The DSL allows Julia variables to be interpolated for the network name, within
323
+
rate constant expressions, or for species/stoichiometry within reactions. Using
324
+
the lower-level symbolic interface we can then define symbolic variables and
325
+
parameters outside of the macro, which can then be used within expressions in
326
+
the DSL (see the [Programmatic Construction of Symbolic Reaction Systems](@ref programmatic_CRN_construction)
327
+
tutorial for details on the lower-level symbolic interface). For example,
0 commit comments