Skip to content

remake no longer works for ODE-jump models #3571

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

Closed
isaacsas opened this issue Apr 17, 2025 · 1 comment · Fixed by #3581
Closed

remake no longer works for ODE-jump models #3571

isaacsas opened this issue Apr 17, 2025 · 1 comment · Fixed by #3581
Assignees
Labels
bug Something isn't working

Comments

@isaacsas
Copy link
Member

isaacsas commented Apr 17, 2025

The following worked on 9.69 but does not work on 9.72:

using ModelingToolkit, JumpProcesses
t = ModelingToolkit.t_nounits
D = ModelingToolkit.D_nounits
@variables X(t)
@parameters a b
eq = D(X) ~ a
rate = b*X
affect = [X ~ X - 1]
crj = ConstantRateJump(rate, affect)
@named jsys = JumpSystem([crj, eq], t, [X], [a,b])
jsys = complete(jsys)
oprob = ODEProblem(jsys, [:X => 1.0], (0.0, 10.0), [:a => 1.0, :b => .5])
jprob = JumpProblem(jsys, oprob)  
jprob2 = remake(jprob; u0 = [:X => 10.0]) 

gives

ERROR: UndefVarError: `X(t)` not defined in local scope
Suggestion: check for an assignment to a local variable that shadows a global of the same name.
Stacktrace:
  [1] macro expansion
    @ ~/.julia/packages/SymbolicUtils/NGWJM/src/code.jl:411 [inlined]
  [2] macro expansion
    @ ~/.julia/packages/Symbolics/B6Z8m/src/build_function.jl:366 [inlined]
  [3] macro expansion
    @ ~/.julia/packages/RuntimeGeneratedFunctions/M9ZX8/src/RuntimeGeneratedFunctions.jl:163 [inlined]
  [4] macro expansion
    @ ./none:0 [inlined]
  [5] generated_callfunc
    @ ./none:0 [inlined]
  [6] (::RuntimeGeneratedFunctions.RuntimeGeneratedFunction{…})(::Nothing, ::MTKParameters{…})
    @ RuntimeGeneratedFunctions ~/.julia/packages/RuntimeGeneratedFunctions/M9ZX8/src/RuntimeGeneratedFunctions.jl:150
  [7] macro expansion
    @ ~/.julia/packages/ModelingToolkit/aau6A/src/systems/codegen_utils.jl:0 [inlined]
  [8] _generated_call(::ModelingToolkit.GeneratedFunctionWrapper{…}, ::Nothing, ::MTKParameters{…})
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/aau6A/src/systems/codegen_utils.jl:262
  [9] (::ModelingToolkit.GeneratedFunctionWrapper{…})(::Nothing, ::Vararg{…})
    @ ModelingToolkit ~/.julia/packages/ModelingToolkit/aau6A/src/systems/codegen_utils.jl:259
 [10] (::SymbolicIndexingInterface.TimeIndependentObservedFunction{…})(::SymbolicIndexingInterface.NotTimeseries, prob::NonlinearProblem{…})
    @ SymbolicIndexingInterface ~/.julia/packages/SymbolicIndexingInterface/3UAF0/src/state_indexing.jl:142
 [11] (::SymbolicIndexingInterface.TimeIndependentObservedFunction{…})(prob::NonlinearProblem{…})
    @ SymbolicIndexingInterface ~/.julia/packages/SymbolicIndexingInterface/3UAF0/src/value_provider_interface.jl:166
 [12] call_composed(fs::Tuple{…}, x::Tuple{…}, kw::@Kwargs{})
    @ Base ./operators.jl:1054
 [13] call_composed
    @ ./operators.jl:1053 [inlined]
 [14] (::ComposedFunction{…})(x::NonlinearProblem{…}; kw::@Kwargs{})
    @ Base ./operators.jl:1050
 [15] get_initial_values(prob::ODEProblem{…}, valp::ODEProblem{…}, f::Function, alg::SciMLBase.OverrideInit{…}, iip::Val{…}; nlsolve_alg::Nothing, abstol::Nothing, reltol::Nothing, kwargs::@Kwargs{})
    @ SciMLBase ~/.julia/packages/SciMLBase/c6Noy/src/initialization.jl:277
 [16] get_initial_values(prob::ODEProblem{…}, valp::ODEProblem{…}, f::Function, alg::SciMLBase.OverrideInit{…}, iip::Val{…})
    @ SciMLBase ~/.julia/packages/SciMLBase/c6Noy/src/initialization.jl:234
 [17] maybe_eager_initialize_problem(prob::ODEProblem{…}, initialization_data::SciMLBase.OverrideInitData{…}, lazy_initialization::Nothing)
    @ SciMLBase ~/.julia/packages/SciMLBase/c6Noy/src/remake.jl:1167
 [18] remake(prob::ODEProblem{…}; f::Missing, u0::Vector{…}, tspan::Missing, p::Missing, kwargs::Missing, interpret_symbolicmap::Bool, build_initializeprob::Type, use_defaults::Bool, lazy_initialization::Nothing, _kwargs::@Kwargs{})
    @ SciMLBase ~/.julia/packages/SciMLBase/c6Noy/src/remake.jl:266
 [19] remake(jprob::JumpProblem{…}; kwargs::@Kwargs{…})
    @ JumpProcesses ~/.julia/packages/JumpProcesses/9lwA6/src/problem.jl:126
 [20] top-level scope
    @ REPL[15]:1
Some type information was truncated. Use `show(err)` to see complete types.

The same error about X(t) is given if one tries to update a parameter

jprob2 = remake(jprob; p = [:a => 10.0])
@isaacsas isaacsas added the bug Something isn't working label Apr 17, 2025
@isaacsas isaacsas changed the title remake doesn't work for ODE-jump models remake no longer works for ODE-jump models Apr 17, 2025
@isaacsas
Copy link
Member Author

Awesome, thanks for the quick fix! We'll add this back into the Catalyst tests too once released.

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