Skip to content

Commit

Permalink
Merge pull request #1024 from isaacsas/add_dsl_temp_variables_for_rea…
Browse files Browse the repository at this point in the history
…dability

cleanup DSL generated expression for readability
  • Loading branch information
isaacsas authored Aug 21, 2024
2 parents feb7e5a + 6219aff commit c1c6e75
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
27 changes: 16 additions & 11 deletions src/dsl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Expand Down Expand Up @@ -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
Expand All @@ -380,23 +380,28 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem)))
end

quote
$ps
$ivexpr
$ps
$vars
$sps
$observed_vars
$comps
$diffexpr

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,
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

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,
combinatoric_ratelaws = $combinatoric_ratelaws);
default_reaction_metadata = $default_reaction_metadata
)
default_reaction_metadata = $default_reaction_metadata)
end
end

Expand Down
4 changes: 3 additions & 1 deletion test/dsl/dsl_advanced_model_construction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ 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)
sys = @eval Catalyst $exsys
@test sys isa ReactionSystem
end

# Miscellaneous interpolation tests. Unsure what they do here (not related to DSL).
Expand Down

0 comments on commit c1c6e75

Please sign in to comment.