Skip to content

Commit 361311e

Browse files
committed
init
1 parent ba1e715 commit 361311e

File tree

9 files changed

+37
-104
lines changed

9 files changed

+37
-104
lines changed

HISTORY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
solver that auto-switches between explicit and implicit methods, install `OrdinaryDiffEqDefault`. To
1414
use `Tsit5` install `OrdinaryDiffEqTsit5`, etc. The possible sub-libraries, each containing different solvers,
1515
can be viewed [here](https://github.com/SciML/OrdinaryDiffEq.jl/tree/master/lib).
16+
- It should now be safe to use `remake` on problems which have had conservation laws removed.
17+
The warning regarding this when eliminating conservation laws have been removed (in conjecture
18+
with the `remove_conserved_warn` argument for disabling this warning).
1619
- New formula for inferring variables from equations (declared using the `@equations` options) in the DSL. The order of inference of species/variables/parameters is now:
1720
(1) Every symbol explicitly declared using `@species`, `@variables`, and `@parameters` are assigned to the correct category.
1821
(2) Every symbol used as a reaction reactant is inferred as a species.

docs/src/model_creation/conservation_laws.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ plot(sol)
6161
!!! note
6262
Any species eliminated using `remove_conserved = true` will not be plotted by default. However, it can be added to the plot using [the `idxs` plotting option](@ref simulation_plotting_options). E.g. here we would use `plot(sol; idxs = [:X₁, :X₂])` to plot both species.
6363

64-
!!! danger
65-
Currently, there is a bug in MTK where the parameters, `Γ`, associated with conservation laws are not updated properly in response to [`remake`](@ref simulation_structure_interfacing_problems_remake) (or [other problem-updating functions, such as `getu`](@ref simulation_structure_interfacing_functions)). Hence, problems created using `remove_conserved = true` *should not* be modified, i.e. by changing initial conditions or the values of the `Γ`'s directly. Instead, to change these values new problems must be generated with the new initial condition map.
66-
6764
While `X₂` is an observable (and not unknown) of the ODE, we can [access it](@ref simulation_structure_interfacing_problems) just like if `remove_conserved = true` had not been used:
6865
```@example conservation_laws
6966
sol[:X₂]

ext/CatalystBifurcationKitExtension/bifurcation_kit_extension.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ function bkext_make_nsys(rs, u0)
3737
cons_default = [cons_eq.rhs for cons_eq in cons_eqs]
3838
cons_default = Catalyst.get_networkproperties(rs).conservedconst => cons_default
3939
defaults = Dict([u0; cons_default])
40-
nsys = convert(NonlinearSystem, rs; defaults,
41-
remove_conserved = true, remove_conserved_warn = false)
40+
nsys = convert(NonlinearSystem, rs; defaults, remove_conserved = true)
4241
return complete(nsys)
4342
end

ext/CatalystHomotopyContinuationExtension/homotopy_continuation_extension.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ function steady_state_polynomial(rs::ReactionSystem, ps, u0)
5151
# Creates the appropriate nonlinear system, and converts parameters to a form that can
5252
# be substituted in later.
5353
rs = Catalyst.expand_registered_functions(rs)
54-
ns = complete(convert(NonlinearSystem, rs;
55-
remove_conserved = true, remove_conserved_warn = false))
54+
ns = complete(convert(NonlinearSystem, rs; remove_conserved = true))
5655
pre_varmap = [symmap_to_varmap(rs, u0)..., symmap_to_varmap(rs, ps)...]
5756
Catalyst.conservationlaw_errorcheck(rs, pre_varmap)
5857
p_dict = make_p_val_dict(pre_varmap, rs, ns)

ext/CatalystStructuralIdentifiabilityExtension/structural_identifiability_extension.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function make_osys(rs::ReactionSystem; remove_conserved = true)
169169
error("Identifiability should only be computed for complete systems. A ReactionSystem can be marked as complete using the `complete` function.")
170170
end
171171
rs = complete(Catalyst.expand_registered_functions(flatten(rs)))
172-
osys = complete(convert(ODESystem, rs; remove_conserved, remove_conserved_warn = false))
172+
osys = complete(convert(ODESystem, rs; remove_conserved))
173173
vars = [unknowns(rs); parameters(rs)]
174174

175175
# Computes equations for system conservation laws.

src/reactionsystem_conversions.jl

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -449,21 +449,6 @@ diff_2_zero(expr) = (Symbolics.is_derivative(expr) ? 0 : expr)
449449

450450
COMPLETENESS_ERROR = "A ReactionSystem must be complete before it can be converted to other system types. A ReactionSystem can be marked as complete using the `complete` function."
451451

452-
# Used to, when required, display a warning about conservation law removal and remake.
453-
function check_cons_warning(remove_conserved, remove_conserved_warn)
454-
(remove_conserved && remove_conserved_warn) || return
455-
@warn "You are creating a system or problem while eliminating conserved quantities. Please note,
456-
due to limitations / design choices in ModelingToolkit if you use the created system to
457-
create a problem (e.g. an `ODEProblem`), or are directly creating a problem, you *should not*
458-
modify that problem's initial conditions for species (e.g. using `remake`). Changing initial
459-
conditions must be done by creating a new Problem from your reaction system or the
460-
ModelingToolkit system you converted it into with the new initial condition map.
461-
Modification of parameter values is still possible, *except* for the modification of any
462-
conservation law constants ($CONSERVED_CONSTANT_SYMBOL), which is not possible. You might
463-
get this warning when creating a problem directly.
464-
465-
You can remove this warning by setting `remove_conserved_warn = false`."
466-
end
467452

468453
### System Conversions ###
469454

@@ -482,19 +467,16 @@ Keyword args and default values:
482467
- `remove_conserved=false`, if set to `true` will calculate conservation laws of the
483468
underlying set of reactions (ignoring constraint equations), and then apply them to reduce
484469
the number of equations.
485-
- `remove_conserved_warn = true`: If `true`, if also `remove_conserved = true`, there will be
486-
a warning regarding limitations of modifying problems generated from the created system.
487470
"""
488471
function Base.convert(::Type{<:ODESystem}, rs::ReactionSystem; name = nameof(rs),
489472
combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
490-
include_zero_odes = true, remove_conserved = false, remove_conserved_warn = true,
473+
include_zero_odes = true, remove_conserved = false,
491474
checks = false, default_u0 = Dict(), default_p = Dict(),
492475
defaults = _merge(Dict(default_u0), Dict(default_p)),
493476
kwargs...)
494477
# Error checks.
495478
iscomplete(rs) || error(COMPLETENESS_ERROR)
496479
spatial_convert_err(rs::ReactionSystem, ODESystem)
497-
check_cons_warning(remove_conserved, remove_conserved_warn)
498480

499481
fullrs = Catalyst.flatten(rs)
500482
remove_conserved && conservationlaws(fullrs)
@@ -529,19 +511,15 @@ Keyword args and default values:
529511
- `remove_conserved=false`, if set to `true` will calculate conservation laws of the
530512
underlying set of reactions (ignoring constraint equations), and then apply them to reduce
531513
the number of equations.
532-
- `remove_conserved_warn = true`: If `true`, if also `remove_conserved = true`, there will be
533-
a warning regarding limitations of modifying problems generated from the created system.
534514
"""
535515
function Base.convert(::Type{<:NonlinearSystem}, rs::ReactionSystem; name = nameof(rs),
536516
combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
537517
include_zero_odes = true, remove_conserved = false, checks = false,
538-
remove_conserved_warn = true, default_u0 = Dict(), default_p = Dict(),
539-
defaults = _merge(Dict(default_u0), Dict(default_p)),
518+
default_u0 = Dict(), default_p = Dict(), defaults = _merge(Dict(default_u0), Dict(default_p)),
540519
all_differentials_permitted = false, kwargs...)
541520
# Error checks.
542521
iscomplete(rs) || error(COMPLETENESS_ERROR)
543522
spatial_convert_err(rs::ReactionSystem, NonlinearSystem)
544-
check_cons_warning(remove_conserved, remove_conserved_warn)
545523
if !isautonomous(rs)
546524
error("Attempting to convert a non-autonomous `ReactionSystem` (e.g. where some rate depend on $(get_iv(rs))) to a `NonlinearSystem`. This is not possible. if you are intending to compute system steady states, consider creating and solving a `SteadyStateProblem.")
547525
end
@@ -612,19 +590,15 @@ Notes:
612590
- `remove_conserved=false`, if set to `true` will calculate conservation laws of the
613591
underlying set of reactions (ignoring constraint equations), and then apply them to reduce
614592
the number of equations.
615-
- `remove_conserved_warn = true`: If `true`, if also `remove_conserved = true`, there will be
616-
a warning regarding limitations of modifying problems generated from the created system.
617593
"""
618594
function Base.convert(::Type{<:SDESystem}, rs::ReactionSystem;
619595
name = nameof(rs), combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
620596
include_zero_odes = true, checks = false, remove_conserved = false,
621-
remove_conserved_warn = true, default_u0 = Dict(), default_p = Dict(),
622-
defaults = _merge(Dict(default_u0), Dict(default_p)),
597+
default_u0 = Dict(), default_p = Dict(), defaults = _merge(Dict(default_u0), Dict(default_p)),
623598
kwargs...)
624599
# Error checks.
625600
iscomplete(rs) || error(COMPLETENESS_ERROR)
626601
spatial_convert_err(rs::ReactionSystem, SDESystem)
627-
check_cons_warning(remove_conserved, remove_conserved_warn)
628602

629603
flatrs = Catalyst.flatten(rs)
630604

@@ -708,12 +682,12 @@ function DiffEqBase.ODEProblem(rs::ReactionSystem, u0, tspan,
708682
p = DiffEqBase.NullParameters(), args...;
709683
check_length = false, name = nameof(rs),
710684
combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
711-
include_zero_odes = true, remove_conserved = false, remove_conserved_warn = true,
712-
checks = false, structural_simplify = false, kwargs...)
685+
include_zero_odes = true, remove_conserved = false, checks = false,
686+
structural_simplify = false, kwargs...)
713687
u0map = symmap_to_varmap(rs, u0)
714688
pmap = symmap_to_varmap(rs, p)
715689
osys = convert(ODESystem, rs; name, combinatoric_ratelaws, include_zero_odes, checks,
716-
remove_conserved, remove_conserved_warn)
690+
remove_conserved)
717691

718692
# Handles potential differential algebraic equations (which requires `structural_simplify`).
719693
if structural_simplify
@@ -732,12 +706,12 @@ function DiffEqBase.NonlinearProblem(rs::ReactionSystem, u0,
732706
p = DiffEqBase.NullParameters(), args...;
733707
name = nameof(rs), include_zero_odes = true,
734708
combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
735-
remove_conserved = false, remove_conserved_warn = true, checks = false,
736-
check_length = false, all_differentials_permitted = false, kwargs...)
709+
remove_conserved = false, checks = false, check_length = false,
710+
all_differentials_permitted = false, kwargs...)
737711
u0map = symmap_to_varmap(rs, u0)
738712
pmap = symmap_to_varmap(rs, p)
739713
nlsys = convert(NonlinearSystem, rs; name, combinatoric_ratelaws, include_zero_odes,
740-
checks, all_differentials_permitted, remove_conserved, remove_conserved_warn)
714+
checks, all_differentials_permitted, remove_conserved)
741715
nlsys = complete(nlsys)
742716
return NonlinearProblem(nlsys, u0map, pmap, args...; check_length,
743717
kwargs...)
@@ -748,11 +722,11 @@ function DiffEqBase.SDEProblem(rs::ReactionSystem, u0, tspan,
748722
p = DiffEqBase.NullParameters(), args...;
749723
name = nameof(rs), combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
750724
include_zero_odes = true, checks = false, check_length = false, remove_conserved = false,
751-
remove_conserved_warn = true, structural_simplify = false, kwargs...)
725+
structural_simplify = false, kwargs...)
752726
u0map = symmap_to_varmap(rs, u0)
753727
pmap = symmap_to_varmap(rs, p)
754728
sde_sys = convert(SDESystem, rs; name, combinatoric_ratelaws,
755-
include_zero_odes, checks, remove_conserved, remove_conserved_warn)
729+
include_zero_odes, checks, remove_conserved)
756730

757731
# Handles potential differential algebraic equations (which requires `structural_simplify`).
758732
if structural_simplify
@@ -876,12 +850,12 @@ function DiffEqBase.SteadyStateProblem(rs::ReactionSystem, u0,
876850
p = DiffEqBase.NullParameters(), args...;
877851
check_length = false, name = nameof(rs),
878852
combinatoric_ratelaws = get_combinatoric_ratelaws(rs),
879-
remove_conserved = false, remove_conserved_warn = true, include_zero_odes = true,
880-
checks = false, structural_simplify = false, kwargs...)
853+
remove_conserved = false, include_zero_odes = true, checks = false,
854+
structural_simplify = false, kwargs...)
881855
u0map = symmap_to_varmap(rs, u0)
882856
pmap = symmap_to_varmap(rs, p)
883857
osys = convert(ODESystem, rs; name, combinatoric_ratelaws, include_zero_odes, checks,
884-
remove_conserved, remove_conserved_warn)
858+
remove_conserved)
885859

886860
# Handles potential differential algebraic equations (which requires `structural_simplify`).
887861
if structural_simplify

src/steady_state_stability.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function steady_state_jac(rs::ReactionSystem; u0 = [sp => 0.0 for sp in unknowns
118118
# Creates an `ODEProblem` with a Jacobian. Dummy values for `u0` and `ps` must be provided.
119119
ps = [p => 0.0 for p in parameters(rs)]
120120
return ODEProblem(rs, u0, 0, ps; jac = true, combinatoric_ratelaws,
121-
remove_conserved = true, remove_conserved_warn = false)
121+
remove_conserved = true)
122122
end
123123

124124
# Converts a `u` vector from a vector of values to a map.

0 commit comments

Comments
 (0)