Repository navigation
Add generic stage-predictor menu for ESDIRK methods - #3668
Merged
ChrisRackauckas merged 5 commits intoMay 25, 2026
Merged
Conversation
Member
Author
…, guard Hermite assumption
Member
Author
|
@ChrisRackauckas Addressed all review comments:
|
singhharsh1708
force-pushed
the
sdirk-stage-predictors
branch
from
May 23, 2026 12:48
471a61f to
22bebdb
Compare
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/OrdinaryDiffEq.jl
that referenced
this pull request
May 25, 2026
BDF algorithms (ABDF2, QNDF2, SBDF, MEBDF2) reuse SDIRK's ESDIRKIMEXCache via ImplicitEulerESDIRKIMEXTableau as a starter step. They eventually hit the SDIRK `_perform_step_iip!` body, which calls `_predictor(alg) = alg.predictor`. BDF algorithms don't carry a `predictor` field, so this throws `type ABDF2 has no field predictor` — which broke `test/integrators/step_limiter_test.jl` (and the Integrators_I/II CI groups) on master after PR SciML#3668. Fall back to `Predictor.Trivial` when the field is absent. This matches the default `extrapolant = :constant` mapping in `_resolve_predictor`, so BDF algorithms now use a zero-increment guess — the behavior they had before PR SciML#3668 introduced the predictor menu. Confirmed locally: `ABDF2(; step_limiter!)` solves the trivial linear ODE and reports n_accept == step_limiter call count. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/OrdinaryDiffEq.jl
that referenced
this pull request
May 25, 2026
The test `@test_broken length(sol_linear.u) < 10` for `solve(prob_linear, ESDIRK659L2SA())` now passes (locally and on the PR's Regression_I CI) because PR SciML#3668's stage-predictor menu improved the per-stage Newton seed for ESDIRK659L2SA — the linear problem now converges in 5 steps instead of >10. The other three ESDIRK methods immediately above (ESDIRK436L2SA2, ESDIRK437L2SA, ESDIRK547L2SA2) already use plain `@test length < 10`; this just brings ESDIRK659L2SA into line. This change is surfaced only because `Regression_I` runs on PRs but not on the master CI workflow. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ChrisRackauckas
added a commit
that referenced
this pull request
May 25, 2026
…ram (#3676) * Inline ESDIRK/IMEX perform_step stages; drop @generated and S type-param Replaces the @generated `_perform_step_iip!` / `_perform_step_oop!` / `calculate_error_estimate!` for the :standard and :ie_dd2 flavors with hand-written non-generated functions. The per-stage logic is now a `if s >= i ... end` ladder for i in 2..MAX_ESDIRKIMEX_STAGES (=12), each branch carrying a fused-coefficient broadcast accumulator written out with literal indices. Drops `S` from `ESDIRKIMEXTableau{T, T2, E}`. Tableaus with s > MAX_ESDIRKIMEX_STAGES now error at construction. The body compiles once per (alg type, T, T2, E) — stage count is purely runtime — which avoids the @generated compilation-cache invalidation issues that motivated this rewrite. :trap_dd3 keeps its hand-written specialization; :standard and :ie_dd2 share a body that branches on `E === :ie_dd2` (constant-folded since E is a type parameter). Local SDIRK test suite passes (Tableau consistency 47/47, Stage predictors 88/88, Convergence 84/84 + 2 pre-existing broken, DAE 8/8). Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Drop pre-allocated zero(u) for OOP z/k locals — lazy assignment The OOP path was pre-allocating z1..z12 and k1..k12 with zero(u) at the top of _perform_step_oop! to give Julia static knowledge of the locals. For algorithms with s < 12 that's 24-2s wasted allocations per solve (e.g., ImplicitEuler s=1: 22 dead allocations). Replace the pre-allocation with `local` declarations — Julia still treats z2..z12 / k1..k12 as function-scope locals, but no allocation happens until something actually assigns to them. Conditional assignment inside `if s >= i ... end` ladders covers the cases that fire; output ladder branches reference only the slots that were filled at runtime. Net effect on OOP solves (Lotka-Volterra, 100 steps): - ImplicitEuler: -4% allocations, neutral time - ESDIRK659L2SA: -8% allocations, -28% time - SFSDIRK8: -5% allocations, -31% time - KenCarp5 OOP: -5% allocations, -50% time Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Apply Runic formatting The PR's runic check flagged `broadcast=false` vs `broadcast = false` and some `Union{...} && ...` indentation. Auto-fixed via `Runic --inplace`. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Make _predictor(alg) tolerate algs without `predictor` field BDF algorithms (ABDF2, QNDF2, SBDF, MEBDF2) reuse SDIRK's ESDIRKIMEXCache via ImplicitEulerESDIRKIMEXTableau as a starter step. They eventually hit the SDIRK `_perform_step_iip!` body, which calls `_predictor(alg) = alg.predictor`. BDF algorithms don't carry a `predictor` field, so this throws `type ABDF2 has no field predictor` — which broke `test/integrators/step_limiter_test.jl` (and the Integrators_I/II CI groups) on master after PR #3668. Fall back to `Predictor.Trivial` when the field is absent. This matches the default `extrapolant = :constant` mapping in `_resolve_predictor`, so BDF algorithms now use a zero-increment guess — the behavior they had before PR #3668 introduced the predictor menu. Confirmed locally: `ABDF2(; step_limiter!)` solves the trivial linear ODE and reports n_accept == step_limiter call count. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Unbreak ESDIRK659L2SA linear-step regression test The test `@test_broken length(sol_linear.u) < 10` for `solve(prob_linear, ESDIRK659L2SA())` now passes (locally and on the PR's Regression_I CI) because PR #3668's stage-predictor menu improved the per-stage Newton seed for ESDIRK659L2SA — the linear problem now converges in 5 steps instead of >10. The other three ESDIRK methods immediately above (ESDIRK436L2SA2, ESDIRK437L2SA, ESDIRK547L2SA2) already use plain `@test length < 10`; this just brings ESDIRK659L2SA into line. This change is surfaced only because `Regression_I` runs on PRs but not on the master CI workflow. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * OOP: pre-allocate k_i locals when f is a SplitFunction When a non-IMEX SDIRK method (Kvaerno3/4/5) is fed a `SplitODEProblem`, `integrator.f isa SplitFunction` is true but `issplit(alg)` is false. The stage-1 setup then skips the k1 assignment, but stages 2..s still enter the `tmp = tmp + Ae[i,j]*kj` accumulator (Ae is all zeros in that case, but Julia still needs k1 defined to evaluate `Ae[2,1] * k1`). Master's @generated body papered over this by pre-allocating all k_i = zero(u) up front; my previous `local k1..k12` declaration dropped the allocation and tripped `UndefVarError` in `sdirk_convergence_tests.jl::Kvaerno SplitODEProblem`. Restore the pre-allocation, but only when `integrator.f isa SplitFunction` (so the common non-split path still pays nothing for unused k slots). Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Apply Runic formatting again The re-assembly after the k_i pre-allocation fix re-introduced `broadcast=false` (no spaces) and the nested `Union{...}` indentation runic dislikes. Re-runic'd via `Runic --inplace`. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Make BDF's ABDF2 declare its predictor explicitly, drop fallback Previous commit added `_predictor(alg) = hasproperty(alg, :predictor) ? alg.predictor : Predictor.Trivial` to tolerate ABDF2 routing through SDIRK's perform_step via its `cache.eulercache`. Reviewer pointed out the fallback is implicit contract: anything reaching SDIRK's perform_step should declare a predictor. Revert `_predictor` to plain `alg.predictor` and define a single explicit override in BDF: OrdinaryDiffEqSDIRK._predictor(::ABDF2) = OrdinaryDiffEqCore.Predictor.Trivial ABDF2 is the only BDF algorithm that reuses SDIRK's `ESDIRKIMEXCache` (via the `eulercache` field for its first step). `Trivial` matches the behavior ABDF2 already takes: the SDIRK Newton-seed branches all gate on `alg isa Union{...SDIRK..., ImplicitEuler, Trapezoid}`, so the menu falls through to the zero-seed branch regardless. If a future algorithm adds this pattern, the missing `predictor` field now surfaces immediately as a `FieldError` instead of being silently filled with a default. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Restore _predictor hasproperty fallback with a docs-comment about ABDF2 Per review: keep the fallback but document *why* — it's the implicit contract for downstream algorithms that reuse `ESDIRKIMEXCache` (e.g. OrdinaryDiffEqBDF's `ABDF2`, which uses the Implicit Euler tableau as a first-step starter via `cache.eulercache`) without carrying a `predictor::Predictor.T` field of their own. Drops the explicit `OrdinaryDiffEqSDIRK._predictor(::ABDF2)` override from `OrdinaryDiffEqBDF/src/alg_utils.jl` and the corresponding `import OrdinaryDiffEqSDIRK` — the fallback alone is enough now. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: ChrisRackauckas-Claude <[email protected]> Co-authored-by: Claude Opus 4.7 (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.
Closes #3658.
Adds a
predictorkeyword to the SDIRK/ESDIRK methods so you can pick how the per-stage Newton initial guess is formed. The SUNDIALS predictors are all there as generic options, plus the existing tableau predictors, plus a couple of stage-extrapolation ones.Options:
:trivial— z=0, same as before (empty α):max_order/:variable_order/:cutoff_order— the SUNDIALS interpolant predictors (previous-step Hermite, evaluated at the stage time):tableau— the tuned α predictors KenCarp/Kvaerno/etc already carry:copy_prev— reuse the last stage's derivative:stage_extrap— extrapolate the last two stage derivativesFor
:variable_order/:cutoff_orderI needed an order-limited interpolant, which the dense output doesn't expose. Rewrote the Hermite cubic in power form (y0 + Θ·dt·k1 + Θ²·... + Θ³·...) so it can be truncated to order q; q=3 gives back the full Hermite exactly.Are the custom ones better?
Chris asked this. Short answer: yes. I benchmarked the whole menu on vdp (μ=1, 1e3, 1e6), Robertson, pollution and oregonator against the 5 ESDIRK*L2SA methods (which had no predictor before).
The SUNDIALS interpolant predictors mostly don't help here and
:max_ordercan actually make stiff solves worse — the trivial guess already uses the accumulated stage value, so extrapolating the old step on top of it overshoots. The stage-derivative ones win instead.:stage_extrapis the best and never blows up (I also tried quadratic and full-Lagrange versions, but those reintroduce a nasty outlier on Robertson, so I kept the 2-point form).Default change
Switched the ESDIRK*L2SA family default from trivial to
:stage_extrap. That changes their step counts vs master (fewer). Everything else still defaults to its tableau predictor. Heads up since it's a behavior change — happy to keep the default trivial if you'd rather, but the numbers are pretty convincing::trivialhere is identical to old behavior. reltol=abstol=1e-8. Total nf 269905 → 177207, about -34%, faster in all 30 cases, accuracy the same or better.full numbers
Tests
Added
predictor_tests.jl: checks every predictor on every method gives a finite, accurate result, and that the new default doesn't regress nf vs trivial. Convergence and tableau tests still pass.Checklist