-
-
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
Update inference of variables and default differential from @equations
macro
#1175
Changes from 12 commits
f94fe04
895292c
a1f916b
006ae00
7d6aa95
da50bf8
d4cdcd5
018fcf6
f2ed0a3
e4c3e4e
6e57098
26b0fb2
fc4d387
734756d
6fbaff4
3385807
6f73003
64f1e39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,9 +97,9 @@ Base.@kwdef mutable struct NetworkProperties{I <: Integer, V <: BasicSymbolic{Re | |
stronglinkageclasses::Vector{Vector{Int}} = Vector{Vector{Int}}(undef, 0) | ||
terminallinkageclasses::Vector{Vector{Int}} = Vector{Vector{Int}}(undef, 0) | ||
|
||
checkedrobust::Bool = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to fix this thing. I have checked an re-checked and there is no actual difference (more than space removal). I think I put in, and then removed, a debug statement in this file (and the space removal happened). Hence changes appeared here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you must have some VSCode setting enabled. |
||
checkedrobust::Bool = false | ||
robustspecies::Vector{Int} = Vector{Int}(undef, 0) | ||
deficiency::Int = -1 | ||
deficiency::Int = -1 | ||
end | ||
#! format: on | ||
|
||
|
@@ -215,11 +215,11 @@ end | |
|
||
### ReactionSystem Structure ### | ||
|
||
""" | ||
""" | ||
WARNING!!! | ||
|
||
The following variable is used to check that code that should be updated when the `ReactionSystem` | ||
fields are updated has in fact been updated. Do not just blindly update this without first checking | ||
The following variable is used to check that code that should be updated when the `ReactionSystem` | ||
fields are updated has in fact been updated. Do not just blindly update this without first checking | ||
all such code and updating it appropriately (e.g. serialization). Please use a search for | ||
`reactionsystem_fields` throughout the package to ensure all places which should be updated, are updated. | ||
""" | ||
|
@@ -318,7 +318,7 @@ struct ReactionSystem{V <: NetworkProperties} <: | |
""" | ||
discrete_events::Vector{MT.SymbolicDiscreteCallback} | ||
""" | ||
Metadata for the system, to be used by downstream packages. | ||
Metadata for the system, to be used by downstream packages. | ||
""" | ||
metadata::Any | ||
""" | ||
|
@@ -480,10 +480,10 @@ function ReactionSystem(iv; kwargs...) | |
ReactionSystem(Reaction[], iv, [], []; kwargs...) | ||
end | ||
|
||
# Called internally (whether DSL-based or programmatic model creation is used). | ||
# Called internally (whether DSL-based or programmatic model creation is used). | ||
# Creates a sorted reactions + equations vector, also ensuring reaction is first in this vector. | ||
# Extracts potential species, variables, and parameters from the input (if not provided as part of | ||
# the model creation) and creates the corresponding vectors. | ||
# Extracts potential species, variables, and parameters from the input (if not provided as part of | ||
# the model creation) and creates the corresponding vectors. | ||
# While species are ordered before variables in the unknowns vector, this ordering is not imposed here, | ||
# but carried out at a later stage. | ||
function make_ReactionSystem_internal(rxs_and_eqs::Vector, iv, us_in, ps_in; | ||
|
@@ -495,7 +495,7 @@ function make_ReactionSystem_internal(rxs_and_eqs::Vector, iv, us_in, ps_in; | |
any(in(obs_vars), us_in) && | ||
error("Found an observable in the list of unknowns. This is not allowed.") | ||
|
||
# Creates a combined iv vector (iv and sivs). This is used later in the function (so that | ||
# Creates a combined iv vector (iv and sivs). This is used later in the function (so that | ||
# independent variables can be excluded when encountered quantities are added to `us` and `ps`). | ||
t = value(iv) | ||
ivs = Set([t]) | ||
|
@@ -560,7 +560,7 @@ function make_ReactionSystem_internal(rxs_and_eqs::Vector, iv, us_in, ps_in; | |
end | ||
psv = collect(new_ps) | ||
|
||
# Passes the processed input into the next `ReactionSystem` call. | ||
# Passes the processed input into the next `ReactionSystem` call. | ||
ReactionSystem(fulleqs, t, usv, psv; spatial_ivs, continuous_events, | ||
discrete_events, observed, kwargs...) | ||
end | ||
|
@@ -1062,8 +1062,8 @@ end | |
|
||
### General `ReactionSystem`-specific Functions ### | ||
|
||
# Checks if the `ReactionSystem` structure have been updated without also updating the | ||
# `reactionsystem_fields` constant. If this is the case, returns `false`. This is used in | ||
# Checks if the `ReactionSystem` structure have been updated without also updating the | ||
# `reactionsystem_fields` constant. If this is the case, returns `false`. This is used in | ||
# certain functionalities which would break if the `ReactionSystem` structure is updated without | ||
# also updating these functionalities. | ||
function reactionsystem_uptodate_check() | ||
|
@@ -1241,7 +1241,7 @@ end | |
### `ReactionSystem` Remaking ### | ||
|
||
""" | ||
remake_ReactionSystem_internal(rs::ReactionSystem; | ||
remake_ReactionSystem_internal(rs::ReactionSystem; | ||
default_reaction_metadata::Vector{Pair{Symbol, T}} = Vector{Pair{Symbol, Any}}()) where {T} | ||
|
||
Takes a `ReactionSystem` and remakes it, returning a modified `ReactionSystem`. Modifications depend | ||
|
@@ -1274,7 +1274,7 @@ function set_default_metadata(rs::ReactionSystem; default_reaction_metadata = [] | |
# Currently, `noise_scaling` is the only relevant metadata supported this way. | ||
drm_dict = Dict(default_reaction_metadata) | ||
if haskey(drm_dict, :noise_scaling) | ||
# Finds parameters, species, and variables in the noise scaling term. | ||
# Finds parameters, species, and variables in the noise scaling term. | ||
ns_expr = drm_dict[:noise_scaling] | ||
ns_syms = [Symbolics.unwrap(sym) for sym in get_variables(ns_expr)] | ||
ns_ps = Iterators.filter(ModelingToolkit.isparameter, ns_syms) | ||
|
@@ -1414,7 +1414,7 @@ function ModelingToolkit.compose(sys::ReactionSystem, systems::AbstractArray; na | |
MT.collect_scoped_vars!(newunknowns, newparams, ssys, iv) | ||
end | ||
|
||
if !isempty(newunknowns) | ||
if !isempty(newunknowns) | ||
@set! sys.unknowns = union(get_unknowns(sys), newunknowns) | ||
sort!(get_unknowns(sys), by = !isspecies) | ||
@set! sys.species = filter(isspecies, get_unknowns(sys)) | ||
|
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.
What happens if someone uses
D
in a reaction as an implicit 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.
Aside from that question this is fine to merge I think.
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.
Using D in any other context (e.g. as a species, variable or parameter) should disable inference of D as a differential. Will clarify this