Repository navigation
Accept a callable stage predictor on the nlsolve algorithms - #4539
Merged
ChrisRackauckas merged 2 commits intoSep 13, 2026
Merged
ChrisRackauckas merged 2 commits into
ChrisRackauckas merged 2 commits into
Conversation
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
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]>
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.
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!.predictorkeyword onNLNewton,NLFunctional,NLAnderson, andNonlinearSolveAlg. 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!callsapply_predictor!(nlsolver, integrator)once per solve attempt, beforeinitialize!, and maps the stage-value guess onto the solver's iteratezby inverting the residual'sustepmap —(u_pred - tmp)/γfor DIRK-style methods,u_predforCOEFFICIENT_MULTISTEP,u_pred - u₀forDAEFunction. That is the same inverse theMaxOrder/CutoffOrder/VariableOrderenum 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'sPredictorenum seed.Predictorenum value as the nlsolvepredictoris rejected with a pointer to the algorithm-level option (ImplicitEuler(predictor = Predictor.Linear)), keeping the two same-named but different-typed options unconfusable.HomotopyNonlinearSolveAlgrejectspredictor: homotopy continuation starts each stage from the exact λ = 0 anchor rather than an initial guess._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 byapply_predictor!. Enum seeding is unchanged when no callable is set. BDF seeds are broadcasts over already-computed history and PDIRK seeds arezero(u), so there is nothing to skip there; StochasticDiffEqImplicit's:interpolantextrapolant has the same dead-work pattern but seeds the stage value amid noise computations and is left for a separate look.nlsolve!(FIRK/Radau, Nordsieck, Rosenbrock) are unaffected — they run their own iteration loops.Test plan
test/predictor_tests.jlin OrdinaryDiffEqNonlinearSolve (registered inruntests.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, aDImplicitEulerDAE solve, an exact-seed iteration-count reduction, callable-overrides-enum precedence, and the rejection errors.newton_tests.jl,dae_initialization_tests.jl, and OrdinaryDiffEqSDIRK'spredictor_tests.jl(121 tests covering everyPredictorenum value on ESDIRK/ImplicitEuler/TRBDF2/KenCarp4, iip+oop) pass locally; mass-matrixShampineCollocationInit(which reusesnlsolve!) verified manually.typosclean on the diff.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)