Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
TorkelE committed Jan 16, 2025
1 parent 3385807 commit 6f73003
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end
@equations D(D(V)) ~ 1
end
```
Please note that this cannot be used at the same time as `D` is used to represent a species, variable, or parameter.
Please note that this cannot be used at the same time as `D` is used to represent a species, variable, or parameter (including is these are implicitly designated as such by e.g. appearing as a reaction reactant).
- Array symbolics support is more consistent with ModelingToolkit v9. Parameter
arrays are no longer scalarized by Catalyst, while species and variables
arrays still are (as in ModelingToolkit). As such, parameter arrays should now
Expand Down
7 changes: 3 additions & 4 deletions src/dsl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem)))
# Excludes any parameters already extracted (if they also was a variable).
declared_syms = union(declared_syms, species_extracted)
vars_extracted, add_default_diff, equations = read_equations_options(
options, declared_syms; requiredec)
options, declared_syms, parameters_extracted; requiredec)
variables = vcat(variables_declared, vars_extracted)
parameters_extracted = setdiff(parameters_extracted, vars_extracted)

Expand Down Expand Up @@ -705,7 +705,7 @@ end
# `vars_extracted`: A vector with extracted variables (lhs in pure differential equations only).
# `dtexpr`: If a differential equation is defined, the default derivative (D ~ Differential(t)) must be defined.
# `equations`: a vector with the equations provided.
function read_equations_options(options, syms_declared; requiredec = false)
function read_equations_options(options, syms_declared, parameters_extracted; requiredec = false)
# Prepares the equations. First, extracts equations from provided option (converting to block form if required).
# Next, uses MTK's `parse_equations!` function to split input into a vector with the equations.
eqs_input = haskey(options, :equations) ? options[:equations].args[3] : :(begin end)
Expand All @@ -725,8 +725,7 @@ function read_equations_options(options, syms_declared; requiredec = false)
end

# If the default differential (`D`) is used, record that it should be decalred later on.

if !in(eq, syms_declared) && find_D_call(eq)
if (:D union(syms_declared, parameters_extracted)) && find_D_call(eq)
requiredec && throw(UndeclaredSymbolicError(
"Unrecognized symbol D was used as a differential in an equation: \"$eq\". Since the @require_declaration flag is set, all differentials in equations must be explicitly declared using the @differentials option."))
add_default_diff = true
Expand Down
10 changes: 5 additions & 5 deletions test/dsl/dsl_options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,11 @@ let
#@equations D(V) ~ 1 - V
#d, X --> 0
#end
@test_broken false # @test_throws Exception @eval @reaction_network begin
#@parameters D
#@equations D(V) ~ 1 - V
#d, X --> 0
#end
@test_throws Exception @eval @reaction_network begin
@parameters D
@equations D(V) ~ 1 - V
d, X --> 0
end

# Symbol only occurring in events.
@test_throws Exception @eval @reaction_network begin
Expand Down

0 comments on commit 6f73003

Please sign in to comment.