Fix NonlinearSolveAlg crashing/stalling with polyalgorithm inner solvers - #3959
Open
singhharsh1708 wants to merge 2 commits into
Open
Fix NonlinearSolveAlg crashing/stalling with polyalgorithm inner solvers#3959singhharsh1708 wants to merge 2 commits into
singhharsh1708 wants to merge 2 commits into
Conversation
singhharsh1708
force-pushed
the
fix-nonlinearsolvealg-polyalg-3859
branch
2 times, most recently
from
July 25, 2026 19:18
7dd8e8a to
4ec539e
Compare
singhharsh1708
force-pushed
the
fix-nonlinearsolvealg-polyalg-3859
branch
from
July 30, 2026 20:35
4ec539e to
85dd0ef
Compare
NonlinearSolvePolyAlgorithmCache (RobustMultiNewton, FastShortcutNonlinearPolyalg, ...) keeps u/fu on the active branch cache instead of as top-level fields, so every raw cache.cache.u-style read in newton.jl threw a FieldError. Read the inner iterate and residual through NonlinearSolveBase.get_u/get_fu, which resolve to the active branch for polyalgorithm caches and are plain field reads otherwise. The nlstep solution no longer carries the inner trace: it only feeds nlprobmap, and polyalgorithm caches expose no accessor for a trace. A second bug lived upstream: the polyalgorithm cache's reinit! left force_stop/retcode set once any branch had converged, so every later step! short-circuited on not_terminated and silently reused a stale iterate. NonlinearSolveBase 2.39 resets both in reinit!, so no local reset is needed; the compat floor bump follows once it is registered.
singhharsh1708
force-pushed
the
fix-nonlinearsolvealg-polyalg-3859
branch
from
July 31, 2026 20:09
54a5ba9 to
49dec7d
Compare
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.
Fixes #3859.
NonlinearSolvePolyAlgorithmCache(RobustMultiNewton, FastShortcutNonlinearPolyalg) keepsu/fuon its active subcache, not at top level, so every rawcache.cache.u-style read in newton.jl threwFieldErrorthe moment a polyalgorithm was used as theNonlinearSolveAlginner solver. Itsreinit!also leftforce_stop/retcodeset after a branch converged once, so a step!-driven loop silently no-oped forever after and reused a stale iterate.Per review, both problems are fixed at the interface level in NonlinearSolve.jl#1115 (merged approach: polyalg
get_u/get_fuaccessors plus theforce_stop/retcodereset inreinit!). This PR is now just the consumer side: every polyalg-unsafe inner-cache read in newton.jl — the resize length check, the stale-W rhs rescale from #4028, bothcompute_step!paths, and the nlstepbuild_solution— goes throughNonlinearSolveBase.get_u/get_fu. No local workaround remains. Top-level fields the polyalg cache genuinely has (retcode,stats,prob,alg) are read as before. The nlstepbuild_solutionno longer attaches the inner trace (no polyalg accessor exists; the transient solution only feedsnlprobmap).Regression test
nsa_polyalg_tests.jlruns TRBDF2 and FBDF with a RobustMultiNewton inner solver and checks both against the analytic solution of a stiff linear system to 1e-4, plus retcodes. Against a locally dev'd NonlinearSolveBase 2.39.0: 8/8, plus newton_tests 6/6 and nsa_jacobian_reuse_tests 11/11 unchanged. The #3859 MWE solves correctly (poly relerr 9.6e-3 at default tolerances vs 4.7e-2 for the NewtonRaphson control; 5.9e-6 at reltol=1e-8).Not mergeable until NonlinearSolve.jl#1115 merges and NonlinearSolveBase 2.39.0 is registered — registry 2.38.1 lacks the polyalg accessor dispatch, so
nsa_polyalg_testswill fail in CI until then. The compat floor bump to"2.39"is deliberately left out until the version exists in General; I'll push it as the final commit once it registers.AI Disclosure
Claude assisted with this work.