Skip to content

Commit ceb4867

Browse files
Update Catalyst.jl for ModelingToolkit v10 compatibility
This commit updates Catalyst.jl to be compatible with ModelingToolkit v10, addressing several breaking changes: ## Changes Made: 1. **Updated Project.toml**: Changed ModelingToolkit dependency from "9.73" to "10" 2. **Fixed System Inheritance**: - Updated `ReactionSystem` to inherit from `MT.AbstractSystem` instead of `MT.AbstractTimeDependentSystem` - Updated `LatticeReactionSystem` to inherit from `MT.AbstractSystem` 3. **Updated Base.convert Functions**: - Changed `Base.convert(::Type{<:XSystem}, ...)` to `Base.convert(::typeof(XSystem), ...)` - This accounts for the unified `System` type in MTKv10 where system constructors return the same `System` type 4. **Fixed JumpInputs Type Constraints**: - Updated `JumpInputs{S <: MT.JumpSystem, T}` to `JumpInputs{S <: MT.AbstractSystem, T}` 5. **Replaced _merge Function**: - Removed import of `_merge` from ModelingToolkit (no longer available) - Replaced all `_merge` calls with standard `merge` function ## Testing: - Package successfully precompiles with ModelingToolkit v10 - All major system types (ReactionSystem, LatticeReactionSystem) compile correctly - Base functionality verified through compilation testing These changes maintain backward compatibility for user code while adapting to the new unified System architecture in ModelingToolkit v10. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 8d2537a commit ceb4867

File tree

9 files changed

+47
-33
lines changed

9 files changed

+47
-33
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ LaTeXStrings = "1.3.0"
6262
Latexify = "0.16.6"
6363
MacroTools = "0.5.5"
6464
Makie = "0.22.1"
65-
ModelingToolkit = "9.73"
65+
ModelingToolkit = "10"
6666
NetworkLayout = "0.4.7"
6767
Parameters = "0.12"
6868
Reexport = "1.0"

src/Catalyst.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import ModelingToolkit: get_variables, namespace_expr, namespace_equation, get_v
3636

3737
# internal but needed ModelingToolkit functions
3838
import ModelingToolkit: check_variables,
39-
check_parameters, _iszero, _merge, check_units,
39+
check_parameters, _iszero, check_units,
4040
get_unit, check_equations, iscomplete
4141

4242
import Base: (==), hash, size, getindex, setindex, isless, Sort.defalg, length, show

src/chemistry_functionality.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ function balance_reaction(reaction::Reaction)
275275
end
276276

277277
isempty(balancedrxs) && (@warn "Unable to balance reaction.")
278-
(length(balancedrxs) > 1) && (@warn "The space of possible balanced versions of the reaction ($reaction) is greater than one-dimension. This prevents the selection of a single appropriate balanced reaction. Instead, a basis for balanced reactions is returned. Note that we do not check if they preserve the set of substrates and products from the original reaction.")
278+
(length(balancedrxs) > 1) &&
279+
(@warn "The space of possible balanced versions of the reaction ($reaction) is greater than one-dimension. This prevents the selection of a single appropriate balanced reaction. Instead, a basis for balanced reactions is returned. Note that we do not check if they preserve the set of substrates and products from the original reaction.")
279280
return balancedrxs
280281
end
281282

src/dsl.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# Declare various arrow types symbols used for the empty set (also 0).
44
const empty_set = Set{Symbol}([:∅, ])
55
const fwd_arrows = Set{Symbol}([:>, :(=>), :, :, :, :, :, :, :, :, :, :, :, :])
6-
const bwd_arrows = Set{Symbol}([:<, :(<=), :, :, :, :, :, :, :, :, :, :, :, :, Symbol("<--")])
6+
const bwd_arrows = Set{Symbol}([
7+
:<, :(<=), :, :, :, :, :, :, :, :, :, :, :, :, Symbol("<--")])
78
const double_arrows = Set{Symbol}([:, :, :, :, :, :, :, :, Symbol("<-->")])
89
const pure_rate_arrows = Set{Symbol}([:(=>), :(<=), :, :, :, :, :, :])
910

