Repository navigation
Fix VelocityVerletCache tmp field typing for unitful state - #4602
Merged
ChrisRackauckas merged 2 commits intoSep 25, 2026
Merged
ChrisRackauckas merged 2 commits into
ChrisRackauckas merged 2 commits into
Conversation
The tmp field of VelocityVerletCache was declared as uType but holds rate-typed buffers: alg_cache built it from zero(rate_prototype) and alloc_symp_state uses cache.tmp.x as the kdu/ku derivative buffers in perform_step!. With Unitful initial conditions uType != rateType, so the parametric inner constructor had no matching method and solve() threw a MethodError. The k/tmp arguments were also swapped relative to the field order, which happened to be harmless only because both were zero(rate_prototype). The field is now typed rateType and the constructor arguments are passed in field order. Unitful is added as a test-only dependency for a SecondOrderODEProblem regression test covering both the in-place and out-of-place paths. Fixes SciML#1397 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> Agent-Harness: Devin CLI Agent-Model: swe-2-high Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-OrdinaryDiffEq.jl-1397/log.txt on amdci2.julia.csail.mit.edu
The zero-acceleration case only exercises the cache construction, not the update formula. Add a gravity case (dv .= [-9.81, 0] m/s^2) checked against the analytic x(t) = x0 + v0*t + g*t^2/2, which VelocityVerlet integrates exactly for constant acceleration. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> Agent-Harness: Devin CLI Agent-Model: swe-2-high Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-OrdinaryDiffEq.jl-1397/log.txt on amdci2.julia.csail.mit.edu
ChrisRackauckas
marked this pull request as ready for review
September 25, 2026 05:01
ChrisRackauckas
referenced
this pull request
Sep 29, 2026
* Bump DiffEqBase to 7.21.3 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqBDF to 2.4.12 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqSDIRK to 2.9.7 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqRosenbrock to 2.7.5 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqLowOrderRK to 2.2.6 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqTsit5 to 2.1.5 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqVerner to 2.4.2 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqSymplecticRK to 2.2.3 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
VelocityVerletCache.tmpwas declareduTypebut holds rate-typed buffers:alg_cachebuilds it fromzero(rate_prototype)andalloc_symp_stateusescache.tmp.xas thekdu/kuderivative buffers. With Unitful initial conditionsuType != rateType, so the parametric inner constructor had no matching method andsolvethrew aMethodError(#1397); thek/tmparguments were also swapped relative to the field order (harmless only because both werezero(rate_prototype)). The field is nowrateTypeand arguments are passed in field order. Unitful is added as a test-only dependency for the regression test, matching the precedent inlib/DelayDiffEq.Verification
New testset in
lib/OrdinaryDiffEqSymplecticRK/test/symplectic_tests.jl("VelocityVerlet with units iip=true/false"), run in a scratch env dev'ing this branch.Failing on unfixed code (src change stashed):
Passing with the fix (now including a constant-acceleration case
dv .= [-9.81, 0] m/s^2checked against the analyticx(t) = x0 + v0*t + g*t^2/2, exact for VelocityVerlet — expectedx(T) = [-49000.0, 0.1] m,v(T) = [-980.5, 0] m/satT = 100 s):Test group run:
cd lib/OrdinaryDiffEqSymplecticRK && GROUP=Core julia --project=. -e 'using Pkg; Pkg.test()'— tail:(The 4 broken are the pre-existing
@test_brokenMcAte42 cases.) Runic: no changes needed on the touched files.typos: clean.NOT verified
GROUP=QApieces: Allocation Tests passed (18@test_broken, 0 failures); JETtest_package(..., mode=:typo)1/1 pass on this branch. The suite-level run died onEMFILE(file-descriptor exhaustion on the shared CI host) before the Aqua lane; SciMLTestingrun_qapassed 20/20 on the sibling branch Fix tmp field typing in remaining symplectic caches for unitful state #4603 which carries the same change pattern in the same file.tmp::uType+ swapped-constructor-args pattern existed inLeapfrogDriftKickDriftCache,VerletLeapfrogCache, andSymplecticGenericCachein the same file — fixed separately in Fix tmp field typing in remaining symplectic caches for unitful state #4603 per review request.DynamicalODEFunctioncases beyondSecondOrderODEProblem.What a reviewer should push back on
tmpshould stay semantically "u-typed scratch" forget_tmp_cache/callback signatures. Note the field already held arateTypeobject before this change (thekargument landed in thetmpslot), so the retype only makes the declared type match actual contents; behavior is unchanged.[extras]+[targets]+ compat1.25.1, mirroring DelayDiffEq).Fixes #1397
Please ignore this draft until reviewed by @ChrisRackauckas.
Risk assessment
VelocityVerletCachein OrdinaryDiffEqSymplecticRK only: the field type oftmp(uType→rateType) and the constructor argument order. For unitless problemsuType == rateTypeand the field already held a rate-typed object, so numerics are unchanged. No public API change. Unitful is added as a test-only dependency.MethodErrorand passes after. It checks against the analytic solution, including a constant-acceleration case.GROUP=Coreof the sublibrary passes. Runic and typos are clean.🤖 Generated with Devin CLI (model: swe-2-high), transcript /home/crackauc/sandbox/goals/issue-backlog/jobs/fix-OrdinaryDiffEq.jl-1397/log.txt on amdci2.julia.csail.mit.edu
Risk assessment and review coordination by 🤖 Claude Code (model: claude-opus-5-5[1m]), https://claude.ai/code/session_01NdFVhANTF4nepTbqYxjfRP
Independent review (Claude Code cloud / claude-opus-5-5)
VERDICT: MERGE
(no risk section)
Full review
VERDICT: MERGE
Risk assessment
The PR changes the declared type of the tmp field and the order of the
constructor arguments, and adds Unitful as a test-only dependency. Nothing
public changes, so no SemVer concern.
...), the old call passed k (a rate-typed zero) into the tmp slot. Julia's
default parametric constructor does not convert arguments. So any problem
where uType != rateType already failed with a MethodError.
built from two identical zero(rate_prototype) objects, only in a different
order.
makes the previously failing case work.
Sublibrary CI is green for Core (Julia 1, lts, pre), QA and downgrade.
Blocking findings
None.
Non-blocking findings
cache.tmp as u-shaped scratch, a Unitful u would get a buffer with the
wrong units. This is not a regression, because the unitful case never ran
before and unitless storage is unchanged. It is worth a follow-up check of
what get_tmp_cache returns for this cache.
the argument reorder is only checked by the fact that the code compiles.
That is acceptable, since the swap never changed values.
(relative tolerance √eps) against analytic solutions. The
constant-acceleration case (VelocityVerlet is exact there, up to rounding
over 1000 steps) does check the update formula, not just cache
construction.
They do not constrain downstream resolution. The downgrade job for
lib/OrdinaryDiffEqSymplecticRK passed, so the lower bound resolves.
VerletLeapfrogCache, SymplecticGenericCache) is left to Fix tmp field typing in remaining symplectic caches for unitful state #4603. Splitting it
out is the right call. This PR fixes Second order ODE errors with Unitful units #1397 only for VelocityVerlet.
narrative. This is cosmetic.
Red CI: SciMLSensitivity Core1/Core3, downgrade
DiffEqBase/OrdinaryDiffEqDifferentiation
Probably not caused by this PR. From the argument above, the only runtime
change is for inputs with uType != rateType on VelocityVerlet, which used to
throw. A downstream test could only turn red if it:
types (for example tracked or dual types in the adjoint path) and fails
somewhere later.
Scenario (b) is possible in principle, but that test would have been
erroring on master too, so it would not be green there.
The untouched lanes are also red. Core1 is red as well. So are downgrade
DiffEqBase and OrdinaryDiffEqDifferentiation, which this PR does not touch;
that points to base or environment drift rather than this diff. Core3's
runtime (26m) is close to Core4's green 25m52s, so it does not look like a
hang.
Evidence that would settle it:
a. The failing testset name and error from the Core3 log (job 107223530580
(https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/35873400912/job/
107223530580)). Check whether it mentions VelocityVerlet, SymplecticRK or
SecondOrderODEProblem.
b. The same Core3 job on master at this PR's base commit, run in the same
time window. Resolved SciMLSensitivity, Zygote and Enzyme versions are
the usual cause of drift.
c. A rerun of Core3 on this PR. If it is still red, run Core3 locally with
this branch dev'd, then again with the two src lines reverted, and
compare.
What I checked
semantics.
SecondOrderODEProblem, x[1] is velocity and x[2] is position.
What I did not verify
diff hunks.
DiffEqBase/Differentiation failures.
passed.
Links
5873400912/job/107223530580
5873400912/job/107223531275
/actions/runs/35873400513/job/107231913502
L/OrdinaryDiffEq.jl/actions/runs/35873400513/job/107231913557
🤖 Posted by an AI agent — orchestrator: Devin Sidekick on behalf of @ChrisRackauckas · reviewer: Claude Code cloud / claude-opus-5-5
Conversation: cloud review session; transcript ~/sandbox/fleet-master/jobs/carry/cloud-out-4602.txt on Chris's Mac