Skip to content

Commit 4f4bb9b

Browse files
Fix UndefVarError for generate_ODENLStepData with nlstep=true
Add a function stub in ModelingToolkitBase that throws a helpful error message when `nlstep=true` is used without ModelingToolkit loaded. ModelingToolkit then overrides this stub with the actual implementation. This fixes the issue where calling `ODEProblem(sys, u0, tspan, p; nlstep=true)` would fail with `UndefVarError: generate_ODENLStepData not defined` because the function was defined in ModelingToolkit but called from ModelingToolkitBase. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 369e793 commit 4f4bb9b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/ModelingToolkitBase/src/problems/odeproblem.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
"""
2+
generate_ODENLStepData(sys, u0, p, mm, nlstep_compile, nlstep_scc)
3+
4+
Generate the NLStep data for implicit ODE solvers. This is a stub that throws an error
5+
if called without ModelingToolkit loaded. The actual implementation is provided by
6+
ModelingToolkit when it is loaded.
7+
"""
8+
function generate_ODENLStepData(sys, u0, p, mm, nlstep_compile, nlstep_scc)
9+
error("""
10+
`nlstep=true` requires ModelingToolkit.jl to be loaded.
11+
Please add `using ModelingToolkit` to your code before creating an ODEProblem with `nlstep=true`.
12+
""")
13+
end
14+
115
@fallback_iip_specialize function SciMLBase.ODEFunction{iip, spec}(
216
sys::System; u0 = nothing, p = nothing, tgrad = false, jac = false,
317
t = nothing, eval_expression = false, eval_module = @__MODULE__, sparse = false,

src/systems/solver_nlprob.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function generate_ODENLStepData(sys::System, u0, p, mm = calculate_massmatrix(sys),
1+
function MTKBase.generate_ODENLStepData(sys::System, u0, p, mm = calculate_massmatrix(sys),
22
nlstep_compile::Bool = true, nlstep_scc::Bool = false)
33
nlsys, outer_tmp, inner_tmp = inner_nlsystem(sys, mm, nlstep_compile)
44
state = ProblemState(; u = u0, p)

0 commit comments

Comments
 (0)