Skip to content

Fix tmp field typing in remaining symplectic caches for unitful state - #4603

Closed
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix-symplectic-units-siblings
Closed

ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix-symplectic-units-siblings

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #4602 for the same defect in the sibling caches: LeapfrogDriftKickDriftCache, VerletLeapfrogCache, and SymplecticGenericCache all declare tmp::uType while the field holds the rate-typed kdu/ku buffers used by alloc_symp_state, and their alg_cache calls pass k/tmp swapped relative to the field order. VerletLeapfrogCache and SymplecticGenericCache additionally build tmp from zero(u) instead of zero(rate_prototype). With Unitful initial conditions uType != rateType, so the in-place path throws the same MethodError as #1397 for LeapfrogDriftKickDrift, VerletLeapfrog, and every generic-tableau algorithm (McAte2, Ruth3, SofSpa10, ...). The out-of-place constant caches (*ConstantCache / tableaus) hold only half/coefficients and are unaffected. Unitful is added as a test-only dependency for the regression test (same as #4602, DelayDiffEq precedent).

Verification

New testset in lib/OrdinaryDiffEqSymplecticRK/test/symplectic_tests.jl ("symplectic $alg with units iip=true/false", alg ∈ {LeapfrogDriftKickDrift, VerletLeapfrog, McAte2}), same Unitful SecondOrderODEProblem setup as #4602 with a constant-acceleration case checked against the analytic x(t) = x0 + v0*t + g*t^2/2 (exact for these order-2 methods).

Failing on unfixed code (src change stashed; per-algorithm probe):

LeapfrogDriftKickDrift iip=true : MethodError - no method matching LeapfrogDriftKickDriftCache(...)
VerletLeapfrog         iip=true : MethodError - no method matching VerletLeapfrogCache(...)
McAte2                 iip=true : MethodError - no method matching SymplecticGenericCache(...)
Ruth3                  iip=true : MethodError - no method matching SymplecticGenericCache(...)
SofSpa10               iip=true : MethodError - no method matching SymplecticGenericCache(...)
(all iip=false constant-cache paths: OK)

Test Summary:                                         | Error  Total  Time
symplectic LeapfrogDriftKickDrift with units iip=true |     1      1  9.7s
ERROR: Some tests did not pass: 0 passed, 0 failed, 1 errored, 0 broken.

Passing with the fix:

symplectic LeapfrogDriftKickDrift with units iip=true  |    4      4  24.6s
symplectic VerletLeapfrog with units iip=true          |    4      4  9.5s
symplectic McAte2 with units iip=true                  |    4      4  8.9s
symplectic LeapfrogDriftKickDrift with units iip=false |    4      4  13.8s
symplectic VerletLeapfrog with units iip=false         |    4      4  8.4s
symplectic McAte2 with units iip=false                 |    4      4  10.5s

Test group run: cd lib/OrdinaryDiffEqSymplecticRK && GROUP=Core julia --project=. -e 'using Pkg; Pkg.test()' — tail:

Test Summary:                | Pass  Broken  Total     Time
Synplectic Convergence Tests |   78       4     82  9m01.8s
Test Summary:    | Pass  Total      Time
Synplectic Tests |  184    184      50m18.8s
     Testing OrdinaryDiffEqSymplecticRK tests passed

(The 4 broken are the pre-existing @test_broken McAte42 cases; the 184 includes the 24 new units tests — 3 algorithms × 2 iip modes × 4 assertions.) Runic: no changes needed on the touched files. typos: clean.

NOT verified

  • QA pieces run individually (suite-level GROUP=QA died on EMFILE — file-descriptor exhaustion on the shared CI host, not a code issue): JET test_package(..., mode=:typo) 1/1 pass; SciMLTesting run_qa (Aqua/ExplicitImports) 20/20 pass. The AllocCheck lane passed on Fix VelocityVerletCache tmp field typing for unitful state #4602's near-identical diff and is unchanged by this branch (same file, same pattern — perform_step! untouched).
  • get_tmp_cache returns cache.tmp for every mutable cache and is used to build continuous-callback condition signatures (OrdinaryDiffEqCore/src/solve.jl:170). With this change the returned scratch is now rate-typed rather than state-typed; it already was rate-typed at runtime before (the k argument landed in the tmp slot), but a reviewer may want a dedicated continuous-callback test on a unitful symplectic problem.
  • Other rate/state-typing mismatches elsewhere in OrdinaryDiffEq (not audited).
  • Downstream packages.

