Skip to content

Document that the termination modes receive the residual, not the increment - #1179

Draft
ChrisRackauckas-Claude wants to merge 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:term-docs
Draft

Document that the termination modes receive the residual, not the increment#1179
ChrisRackauckas-Claude wants to merge 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:term-docs

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Aug 18, 2026

Copy link
Copy Markdown
Member

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 u is "the increment computed by the nonlinear solver". It is not: every solver in this package passes cache.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 Δu is the increment, because Δu + u is 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‖:

case ‖F‖ ‖u‖ objective
residual small, u large 1e-6 1e+3 1.0e-9 — fires, but only because ‖u‖ is large
residual small, u tiny 1e-6 1e-9 0.999 — converged, will not fire
u ≈ -F 1e0 1e0 6.0e+23 — denominator cancels

So 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 reltol has no effect on a NonlinearProblem, 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); only abstol moves them.

Docs only, no behaviour change. Runic clean.

🤖 Generated with Claude Code

Follow-up: SciMLStyle contract documentation

Commit 35e11e99 expands the generated termination-mode docstrings without changing solver code or termination behavior. The docs now use r = f(u) in the criteria, document the cache arguments and Boolean result separately from solver return codes, list internalnorm and every safe-mode keyword/default, describe Success/Unstable/Stalled/StalledSuccess, and provide examples for all nine modes. It also corrects the norm constructor signature and the termination-guide init example.

Focused verification:

  • all nine modes constructed and solved a nonlinear problem with ReturnCode.Success;
  • generated-doc inspection found # Returns and # Examples on all nine modes, # Arguments on norm constructors, and # Keywords on safe modes;
  • Runic.format_string check: pass;
  • typos lib/NonlinearSolveBase/src/public.jl docs/src/basics/termination_condition.md: pass;
  • git diff --check: pass;
  • isolated NonlinearSolveBase QA: 20/20 passed;
  • focused Documenter build of the termination page: doctests and rendering passed. The repository-wide docs build was not used as a gate because it remained in the unrelated full-site doctest/render pass.

…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>
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
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.

2 participants