Skip to content

Commit 354ed0b

Browse files
committed
make t a parameter now
1 parent fa42336 commit 354ed0b

File tree

13 files changed

+176
-177
lines changed

13 files changed

+176
-177
lines changed

docs/src/model_creation/model_file_loading_and_export.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Here, `include` is used to execute the Julia code from any file. This means that
3030
let
3131
3232
# Independent variable:
33-
@variables t
33+
@parameters t
3434
3535
# Parameters:
3636
ps = @parameters kB kD kP
@@ -52,7 +52,7 @@ complete(rs)
5252
end
5353
```
5454
!!! note
55-
The code that `save_reactionsystem` prints uses [programmatic modelling](@ref programmatic_CRN_construction) to generate the written model.
55+
The code that `save_reactionsystem` prints uses [programmatic modelling](@ref programmatic_CRN_construction) to generate the written model.
5656

5757
In addition to transferring models between Julia sessions, the `save_reactionsystem` function can also be used or print a model to a text file where you can easily inspect its components.
5858

@@ -76,7 +76,7 @@ A general-purpose format for storing CRN models is so-called .net files. These c
7676
using ReactionNetworkImporters
7777
prn = loadrxnetwork(BNGNetwork(), "repressilator.net")
7878
```
79-
Here, .net files not only contain information regarding the reaction network itself, but also the numeric values (initial conditions and parameter values) required for simulating it. Hence, `loadrxnetwork` generates a `ParsedReactionNetwork` structure, containing all this information. You can access the model as `prn.rn`, the initial conditions as `prn.u0`, and the parameter values as `prn.p`. Furthermore, these initial conditions and parameter values are also made [*default* values](@ref dsl_advanced_options_default_vals) of the model.
79+
Here, .net files not only contain information regarding the reaction network itself, but also the numeric values (initial conditions and parameter values) required for simulating it. Hence, `loadrxnetwork` generates a `ParsedReactionNetwork` structure, containing all this information. You can access the model as `prn.rn`, the initial conditions as `prn.u0`, and the parameter values as `prn.p`. Furthermore, these initial conditions and parameter values are also made [*default* values](@ref dsl_advanced_options_default_vals) of the model.
8080