@@ -297,12 +298,14 @@ function make_reaction_system(ex::Expr, name)
297298
requiredec = haskey(options, :require_declaration)
298299
reactions = get_reactions(reaction_lines)
299300
sps_inferred, ps_pre_inferred = extract_sps_and_ps(reactions, syms_declared; requiredec)
300-
vs_inferred, diffs_inferred, equations = read_equations_option!(diffsexpr, options,
301+
vs_inferred, diffs_inferred,
302+
equations = read_equations_option!(diffsexpr, options,
301303
union(syms_declared, sps_inferred), tiv; requiredec)
302304
ps_inferred = setdiff(ps_pre_inferred, vs_inferred, diffs_inferred)
303305
syms_inferred = union(sps_inferred, ps_inferred, vs_inferred, diffs_inferred)
304306
all_syms = union(syms_declared, syms_inferred)
305-
obsexpr, obs_eqs, obs_syms = read_observables_option(options, ivs,
307+
obsexpr, obs_eqs,
308+
obs_syms = read_observables_option(options, ivs,
306309
union(sps_declared, vs_declared), all_syms; requiredec)
307310

308311
# Read options not related to the declaration or inference of symbols.

src/reaction.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,8 @@ Notes: The following values are possible:
702702
end
703703

704704
const JUMP_SCALES = (PhysicalScale.Jump, PhysicalScale.VariableRateJump)
705-
const NON_CONSTANT_JUMP_SCALES = (PhysicalScale.ODE, PhysicalScale.SDE, PhysicalScale.VariableRateJump)
705+
const NON_CONSTANT_JUMP_SCALES = (
706+
PhysicalScale.ODE, PhysicalScale.SDE, PhysicalScale.VariableRateJump)
706707

707708
"""
708709
has_physical_scale(rx::Reaction)

src/reactionsystem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ Notes:
276276
units). Unit checking can be disabled by passing the keyword argument `checks=false`.
277277
"""
278278
struct ReactionSystem{V <: NetworkProperties} <:
279-
MT.AbstractTimeDependentSystem
279+
MT.AbstractSystem
280280
"""The equations (reactions and algebraic/differential) defining the system."""
281281
eqs::Vector{CatalystEqType}
282282
"""The Reactions defining the system. """
@@ -398,7 +398,7 @@ function ReactionSystem(eqs, iv, unknowns, ps;
398398
name = nothing,
399399
default_u0 = Dict(),
400400
default_p = Dict(),
401-
defaults = _merge(Dict(default_u0), Dict(default_p)),
401+
defaults = merge(Dict(default_u0), Dict(default_p)),
402402
connection_type = nothing,
403403
checks = true,
404404
networkproperties = nothing,

src/reactionsystem_conversions.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ COMPLETENESS_ERROR = "A ReactionSystem must be complete before it can be convert
507507

508508
"""
509509
```julia
510-
Base.convert(::Type{<:ODESystem},rs::ReactionSystem)
510+
Base.convert(::typeof(ODESystem),rs::ReactionSystem)
511511
```
512512
Convert a [`ReactionSystem`](@ref) to an `ModelingToolkit.ODESystem`.
513513
@@ -524,11 +524,11 @@ Keyword args and default values:
524524
with their rational function representation when converting to another system type. Set to
525525
`false`` to disable.
526526
"""
527-
function Base.convert(::Type{<:ODESystem}, rs::ReactionSystem; name = nameof(rs),
527+
function Base.convert(::typeof(ODESystem), rs::ReactionSystem; name = nameof(rs),
528528
combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
529529
include_zero_odes = true, remove_conserved = false, checks = false,
530530
default_u0 = Dict(), default_p = Dict(),
531-
defaults = _merge(Dict(default_u0), Dict(default_p)), expand_catalyst_funs = true,
531+
defaults = merge(Dict(default_u0), Dict(default_p)), expand_catalyst_funs = true,
532532
kwargs...)
533533
# Error checks.
534534
iscomplete(rs) || error(COMPLETENESS_ERROR)
@@ -544,7 +544,7 @@ function Base.convert(::Type{<:ODESystem}, rs::ReactionSystem; name = nameof(rs)
544544
ODESystem(eqs, get_iv(fullrs), us, ps;
545545
observed = obs,
546546
name,
547-
defaults = _merge(defaults, defs),
547+
defaults = merge(defaults, defs),
548548
checks,
549549
continuous_events = MT.get_continuous_events(fullrs),
550550
discrete_events = MT.get_discrete_events(fullrs),
@@ -569,7 +569,7 @@ end
569569

570570
"""
571571
```julia
572-
Base.convert(::Type{<:NonlinearSystem},rs::ReactionSystem)
572+
Base.convert(::typeof(NonlinearSystem),rs::ReactionSystem)
573573
```
574574
575575
Convert a [`ReactionSystem`](@ref) to an `ModelingToolkit.NonlinearSystem`.
@@ -592,11 +592,11 @@ Keyword args and default values:
592592
with their rational function representation when converting to another system type. Set to
593593
`false`` to disable.
594594
"""
595-
function Base.convert(::Type{<:NonlinearSystem}, rs::ReactionSystem; name = nameof(rs),
595+
function Base.convert(::typeof(NonlinearSystem), rs::ReactionSystem; name = nameof(rs),
596596
combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
597597
remove_conserved = false, conseqs_remake_warn = true, checks = false,
598598
default_u0 = Dict(), default_p = Dict(),
599-
defaults = _merge(Dict(default_u0), Dict(default_p)),
599+
defaults = merge(Dict(default_u0), Dict(default_p)),
600600
all_differentials_permitted = false, expand_catalyst_funs = true, kwargs...)
601601
# Error checks.
602602
iscomplete(rs) || error(COMPLETENESS_ERROR)
@@ -625,7 +625,7 @@ function Base.convert(::Type{<:NonlinearSystem}, rs::ReactionSystem; name = name
625625
NonlinearSystem(eqs, us, ps;
626626
name,
627627
observed = obs, initialization_eqs = initeqs,
628-
defaults = _merge(defaults, defs),
628+
defaults = merge(defaults, defs),
629629
checks,
630630
kwargs...)
631631
end
@@ -661,7 +661,7 @@ end
661661

662662
"""
663663
```julia
664-
Base.convert(::Type{<:SDESystem},rs::ReactionSystem)
664+
Base.convert(::typeof(SDESystem),rs::ReactionSystem)
665665
```
666666
667667
Convert a [`ReactionSystem`](@ref) to an `ModelingToolkit.SDESystem`.
@@ -679,11 +679,11 @@ Notes:
679679
with their rational function representation when converting to another system type. Set to
680680
`false`` to disable.
681681
"""
682-
function Base.convert(::Type{<:SDESystem}, rs::ReactionSystem;
682+
function Base.convert(::typeof(SDESystem), rs::ReactionSystem;
683683
name = nameof(rs), combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
684684
include_zero_odes = true, checks = false, remove_conserved = false,
685685
default_u0 = Dict(), default_p = Dict(),
686-
defaults = _merge(Dict(default_u0), Dict(default_p)),
686+
defaults = merge(Dict(default_u0), Dict(default_p)),
687687
expand_catalyst_funs = true,
688688
kwargs...)
689689
# Error checks.
@@ -707,7 +707,7 @@ function Base.convert(::Type{<:SDESystem}, rs::ReactionSystem;
707707
SDESystem(eqs, noiseeqs, get_iv(flatrs), us, ps;
708708
observed = obs,
709709
name,
710-
defaults = _merge(defaults, defs),
710+
defaults = merge(defaults, defs),
711711
checks,
712712
continuous_events = MT.get_continuous_events(flatrs),
713713
discrete_events = MT.get_discrete_events(flatrs),
@@ -747,7 +747,7 @@ end
747747

748748
"""
749749
```julia
750-
Base.convert(::Type{<:JumpSystem},rs::ReactionSystem; combinatoric_ratelaws=true)
750+
Base.convert(::typeof(JumpSystem),rs::ReactionSystem; combinatoric_ratelaws=true)
751751
```
752752
753753
Convert a [`ReactionSystem`](@ref) to an `ModelingToolkit.JumpSystem`.
@@ -769,10 +769,10 @@ Notes:
769769
`VariableRateJump` to save the solution before and/or after the jump occurs. Defaults to
770770
true for both.
771771
"""
772-
function Base.convert(::Type{<:JumpSystem}, rs::ReactionSystem; name = nameof(rs),
772+
function Base.convert(::typeof(JumpSystem), rs::ReactionSystem; name = nameof(rs),
773773
combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
774774
remove_conserved = nothing, checks = false, default_u0 = Dict(), default_p = Dict(),
775-
defaults = _merge(Dict(default_u0), Dict(default_p)), expand_catalyst_funs = true,
775+
defaults = merge(Dict(default_u0), Dict(default_p)), expand_catalyst_funs = true,
776776
save_positions = (true, true), physical_scales = nothing, kwargs...)
777777
iscomplete(rs) || error(COMPLETENESS_ERROR)
778778
spatial_convert_err(rs::ReactionSystem, JumpSystem)
@@ -814,7 +814,7 @@ function Base.convert(::Type{<:JumpSystem}, rs::ReactionSystem; name = nameof(rs
814814
JumpSystem(eqs, get_iv(flatrs), us, ps;
815815
observed = obs,
816816
name,
817-
defaults = _merge(defaults, defs),
817+
defaults = merge(defaults, defs),
818818
checks,
819819
discrete_events = MT.discrete_events(flatrs),
820820
continuous_events = MT.continuous_events(flatrs),
@@ -923,7 +923,7 @@ Inputs for a JumpProblem from a given `ReactionSystem`.
923923
# Fields
924924
$(FIELDS)
925925
"""
926-
struct JumpInputs{S <: MT.JumpSystem, T <: SciMLBase.AbstractODEProblem}
926+
struct JumpInputs{S <: MT.AbstractSystem, T <: SciMLBase.AbstractODEProblem}
927927
"""The `JumpSystem` to define the problem over"""
928928
sys::S
929929
"""The problem the JumpProblem should be defined over, for example DiscreteProblem"""

src/reactionsystem_serialisation/serialise_fields.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,15 @@ function handle_us_n_ps(file_text::String, rn::ReactionSystem, annotate::Bool,
102102
while !(isempty(remaining_ps) && isempty(remaining_sps) && isempty(remaining_vars))
103103
# Checks which parameters/species/variables can be written. The `dependency_split`
104104
# function updates the `remaining_` input.
105-
writable_ps = dependency_split!(remaining_ps, [remaining_ps; remaining_sps; remaining_vars])
106-
writable_sps = dependency_split!(remaining_sps, [remaining_ps; remaining_sps; remaining_vars])
107-
writable_vars = dependency_split!(remaining_vars, [remaining_ps; remaining_sps; remaining_vars])
105+
writable_ps = dependency_split!(
106+
remaining_ps, [remaining_ps; remaining_sps;
107+
remaining_vars])
108+
writable_sps = dependency_split!(
109+
remaining_sps, [remaining_ps; remaining_sps;
110+
remaining_vars])
111+
writable_vars = dependency_split!(
112+
remaining_vars, [remaining_ps; remaining_sps;
113+
remaining_vars])
108114

109115
# Writes those that can be written.
110116
isempty(writable_ps) ||
@@ -427,7 +433,8 @@ function get_continuous_events_annotation(rn::ReactionSystem)
427433
end
428434

429435
# Combines the 3 -related functions in a constant tuple.
430-
CONTINUOUS_EVENTS_FS = (seri_has_continuous_events, get_continuous_events_string, get_continuous_events_annotation)
436+
CONTINUOUS_EVENTS_FS = (seri_has_continuous_events, get_continuous_events_string,
437+
get_continuous_events_annotation)
431438

432439
### Handles Discrete Events ###
433440

@@ -483,7 +490,8 @@ function get_discrete_events_annotation(rn::ReactionSystem)
483490
end
484491

485492
# Combines the 3 -related functions in a constant tuple.
486-
DISCRETE_EVENTS_FS = (seri_has_discrete_events, get_discrete_events_string, get_discrete_events_annotation)
493+
DISCRETE_EVENTS_FS = (
494+
seri_has_discrete_events, get_discrete_events_string, get_discrete_events_annotation)
487495

488496
### Handles Systems ###
489497

@@ -558,4 +566,5 @@ function get_connection_type_annotation(rn::ReactionSystem)
558566
end
559567

560568
# Combines the 3 connection types-related functions in a constant tuple.
561-
CONNECTION_TYPE_FS = (seri_has_connection_type, get_connection_type_string, get_connection_type_annotation)
569+
CONNECTION_TYPE_FS = (
570+
seri_has_connection_type, get_connection_type_string, get_connection_type_annotation)

src/spatial_reaction_systems/lattice_reaction_systems.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ continuous space systems with them is possible, but requires the user to determi
5757
(the lattice). Better support for continuous space models is a work in progress.
5858
- Catalyst contains extensive documentation on spatial modelling, which can be found [here](https://docs.sciml.ai/Catalyst/stable/spatial_modelling/lattice_reaction_systems/).
5959
"""
60-
struct LatticeReactionSystem{Q, R, S, T} <: MT.AbstractTimeDependentSystem
60+
struct LatticeReactionSystem{Q, R, S, T} <: MT.AbstractSystem
6161
# Input values.
6262
"""The (non-spatial) reaction system within each vertex."""
6363
reactionsystem::ReactionSystem{Q}

0 commit comments

Comments
 (0)