Skip to content

WIP: MTK v10 #1296

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ LaTeXStrings = "1.3.0"
Latexify = "0.16.6"
MacroTools = "0.5.5"
Makie = "0.22.1"
ModelingToolkit = "9.73"
ModelingToolkit = "10"
NetworkLayout = "0.4.7"
Parameters = "0.12"
Reexport = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/latexify_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const LATEX_DEFS = CatalystLatexParams()
return rs
elseif form == :ode # Returns ODE system code.
mult_symbol --> ""
return convert(ODESystem, rs)
return convert(System, rs)
elseif form == :sde # Returns SDE system code.
mult_symbol --> ""
return convert(SDESystem, rs)
Expand Down
20 changes: 10 additions & 10 deletions src/reactionsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ Continuing from the example in the [`Reaction`](@ref) definition:
Keyword Arguments:
- `observed::Vector{Equation}`, equations specifying observed variables.
- `systems::Vector{AbstractSystems}`, vector of sub-systems. Can be `ReactionSystem`s,
`ODESystem`s, or `NonlinearSystem`s.
`System`s, or `NonlinearSystem`s.
- `name::Symbol`, the name of the system (must be provided, or `@named` must be used).
- `defaults::Dict`, a dictionary mapping parameters to their default values and species to
their default initial values.
Expand Down Expand Up @@ -545,7 +545,7 @@ function make_ReactionSystem_internal(rxs_and_eqs::Vector, iv, us_in, ps_in;
# Extracts any species, variables, and parameters that occur in (non-reaction) equations.
# Creates the new reactions + equations vector, `fulleqs` (sorted reactions first, equations next).
if !isempty(eqs)
osys = ODESystem(eqs, iv; name = gensym())
osys = System(eqs, iv; name = gensym())
fulleqs = CatalystEqType[rxs; equations(osys)]
union!(us, unknowns(osys))
union!(ps, parameters(osys))
Expand Down Expand Up @@ -1399,7 +1399,7 @@ Notes:
- All `Reaction`s within subsystems are namespaced and merged into the list of `Reactions`
of `rs`. The merged list is then available as `reactions(rs)`.
- All algebraic and differential equations are merged in the equations of `rs`.
- Currently only `ReactionSystem`s, `NonlinearSystem`s and `ODESystem`s are supported as
- Currently only `ReactionSystem`s, `NonlinearSystem`s and `System`s are supported as
sub-systems when flattening.
- `rs.networkproperties` is reset upon flattening.
- The default value of `combinatoric_ratelaws` will be the logical or of all
Expand All @@ -1408,11 +1408,11 @@ Notes:
function MT.flatten(rs::ReactionSystem; name = nameof(rs))
isempty(get_systems(rs)) && return rs

# right now only NonlinearSystems and ODESystems can be handled as subsystems
# right now only NonlinearSystems and Systems can be handled as subsystems
subsys_types = getsubsystypes(rs)
allowed_types = (ReactionSystem, NonlinearSystem, ODESystem)
allowed_types = (ReactionSystem, NonlinearSystem, System)
all(T -> any(T .<: allowed_types), subsys_types) ||
error("flattening is currently only supported for subsystems mixing ReactionSystems, NonlinearSystems and ODESystems.")
error("flattening is currently only supported for subsystems mixing ReactionSystems, NonlinearSystems and Systems.")

ReactionSystem(equations(rs), get_iv(rs), unknowns(rs), parameters(rs);
observed = MT.observed(rs),
Expand Down Expand Up @@ -1440,7 +1440,7 @@ end
Compose the indicated [`ReactionSystem`](@ref) with one or more `AbstractSystem`s.

Notes:
- The `AbstractSystem` being added in must be an `ODESystem`, `NonlinearSystem`,
- The `AbstractSystem` being added in must be an `System`, `NonlinearSystem`,
or `ReactionSystem` currently.
- Returns a new `ReactionSystem` and does not modify `rs`.
- By default, the new `ReactionSystem` will have the same name as `sys`.
Expand Down Expand Up @@ -1479,7 +1479,7 @@ end
Extends the indicated [`ReactionSystem`](@ref) with another `AbstractSystem`.

Notes:
- The `AbstractSystem` being added in must be an `ODESystem`, `NonlinearSystem`,
- The `AbstractSystem` being added in must be an `System`, `NonlinearSystem`,
or `ReactionSystem` currently.
- Returns a new `ReactionSystem` and does not modify `rs`.
- By default, the new `ReactionSystem` will have the same name as `sys`.
Expand All @@ -1490,8 +1490,8 @@ function ModelingToolkit.extend(sys::MT.AbstractSystem, rs::ReactionSystem;
complete_check(sys, "ModelingToolkit.extend")
complete_check(rs, "ModelingToolkit.extend")

any(T -> sys isa T, (ReactionSystem, ODESystem, NonlinearSystem)) ||
error("ReactionSystems can only be extended with ReactionSystems, ODESystems and NonlinearSystems currently. Received a $(typeof(sys)) system.")
any(T -> sys isa T, (ReactionSystem, System, NonlinearSystem)) ||
error("ReactionSystems can only be extended with ReactionSystems, Systems and NonlinearSystems currently. Received a $(typeof(sys)) system.")

t = get_iv(rs)
if MT.has_iv(sys)
Expand Down
16 changes: 8 additions & 8 deletions src/reactionsystem_conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ function addconstraints!(eqs, rs::ReactionSystem, ists, ispcs; remove_conserved
conservation laws. Catalyst does not check that the conserved equations
still hold for the final coupled system of equations. Consider using
`remove_conserved = false` and instead calling
ModelingToolkit.structural_simplify to simplify any generated ODESystem or
ModelingToolkit.structural_simplify to simplify any generated System or
NonlinearSystem.
"""
end
Expand Down Expand Up @@ -509,9 +509,9 @@ COMPLETENESS_ERROR = "A ReactionSystem must be complete before it can be convert

"""
```julia
Base.convert(::Type{<:ODESystem},rs::ReactionSystem)
Base.convert(::Type{<:System},rs::ReactionSystem)
```
Convert a [`ReactionSystem`](@ref) to an `ModelingToolkit.ODESystem`.
Convert a [`ReactionSystem`](@ref) to an `ModelingToolkit.System`.

Keyword args and default values:
- `combinatoric_ratelaws=true` uses factorial scaling factors in calculating the rate law,
Expand All @@ -526,15 +526,15 @@ Keyword args and default values:
with their rational function representation when converting to another system type. Set to
`false`` to disable.
"""
function Base.convert(::Type{<:ODESystem}, rs::ReactionSystem; name = nameof(rs),
function Base.convert(::Type{<:System}, rs::ReactionSystem; name = nameof(rs),
combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
include_zero_odes = true, remove_conserved = false, checks = false,
default_u0 = Dict(), default_p = Dict(),
defaults = _merge(Dict(default_u0), Dict(default_p)), expand_catalyst_funs = true,
kwargs...)
# Error checks.
iscomplete(rs) || error(COMPLETENESS_ERROR)
spatial_convert_err(rs::ReactionSystem, ODESystem)
spatial_convert_err(rs::ReactionSystem, System)

fullrs = Catalyst.flatten(rs)
remove_conserved && conservationlaws(fullrs)
Expand All @@ -543,7 +543,7 @@ function Base.convert(::Type{<:ODESystem}, rs::ReactionSystem; name = nameof(rs)
include_zero_odes, expand_catalyst_funs)
eqs, us, ps, obs, defs = addconstraints!(eqs, fullrs, ists, ispcs; remove_conserved)

ODESystem(eqs, get_iv(fullrs), us, ps;
System(eqs, get_iv(fullrs), us, ps;
observed = obs,
name,
defaults = _merge(defaults, defs),
Expand Down Expand Up @@ -828,7 +828,7 @@ function DiffEqBase.ODEProblem(rs::ReactionSystem, u0, tspan,
combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
include_zero_odes = true, remove_conserved = false, checks = false,
expand_catalyst_funs = true, structural_simplify = false, kwargs...)
osys = convert(ODESystem, rs; name, combinatoric_ratelaws, include_zero_odes, checks,
osys = convert(System, rs; name, combinatoric_ratelaws, include_zero_odes, checks,
remove_conserved, expand_catalyst_funs)

# Handles potential differential algebraic equations (which requires `structural_simplify`).
Expand Down Expand Up @@ -1058,7 +1058,7 @@ function DiffEqBase.SteadyStateProblem(rs::ReactionSystem, u0,
combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
remove_conserved = false, include_zero_odes = true, checks = false,
expand_catalyst_funs = true, structural_simplify = false, kwargs...)
osys = convert(ODESystem, rs; name, combinatoric_ratelaws, include_zero_odes, checks,
osys = convert(System, rs; name, combinatoric_ratelaws, include_zero_odes, checks,
remove_conserved, expand_catalyst_funs)

# Handles potential differential algebraic equations (which requires `structural_simplify`).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ rn = include("rn.jls")
Notes:
- `ReactionSystem`s with the `connection_type` field has this ignored (saving of this field has not
been implemented yet).
- `ReactionSystem`s with non-`ReactionSystem` sub-systems (e.g. `ODESystem`s) cannot be saved.
- `ReactionSystem`s with non-`ReactionSystem` sub-systems (e.g. `System`s) cannot be saved.
- Reaction systems with components that have units cannot currently be saved.
- The `ReactionSystem` is saved using *programmatic* (not DSL) format for model creation.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ function rebuild_lat_internals!(lt_ofun::LatticeTransportODEFunction, ps_new,

# Updating the `MTKParameters` structure is a bit more complicated.
p_dict = Dict(ps_new)
osys = complete(convert(ODESystem, reactionsystem(lrs)))
osys = complete(convert(System, reactionsystem(lrs)))
for p in parameters(osys)
MT.setp(osys, p)(lt_ofun.mtk_ps, (p_dict[p] isa Number) ? p_dict[p] : p_dict[p][1])
end
Expand Down
4 changes: 2 additions & 2 deletions src/spatial_reaction_systems/spatial_ODE_systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ end
# the vertex parameter values during the simulations).
function make_mtk_ps_structs(ps, lrs, heterogeneous_vert_p_idxs)
p_dict = Dict(ps)
nonspatial_osys = complete(convert(ODESystem, reactionsystem(lrs)))
nonspatial_osys = complete(convert(System, reactionsystem(lrs)))
p_init = [p => p_dict[p][1] for p in parameters(nonspatial_osys)]
mtk_ps = MT.MTKParameters(nonspatial_osys, p_init)
p_setters = [MT.setp(nonspatial_osys, p)
Expand Down Expand Up @@ -220,7 +220,7 @@ function build_odefunction(lrs::LatticeReactionSystem, vert_ps::Vector{Pair{R, V
end

# Prepares the inputs to the `LatticeTransportODEFunction` functor.
osys = complete(convert(ODESystem, reactionsystem(lrs);
osys = complete(convert(System, reactionsystem(lrs);
name, combinatoric_ratelaws, include_zero_odes, checks))
ofunc_dense = ODEFunction(osys; jac = true, sparse = false)
ofunc_sparse = ODEFunction(osys; jac = true, sparse = true)
Expand Down
Loading