8181
A parsed reaction network's content can then be provided to various problem types for simulation. E.g. here we perform an ODE simulation of our repressilator model:
8282
```julia
@@ -128,7 +128,7 @@ Above, we described how to use SBMLImporter to import SBML files. Alternatively,
128128
While CRN models can be represented through various file formats, they can also be represented in various matrix forms. E.g. a CRN with $m$ species and $n$ reactions (and with constant rates) can be represented with either
129129
- An $mxn$ substrate matrix (with each species's substrate stoichiometry in each reaction) and an $nxm$ product matrix (with each species's product stoichiometry in each reaction).
130130

131-
Or
131+
Or
132132
- An $mxn$ complex stoichiometric matrix (...) and a $2mxn$ incidence matrix (...).
133133

134134
The advantage of these forms is that they offer a compact and very general way to represent a large class of CRNs. ReactionNetworkImporters have the functionality for converting matrices of these forms directly into Catalyst `ReactionSystem` models. Instructions on how to do this are available in [ReactionNetworkImporter's documentation](https://docs.sciml.ai/ReactionNetworkImporters/stable/#Loading-a-matrix-representation).

ext/CatalystStructuralIdentifiabilityExtension/structural_identifiability_extension.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
### Structural Identifiability ODE Creation ###
22

3-
# For a reaction system, list of measured quantities and known parameters, generate a StructuralIdentifiability compatible ODE.
3+
# For a reaction system, list of measured quantities and known parameters, generate a StructuralIdentifiability compatible ODE.
44
"""
55
make_si_ode(rs::ReactionSystem; measured_quantities=observed(rs), known_p = [], ignore_no_measured_warn=false)
66
7-
Creates a reaction rate equation ODE system of the form used within the StructuralIdentifiability.jl package. The output system is compatible with all StructuralIdentifiability functions.
7+
Creates a reaction rate equation ODE system of the form used within the StructuralIdentifiability.jl package. The output system is compatible with all StructuralIdentifiability functions.
88
99
Arguments:
1010
- `rs::ReactionSystem`; The reaction system we wish to convert to an ODE.
11-
- `measured_quantities=[]`: The quantities of the system we can measure. May either be equations (e.g. `x1 + x2`), or single species (e.g. the symbolic `x`, `rs.x`, or the symbol `:x`).
11+
- `measured_quantities=[]`: The quantities of the system we can measure. May either be equations (e.g. `x1 + x2`), or single species (e.g. the symbolic `x`, `rs.x`, or the symbol `:x`).
1212
- `known_p = []`: List of parameters for which their values are assumed to be known.
13-
- `ignore_no_measured_warn = false`: If set to `true`, no warning is provided when the `measured_quantities` vector is empty.
14-
- `remove_conserved = true`: Whether to eliminate conservation laws when computing the ode (this can reduce runtime of identifiability analysis significantly).
13+
- `ignore_no_measured_warn = false`: If set to `true`, no warning is provided when the `measured_quantities` vector is empty.
14+
- `remove_conserved = true`: Whether to eliminate conservation laws when computing the ode (this can reduce runtime of identifiability analysis significantly).
1515
1616
Example:
1717
```julia
@@ -45,10 +45,10 @@ Applies StructuralIdentifiability.jl's `assess_local_identifiability` function t
4545
4646
Arguments:
4747
- `rs::ReactionSystem`; The reaction system for which we wish to compute structural identifiability of the associated reaction rate equation ODE model.
48-
- `measured_quantities=[]`: The quantities of the system we can measure. May either be equations (e.g. `x1 + x2`), or single species (e.g. the symbolic `x`, `rs.s`, or the symbol `:x`).
49-
- `known_p = []`: List of parameters which values are known.
50-
- `ignore_no_measured_warn = false`: If set to `true`, no warning is provided when the `measured_quantities` vector is empty.
51-
- `remove_conserved = true`: Whether to eliminate conservation laws when computing the ode (this can reduce runtime of identifiability analysis significantly).
48+
- `measured_quantities=[]`: The quantities of the system we can measure. May either be equations (e.g. `x1 + x2`), or single species (e.g. the symbolic `x`, `rs.s`, or the symbol `:x`).
49+
- `known_p = []`: List of parameters which values are known.
50+
- `ignore_no_measured_warn = false`: If set to `true`, no warning is provided when the `measured_quantities` vector is empty.
51+
- `remove_conserved = true`: Whether to eliminate conservation laws when computing the ode (this can reduce runtime of identifiability analysis significantly).
5252
5353
Example:
5454
```julia
@@ -85,10 +85,10 @@ Applies StructuralIdentifiability.jl's `assess_identifiability` function to a Ca
8585
8686
Arguments:
8787
- `rs::ReactionSystem`; The reaction system we wish to compute structural identifiability for.
88-
- `measured_quantities=[]`: The quantities of the system we can measure. May either be equations (e.g. `x1 + x2`), or single species (e.g. the symbolic `x`, `rs.s`, or the symbol `:x`).
89-
- `known_p = []`: List of parameters which values are known.
90-
- `ignore_no_measured_warn = false`: If set to `true`, no warning is provided when the `measured_quantities` vector is empty.
91-
- `remove_conserved = true`: Whether to eliminate conservation laws when computing the ode (this can reduce runtime of identifiability analysis significantly).
88+
- `measured_quantities=[]`: The quantities of the system we can measure. May either be equations (e.g. `x1 + x2`), or single species (e.g. the symbolic `x`, `rs.s`, or the symbol `:x`).
89+
- `known_p = []`: List of parameters which values are known.
90+
- `ignore_no_measured_warn = false`: If set to `true`, no warning is provided when the `measured_quantities` vector is empty.
91+
- `remove_conserved = true`: Whether to eliminate conservation laws when computing the ode (this can reduce runtime of identifiability analysis significantly).
9292
9393
Example:
9494
```julia
@@ -125,10 +125,10 @@ Applies StructuralIdentifiability.jl's `find_identifiable_functions` function to
125125
126126
Arguments:
127127
- `rs::ReactionSystem`; The reaction system we wish to compute structural identifiability for.
128-
- `measured_quantities=[]`: The quantities of the system we can measure. May either be equations (e.g. `x1 + x2`), or single species (e.g. the symbolic `x`, `rs.s`, or the symbol `:x`).
129-
- `known_p = []`: List of parameters which values are known.
130-
- `ignore_no_measured_warn = false`: If set to `true`, no warning is provided when the `measured_quantities` vector is empty.
131-
- `remove_conserved = true`: Whether to eliminate conservation laws when computing the ode (this can reduce runtime of identifiability analysis significantly).
128+
- `measured_quantities=[]`: The quantities of the system we can measure. May either be equations (e.g. `x1 + x2`), or single species (e.g. the symbolic `x`, `rs.s`, or the symbol `:x`).
129+
- `known_p = []`: List of parameters which values are known.
130+
- `ignore_no_measured_warn = false`: If set to `true`, no warning is provided when the `measured_quantities` vector is empty.
131+
- `remove_conserved = true`: Whether to eliminate conservation laws when computing the ode (this can reduce runtime of identifiability analysis significantly).
132132
133133
Example:
134134
```julia
@@ -158,7 +158,7 @@ end
158158

159159
### Helper Functions ###
160160

161-
# From a reaction system, creates the corresponding MTK-style ODESystem for SI application
161+
# From a reaction system, creates the corresponding MTK-style ODESystem for SI application
162162
# Also compute the, later needed, conservation law equations and list of system symbols (unknowns and parameters).
163163
function make_osys(rs::ReactionSystem; remove_conserved = true)
164164
# Creates the ODESystem corresponding to the ReactionSystem (expanding functions and flattening it).
@@ -200,7 +200,7 @@ function make_measured_quantities(
200200

201201
# Creates one internal observation variable for each measured quantity (`___internal_observables`).
202202
# Creates a vector of equations, setting each measured quantity equal to one observation variable.
203-
@variables t (___internal_observables(Catalyst.get_iv(rs)))[1:length(mqs)]
203+
@variables (___internal_observables(Catalyst.get_iv(rs)))[1:length(mqs)]
204204
return Equation[(q isa Equation) ? q : (___internal_observables[i] ~ q)
205205
for (i, q) in enumerate(mqs)]
206206
end

src/dsl.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,10 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem)))
324324
if haskey(options, :ivs)
325325
ivs = Tuple(extract_syms(options, :ivs))
326326
ivexpr = copy(options[:ivs])
327-
ivexpr.args[1] = Symbol("@", "variables")
327+
ivexpr.args[1] = Symbol("@", "parameters")
328328
else
329329
ivs = (DEFAULT_IV_SYM,)
330-
ivexpr = :(@variables $(DEFAULT_IV_SYM))
330+
ivexpr = :($(DEFAULT_IV_SYM) = default_t())
331331
end
332332
tiv = ivs[1]
333333
sivs = (length(ivs) > 1) ? Expr(:vect, ivs[2:end]...) : nothing
@@ -877,7 +877,7 @@ function make_reaction(ex::Expr)
877877
sexprs = get_sexpr(species, Dict{Symbol, Expr}())
878878
pexprs = get_pexpr(parameters, Dict{Symbol, Expr}())
879879
rxexpr = get_rxexprs(reaction)
880-
iv = :(@variables $(DEFAULT_IV_SYM))
880+
iv = :($(DEFAULT_IV_SYM) = default_t())
881881

882882
# Returns the rephrased expression.
883883
quote

src/reactionsystem_serialisation/serialise_fields.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ end
88
# Extract a string which declares the system's independent variable.
99
function get_iv_string(rn::ReactionSystem)
1010
iv_dec = MT.get_iv(rn)
11-
return "@variables $(iv_dec)"
11+
return "@parameters $(iv_dec)"
1212
end
1313

1414
# Creates an annotation for the system's independent variable.
@@ -92,12 +92,12 @@ function handle_us_n_ps(file_text::String, rn::ReactionSystem, annotate::Bool,
9292

9393
# Pre-declares the sets with written/remaining parameters/species/variables.
9494
# Whenever all/none are written depends on whether there were any initial dependencies.
95-
# `deepcopy` is required as these get mutated by `dependency_split!`.
95+
# `deepcopy` is required as these get mutated by `dependency_split!`.
9696
remaining_ps = (p_deps ? deepcopy(ps_all) : [])
9797
remaining_sps = (sp_deps ? deepcopy(sps_all) : [])
9898
remaining_vars = (var_deps ? deepcopy(vars_all) : [])
9999

100-
# Iteratively loops through all parameters, species, and/or variables. In each iteration,
100+
# Iteratively loops through all parameters, species, and/or variables. In each iteration,
101101
# adds the declaration of those that can still be declared.
102102
while !(isempty(remaining_ps) && isempty(remaining_sps) && isempty(remaining_vars))
103103
# Checks which parameters/species/variables can be written. The `dependency_split`
@@ -145,7 +145,7 @@ function seri_has_parameters(rn::ReactionSystem)
145145
return !isempty(get_ps(rn))
146146
end
147147

148-
# Extract a string which declares the system's parameters. Uses multiline declaration (a
148+
# Extract a string which declares the system's parameters. Uses multiline declaration (a
149149
# `begin ... end` block) if more than 3 parameters have a "complicated" declaration (if they
150150
# have metadata, default value, or type designation).
151151
function get_parameters_string(ps)
@@ -167,7 +167,7 @@ function seri_has_species(rn::ReactionSystem)
167167
return !isempty(get_species(rn))
168168
end
169169

170-
# Extract a string which declares the system's species. Uses multiline declaration (a
170+
# Extract a string which declares the system's species. Uses multiline declaration (a
171171
# `begin ... end` block) if more than 3 species have a "complicated" declaration (if they
172172
# have metadata, default value, or type designation).
173173
function get_species_string(sps)
@@ -189,7 +189,7 @@ function seri_has_variables(rn::ReactionSystem)
189189
return length(get_unknowns(rn)) > length(get_species(rn))
190190
end
191191

192-
# Extract a string which declares the system's variables. Uses multiline declaration (a
192+
# Extract a string which declares the system's variables. Uses multiline declaration (a
193193
# `begin ... end` block) if more than 3 variables have a "complicated" declaration (if they
194194
# have metadata, default value, or type designation).
195195
function get_variables_string(vars)
@@ -222,7 +222,7 @@ function get_reactions_string(rn::ReactionSystem)
222222
return "rxs = [$(reaction_string(get_rxs(rn)[1], strip_call_dict))]"
223223
end
224224

225-
# Creates the string corresponding to the code which generates the system's reactions.
225+
# Creates the string corresponding to the code which generates the system's reactions.
226226
rxs_string = "rxs = ["
227227
for rx in get_rxs(rn)
228228
@string_append! rxs_string "\n\t"*reaction_string(rx, strip_call_dict) ","
@@ -286,7 +286,7 @@ function get_equations_string(rn::ReactionSystem)
286286
return "eqs = [$(expression_2_string(get_eqs(rn)[end]; strip_call_dict))]"
287287
end
288288

289-
# Creates the string corresponding to the code which generates the system's reactions.
289+
# Creates the string corresponding to the code which generates the system's reactions.
290290
eqs_string = "eqs = ["
291291
for eq in get_eqs(rn)[(length(get_rxs(rn)) + 1):end]
292292
@string_append! eqs_string "\n\t" expression_2_string(eq; strip_call_dict) ","
@@ -392,7 +392,7 @@ function get_continuous_events_string(rn::ReactionSystem)
392392
return "continuous_events = [$(continuous_event_string(MT.get_continuous_events(rn)[1], strip_call_dict))]"
393393
end
394394

395-
# Creates the string corresponding to the code which generates the system's reactions.
395+
# Creates the string corresponding to the code which generates the system's reactions.
396396
continuous_events_string = "continuous_events = ["
397397
for continuous_event in MT.get_continuous_events(rn)
398398
@string_append! continuous_events_string "\n\t" continuous_event_string(
@@ -450,7 +450,7 @@ function get_discrete_events_string(rn::ReactionSystem)
450450
return "discrete_events = [$(discrete_event_string(MT.get_discrete_events(rn)[1], strip_call_dict))]"
451451
end
452452

453-
# Creates the string corresponding to the code which generates the system's reactions.
453+
# Creates the string corresponding to the code which generates the system's reactions.
454454
discrete_events_string = "discrete_events = ["
455455
for discrete_event in MT.get_discrete_events(rn)
456456
@string_append! discrete_events_string "\n\t" discrete_event_string(
@@ -493,7 +493,7 @@ DISCRETE_EVENTS_FS = (seri_has_discrete_events, get_discrete_events_string,
493493
### Handles Systems ###
494494

495495
# Specific `push_field` function, which is used for the system field (where the annotation option
496-
# must be passed to the `get_component_string` function). Since non-ReactionSystem systems cannot be
496+
# must be passed to the `get_component_string` function). Since non-ReactionSystem systems cannot be
497497
# written to file, this function throws an error if any such systems are encountered.
498498
function push_systems_field(file_text::String, rn::ReactionSystem, annotate::Bool,
499499
top_level::Bool)

src/spatial_reaction_systems/spatial_reactions.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function make_transport_reaction(rateex, species)
5959
# Creates expressions corresponding to actual code from the internal DSL representation.
6060
sexprs = get_sexpr([species], Dict{Symbol, Expr}())
6161
pexprs = get_pexpr(parameters, Dict{Symbol, Expr}())
62-
iv = :(@variables $(DEFAULT_IV_SYM))
62+
iv = :($(DEFAULT_IV_SYM) = default_t())
6363
trxexpr = :(TransportReaction($rateex, $species))
6464

6565
# Appends `edgeparameter` metadata to all declared parameters.
@@ -86,12 +86,12 @@ function check_spatial_reaction_validity(rs::ReactionSystem, tr::TransportReacti
8686
edge_parameters = [])
8787
# Checks that the species exist in the reaction system.
8888
# (ODE simulation code becomes difficult if this is not required,
89-
# as non-spatial jacobian and f function generated from rs are of the wrong size).
89+
# as non-spatial jacobian and f function generated from rs are of the wrong size).
9090
if !any(isequal(tr.species), species(rs))
9191
error("Currently, species used in TransportReactions must have previously been declared within the non-spatial ReactionSystem. This is not the case for $(tr.species).")
9292
end
9393

94-
# Checks that the rate does not depend on species.
94+
# Checks that the rate does not depend on species.
9595
rate_vars = ModelingToolkit.getname.(Symbolics.get_variables(tr.rate))
9696
if !isempty(intersect(ModelingToolkit.getname.(species(rs)), rate_vars))
9797
error("The following species were used in rates of a transport reactions: $(setdiff(ModelingToolkit.getname.(species(rs)), rate_vars)).")

test/dsl/dsl_advanced_model_construction.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ end
154154
# Tests reaction metadata accessor functions.
155155
let
156156
# Creates reactions directly.
157-
@variables t
157+
t = default_t()
158158
@parameters k η
159159
@species X(t) X2(t)
160160

@@ -195,7 +195,7 @@ let
195195
@test Catalyst.hasmetadata(rxs[2], :md_1)
196196
@test !Catalyst.hasmetadata(rxs[3], :noise_scaling)
197197
@test !Catalyst.hasmetadata(rxs[3], :md_1)
198-
198+
199199
@test isequal(Catalyst.getmetadata(rxs[1], :noise_scaling), η)
200200
@test isequal(Catalyst.getmetadata(rxs[2], :md_1), 1.0)
201201

@@ -211,11 +211,11 @@ let
211211
end
212212

213213
# Checks that repeated metadata throws errors.
214-
let
215-
@test_throws LoadError @eval @reaction k, 0 --> X, [md1=1.0, md1=2.0]
214+
let
215+
@test_throws LoadError @eval @reaction k, 0 --> X, [md1=1.0, md1=2.0]
216216
@test_throws LoadError @eval @reaction_network begin
217-
k, 0 --> X, [md1=1.0, md1=1.0]
218-
end
217+
k, 0 --> X, [md1=1.0, md1=1.0]
218+
end
219219
end
220220

221221
# Tests for nested metadata.
@@ -233,14 +233,14 @@ let
233233
k8, Y7 --> X7, [md7="Hello"]
234234
k8, Y8 --> X7, [md7="Hi",md8="Yo"]
235235
end
236-
236+
237237
rn2 = @reaction_network reactions begin
238238
(k1,k2,k3), (X1,X2,X3) --> (Y1,Y2,Y3), ([md1=1.0,md2=2.0],[md1=0.0],[md3="Hello world"])
239239
k, (X4,X5) --> (Y4,Y5), [md4=:sym]
240240
(k6, k6), X6 <--> Y6, ([md6=0.0],[md6=2.0])
241241
(k7,k8), X7 <--> (Y7,Y8), ([md7="Hi"],([md7="Hello"],[md7="Hi",md8="Yo"]))
242242
end
243-
243+
244244
@test isequal(rn1, rn2)
245245
end
246246

@@ -254,7 +254,7 @@ let
254254
k5, 3X5 --> Z5, [unnecessary_metadata=[1,2,3]]
255255
k6, X6 => Z6, [unnecessary_metadata=true]
256256
end
257-
257+
258258
rn2 = @reaction_network reactions begin
259259
k1*X1, X1 + 2Y1 --> Z1, [only_use_rate=false]
260260
k2, 4X2 --> Z2 + W3, [only_use_rate=true]
@@ -263,7 +263,7 @@ let
263263
k5, 3X5 --> Z5, [only_use_rate=false, unnecessary_metadata=[1,2,3]]
264264
k6, X6 --> Z6, [only_use_rate=true, unnecessary_metadata=true]
265265
end
266-
266+
267267
@test isequal(rn1,rn2)
268268
end
269269

0 commit comments

Comments
 (0)