Skip to content

Fix SERK2 stage times for non-autonomous problems - #4108

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix-serk2-stage-times
Aug 3, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix-serk2-stage-times

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Aug 3, 2026 •

Copy link
Copy Markdown
Member

Fixes #3950.

Please ignore this PR until it has been reviewed by @ChrisRackauckas.

Root cause

Not what the issue hypothesized. The issue guessed that the Bᵢ tableau and the stage-time layout disagreed and that the SERK2 papers would be needed to resolve it. They don't disagree — the tableau is correct, and the bug is an off-by-one in exactly the same family as #3948 and #3949.

perform_step! evaluated f at the time of the stage it was producing, not the stage it was evaluating at:

for j in 2:internal_deg
    k = f(uᵢ₋₁, p, t + (j^2 + (i - 1) * internal_deg^2) * α * dt)   # time of u, not uᵢ₋₁
    u = 2 * uᵢ₋₁ - uᵢ₋₂ + 2 * α * dt * k

Applying the recurrence to u' = 1 does give cⱼ = (j² + (i-1)·d²)·α — the issue is right about that — but that is the row sum of the stage being written, while f is applied to uᵢ₋₁. The consistent argument is therefore ((j-1)² + (i-1)·d²)·α, and the leading forward-Euler stage of block i sits at the last stage time of block i-1, i.e. (i-1)·d²·α rather than (1 + (i-1)·d²)·α.

Evidence

Reconstructing A and B from the implementation and forming bₗ = Σᵢ Bᵢ Aᵢₗ, for every mdeg in the tableau:

mdeg ΣB Σb Σb·ĉ (as shipped) Σb·c (consistent)
10 1.0 1.0 0.525 0.5
30 1.0 1.0 0.5076301 0.5
100 1.0 1.0 0.5018747 0.5
250 1.0 1.0 0.5006952 0.5

Σb·c = 1/2 holds exactly with the internally consistent times, so the generated Bᵢ are fine and no paper/Fortran reference is needed. The shipped times miss the second-order condition by O(1/mdeg), a fixed defect that does not shrink with dt — hence order ~1 rather than 2.

Directly probing the times the integrator passes to f while solving u' = 1 (where a stage value equals its own row sum) gives max|u - t|:

before after
SERK2 4.34e-4 1.4e-12

Measured convergence

dts = 2⁻¹⁰..2⁻⁵, forced eigen_est; fixed = 55.0, scaled = 500/dt.

problem eigen_est before after
quadrature u' = cos(t) oop fixed 0.953 2.000
quadrature u' = cos(t) oop scaled 0.804 2.000
quadrature u' = cos(t) iip fixed 0.953 2.000
quadrature u' = cos(t) iip scaled 0.804 2.000
Prothero–Robinson oop fixed 1.011 2.004
Prothero–Robinson oop scaled 1.032 2.003
Prothero–Robinson iip fixed 1.011 2.004
Prothero–Robinson iip scaled 1.032 2.003
linear autonomous fixed 1.998 1.998
linear autonomous scaled 1.994 1.994

Autonomous convergence is unchanged, as expected.

Tests

Two new testsets in lib/OrdinaryDiffEqStabilizedRK/test/rkc_tests.jl, mirroring the RKL/RKG ones:

  • SERK2 non-autonomous convergence — Prothero–Robinson and pure quadrature, oop and iip, both eigen_est regimes.
  • SERK2 stage times are internally consistent — probes every f call on u' = 1 and asserts the stage value equals the time argument. Separates fixed from broken by eight orders of magnitude (4.3e-4 vs 1.4e-12), so it is a tight regression guard.

Both fail on master and pass here.

Full group run on this branch:

$ GROUP=Core julia --project -e 'using Pkg; Pkg.test()'
Test Summary: | Pass  Total     Time
RKC Tests     | 1258   1258  9m12.9s
     Testing OrdinaryDiffEqStabilizedRK tests passed

Runic clean.

Note on ESERK4/ESERK5

The issue's closing note that ESERK4/ESERK5 are unaffected holds up. Their stage times are laid out differently (the time argument lags by one stage but is recomputed from a global stage counter that does not reset per block), and probing u' = 1 shows a 0.053/0.057 discrepancy against the stage row sums — but it does not cost them order. Measuring on a dt range where the error is above roundoff, on the same quadrature problem:

dts ESERK4 fixed ESERK4 scaled ESERK5 fixed ESERK5 scaled
2⁻⁶..2⁻² 4.911 3.975 4.101 3.689
2⁻⁵..2⁻¹ 5.192 3.943 5.939 5.535

At the dts = 2⁻¹⁰..2⁻⁵ used for SERK2 above, ESERK errors are already down at 1e-13, so an order estimate there measures roundoff rather than truncation. Nothing to fix here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QPE849e5oSrZreh3mkE8AJ

SERK2 passed each f evaluation the time of the stage it was *producing*
rather than the stage it was *evaluating at*, an off-by-one in the same
family as the RKL/RKG fixes in SciML#3948/SciML#3949. Stage j of block i sits at
t + (j^2 + (i-1)*internal_deg^2)*alpha*dt, but f is applied to the
previous stage, so the correct argument uses (j-1)^2, and the leading
Euler stage of each block sits at the last stage time of the previous
block.

Reconstructing the tableau confirms the coefficients themselves are
correct: for every mdeg in the tableau, sum(B) = 1, sum(b) = 1 and
sum(b .* c) = 0.5 exactly with the internally consistent stage times,
while the times the code passed gave 0.5 + O(1/mdeg) - breaking the
second-order condition by a fixed amount and dropping the observed
order to ~1.

On dts = 2^-10..2^-5 with forced eigen_est, order on a Prothero-Robinson
problem goes 1.01 -> 2.00 and on pure quadrature u' = cos(t) 0.80 -> 2.00,
in-place and out-of-place alike. Autonomous convergence is unchanged.

Fixes SciML#3950

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01QPE849e5oSrZreh3mkE8AJ
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review August 3, 2026 13:22
@ChrisRackauckas
ChrisRackauckas merged commit 1aa56ee into SciML:master Aug 3, 2026
125 of 133 checks passed
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.

SERK2 converges at order 1 on non-autonomous problems (stage-time formula)

2 participants