Skip to content

Accept a stage predictor on the Newton nonlinear solvers - #4471

Closed
singhharsh1708 wants to merge 1 commit into
SciML:masterfrom
singhharsh1708:custom-predictor
Closed

singhharsh1708 wants to merge 1 commit into
SciML:masterfrom
singhharsh1708:custom-predictor

Conversation

@singhharsh1708

@singhharsh1708 singhharsh1708 commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

NLNewton and NonlinearSolveAlg now take predictor, a callable giving the initial guess for the state at each implicit stage: predictor(uprev, p, t, dt) out of place and predictor(upred, uprev, p, t, dt) in place, with t the stage time and dt the time from uprev to it. It is applied once per stage in nlsolve! and mapped back to the stage unknown the way compute_ustep maps it forward, so every method that solves through these (SDIRK and ESDIRK, BDF, PDIRK, IMEX multistep, the implicit StochasticDiffEq solvers) gets it, and the SDIRK-only version is gone. A DAEProblem stage solve rejects it with an ArgumentError.

The new test runs ImplicitEuler, TRBDF2 and FBDF with both solvers, in and out of place: all 36 pass, and 12 fail with the call removed from nlsolve!.

On u' = -50u at 1e-8, passing the exact solution as the guess takes Kvaerno5 from 662 to 516 Newton iterations and in-place FBDF from 323 to 244, with the same accepted and rejected steps. A first-order Euler guess on Lotka-Volterra is slower than the methods' own predictors (TRBDF2 48057 to 55299, FBDF 8726 to 26165), so this is for guesses that know something about the problem rather than a better default.

Closes #4331.

AI Disclosure: Claude assisted with this change.

@ChrisRackauckas

Copy link
Copy Markdown
Member

Why just SDIRK? This should generally be for any implicit method? And it should be done in the newton setup not in the algorithm, given all newton's can do this?

@singhharsh1708 singhharsh1708 changed the title Accept a callable predictor for SDIRK stage guesses Accept a stage predictor on the Newton nonlinear solvers Sep 12, 2026
@singhharsh1708

Copy link
Copy Markdown
Member Author

Moved it into NLNewton and NonlinearSolveAlg, applied once per stage in nlsolve!, so any implicit method solving through them gets it; the SDIRK-specific version is gone.

ChrisRackauckas added a commit that referenced this pull request Sep 13, 2026
* Accept a callable stage predictor on the nlsolve algorithms

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 #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)

* Skip enum predictor seeding in SDIRK when a callable is set

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)

---------

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@singhharsh1708
singhharsh1708 deleted the custom-predictor branch September 13, 2026 17:27
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.

Generalize extrapolant/predictor interface for next state prediction

2 participants