Skip to content

Make the stabilized-RK step cap and eigenvalue tolerance direction-agnostic - #4536

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:stabilized-dt-cap-direction
Sep 12, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:stabilized-dt-cap-direction

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Ignore until reviewed by @ChrisRackauckas. Draft.

What changed and why

Two sign bugs of the same kind, in OrdinaryDiffEqStabilizedRK and its sibling OrdinaryDiffEqStabilizedIRK.

1. The stability-limit step cap. dtnew_modification caps the controller's proposed step at the method's stability limit. The limit is a magnitude, so min(dtnew, bound) does nothing at all for a backward solve, where dtnew < 0 < bound:

+_cap(dtnew, bound) = copysign(min(abs(dtnew), abs(bound)), dtnew)
+
 function dtnew_modification(integrator, alg::ROCK2, dtnew)
-    return min(
+    return _cap(

Ten methods: ROCK2, ROCK4, SERK2, ESERK4, ESERK5, RKMC2, RKL1, RKL2, RKG1, RKG2. With eigen_est = 1e6 and a proposed |dt| of 1.0, ROCK2 forward caps to 0.0324385 and backward leaves it at 1.0 — a 30× difference.

2. The power-iteration convergence tolerance. maxeig! compares against max(eigen_est, inv(integrator.opts.dtmax)). dtmax is negative for tdir < 0, so the floor term goes negative and the tolerance differs between the two directions, giving a different number of power iterations and hence a different spectral-radius estimate. Same one-liner in OrdinaryDiffEqStabilizedIRK's maxeig! (1.0 / integrator.opts.dtmax).

Important caveat: the cap is currently dead code

OrdinaryDiffEqStabilizedRK defines dtnew_modification without importing it from OrdinaryDiffEqCore, so it shadows rather than extends, and calc_dt_propose! calls Core's generic identity method. See #4535. That means:

  • fix (1) has no observable end-to-end effect today — it makes the shadowed implementation correct so that switching the import on (a separate, reviewable behavior change) does not immediately reintroduce a direction bug;
  • fix (2) is live, but see below.

I am not fixing the import here on purpose: enabling a dormant stability cap for ten methods changes step sizes for every user of them and deserves its own PR.

Verification

New lib/OrdinaryDiffEqStabilizedRK/test/dtnew_cap_direction_tests.jl, registered in runtests.jl. It calls the package's own dtnew_modification directly (the only way to reach it, per the caveat above), with eigen_est set high enough that the bound binds for every method, and asserts (a) the cap actually binds forward and (b) the capped magnitude is identical backward.

Failing on master (git stash push -- lib/OrdinaryDiffEqStabilizedRK/src/alg_utils.jl) — one assertion per method:

Test Summary:                       | Pass  Fail  Total     Time
stability cap is direction-agnostic |   10    10     20  1m00.4s
  ROCK2                             |    1     1      2     4.5s
  ROCK4                             |    1     1      2     2.4s
  SERK2                             |    1     1      2     0.9s
  ESERK4                            |    1     1      2    38.6s
  ESERK5                            |    1     1      2    11.2s
  RKMC2                             |    1     1      2     0.6s
  RKL1                              |    1     1      2     0.5s
  RKL2                              |    1     1      2     0.5s
  RKG1                              |    1     1      2     0.5s
  RKG2                              |    1     1      2     0.5s

Passing with the fix:

Test Summary:                       | Pass  Total   Time
stability cap is direction-agnostic |   20     20  58.2s

Full package suites on this branch (Julia 1.10.11):

Testing OrdinaryDiffEqStabilizedRK tests passed
Testing OrdinaryDiffEqStabilizedIRK tests passed

What I did not verify — please read

The two inv(dtmax) changes have no discriminating test. I could not surface an end-to-end difference from them. The floor only matters when eigen_est < 1/|tspan|; I tried u' = 1e-3 u over a unit-length tspan with abstol = reltol = 1e-10 across ROCK2/ROCK4/RKC/SERK2/RKL2/RKG2, in-place and out-of-place, and every case was already bitwise reversible. I am shipping them as sign corrections that are obviously right by inspection, not as fixes to an observed failure — if you would rather they went in with a demonstration, say so and I will drop them from this PR.

Also not verified: GPU and Downstream groups, Julia pre; and whether the intended stability bounds are still the right ones (that question belongs with #4535).

Worth pushing back on

  • _cap is a new unexported one-line helper in alg_utils.jl. If you would prefer the copysign(min(abs(...), ...), ...) written out at each of the ten sites, or the helper placed elsewhere, easy to change.
  • Bundling two packages in one PR: they are the identical one-line defect in sibling maxeig! implementations, so splitting felt like more noise than signal. Happy to split.

Related: #4535 (the cap never runs).

🤖 Generated with Claude Code (model: claude-opus-5[1m], harness: Claude Code 2.1.269)

https://claude.ai/code/session_01JQATpLKMyYX3VbPPX8qdeE

…nostic

`dtnew_modification` caps the controller's proposed step at the method's
stability limit, which is a magnitude: `min(dtnew, bound)` silently does nothing
for a backward solve, where dtnew < 0 < bound. Cap on |dtnew| and restore the
sign. Affects ROCK2, ROCK4, SERK2, ESERK4, ESERK5, RKMC2, RKL1, RKL2, RKG1,
RKG2.

The power-iteration convergence test in `maxeig!` compares against
`max(eigen_est, inv(integrator.opts.dtmax))`. `dtmax` is negative for tdir < 0,
so the floor term went negative and the tolerance differed between directions;
take `abs` of dtmax. Same one-liner in OrdinaryDiffEqStabilizedIRK's `maxeig!`.

Note: these caps are currently unreachable from `calc_dt_propose!` because
OrdinaryDiffEqStabilizedRK defines `dtnew_modification` without importing it
from OrdinaryDiffEqCore, so the generic identity method is what runs. Filed
separately; this commit only makes the shadowed implementation correct.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Agent-Harness: Claude Code 2.1.269
Agent-Model: claude-opus-5[1m]
Agent-Session: https://claude.ai/code/session_01JQATpLKMyYX3VbPPX8qdeE
Claude-Session: https://claude.ai/code/session_01JQATpLKMyYX3VbPPX8qdeE
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 12, 2026 20:48
@ChrisRackauckas
ChrisRackauckas merged commit 3b193fa into SciML:master Sep 12, 2026
135 of 138 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 13, 2026
- OrdinaryDiffEqDefault: require OrdinaryDiffEqCore 4.17.1 (#4520)
- Add adaptive step size control to SDC (#4346)
- Allow JET 0.12 in every QA test environment (#4513)
- Resolve OrdinaryDiffEqDefault against the local sublibraries (#4514)
- NonlinearSolveAlg: stale-Jacobian retry + rejected-step W reassembly (carries #4282 to current master) (#4505)
- Do not seed a retry from the previous-step interpolant (#4473)
- Say why the linear path ignores new_W_dt_cutoff (#4527)
- Carry the QNDF2 difference array across steps (#4526)
- Pass Θ = 0, not the absolute time, to the AN5 startup interpolant (#4534)
- Make the stabilized-RK step cap and eigenvalue tolerance direction-agnostic (#4536)



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