Skip to content

Commit 3513ad4

Browse files
committed
init
1 parent b85475f commit 3513ad4

File tree

5 files changed

+60
-10
lines changed

5 files changed

+60
-10
lines changed

HISTORY.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@
7676
functions (as a parameter) in a model. For more details on how to use these,
7777
please read:
7878
https://docs.sciml.ai/Catalyst/stable/model_creation/functional_parameters/.
79+
- We have introduced a restriction on bundling of reactions in the DSL. Now,
80+
bundling is not permitted if multiple rates are provided but only one set each
81+
of substrates/products. E.g. this model:
82+
```julia
83+
@reaction_network begin
84+
(k1,k2), X --> Y
85+
end
86+
```
87+
will now throw an error. The reason that users attempting to write bi-directional
88+
reactions but typing `-->` instead of `<-->` would get a wrong model. We decided that
89+
this kind of bundling was unlikely to be used, and throwing errors for people who
90+
made the typo was more important.
91+
92+
If you use this type of bundling and it indeed is useful to you, please raise and issue
93+
and we will see if we can sort something out.
7994
- Scoped species/variables/parameters are now treated similar to the latest MTK
8095
releases ( 9.49).
8196
- A tutorial on making interactive plot displays using Makie has been added.

docs/src/model_creation/dsl_basics.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ end
188188
```
189189
However, like for the above model, bundling reactions too zealously can reduce (rather than improve) a model's readability.
190190

191+
The one exception to reaction bundling is that we do not permit the user to provide multiple rates but only set one set each for the substrates and products. I.e.
192+
```julia
193+
rn = @reaction_network begin
194+
(k1,k2), X --> Y
195+
end
196+
```
197+
is not permitted (due to this notation's similarity to a bidirectional reaction). However, if multiples are provided for substrates and/or products, like `(k1,k2), (X1,X2) --> Y`, then bundling works.
198+
199+
191200
## [Non-constant reaction rates](@id dsl_description_nonconstant_rates)
192201
So far we have assumed that all reaction rates are constant (being either a number of a parameter). Non-constant rates that depend on one (or several) species are also possible. More generally, the rate can be any valid expression of parameters and species.
193202

src/dsl.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,13 @@ function get_reactions(exprs::Vector{Expr})
365365
# Reads core reaction information.
366366
arrow, rate, reaction, metadata = read_reaction_line(line)
367367

368+
# Currently, reaction bundling where rates (but neither substrates nor products) are
369+
# bundled, is disabled. See discussion in https://github.com/SciML/Catalyst.jl/issues/1219.
370+
if !in(arrow, double_arrows) && Meta.isexpr(rate, :tuple) &&
371+
!Meta.isexpr(reaction.args[2], :tuple) && !Meta.isexpr(reaction.args[3], :tuple)
372+
error("Bundling of reactions with multiple rates but singular substrates and product sets is disallowed. This error is potentially due to a bidirectional (`<-->`) reaction being types as `-->`.")
373+
end
374+
368375
# Checks which type of line is used, and calls `push_reactions!` on the processed line.
369376
if in(arrow, double_arrows)
370377
(typeof(rate) != Expr || rate.head != :tuple) &&

test/dsl/dsl_basic_model_construction.jl

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ let
179179
different_arrow_8 = @reaction_network begin
180180
p, 2X1 <
181181
k1, X2 X1
182-
(k2, k3), X3 X2
182+
(k2, k3), X3 (X2,X2)
183183
d, ∅ X3
184184
end
185185
push!(identical_networks_1, reaction_networks_standard[8] => different_arrow_8)
@@ -298,10 +298,11 @@ let
298298

299299
no_parameters_10 = @reaction_network begin
300300
0.01, ∅ X1
301-
(3.1, 3.2), X1 X2
302-
(0.0, 2.1), X2 X3
303-
(901.0, 63.5), X3 X4
304-
(7, 8), X4 X5
301+
(3.1, 3.2), (X1,X1) X2
302+
(0.0, 2.1), X2 (X3,X3)
303+
(901.0, 63.5), (X3,X3) (C4,X4)
304+
7, X4 X5
305+
8, X4 X5
305306
1.0, X5
306307
end
307308
push!(identical_networks_3, reaction_networks_standard[10] => no_parameters_10)
@@ -591,3 +592,20 @@ let
591592
d, X 0
592593
end
593594
end
595+
596+
# Tests that bundling, but where the rate only have been given multiple alternatives, errors.
597+
# Checks for two, more than two, and for functional rates. Uses different arrow types and directions.
598+
let
599+
@test_throws Exception @eval @reaction_network begin
600+
(k1,k2), X --> 0
601+
end
602+
@test_throws Exception @eval @reaction_network begin
603+
(k1,k2,k3), X 0
604+
end
605+
@test_throws Exception @eval @reaction_network begin
606+
(k1,k1), X => Y
607+
end
608+
@test_throws Exception @eval @reaction_network begin
609+
(mm(X,v1,K1),mm(X,v2,K2)), 0 <-- 0
610+
end
611+
end

test/test_networks.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ end
6464
reaction_networks_standard[8] = @reaction_network rns8 begin
6565
p, ∅ 2X1
6666
k1, X1 X2
67-
(k2, k3), X2 X3
67+
k2, X2 X3
68+
k3, X2 X3
6869
d, X3
6970
end
7071

@@ -78,10 +79,10 @@ end
7879

7980
reaction_networks_standard[10] = @reaction_network rns10 begin
8081
p, ∅ X1
81-
(k1, k2), X1 X2
82-
(k3, k4), X2 X3
83-
(k5, k6), X3 X4
84-
(k7, k8), X4 X5
82+
(k1, k2), (X1,X1) X2
83+
(k3, k4), (X2,X2) X3
84+
(k5, k6), (X3,X3) X4
85+
(k7, k8), (X4,X4) X5
8586
d, X5
8687
end
8788

0 commit comments

Comments
 (0)