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 <accounts@chrisrackauckas.com> Co-Authored-By: Claude Sonnet <noreply@anthropic.com> 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 |
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