Repository navigation
Zero AdaptiveRadau's stage-value slots at initialization - #4160
Merged
ChrisRackauckas merged 1 commit intoAug 8, 2026
Merged
ChrisRackauckas merged 1 commit into
ChrisRackauckas merged 1 commit into
Conversation
`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]>
This was referenced Aug 8, 2026
ChrisRackauckas
marked this pull request as ready for review
August 8, 2026 10:58
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.
What changed
initialize!(::AdaptiveRadauCache)allocated the stage-value slotsintegrator.k[3:end]withsimilar, leaving them uninitialized. Those slots hold one stage value per possible stage, and the extrapolated initial guess readsintegrator.k[i + 2]for alli in 1:num_stageswhile only the firstnum_stagesare ever written back. As soon asstep_accept_controller!raisescache.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 withreltol = abstol = 1e-9, single-threaded, unmodified master:("unstable N/20" = runs of the identical
solvecall that did not returnReturnCode.Success; "distinct |u|" = number of distinct finalnorm(u, Inf)values across the 20 runs.) OnlyAdaptiveRadauwith a stage count free to move is affected — pinningmin_order == max_orderremoves it, and the fixed-stage Radau methods never had it.With this commit applied, the same script:
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):With the fix (
zero):Verification
Not verified
GROUP=QA(Aqua/ExplicitImports/JET) was not run; this change adds no names and no imports.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