What a reviewer should push back on

  • SymplecticEulerCache keeps tmp::uType/zero(u) — its perform_step! never uses tmp as a rate buffer, so it is consistent; double-check no other code path expects a rate buffer there.
  • Whether these fixes and Fix VelocityVerletCache tmp field typing for unitful state #4602 should be squashed into one PR; this was kept separate per review request.
  • Adding Unitful as a test-only dep to this sublibrary.

Part of #1397. See also #4602.

Please ignore this draft until reviewed by @ChrisRackauckas.

Risk assessment

  • Risk: low (author assessment)
  • Blast radius: LeapfrogDriftKickDriftCache, VerletLeapfrogCache and SymplecticGenericCache in OrdinaryDiffEqSymplecticRK. The fix is the same tmp::rateType / zero(rate_prototype) / field-order change as Fix VelocityVerletCache tmp field typing for unitful state #4602. It covers every generic symplectic tableau method. No public API change.
  • Evidence: the new Unitful testset over LeapfrogDriftKickDrift, VerletLeapfrog and McAte2 (iip and oop) fails before and passes after. The sublibrary tests pass.
  • Independent review: pending. A Claude Code (Opus 5.5) review is in progress and was not finished when this cycle stopped on its usage budget.
  • Merge: needs review first. Do not merge before the independent review comes back 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

  • Risk: low
  • Blast radius: In-place (Val{true}) caches of LeapfrogDriftKickDrift,
    VerletLeapfrog and the 14 SymplecticGenericAlgorithm methods in
    lib/OrdinaryDiffEqSymplecticRK. The out-of-place constant caches are
    untouched. Unitful is added only as a test dependency. No public API change,
    so a patch release fits SemVer.
  • Evidence: I read the base source at master 418f783 (symplectic_caches.jl
    (https://github.com/SciML/OrdinaryDiffEq.jl/blob/418f7834c143dbb95db9d45c40a
    d83ed52cedafe/lib/OrdinaryDiffEqSymplecticRK/src/symplectic_caches.jl),
    symplectic_perform_step.jl (https://github.com/SciML/OrdinaryDiffEq.jl/blob/
    418f783/lib/OrdinaryDiffEqSymplecticRK/src/
    symplectic_perform_step.jl)).
    • Before the fix, the (u, uprev, k, tmp, ...) call put zero(rate_prototype)
      into the field tmp::uType. For the generic and VerletLeapfrog caches it
      also put zero(u) into the field k::rateType. So the constructor only
      worked when typeof(zero(u)) == typeof(zero(rate_prototype)).
    • After the fix, both fields get zero(rate_prototype). In every case that
      constructed before, the objects are the same type with the same contents.
      perform_step! reaches cache.tmp only through alloc_symp_state
      (perform_step.jl:121), where it destructures into the rate buffers kdu,
      ku. It never uses cache.k by name.
    • So the change does not alter behaviour on any path that previously worked.
      It only unblocks the paths that previously threw a MethodError.
    • PR-side results: the author reports failing-before / passing-after output,
      and CI sublibrary-ci / OrdinaryDiffEqSymplecticRK Core (1, lts, pre) plus
      QA are green.
  • Independent review: this review
  • Merge: needs review (Chris). I have no blocking findings.

Blocking findings

None.

