From a64c2bff2cfac1c2307bb568029548a18e0914ca Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Wed, 14 Aug 2024 15:20:21 -0400 Subject: [PATCH 01/10] cleanup macro expression for readability --- src/dsl.jl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/dsl.jl b/src/dsl.jl index 7f5e2d6125..484c4e7457 100644 --- a/src/dsl.jl +++ b/src/dsl.jl @@ -380,23 +380,28 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem))) end quote - $ps $ivexpr + $ps $vars $sps $observed_vars $comps $diffexpr + sivs_vec = $sivs + rx_eq_vec = $rxexprs + vars = setdiff(union($spssym, $varssym, $compssym), $obs_syms) + obseqs = $observed_eqs + cevents = $continuous_events_expr + devents = $discrete_events_expr + Catalyst.remake_ReactionSystem_internal( Catalyst.make_ReactionSystem_internal( - $rxexprs, $tiv, setdiff(union($spssym, $varssym, $compssym), $obs_syms), - $pssym; name = $name, spatial_ivs = $sivs, observed = $observed_eqs, - continuous_events = $continuous_events_expr, - discrete_events = $discrete_events_expr, + rx_eq_vec, $tiv, vars, $pssym; + name = $name, spatial_ivs = sivs_vec, observed = obseqs, + continuous_events = cevents, discrete_events = devents, combinatoric_ratelaws = $combinatoric_ratelaws); - default_reaction_metadata = $default_reaction_metadata - ) + default_reaction_metadata = $default_reaction_metadata) end end From debe8dcb48941042457678fce3f2b28d94cc9d53 Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Wed, 14 Aug 2024 15:25:03 -0400 Subject: [PATCH 02/10] drop Catalyst qualification --- src/dsl.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dsl.jl b/src/dsl.jl index 484c4e7457..a2eb18675b 100644 --- a/src/dsl.jl +++ b/src/dsl.jl @@ -395,8 +395,8 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem))) cevents = $continuous_events_expr devents = $discrete_events_expr - Catalyst.remake_ReactionSystem_internal( - Catalyst.make_ReactionSystem_internal( + remake_ReactionSystem_internal( + make_ReactionSystem_internal( rx_eq_vec, $tiv, vars, $pssym; name = $name, spatial_ivs = sivs_vec, observed = obseqs, continuous_events = cevents, discrete_events = devents, From 7f185790d89fdfa46d255ff0e5205d7599c67d0f Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Wed, 14 Aug 2024 15:25:45 -0400 Subject: [PATCH 03/10] format --- src/dsl.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dsl.jl b/src/dsl.jl index a2eb18675b..6534444e89 100644 --- a/src/dsl.jl +++ b/src/dsl.jl @@ -397,7 +397,7 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem))) remake_ReactionSystem_internal( make_ReactionSystem_internal( - rx_eq_vec, $tiv, vars, $pssym; + rx_eq_vec, $tiv, vars, $pssym; name = $name, spatial_ivs = sivs_vec, observed = obseqs, continuous_events = cevents, discrete_events = devents, combinatoric_ratelaws = $combinatoric_ratelaws); From d753f76dad47dfc0bc0f87fd989eb89739143a6a Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Wed, 14 Aug 2024 16:45:16 -0400 Subject: [PATCH 04/10] fix test --- test/dsl/dsl_advanced_model_construction.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/dsl/dsl_advanced_model_construction.jl b/test/dsl/dsl_advanced_model_construction.jl index 5638c9173c..b0020c34f5 100644 --- a/test/dsl/dsl_advanced_model_construction.jl +++ b/test/dsl/dsl_advanced_model_construction.jl @@ -131,7 +131,8 @@ let end # Line number nodes aren't ignored so have to be manually removed Base.remove_linenums!(ex) - @test eval(Catalyst.make_reaction_system(ex)) isa ReactionSystem + exsys = Catalyst.make_reaction_system(ex) + @test (@eval Catalyst $exsys) isa ReactionSystem end # Miscellaneous interpolation tests. Unsure what they do here (not related to DSL). From 27c31cdf1ae13b54ab965c5759656975672c9b81 Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Wed, 14 Aug 2024 16:45:55 -0400 Subject: [PATCH 05/10] cleanup test --- test/dsl/dsl_advanced_model_construction.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/dsl/dsl_advanced_model_construction.jl b/test/dsl/dsl_advanced_model_construction.jl index b0020c34f5..55eefd0213 100644 --- a/test/dsl/dsl_advanced_model_construction.jl +++ b/test/dsl/dsl_advanced_model_construction.jl @@ -132,7 +132,8 @@ let # Line number nodes aren't ignored so have to be manually removed Base.remove_linenums!(ex) exsys = Catalyst.make_reaction_system(ex) - @test (@eval Catalyst $exsys) isa ReactionSystem + sys = @eval Catalyst $exsys + @test sys isa ReactionSystem end # Miscellaneous interpolation tests. Unsure what they do here (not related to DSL). From 4feb9a53c49c64a97237d9876534bfc3ade466be Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Wed, 14 Aug 2024 16:51:59 -0400 Subject: [PATCH 06/10] try removing Catalyst qualification in macro --- src/dsl.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dsl.jl b/src/dsl.jl index 6534444e89..04e35e607d 100644 --- a/src/dsl.jl +++ b/src/dsl.jl @@ -87,13 +87,13 @@ macro species(ex...) resize!(vars.args, idx + length(lastarg.args) + 1) for sym in lastarg.args vars.args[idx] = :($sym = ModelingToolkit.wrap(setmetadata( - ModelingToolkit.value($sym), Catalyst.VariableSpecies, true))) + ModelingToolkit.value($sym), VariableSpecies, true))) idx += 1 end # check nothing was declared isconstantspecies ex = quote - all(!Catalyst.isconstant ∘ ModelingToolkit.value, $lastarg) || + all(!isconstant ∘ ModelingToolkit.value, $lastarg) || throw(ArgumentError("isconstantspecies metadata can only be used with parameters.")) end vars.args[idx] = ex @@ -371,7 +371,7 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem))) vars, varssym = scalarize_macro(!isempty(variables), vexprs, "vars") sps, spssym = scalarize_macro(!isempty(species), sexprs, "specs") comps, compssym = scalarize_macro(!isempty(compound_species), compound_expr, "comps") - rxexprs = :(Catalyst.CatalystEqType[]) + rxexprs = :(CatalystEqType[]) for reaction in reactions push!(rxexprs.args, get_rxexprs(reaction)) end From ea3078d26f531d15a10174445dedc88d538ab2ab Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Wed, 14 Aug 2024 17:24:10 -0400 Subject: [PATCH 07/10] fix tests --- src/dsl.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dsl.jl b/src/dsl.jl index 04e35e607d..a4a70266ef 100644 --- a/src/dsl.jl +++ b/src/dsl.jl @@ -87,13 +87,13 @@ macro species(ex...) resize!(vars.args, idx + length(lastarg.args) + 1) for sym in lastarg.args vars.args[idx] = :($sym = ModelingToolkit.wrap(setmetadata( - ModelingToolkit.value($sym), VariableSpecies, true))) + ModelingToolkit.value($sym), Catalyst.VariableSpecies, true))) idx += 1 end # check nothing was declared isconstantspecies ex = quote - all(!isconstant ∘ ModelingToolkit.value, $lastarg) || + all(!Catalyst.isconstant ∘ ModelingToolkit.value, $lastarg) || throw(ArgumentError("isconstantspecies metadata can only be used with parameters.")) end vars.args[idx] = ex @@ -150,7 +150,7 @@ macro reaction_network(name::Expr, ex::Expr) MacroTools.striplines(ex); name = :($(esc(name.args[1]))))))) end -macro reaction_network(ex::Expr) +macro reaction_network(ex::Expr) ex = MacroTools.striplines(ex) # no name but equations: @reaction_network begin ... end ... From cc418bf06883b05f575a41ca050532fe53aa2df5 Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Wed, 21 Aug 2024 13:55:06 -0400 Subject: [PATCH 08/10] update kwargs --- src/dsl.jl | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/dsl.jl b/src/dsl.jl index a4a70266ef..ef3ec34265 100644 --- a/src/dsl.jl +++ b/src/dsl.jl @@ -388,18 +388,17 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem))) $comps $diffexpr - sivs_vec = $sivs + spatial_ivs = $sivs rx_eq_vec = $rxexprs vars = setdiff(union($spssym, $varssym, $compssym), $obs_syms) - obseqs = $observed_eqs - cevents = $continuous_events_expr - devents = $discrete_events_expr + observed = $observed_eqs + continuous_events = $continuous_events_expr + discrete_events = $discrete_events_expr remake_ReactionSystem_internal( make_ReactionSystem_internal( - rx_eq_vec, $tiv, vars, $pssym; - name = $name, spatial_ivs = sivs_vec, observed = obseqs, - continuous_events = cevents, discrete_events = devents, + rx_eq_vec, $tiv, vars, $pssym; name = $name, spatial_ivs, observed, + continuous_events, discrete_events, combinatoric_ratelaws = $combinatoric_ratelaws); default_reaction_metadata = $default_reaction_metadata) end From 3d983f92ea7f1a48bbe1457eaa1aeac9d0f69877 Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Wed, 21 Aug 2024 13:59:41 -0400 Subject: [PATCH 09/10] format --- src/dsl.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dsl.jl b/src/dsl.jl index ef3ec34265..7d1a662dd6 100644 --- a/src/dsl.jl +++ b/src/dsl.jl @@ -150,7 +150,7 @@ macro reaction_network(name::Expr, ex::Expr) MacroTools.striplines(ex); name = :($(esc(name.args[1]))))))) end -macro reaction_network(ex::Expr) +macro reaction_network(ex::Expr) ex = MacroTools.striplines(ex) # no name but equations: @reaction_network begin ... end ... From 6219aff0bd86c495241f6a2fccbbe2177ded9d86 Mon Sep 17 00:00:00 2001 From: Sam Isaacson Date: Wed, 21 Aug 2024 15:19:43 -0400 Subject: [PATCH 10/10] revert names --- src/dsl.jl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/dsl.jl b/src/dsl.jl index 7d1a662dd6..a4a70266ef 100644 --- a/src/dsl.jl +++ b/src/dsl.jl @@ -150,7 +150,7 @@ macro reaction_network(name::Expr, ex::Expr) MacroTools.striplines(ex); name = :($(esc(name.args[1]))))))) end -macro reaction_network(ex::Expr) +macro reaction_network(ex::Expr) ex = MacroTools.striplines(ex) # no name but equations: @reaction_network begin ... end ... @@ -388,17 +388,18 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem))) $comps $diffexpr - spatial_ivs = $sivs + sivs_vec = $sivs rx_eq_vec = $rxexprs vars = setdiff(union($spssym, $varssym, $compssym), $obs_syms) - observed = $observed_eqs - continuous_events = $continuous_events_expr - discrete_events = $discrete_events_expr + obseqs = $observed_eqs + cevents = $continuous_events_expr + devents = $discrete_events_expr remake_ReactionSystem_internal( make_ReactionSystem_internal( - rx_eq_vec, $tiv, vars, $pssym; name = $name, spatial_ivs, observed, - continuous_events, discrete_events, + rx_eq_vec, $tiv, vars, $pssym; + name = $name, spatial_ivs = sivs_vec, observed = obseqs, + continuous_events = cevents, discrete_events = devents, combinatoric_ratelaws = $combinatoric_ratelaws); default_reaction_metadata = $default_reaction_metadata) end