-
-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor "src/dsl.jl" file #985
base: master
Are you sure you want to change the base?
Conversation
3f92a31
to
b6ba044
Compare
src/dsl.jl
Outdated
variables = vcat(variables_declared, vars_extracted) | ||
|
||
# handle independent variables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of the organisations so that options are handled together (in two sets, some before and some after the reactions are considered, depending on whichever is possible for which option)
src/dsl.jl
Outdated
symvec = gensym() | ||
ex = quote | ||
$symvec = $ex | ||
expr = quote |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in some places we used ex and some expr, here I just made it uniform
(sum(length, [reaction_lines, option_lines]) != length(ex.args)) && | ||
error("@reaction_network input contain $(length(ex.args) - sum(length.([reaction_lines,option_lines]))) malformed lines.") | ||
any(!in(option_keys), keys(options)) && | ||
error("The following unsupported options were used: $(filter(opt_in->!in(opt_in,option_keys), keys(options)))") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Step one, read the macro input and check that it is correctly formatted.
if !allunique(syms_declared) | ||
nonunique_syms = [s for s in syms_declared if count(x -> x == s, syms_declared) > 1] | ||
error("The following symbols $(unique(nonunique_syms)) have explicitly been declared as multiple types of components (e.g. occur in at least two of the `@species`, `@parameters`, `@variables`, `@ivs`, `@compounds`, `@differentials`). This is not allowed.") | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Step 2, read all options that explicitly declares symbols as stuff.
continuous_events_expr = read_events_option(options, :continuous_events) | ||
discrete_events_expr = read_events_option(options, :discrete_events) | ||
default_reaction_metadata = read_default_noise_scaling_option(options) | ||
combinatoric_ratelaws = read_combinatoric_ratelaws_option(options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Step 4, read the other options.
spsexpr, spsvar = scalarize_macro(spsexpr_init, "specs") | ||
vsexpr, vsvar = scalarize_macro(vsexpr_init, "vars") | ||
cmpsexpr, cmpsvar = scalarize_macro(cmpexpr_init, "comps") | ||
rxsexprs = get_rxexprs(reactions, equations, all_syms) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Step 5, creates the various expressions to put in the macro.
end | ||
union!(excluded_syms, species) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
union!
replaces foreach(s -> push!(excluded_syms, s), species)
syms_inferred = union(sps_inferred, ps_inferred, vs_inferred, diffs_inferred) | ||
all_syms = union(syms_declared, syms_inferred) | ||
obsexpr, obs_eqs, obs_syms = read_observed_option(options, ivs, | ||
union(sps_declared, vs_declared), all_syms; requiredec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Step 3: Read all reactions and equations. Finds all symbols that are inferred as something.
function escape_equation!(eqexpr::Expr, all_syms) | ||
eqexpr.args[2] = recursive_escape_functions!(eqexpr.args[2], all_syms) | ||
eqexpr.args[3] = recursive_escape_functions!(eqexpr.args[3], all_syms) | ||
eqexpr | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
escape equations is called by get_rxexprs
|
||
# Checks for input errors. | ||
# Checks for input errors. Needed here but not in `@reaction_network` as `ReactionSystem` perform this check but `Reaction` don't. | ||
forbidden_symbol_check(union(species, parameters)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For @reaction_network
this check is not needed as ReactionSystem
does a similar one. We might consider whether Reaction
should also perform this type of check (and we remove it from here entirely.
E.g. this works:
@parameters Γ
@species X(t)
Reaction(Γ, [X], [])
while this errors:
@reaction Γ, X --> 0
This should be ready now. However, Plots fails on precompilation, so have to wait until that is fixed. Not high priority though, doesn't actually change anything (but should make further updates to the DSL easier). Once this PR is merged, I will have a follow-up one which reorders the option handling functions to follow the order with which they are called. |
…to src___refactoring___dsl_file
Also does the "src/expression_utils.jl" file, as that primarily support the dsl file (the other relevant file is the chemistry one).
Primarily four types of changes:
@reaction_network
and@network_component
macros reuse minimal amount of code (where as previously it the second was basically ctrl+copied versions of the first.I also add some tests of all the various ways to create models via the DSL, mostly stuff that was not tested before.