Non-blocking findings

  1. The base is master, not Fix VelocityVerletCache tmp field typing for unitful state #4602, so expect merge conflicts. On master,
    VelocityVerletCache still has tmp::uType and the swapped call
    (symplectic_caches.jl:36,56), so Fix VelocityVerletCache tmp field typing for unitful state #4602 has not landed and this diff does
    not include it. Both PRs add Unitful to the same [extras], [compat] and
    [targets] lines, and both append a units testset at the end of
    symplectic_tests.jl. If Fix VelocityVerletCache tmp field typing for unitful state #4602 defines helpers with the same names
    (accel_units! etc.; the body says it uses the "same setup"), whichever PR
    merges second needs a rebase and should reuse or deduplicate those helpers.
    I have not seen Fix VelocityVerletCache tmp field typing for unitful state #4602's diff, so the name clash is unconfirmed.
  2. The test's analytic check is sound, not fitted to observed error.
    • Every tested method (LDKD, VerletLeapfrog, McAte2) is exact for constant
      acceleration.
    • Over 1000 steps the only error is roundoff, well inside the default ≈
      rtol (√eps).
    • McAte2 exercises the shared SymplecticGenericCache, so the other 13
      tableau methods get the constructor fix, though they are not tested
      individually. That is acceptable.
  3. get_tmp_cache now returns rate-typed scratch. The body already flags this.
    At runtime it already returned a rate-typed buffer before the fix, so
    nothing changes. A continuous-callback test on a unitful problem would be a
    follow-up, not a merge requirement.
  4. The PR body mentions only Core3, but Core1 is also red.
    SciMLSensitivity.jl/Core1/1 failed after 1h2m, and so did Core3. Both
    downgrade jobs that failed, lib/DiffEqBase and
    lib/OrdinaryDiffEqDifferentiation, cover sublibraries that this PR does not
    touch and that do not depend on SymplecticRK. They are almost certainly
    pre-existing.

SciMLSensitivity Core3 (and Core1): probably not caused by this PR.

  • The type argument above means that any downstream problem that solved before
    the fix builds the same cache objects afterwards. For this PR to cause a
    failure, a test would have to hit a path that previously threw a
    MethodError, which would have made the test fail before as well.
  • The failure pattern also points elsewhere. Core2, Core4 and Core5 are green,
    as are the SymplecticRK sublibrary, AD, Integrators, Downstream and GPU
    groups.

To settle it:

  • (a) Open the Core3 job log (107225931220 (https://github.com/SciML/OrdinaryD
    iffEq.jl/actions/runs/35874247391/job/107225931220)) and find the failing
    testset and stack trace. If no frame is in OrdinaryDiffEqSymplecticRK and no
    symplectic algorithm appears, the PR is cleared.
  • (b) Compare against the same downstream job on a master run from the same
    day. The resolved SciMLSensitivity version must match, because a newly
    released SciMLSensitivity or dependency is the usual cause.
  • (c) Re-run the job on this PR. A flaky or time-limit failure will flip.

What I checked

  • The base cache definitions and constructor calls against the diff. The field
    order now matches the positional arguments in all three caches.
  • The only use of cache.tmp in perform_step, alloc_symp_state, and its
    destructuring into kdu, ku, which are rate buffers.
  • SymplecticEulerCache: tmp = zero(u) in a uType field is internally
    consistent and correctly left alone.
  • The test's physics and units:
    • the out-of-place acceleration 0.0u"1/s" .* v has units m/s².
    • the analytic solution is exact for these order-2 methods.
    • the test covers both iip and oop.
  • No existing tests were weakened, skipped or loosened, and no solvers were
    dropped. The Unitful dependency is test-only and has a compat bound.
  • Prose against the diff: the body's claims match what the diff changes.

What I did not verify

  • I ran nothing locally, and I did not see the failing-before output myself. I
    relied on the author's paste plus green CI.
  • The contents of the SciMLSensitivity Core1/Core3 and downgrade job logs, and
    master's status for those jobs.
  • Fix VelocityVerletCache tmp field typing for unitful state #4602's diff (helper-name collisions or conflicts).
  • Continuous callbacks on unitful symplectic problems.

Links


🤖 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-4603.txt on Chris's Mac

LeapfrogDriftKickDriftCache, VerletLeapfrogCache, and
SymplecticGenericCache have the same defect as VelocityVerletCache
(SciML#1397): tmp was declared uType but holds the rate-typed kdu/ku buffers
used by alloc_symp_state, and the alg_cache constructor calls passed
k/tmp swapped relative to the field order. VerletLeapfrogCache and
SymplecticGenericCache additionally built tmp from zero(u) instead of
zero(rate_prototype). With Unitful initial conditions uType != rateType,
so the inner constructors had no matching method and solve() threw a
MethodError for the in-place path of every affected algorithm (the
out-of-place constant caches are unaffected).

Fields are now typed rateType, tmp is built from zero(rate_prototype),
and constructor arguments are passed in field order. Unitful is added as
a test-only dependency for a regression test covering
LeapfrogDriftKickDrift, VerletLeapfrog, and McAte2 in both in-place and
out-of-place modes.

Part of 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
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