Repository navigation
Guard against infinite recursion when NonlinearProblem(prob) makes no progress - #1327
Closed
ChrisRackauckas-Claude wants to merge 1 commit into
Closed
ChrisRackauckas-Claude wants to merge 1 commit into
ChrisRackauckas-Claude wants to merge 1 commit into
Conversation
… progress SciMLBase.__init/__solve for an AbstractSteadyStateProblem with no algorithm convert via SciMLBase.NonlinearProblem(prob) and recurse on the result. That conversion returns some inputs verbatim (a stored NonlinearProblem or LinearProblem lowering already tested elsewhere, or - once SciMLBase.NonlinearProblem(::SCCNonlinearProblem) is an identity, see SciML/SciMLBase.jl#1614 - an SCCNonlinearProblem, which has no u0 field to rebuild from). Recursing when nlprob === prob makes no progress and previously stack-overflowed instead of raising a clear error. This guard is a no-op against the currently released SciMLBase, where NonlinearProblem(::SCCNonlinearProblem) still throws a FieldError one line earlier; it only matters once the SciMLBase companion PR ships. See that PR's body for a full fail-before/pass-after trace using a locally `Pkg.develop`'d SciMLBase. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Sonnet <[email protected]> Agent-Harness: Claude Code 2.1.251 (subagent) Agent-Model: claude-sonnet Agent-Session: https://claude.ai/code/session_01NB3oFTNzGW79UtDt8AyjsM
Member
Author
|
Closing: SciMLBase.jl#1614 was changed to have |
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SteadyStateDiffEq.jl
that referenced
this pull request
Oct 7, 2026
…inearSolve DynamicSS and SICNM only had __solve; init(ssprob, DynamicSS(...)) had no matching __init here, so it fell through to NonlinearSolveBase's generic fallback, which treats "no algorithm-specific __init exists" the same as "no algorithm given" and rewrites the call to NonlinearSolve's default-algorithm converter with ::Nothing in place of the algorithm - silently discarding DynamicSS/SICNM. For a plain SteadyStateProblem that converter still finds a NonlinearProblem to solve, so init() "worked" but ignored the requested algorithm; for a SteadyStateProblem whose lowered_problem is an SCCNonlinearProblem, the converter's NonlinearProblem(prob) call hits a FieldError (SCCNonlinearProblem has no u0 field) - the reported CI failure, init(ssprob, DynamicSS(Tsit5())) in SciMLBase.jl's downstream SymbolicIndexingInterface test group. Add SciMLBase.__init(prob::AbstractSteadyStateProblem, alg::DynamicSS/SICNM, ...), mirroring the existing __solve methods (extracted into shared __dynamicss_ode_setup/__sicnm_ode_setup helpers): for a plain problem it returns the live ODE/DAE integrator so init/solve!/step! compose normally; for an SCC lowering there is no single integrator to hand back (blocks solve sequentially), so it eagerly solves via the existing __solve_scc_lowering and returns the finished solution, matching how a stored NonlinearProblem/ LinearProblem lowering is already handled verbatim elsewhere in this file. Being a more specific method than NonlinearSolveBase's generic fallback, this is picked by ordinary dispatch and the buggy conversion path is never reached for these two algorithms - independent of SciML/SciMLBase.jl#1614 (the generic converter itself is fixed separately there and in SciML/NonlinearSolve.jl#1327). Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Sonnet <[email protected]> Agent-Harness: Claude Code 2.1.251 (subagent) Agent-Model: claude-sonnet Agent-Session: https://claude.ai/code/session_01NB3oFTNzGW79UtDt8AyjsM
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SteadyStateDiffEq.jl
that referenced
this pull request
Oct 21, 2026
…inearSolve DynamicSS and SICNM only had __solve; init(ssprob, DynamicSS(...)) had no matching __init here, so it fell through to NonlinearSolveBase's generic fallback, which treats "no algorithm-specific __init exists" the same as "no algorithm given" and rewrites the call to NonlinearSolve's default-algorithm converter with ::Nothing in place of the algorithm - silently discarding DynamicSS/SICNM. For a plain SteadyStateProblem that converter still finds a NonlinearProblem to solve, so init() "worked" but ignored the requested algorithm; for a SteadyStateProblem whose lowered_problem is an SCCNonlinearProblem, the converter's NonlinearProblem(prob) call hits a FieldError (SCCNonlinearProblem has no u0 field) - the reported CI failure, init(ssprob, DynamicSS(Tsit5())) in SciMLBase.jl's downstream SymbolicIndexingInterface test group. Add SciMLBase.__init(prob::AbstractSteadyStateProblem, alg::DynamicSS/SICNM, ...), mirroring the existing __solve methods (extracted into shared __dynamicss_ode_setup/__sicnm_ode_setup helpers): for a plain problem it returns the live ODE/DAE integrator so init/solve!/step! compose normally; for an SCC lowering there is no single integrator to hand back (blocks solve sequentially), so it eagerly solves via the existing __solve_scc_lowering and returns the finished solution, matching how a stored NonlinearProblem/ LinearProblem lowering is already handled verbatim elsewhere in this file. Being a more specific method than NonlinearSolveBase's generic fallback, this is picked by ordinary dispatch and the buggy conversion path is never reached for these two algorithms - independent of SciML/SciMLBase.jl#1614 (the generic converter itself is fixed separately there and in SciML/NonlinearSolve.jl#1327). Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Sonnet <[email protected]> Agent-Harness: Claude Code 2.1.251 (subagent) Agent-Model: claude-sonnet Agent-Session: https://claude.ai/code/session_01NB3oFTNzGW79UtDt8AyjsM
ChrisRackauckas
added a commit
to SciML/SteadyStateDiffEq.jl
that referenced
this pull request
Oct 31, 2026
…inearSolve's default (#173) * Add __init for DynamicSS/SICNM so init() doesn't fall through to NonlinearSolve DynamicSS and SICNM only had __solve; init(ssprob, DynamicSS(...)) had no matching __init here, so it fell through to NonlinearSolveBase's generic fallback, which treats "no algorithm-specific __init exists" the same as "no algorithm given" and rewrites the call to NonlinearSolve's default-algorithm converter with ::Nothing in place of the algorithm - silently discarding DynamicSS/SICNM. For a plain SteadyStateProblem that converter still finds a NonlinearProblem to solve, so init() "worked" but ignored the requested algorithm; for a SteadyStateProblem whose lowered_problem is an SCCNonlinearProblem, the converter's NonlinearProblem(prob) call hits a FieldError (SCCNonlinearProblem has no u0 field) - the reported CI failure, init(ssprob, DynamicSS(Tsit5())) in SciMLBase.jl's downstream SymbolicIndexingInterface test group. Add SciMLBase.__init(prob::AbstractSteadyStateProblem, alg::DynamicSS/SICNM, ...), mirroring the existing __solve methods (extracted into shared __dynamicss_ode_setup/__sicnm_ode_setup helpers): for a plain problem it returns the live ODE/DAE integrator so init/solve!/step! compose normally; for an SCC lowering there is no single integrator to hand back (blocks solve sequentially), so it eagerly solves via the existing __solve_scc_lowering and returns the finished solution, matching how a stored NonlinearProblem/ LinearProblem lowering is already handled verbatim elsewhere in this file. Being a more specific method than NonlinearSolveBase's generic fallback, this is picked by ordinary dispatch and the buggy conversion path is never reached for these two algorithms - independent of SciML/SciMLBase.jl#1614 (the generic converter itself is fixed separately there and in SciML/NonlinearSolve.jl#1327). Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Sonnet <[email protected]> Agent-Harness: Claude Code 2.1.251 (subagent) Agent-Model: claude-sonnet Agent-Session: https://claude.ai/code/session_01NB3oFTNzGW79UtDt8AyjsM * Update test comment to match SciMLBase's final ArgumentError behavior The comment still described SciMLBase's NonlinearProblem(::SCCNonlinearProblem) conversion as an identity that could recurse forever; it now raises an ArgumentError, and this repo's new __init methods are more specific than the default path anyway, so it is never reached. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Sonnet <[email protected]> Agent-Harness: Claude Code 2.1.251 (subagent) Agent-Model: claude-sonnet Agent-Session: https://claude.ai/code/session_01NB3oFTNzGW79UtDt8AyjsM * Forward save_idxs in DynamicSS/SICNM init; trim comments Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Agent-Harness: Claude Code (subagent of ci-green head) Agent-Model: claude-opus-5-5[1m] Agent-Session: https://claude.ai/code/session_011aK5Xvp9NpdkzKuEwtiMGd * Return steady-state caches from DynamicSS/SICNM init `init(prob, ::DynamicSS/SICNM)` returned the raw ODE integrator, so `solve!` skipped the termination-condition finalization of `solve`: finite-time nonconvergence reported Success and a protective safe termination reported Terminated instead of Unstable. For SCC lowerings `init` returned a finished solution that `solve!` could not accept. `init` now returns a `SteadyStateODECache` (ODE integrator plus the setup holding the termination cache) or a `SteadyStateSCCCache`; `solve!` on either runs the same finalization as `__solve`, and `step!` advances the ODE integrator. Documents the init/solve! contract, including SICNM's extended `[y; z]` integrator state. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Agent-Harness: Claude Code (subagent of ci-green head) Agent-Model: claude-opus-5-5[1m] Agent-Session: https://claude.ai/code/session_011aK5Xvp9NpdkzKuEwtiMGd * Restore steady-state cache indexing and reinitialization Expose symbolic state access and current parameters on DynamicSS/SICNM caches. Rebuild the integration and termination setup on reinitialization so SICNM uses the updated parameters and consistent Newton direction. Cover cache access, repeated solves, termination modes, and solution slicing in Core. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Codex <[email protected]> Agent-Harness: Codex CLI 0.163.0 Agent-Model: gpt-6.1-sol Agent-Session: local session 01a157c8-4f1a-7691-afcc-019806096637 (no session URL) * Allow type-changing steady-state cache reset options Install rebuilt cache state in one assignment so slicing, ODE-option and termination-mode overrides can change concrete types. Preserve cache identity and retain the previous state when initialization fails. Add regressions for option transitions, retained data, failed rebuilds and subsequent reuse. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Codex <[email protected]> Agent-Harness: Codex CLI 0.163.0 Agent-Model: gpt-6.1-sol Agent-Session: local session 01a157c8-4f1a-7691-afcc-019806096637 (no session URL) * Document that step!/reinit!/indexing apply only to the ODE integrator cache Review (Grok, grok-4.7): clarify that step!, reinit!, and symbolic indexing are defined only on SteadyStateODECache; calling any of them on a SteadyStateSCCCache (the SCC-lowering case) throws MethodError, since only solve! is supported on it. Confirmed by running both calls directly. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Sonnet <[email protected]> Agent-Harness: Claude Code 2.1.251 (subagent) Agent-Model: claude-sonnet Agent-Session: https://claude.ai/code/session_01NB3oFTNzGW79UtDt8AyjsM * Restore cache.ps and symbolic state assignment on SteadyStateODECache init caches forwarded :ps to a NamedTuple and had getindex without setindex!, so cache.ps[:a] and cache[:x] = value failed after the wrapper was introduced. Expose the parameter proxy, assign states through setu, and keep SICNM's residual and Newton direction consistent with live parameters after mutation. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent CLI Agent-Model: auto Agent-Session: local fixer job SciML__SteadyStateDiffEq.jl__173 (no session URL) * Accept u0 as a keyword in SteadyStateODECache reinit! reinit!(cache; u0 = ..., p = ...) forwarded the keyword u0 through kwargs to the ODE initializer instead of remake. SICNM then saw an initial state half the extended [y; z] length and threw IncompatibleMassMatrixError, while DynamicSS stored u0 among the persistent initialization options so a later positional reset restarted from the stale keyword value. Consume the keyword through remake and keep it out of the stored ODE options. Fail-before (unfixed head, keyword-then-positional reset probe): DynamicSS keyword reset state=[-3.0] DynamicSS positional reset state=[-3.0] (expected [7.0]) SICNM keyword reset ERROR IncompatibleMassMatrixError Pass-after: DynamicSS keyword reset state=[-3.0] DynamicSS positional reset state=[7.0] SICNM keyword reset state=[-3.0] SICNM positional reset state=[7.0] keyword then positional cache reset | Pass 4 Total 4 The new "keyword u0 cache reset" testset in test/cache_interface.jl covers both algorithms, iip and oop: it fails 22 and errors 4 on the unfixed source and passes after. GROUP=Core and GROUP=QA pass. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> Agent-Harness: Devin CLI 3000.11.228 Agent-Model: swe-2-high Agent-Session: local fixer job SciML__SteadyStateDiffEq.jl__173 (no session URL) * Defer SICNM direction refresh until batched state writes complete Track pending direction synchronization in the steady-state cache. Refresh on state/integrator reads and before stepping or solving, and clear the flag after synchronization or reinitialization. Integrator notification uses the public mutation interface. Add coupled-domain regressions for batched symbolic and direct SII setters, plus scalar changes after stepping. Document deferred synchronization. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Codex <[email protected]> Agent-Harness: Codex CLI 0.164.0 Agent-Model: gpt-6.1-sol Agent-Session: local job 20261028T065010Z-codex-gpt-6.1-sol (no session URL) --------- Co-authored-by: ChrisRackauckas-Claude <[email protected]> Co-authored-by: Claude Sonnet <[email protected]> Co-authored-by: Codex <[email protected]> Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: Devin <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ignore until reviewed by @ChrisRackauckas.
Context
This is a companion to a review finding on SciML/SciMLBase.jl#1614. The original bug report was
GROUP=SymbolicIndexingInterfacered onSciMLBase.jl(CI run https://github.com/SciML/SciMLBase.jl/actions/runs/35839187919):init(ssprob, DynamicSS(Tsit5()))on an MTK-lowered SCC steady-state problem throwsFieldError: type SCCNonlinearProblem has no field u0. A reviewer of the first fix attempt (SciMLBase PR #1614, which addedNonlinearProblem(prob::SCCNonlinearProblem) = prob) found that identity alone turns thatFieldErrorinto an infinite recursion /StackOverflowErroron this repo'ssrc/default.jl:59-62:AbstractSteadyStateProblemis a type alias forAbstractNonlinearProblem, so this method also matches anSCCNonlinearProblem. First call:NonlinearProblem(ssprob)returns the storedSCCNonlinearProblem— correct, and already tested. Second call (recursing on that result):NonlinearProblem(scc)returnssccitself (once SciMLBase's identity ships) — and the method recurses on the same object forever.The actual CI failure is fixed at its real cause in SciML/SteadyStateDiffEq.jl#173 (adding
DynamicSS/SICNM-specific__initthere means this default-algorithm path is never reached for that case — confirmed by testing that SteadyStateDiffEq's fix alone, with today's unmodified SciMLBase and this repo, already resolves the reported failure). This PR is defense-in-depth for the general case: any algorithm without its own__init/__solvefor aSteadyStateProblem, or a bareinit(ssprob)/solve(ssprob)with no algorithm at all, still falls through to this converter.What changed
Guard both
__initand__solveforAbstractSteadyStateProblemwith::Nothing: ifNonlinearProblem(prob)returnsprobunchanged (no progress was made toward an actualNonlinearProblem), raise a clearArgumentErrorinstead of recursing.Verification
This repo's own test suite passes unchanged (
GROUP=Core, tail):The guard's
nlprob === probbranch is unreachable against the currently-released SciMLBase:NonlinearProblem(::SCCNonlinearProblem)still throws aFieldErrorone line earlier there, so this PR is a no-op change today (confirmed: adding a@test_throws ArgumentErrorregression test totest/Core/default_alg_tests__item1.jland runningGROUP=Coreagainst the released SciMLBase reproduces the pre-existingFieldError, not the newArgumentError— so that test was not committed; it cannot pass until SciMLBase/SciMLBase.jl#1614 merges and releases). Instead, verified byPkg.develop-ing this branch together with a local checkout of SciMLBase.jl#1614 (Pkg.developon both) and running:Before this PR (SciMLBase's identity + unmodified NonlinearSolve):
After this PR (SciMLBase's identity + this guard):
What I did not verify / anything to push back on
@test_throws ArgumentErrortest would be the natural next step once that happens).GROUP=Everything/QA suites, onlyGROUP=Core.Runic
--checkandtyposare clean on the changed file (Runic reformatted thethrow(ArgumentError(...))call).Related
🤖 Generated with Claude Code
https://claude.ai/code/session_01NB3oFTNzGW79UtDt8AyjsM