Skip to content

Zero AdaptiveRadau's stage-value slots at initialization - #4160

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/adaptive-radau-uninitialized-k
Aug 8, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/adaptive-radau-uninitialized-k

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

What changed

initialize!(::AdaptiveRadauCache) allocated the stage-value slots integrator.k[3:end] with similar, leaving them uninitialized. Those slots hold one stage value per possible stage, and the extrapolated initial guess reads integrator.k[i + 2] for all i in 1:num_stages while only the first num_stages are ever written back. As soon as step_accept_controller! raises cache.num_stages, the newly used slots are read before anything has written them.

similar → zero. That is the whole fix.

Why it matters

The consequence is intermittent and silent: garbage stage values feed the Newton initial guess, so the step either diverges into a dt-below-epsilon abort or converges to a slightly different (still tolerance-satisfying) answer. On a 48-state Brusselator with reltol = abstol = 1e-9, single-threaded, unmodified master:

M=I,       adaptive stages  unstable  4/20  distinct |u| 11
M=Diag,    adaptive stages  unstable  4/20  distinct |u| 3
M=2I,      adaptive stages  unstable  6/20  distinct |u| 4
M=Diag,    fixed 3 stages   unstable  0/20  distinct |u| 1
M=Diag,    fixed 5 stages   unstable  0/20  distinct |u| 1
M=Diag,    RadauIIA5        unstable  0/20  distinct |u| 1
M=Diag,    RadauIIA9        unstable  0/20  distinct |u| 1

("unstable N/20" = runs of the identical solve call that did not return ReturnCode.Success; "distinct |u|" = number of distinct final norm(u, Inf) values across the 20 runs.) Only AdaptiveRadau with a stage count free to move is affected — pinning min_order == max_order removes it, and the fixed-stage Radau methods never had it.

With this commit applied, the same script:

M=I,       adaptive stages  unstable  0/20  distinct |u| 1
M=Diag,    adaptive stages  unstable  0/20  distinct |u| 1
M=2I,      adaptive stages  unstable  0/20  distinct |u| 1
M=Diag,    fixed 3 stages   unstable  0/20  distinct |u| 1
M=Diag,    fixed 5 stages   unstable  0/20  distinct |u| 1
M=Diag,    RadauIIA5        unstable  0/20  distinct |u| 1
M=Diag,    RadauIIA9        unstable  0/20  distinct |u| 1

Failing before / passing after

The test leaves dirty blocks in the allocator's free lists before init — otherwise an uninitialized slot can come back zeroed by luck, which is exactly why the bug is intermittent rather than deterministic.

Unfixed code (similar):

Test Summary:                                   | Pass  Fail  Total   Time
AdaptiveRadau initializes all stage-value slots |    3     1      4  22.3s
ERROR: LoadError: Some tests did not pass: 3 passed, 1 failed, 0 errored, 0 broken.

With the fix (zero):

Test Summary:                                   | Pass  Total   Time
AdaptiveRadau initializes all stage-value slots |    4      4  19.4s

Verification

$ GROUP=Core julia --project=lib/OrdinaryDiffEqFIRK -e 'using Pkg; Pkg.test()'
Test Summary: | Pass  Total     Time
FIRK Tests    |  107    107  4m06.5s
     Testing OrdinaryDiffEqFIRK tests passed
$ julia -e 'using Runic; exit(Runic.main(["--check","--diff","lib/OrdinaryDiffEqFIRK/"]))'   # clean
$ typos lib/OrdinaryDiffEqFIRK/                                                              # clean

Not verified

  • GROUP=QA (Aqua/ExplicitImports/JET) was not run; this change adds no names and no imports.
  • Docs build not run — no docstrings or public API touched.
  • GPU and downstream lanes not run locally.

For the reviewer

The regression test's discriminating power depends on the allocator handing back dirty memory, which is inherent to the bug. It is deterministic in the passing direction: after the fix the slots are always zero. If you would rather not carry an allocator-dependent test, the alternative is to drop it and rely on the invariant being obvious from the diff.


Please ignore until reviewed by @ChrisRackauckas.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Gstik9KAfxtNAz53ejBPwN

`initialize!(::AdaptiveRadauCache)` allocated `integrator.k[3:end]` with `similar`,
leaving them uninitialized. Those slots hold one stage value each; the extrapolated
initial guess reads `integrator.k[i + 2]` for all `i in 1:num_stages`, while only the
first `num_stages` are ever written back. As soon as the controller raises the stage
count, the newly used slots are read before anything has written them.

The result was intermittent: on a 48-state Brusselator, `AdaptiveRadau()` returned
`ReturnCode.Unstable` in 4 of 20 identical single-threaded runs, and the successful
runs disagreed with each other (11 distinct final states out of 20). Fixing the
initialization gives 0 of 20 unstable and 1 distinct result.

Co-Authored-By: Chris Rackauckas <[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