Skip to content

Fix NonlinearSolveAlg crashing/stalling with polyalgorithm inner solvers - #3959

Open
singhharsh1708 wants to merge 2 commits into
SciML:masterfrom
singhharsh1708:fix-nonlinearsolvealg-polyalg-3859
Open

Fix NonlinearSolveAlg crashing/stalling with polyalgorithm inner solvers#3959
singhharsh1708 wants to merge 2 commits into
SciML:masterfrom
singhharsh1708:fix-nonlinearsolvealg-polyalg-3859

Conversation

@singhharsh1708

@singhharsh1708 singhharsh1708 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #3859.

NonlinearSolvePolyAlgorithmCache (RobustMultiNewton, FastShortcutNonlinearPolyalg) keeps u/fu on its active subcache, not at top level, so every raw cache.cache.u-style read in newton.jl threw FieldError the moment a polyalgorithm was used as the NonlinearSolveAlg inner solver. Its reinit! also left force_stop/retcode set 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_fu accessors plus the force_stop/retcode reset in reinit!). 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, both compute_step! paths, and the nlstep build_solution — goes through NonlinearSolveBase.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 nlstep build_solution no longer attaches the inner trace (no polyalg accessor exists; the transient solution only feeds nlprobmap).

Regression test nsa_polyalg_tests.jl runs 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_tests will 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.

@singhharsh1708
singhharsh1708 force-pushed the fix-nonlinearsolvealg-polyalg-3859 branch 2 times, most recently from 7dd8e8a to 4ec539e Compare July 25, 2026 19:18
Comment thread lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl Outdated
@singhharsh1708
singhharsh1708 force-pushed the fix-nonlinearsolvealg-polyalg-3859 branch from 4ec539e to 85dd0ef Compare July 30, 2026 20:35
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
singhharsh1708 force-pushed the fix-nonlinearsolvealg-polyalg-3859 branch from 54a5ba9 to 49dec7d Compare July 31, 2026 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NonlinearSolveAlg: NonlinearSolve polyalg inner solvers crash (FieldError: PolyAlgorithmCache has no field u)

2 participants