Repository navigation
Pass the integrator and the stage buffer to stage limiters - #4356
Merged
ChrisRackauckas merged 1 commit intoAug 26, 2026
Merged
Conversation
singhharsh1708
force-pushed
the
fix-stage-limiter-args
branch
from
August 24, 2026 07:43
1d8e0e7 to
f2dd8c9
Compare
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.
Three explicit RK methods pass the wrong object to a user-supplied stage limiter.
The limiter contract is
limiter!(u, integrator, p, t)(
OrdinaryDiffEqCore.trivial_limiter!), and all four arguments are untyped, so awrong one type-checks and the default no-op limiter hides it.
What is wrong
Tsit5(in-place) passes theODEFunctionwhere the integrator belongs, at fiveof its six stages:
The sixth call in the same method uses
integrator, so this is not a localconvention. Any limiter that reads the integrator throws
type ODEFunction has no field ...onTsit5but works onRK4.Midpoint(in-place) passes the stage buffer as the integrator and limits thewrong array:
The limiter's writes land in
k, which the next line overwrites, so the midpointstage is never limited at all.
QPRK98(in-place) handsuprevto the limiter at stage 5, where the other 14stages pass
tmp:The limiter mutates what it is given, so this writes into the previous step's
value, which every later stage and the step update then read. Stage 16 likewise
limits
uwhilefconsumestmp.Effect
Limiters that only clamp
uand ignore their other arguments — the common case,and what the existing tests use — are unaffected on
Tsit5. OnMidpointthestage limiter is a no-op regardless. On
QPRK98, an ordinary positivity limitercorrupts
uprev: onu' = u,u0 = [-1.0], one step ofdt = 0.1,uprevchanges from
-1.0to0.0partway through the step.What this changes for users
A limiter that only clamps
uand ignores its other arguments -- the common case --sees no difference on
Tsit5, because the object in the wrong slot was never used.MidpointandQPRK98do change.Midpoint's stage limiter was a no-op and nowruns, so a solve that passes one will give different numbers; those numbers are the
limited ones it was asking for.
QPRK98stops writing intouprev, which is astraight correctness fix -- any limiter that mutated its argument was corrupting the
step.
Testing
test/Integrators_I/step_limiter_test.jlgains three testsets. The existinglimiters there ignore their arguments, which is why this was not caught; the new
ones assert which objects are passed:
DEIntegrator, over 27 stage-limiter-supporting methodsintegrator.uprev, same setuprevholds one value across a singleQPRK98stepEach fails on master and passes here: the first reports
Midpoint, Tsit5, thesecond reports
QPRK98, and the third seesuprevtake both-1.0and0.0.Bumps
OrdinaryDiffEqTsit5,OrdinaryDiffEqLowOrderRKandOrdinaryDiffEqQPRKone patch from master.
#4035 also edits
test/Integrators_I/step_limiter_test.jl. It is a different bug --refreshing FSAL after solve-level step limiters, where this is about which
arguments the stage limiters receive -- but whichever lands second will need a
rebase in that file. No version overlap: #4035 bumps Core and ExponentialRK.
AI Disclosure
Claude assisted with this change.