NSA: gate iter-1 convergence on inner solver retcode (#3817)#3893
Open
singhharsh1708 wants to merge 1 commit into
Open
NSA: gate iter-1 convergence on inner solver retcode (#3817)#3893singhharsh1708 wants to merge 1 commit into
singhharsh1708 wants to merge 1 commit into
Conversation
Member
|
don't stack this |
singhharsh1708
force-pushed
the
nsa-trustregion-ndz-convergence-3817
branch
from
July 13, 2026 17:30
4f63a59 to
eae4139
Compare
Contributor
Author
done. |
singhharsh1708
force-pushed
the
nsa-trustregion-ndz-convergence-3817
branch
3 times, most recently
from
July 17, 2026 02:10
adbd943 to
8628e6d
Compare
singhharsh1708
force-pushed
the
nsa-trustregion-ndz-convergence-3817
branch
from
July 18, 2026 07:33
8628e6d to
7718a44
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 #3817. Standalone on master.
Bug
nlsolve!has an iteration-1 shortcut:ndzis the displacement of the iterate. For a plain (modified-)Newton inner solver a tiny first-iterate displacement means the initial guess was already the solution, so the shortcut is sound. For a globalized inner solver it is not: aTrustRegionstep that gets rejected or truncated leaves the iterate essentially unmoved, which produces the same tinyndzwhile the solver has not actually decided anything. The outer loop reads that as convergence and accepts the stage with no correction applied.Reproduced on current master, Robertson with an analytic jac,
FBDF + NonlinearSolveAlg(TrustRegion()), fixeddt = 1.0:Every step "converges" instantly, the state never changes, and the solve reports
Success.NonlinearSolveAlg(NewtonRaphson())on the same problem correctly reportsConvergenceFailure.Fix
Only take the iter-1 shortcut when the inner cache's own retcode says it actually converged:
Iterations past the first derive
η/θfrom real step history and are not vulnerable to the false positive, so they are untouched — an earlier attempt that also gated theη * ndz < κbranch cost roughly one extra outer iteration per solve and pushed marginal solves over the defaultmax_iter = 10, so the gate is deliberately confined toiter == 1.The predicate excludes
AbstractSimpleNonlinearSolveAlgorithminner algs. Those caches are solved to completion rather than stepped and never update their own retcode, so without the exclusion they would lose the shortcut and run two full inner solves per stage.Result
TrustRegion now reaches the same verdict as NewtonRaphson everywhere tested — no more silent
Successon a frozen state:Success, u frozen at u0ConvergenceFailureConvergenceFailureSuccess, u frozen at u0ConvergenceFailureConvergenceFailureSuccess, u frozen at u0ConvergenceFailureConvergenceFailureSuccess, u frozen at u0ConvergenceFailureConvergenceFailureWhere the solves genuinely do converge (
dt = 2^-15 … 2^-18), results are bit-identical to before the change, with no extra f-evals.Tests
Two testsets added to
nsa_jacobian_reuse_tests.jl: one asserting a frozen state is never reported as a successful solve and that TrustRegion agrees with NewtonRaphson on the verdict, one asserting TrustRegion still converges to the reference where it should. Both fail on master and pass with this change.The
OrdinaryDiffEqNonlinearSolvesuite passes, as doesOrdinaryDiffEqMultirate(88/88), which sharesnlsolve!for its implicit MRI-GARK stages.AI Disclosure
Claude assisted with this work.