Skip to content
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

Parameter initial conditions broken for DiscreteProblems #3297

Open
TorkelE opened this issue Jan 8, 2025 · 0 comments · May be fixed by #3329
Open

Parameter initial conditions broken for DiscreteProblems #3297

TorkelE opened this issue Jan 8, 2025 · 0 comments · May be fixed by #3329
Assignees
Labels
bug Something isn't working

Comments

@TorkelE
Copy link
Member

TorkelE commented Jan 8, 2025

using ModelingToolkit, JumpProcesses
using ModelingToolkit: t_nounits as t

# Works.
let
    @parameters β γ
    @variables S(t) I(t) R(t)
    rate₁   = β*S*I
    affect₁ = [S ~ S - 1, I ~ I + 1]
    rate₂   = γ*I
    affect₂ = [I ~ I - 1, R ~ R + 1]
    j₁      = ConstantRateJump(rate₁,affect₁)
    j₂      = ConstantRateJump(rate₂,affect₂)
    j₃      = MassActionJump(2*β+γ, [R => 1], [S => 1, R => -1])
    @mtkbuild js      = JumpSystem([j₁,j₂,j₃], t, [S,I,R], [β,γ])

    u0s = [S => 999, I => 1, R => 0]
    ps ==> 0.01, γ => 0.001]
    dprob = DiscreteProblem(js, u0s, (0.0, 10.0), ps)
end

# Errors.
let
    @parameters β γ S0
    @variables S(t) = S0 I(t) R(t)
    rate₁   = β*S*I
    affect₁ = [S ~ S - 1, I ~ I + 1]
    rate₂   = γ*I
    affect₂ = [I ~ I - 1, R ~ R + 1]
    j₁      = ConstantRateJump(rate₁,affect₁)
    j₂      = ConstantRateJump(rate₂,affect₂)
    j₃      = MassActionJump(2*β+γ, [R => 1], [S => 1, R => -1])
    @mtkbuild js      = JumpSystem([j₁,j₂,j₃], t, [S,I,R], [β,γ])

    u0s = [I => 1, R => 0]
    ps = [S0 => 999, β => 0.01, γ => 0.001]
    dprob = DiscreteProblem(js, u0s, (0.0, 10.0), ps) # ERROR: MethodError: no method matching unhack_observed(::Vector{Equation}, ::RecursiveArrayTools.ArrayPartition{Any, Tuple{Vector{MassActionJump}, Vector{ConstantRateJump}, Vector{VariableRateJump}, Vector{Equation}}})
end
ERROR: MethodError: no method matching unhack_observed(::Vector{Equation}, ::RecursiveArrayTools.ArrayPartition{Any, Tuple{…}})
The function `unhack_observed` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  unhack_observed(::Vector{Equation}, ::Vector{Equation})
   @ ModelingToolkit ~/.julia/packages/ModelingToolkit/iQ7So/src/systems/nonlinear/initializesystem.jl:352

Stacktrace:
  [1] generate_initializesystem(sys::JumpSystem{…}; u0map::Dict{…}, pmap::Dict{…}, initialization_eqs::Vector{…}, guesses::Dict{…}, default_dd_guess::Float64, algebraic_only::Bool, check_units::Bool, check_defguess::Bool, name::Symbol, extra_metadata::@NamedTuple{…}, kwargs::@Kwargs{})
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/iQ7So/src/systems/nonlinear/initializesystem.jl:17
  [2] generate_initializesystem
    @ ~/.julia/packages/ModelingToolkit/iQ7So/src/systems/nonlinear/initializesystem.jl:6 [inlined]
  [3] ModelingToolkit.InitializationProblem{…}(sys::JumpSystem{…}, t::Float64, u0map::Dict{…}, parammap::Dict{…}; guesses::Dict{…}, check_length::Bool, warn_initialize_determined::Bool, initialization_eqs::Vector{…}, fully_determined::Nothing, check_units::Bool, use_scc::Bool, kwargs::@Kwargs{…})
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/iQ7So/src/systems/diffeqs/abstractodesystem.jl:1307
  [4] InitializationProblem
    @ ~/.julia/packages/ModelingToolkit/iQ7So/src/systems/diffeqs/abstractodesystem.jl:1285 [inlined]
  [5] #_#1075
    @ ~/.julia/packages/ModelingToolkit/iQ7So/src/systems/diffeqs/abstractodesystem.jl:1263 [inlined]
  [6] InitializationProblem
    @ ~/.julia/packages/ModelingToolkit/iQ7So/src/systems/diffeqs/abstractodesystem.jl:1262 [inlined]
  [7] #InitializationProblem#1073
    @ ~/.julia/packages/ModelingToolkit/iQ7So/src/systems/diffeqs/abstractodesystem.jl:1251 [inlined]
  [8] InitializationProblem
    @ ~/.julia/packages/ModelingToolkit/iQ7So/src/systems/diffeqs/abstractodesystem.jl:1250 [inlined]
  [9] maybe_build_initialization_problem(sys::JumpSystem{…}, op::Dict{…}, u0map::Dict{…}, pmap::Dict{…}, t::Float64, defs::Dict{…}, guesses::Dict{…}, missing_unknowns::Set{…}; implicit_dae::Bool, kwargs::@Kwargs{…})
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/iQ7So/src/systems/problem_utils.jl:546
 [10] maybe_build_initialization_problem
    @ ~/.julia/packages/ModelingToolkit/iQ7So/src/systems/problem_utils.jl:526 [inlined]
 [11] process_SciMLProblem(constructor::Type, sys::JumpSystem{…}, u0map::Vector{…}, pmap::Vector{…}; build_initializeprob::Bool, implicit_dae::Bool, t::Float64, guesses::Dict{…}, warn_initialize_determined::Bool, initialization_eqs::Vector{…}, eval_expression::Bool, eval_module::Module, fully_determined::Nothing, check_initialization_units::Bool, tofloat::Bool, use_union::Bool, u0_constructor::typeof(identity), du0map::Nothing, check_length::Bool, symbolic_u0::Bool, warn_cyclic_dependency::Bool, circular_dependency_max_cycle_length::Int64, circular_dependency_max_cycles::Int64, substitution_limit::Int64, use_scc::Bool, kwargs::@Kwargs{})
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/iQ7So/src/systems/problem_utils.jl:669
 [12] DiscreteProblem(sys::JumpSystem{…}, u0map::Vector{…}, tspan::Tuple{…}, parammap::Vector{…}; use_union::Bool, eval_expression::Bool, eval_module::Module, kwargs::@Kwargs{})
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/iQ7So/src/systems/jumps/jumpsystem.jl:428
 [13] DiscreteProblem(sys::JumpSystem{…}, u0map::Vector{…}, tspan::Tuple{…}, parammap::Vector{…})
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/iQ7So/src/systems/jumps/jumpsystem.jl:414
 [14] top-level scope
    @ ~/Desktop/Julia Playground/Environment - Catalyst only/catalyst_playground.jl:39
Some type information was truncated. Use `show(err)` to see complete types.

Other problem types seems to be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants