Skip to content

Accept a callable stage predictor on the nlsolve algorithms - #4539

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:callable-stage-predictor-nlsolve
Sep 13, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:callable-stage-predictor-nlsolve

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Implements the restructuring requested in review of #4471 (#4471 (comment)): the callable stage predictor lives in the nonlinear-solver setup instead of the SDIRK stage kernels, so it applies to every implicit method driven through nlsolve!.

  • predictor keyword on NLNewton, NLFunctional, NLAnderson, and NonlinearSolveAlg. The callable guesses the stage value: predictor(uprev, p, t + c*dt, dt) out of place, predictor(upred, uprev, p, t + c*dt, dt) in place.
  • nlsolve! calls apply_predictor!(nlsolver, integrator) once per solve attempt, before initialize!, and maps the stage-value guess onto the solver's iterate z by inverting the residual's ustep map — (u_pred - tmp)/γ for DIRK-style methods, u_pred for COEFFICIENT_MULTISTEP, u_pred - u₀ for DAEFunction. That is the same inverse the MaxOrder/CutoffOrder/VariableOrder enum predictors already apply inside the kernels, so the callable covers DIRK/IMEX RK, QNDF/FBDF/BDF, DAE solvers, and PDIRK uniformly. When both are set, the callable overrides the algorithm's Predictor enum seed.
  • Passing a Predictor enum value as the nlsolve predictor is rejected with a pointer to the algorithm-level option (ImplicitEuler(predictor = Predictor.Linear)), keeping the two same-named but different-typed options unconfusable.
  • HomotopyNonlinearSolveAlg rejects predictor: homotopy continuation starts each stage from the exact λ = 0 anchor rather than an initial guess.
  • When a callable is configured, _perform_step_iip!/_perform_step_oop! in OrdinaryDiffEqSDIRK collapse the kernel's enum seed to the zero fill (Predictor.Trivial) so the interpolant predictors (addsteps!, current_extrapolant, Hermite evaluation) are skipped instead of computed and then overwritten by apply_predictor!. Enum seeding is unchanged when no callable is set. BDF seeds are broadcasts over already-computed history and PDIRK seeds are zero(u), so there is nothing to skip there; StochasticDiffEqImplicit's :interpolant extrapolant has the same dead-work pattern but seeds the stage value amid noise computations and is left for a separate look.
  • Methods not routed through nlsolve! (FIRK/Radau, Nordsieck, Rosenbrock) are unaffected — they run their own iteration loops.

Test plan

  • New test/predictor_tests.jl in OrdinaryDiffEqNonlinearSolve (registered in runtests.jl): 63 tests, all passing locally. Covers ImplicitEuler / TRBDF2 / KenCarp4 / QNDF / FBDF out-of-place and in-place, all four nlsolve backends, per-stage seed landing and stage times, a DImplicitEuler DAE solve, an exact-seed iteration-count reduction, callable-overrides-enum precedence, and the rejection errors.
  • newton_tests.jl, dae_initialization_tests.jl, and OrdinaryDiffEqSDIRK's predictor_tests.jl (121 tests covering every Predictor enum value on ESDIRK/ImplicitEuler/TRBDF2/KenCarp4, iip+oop) pass locally; mass-matrix ShampineCollocationInit (which reuses nlsolve!) verified manually.
  • Runic format and typos clean on the diff.
  • Full GROUP= CI matrix not run locally (too large); relying on CI for the remaining groups.

🤖 Generated with Devin (Devin CLI 3000.10.21, model: SWE-2 Max) — local session transcript: /home/crackauc/.local/share/devin/cli/summaries/history_7369bf642d694288.md (continued) (Devin CLI exposes no shareable URL)

ChrisRackauckas and others added 2 commits September 12, 2026 17:11
A `predictor` keyword on `NLNewton`, `NLFunctional`, `NLAnderson`, and
`NonlinearSolveAlg` takes a callable that guesses the stage *value*:
`predictor(uprev, p, t + c*dt, dt)` out of place and
`predictor(upred, uprev, p, t + c*dt, dt)` in place. `nlsolve!` applies it
once per solve attempt via `apply_predictor!`, so every implicit method
driven through the shared nonlinear solver (DIRK/IMEX RK, coefficient-form
multistep, DAE BDF, PDIRK) gets it for free — the generalization requested
in review of SciML#4471, which had wired the same callable through SDIRK's
stage kernels by hand.

The guess is mapped onto the solver's iterate `z` by inverting the
residual's `ustep` map — `z = (u_pred - tmp)/γ` for DIRK-style methods,
`z = u_pred` for `COEFFICIENT_MULTISTEP`, `z = u_pred - u₀` for
`DAEFunction` — the same inverse the tableau/interpolant predictors already
apply inside the kernels. When both are set, the callable overrides the
algorithm's `Predictor` enum seed. Passing a `Predictor` enum value to the
nlsolve `predictor` is rejected with a pointer at the algorithm-level
option, and `HomotopyNonlinearSolveAlg` rejects `predictor` outright:
continuation starts each stage from the λ = 0 anchor, not an initial guess.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: local transcript /home/crackauc/.local/share/devin/cli/summaries/history_68a468ef87ff4372.md (Devin CLI exposes no shareable URL)
With `nlsolve = NLNewton(predictor = f)` the kernel's `Predictor` enum
seed is dead work: `apply_predictor!` inside `nlsolve!` overwrites
`nlsolver.z` before Newton iterates. Collapse the local predictor to
`Trivial` in `_perform_step_iip!`/`_perform_step_oop!` when
`stage_predictor(nlsolver.alg)` is set, so the interpolant predictors
(`addsteps!`, `current_extrapolant`, Hermite evaluation) are skipped
instead of computed and thrown away. Enum behavior is unchanged when no
callable is configured.

BDF seeds are broadcasts over already-computed history and PDIRK seeds
are `zero(u)`, so nothing is gated there. StochasticDiffEqImplicit's
`:interpolant` extrapolant has the same dead-work pattern but seeds the
stage value `u` (not `z`) amid noise computations — left for a separate
look.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 Max
Agent-Session: local transcript /home/crackauc/.local/share/devin/cli/summaries/history_7369bf642d694288.md (Devin CLI exposes no shareable URL)
@ChrisRackauckas
ChrisRackauckas merged commit 01276e4 into SciML:master Sep 13, 2026
124 of 126 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 13, 2026
- Stop tying the state Jacobian's finite-difference direction to tdir (#4543)
- Extend OrdinaryDiffEqCore.dtnew_modification instead of shadowing it (#4547)
- Pick the DAE initialization dt by magnitude, not signed min (#4549)
- Accept a callable stage predictor on the nlsolve algorithms (#4539)
- Run the QA test group last in every sublibrary that ran it first (#4551)
- Apply stage limiters in every StabilizedRK method (#4550)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Sep 13, 2026
OrdinaryDiffEqSDIRK 2.9.4 imports `stage_predictor` from
OrdinaryDiffEqNonlinearSolve (#4539), but that function first shipped in
registered OrdinaryDiffEqNonlinearSolve 2.9.8 — 2.9.7 and earlier do not
define it. The declared "2.6" floor therefore admits an unsatisfiable
combination: SDIRK 2.9.4 + OrdinaryDiffEqNonlinearSolve <2.9.8 fails
precompilation with `UndefVarError: stage_predictor`, which is what
DiffEqGPU's downgrade CI just hit.

Bump the floor to the version that actually provides the function and
release as 2.9.5.



Agent-Harness: Devin CLI 3000.10.21
Agent-Model: swe-2-max
Agent-Session: local session ID: atom-voice

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
ChrisRackauckas added a commit that referenced this pull request Sep 13, 2026
- Stop tying the state Jacobian's finite-difference direction to tdir (#4543)
- Extend OrdinaryDiffEqCore.dtnew_modification instead of shadowing it (#4547)
- Pick the DAE initialization dt by magnitude, not signed min (#4549)
- Accept a callable stage predictor on the nlsolve algorithms (#4539)
- Run the QA test group last in every sublibrary that ran it first (#4551)
- Apply stage limiters in every StabilizedRK method (#4550)
- Release OrdinaryDiffEqNonlinearSolve 2.9.8 (#4552)
- Declare OrdinaryDiffEqCore.dtnew_modification public (#4553)
- Fix baseline spelling and whitespace checks in tests (#4524)
- Raise OrdinaryDiffEqNonlinearSolve floor for stage_predictor (#4554)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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