Document that the termination modes receive the residual, not the increment - #1179
Draft
ChrisRackauckas-Claude wants to merge 3 commits into
Draft
Document that the termination modes receive the residual, not the increment#1179ChrisRackauckas-Claude wants to merge 3 commits into
ChrisRackauckas-Claude wants to merge 3 commits into
Conversation
…rement The mode docstrings said the first argument is "the increment computed by the nonlinear solver". It is not: every solver in this package passes `cache.fu`, the residual. The name is inherited from the step-based use of the same machinery in DifferentialEquations.jl. The distinction matters for the relative modes. `‖Δu‖ ≤ reltol·‖Δu + u‖` is the textbook relative-step test when `Δu` is the increment, because `Δu + u` is then the next iterate. Fed the residual instead it compares `‖f(u)‖` against `‖f(u) + u‖`, which is satisfied whenever `‖u‖` is large, is not satisfied for a converged solve with a small `‖u‖`, and diverges when `u ≈ -f(u)` makes the denominator cancel. Documented with a warning rather than changed, since changing it is a behaviour change for every user of those modes. Also notes that `reltol` has no effect on a `NonlinearProblem`, whose default mode is absolute. Refs SciML#1149. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
ChrisRackauckas-Claude
force-pushed
the
term-docs
branch
from
August 20, 2026 17:43
9bc5621 to
0365b63
Compare
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
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.
Follow-up to #1149, which was closed after #1176 merged — but this half did not make it in. It was pushed to the same branch shortly after the merge, so master still carries the incorrect claim in two places.
The mode docstrings say
\Delta uis "the increment computed by the nonlinear solver". It is not: every solver in this package passescache.fu, the residual. The naming is inherited from the step-based use of the same machinery in DifferentialEquations.jl.The distinction is what #1149 was reported over.
‖Δu‖ ≤ reltol·‖Δu + u‖is the textbook relative-step test whenΔuis the increment, becauseΔu + uis then the next iterate — the formula was never wrong, it is being handed the wrong vector. Fed the residual it compares‖f(u)‖against‖f(u) + u‖:ularge‖u‖is largeutinyu ≈ -FSo this documents the modes accurately and adds a warning pointing at #1149, rather than changing the semantics — that is a behaviour change for every user of those modes and wants a decision. The issue reporter has endorsed redefining them as a relative-residual test (
‖F(u)‖ ≤ reltol·‖F(u₀)‖) and additionally suggests a gradient-based criterion (‖Jᵀ F‖) for least-squares, which is the Nocedal & Wright convention and does not degenerate when the residual is nonzero at the solution. Neither is in this PR.Also documents that
reltolhas no effect on aNonlinearProblem, whose default mode is absolute — verified:reltol ∈ {1e-1, 1e-3, 1e-8}gives identical iterations (5), f-evaluations (5) and residual (4.75e-14); onlyabstolmoves them.Docs only, no behaviour change. Runic clean.
🤖 Generated with Claude Code
Follow-up: SciMLStyle contract documentation
Commit
35e11e99expands the generated termination-mode docstrings without changing solver code or termination behavior. The docs now user = f(u)in the criteria, document the cache arguments and Boolean result separately from solver return codes, listinternalnormand every safe-mode keyword/default, describeSuccess/Unstable/Stalled/StalledSuccess, and provide examples for all nine modes. It also corrects the norm constructor signature and the termination-guideinitexample.Focused verification:
ReturnCode.Success;# Returnsand# Exampleson all nine modes,# Argumentson norm constructors, and# Keywordson safe modes;Runic.format_stringcheck: pass;typos lib/NonlinearSolveBase/src/public.jl docs/src/basics/termination_condition.md: pass;git diff --check: pass;NonlinearSolveBaseQA:20/20passed;