Skip to content

Fix SERK2 in-place inner stage loop evaluating f at the wrong stage vector - #3947

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:serk2-iip-stage-fix
Jul 22, 2026
Merged

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

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Important

This PR should be ignored until reviewed by @ChrisRackauckas.

What

The in-place SERK2 perform_step! evaluated f at tmp (which holds uᵢ₋₂) instead of uᵢ₋₁ in its inner stage loop, and used a different buffer-shift guard (j < mdeg) than the out-of-place implementation (j * i < mdeg).

Why it went undetected

The divergent code path only executes when mdeg >= 20 (internal_deg = mdeg ÷ 10 >= 2), i.e. for genuinely stiff steps with dt·λ ≳ 300. The existing convergence tests use prob_ode_linear/prob_ode_2Dlinear with mild step sizes, which never reach that regime.

Impact

In the stiff regime the in-place solver is unstable. On a forced heat equation (N = 32, dt·λ ≈ 217, fixed dt = 0.05):

‖u − ref‖∞
out-of-place 2.5e-3
in-place (before) 3.8e83
in-place (after) 2.5e-3 (agrees with oop to 1.7e-13)

Tests

Adds a stiff fixed-dt in-place/out-of-place agreement regression testset covering all 13 stabilized RK methods (ROCK2/4, RKC, RKMC2, TSRKC2/3, SERK2, ESERK4/5, RKL1/2, RKG1/2). It fails on the previous code for SERK2 and passes with this fix.

Ran locally: ODEDIFFEQ_TEST_GROUP=Core Pkg.test() on the sublibrary — 210/210 pass. Runic applied to changed files.

Process notes

Found during a correctness/performance audit of the stabilized RK family: code inspection flagged the oop/iip asymmetry, then a fixed-dt stiff comparison confirmed the blow-up, and the one-line fix restores roundoff-level agreement. Related (separate PRs): RKL/RKG non-autonomous stage-time fixes; SERK2 also has a separate non-autonomous order-reduction issue that needs the original paper's coefficients and is intentionally NOT addressed here.

🤖 Generated with Claude Code

https://claude.ai/code/session_015WU5V4PXt8SZ3BpjxdtM7d

…ector

The in-place SERK2 perform_step! evaluated f at tmp (which holds uᵢ₋₂)
instead of uᵢ₋₁ in the inner stage loop, and used a different
buffer-shift guard (j < mdeg) than the out-of-place method (j * i < mdeg).
The divergent path only executes when mdeg >= 20 (internal_deg >= 2),
i.e. for genuinely stiff steps with dt*λ ≳ 300, a regime the existing
autonomous test problems never reach. In that regime the in-place solver
is unstable: on a forced heat equation with dt*λ ≈ 217 it reaches ~1e83
while the out-of-place solver has error ~2.5e-3.

With this fix the two implementations agree to ~1e-13. Adds a stiff
fixed-dt in-place/out-of-place agreement regression test across all
stabilized RK methods, which fails on the previous code.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015WU5V4PXt8SZ3BpjxdtM7d
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

CI triage (2026-07-18): the failing checks here are pre-existing on master (commit 4e1a434, same base as this PR) and unrelated to this diff:

  • downgrade-sublibraries (9 sublibs, none touched by this PR) — also failing on master's own run.
  • sublibrary-ci / lib/OrdinaryDiffEqStabilizedIRK [QA] — ExplicitImports all_explicit_imports_are_public errors for build_nlsolver/nlsolve!/du_alias_or_new/markfirststage!/dolinsolve/update_W! in StabilizedIRK (a sublib this PR does not modify).

A separate investigation of the master failures is underway and will be filed as its own issue/PR. All checks that exercise this PR's code (lib/OrdinaryDiffEqStabilizedRK Core + QA) pass.

Additionally: tests / GPU fails here but also fails on master's own CI run for 4e1a434 (self-hosted runner) — pre-existing.

@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review July 22, 2026 20:52
@ChrisRackauckas
ChrisRackauckas merged commit 3c819b7 into SciML:master Jul 22, 2026
121 of 132 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.

2 participants