Skip to content

Fix PDIRK44 DimensionMismatch on callback resize! - #4744

Merged
ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:pdirk-resize-cache
Oct 7, 2026
Merged

ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:pdirk-resize-cache

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Oct 3, 2026 •

Copy link
Copy Markdown
Member

Summary

PDIRK44Cache.k1/k2 are Array{rateType} (vectors of stage vectors), so @cache's full_cache never reaches them and a callback resize!(integrator, n) leaves the stage buffers at the old length — perform_step! then hits DimensionMismatch. This adds resize_non_user_cache! for PDIRK44Cache (same SciMLBase hook as SDC #4673 / ABM #4703 / BDF #4719), resizing every k1[i]/k2[i] and the nested nlsolvers so deleteat! (which only calls that hook) stays consistent. Regression test: coupled linear u'=Au (nonzero off-diagonals), grow 2→3 then shrink back via DiscreteCallback, compared to piecewise exp(At) at rtol=1e-8; also covers deleteat!. Both Boolean threading modes (false and default true) are exercised independently. The grow callback initializes the new uprev slot (see #4722).

Compat: raised OrdinaryDiffEqNonlinearSolve floor from 2.9.1 to 2.9.9 (and aligned OrdinaryDiffEqCore/OrdinaryDiffEqDifferentiation/SciMLBase with 2.9.9's floors). PDIRK stores nlsolver as an Array; pre-2.9.9 resize_nlsolver! resized each element but still accessed .alg on the container (type Array has no field alg), which broke downgrade-sublibraries CI on the new resize test. Verified: pinned =2.9.1 fails that way; pinned =2.9.9 and current env both Pass 14.

Scope: in-place PDIRK44Cache / Vector state only. Out-of-place RHS / PDIRK44ConstantCache callback resize is not covered and still fails (MethodError on full_cache(::PDIRK44ConstantCache...)); that needs a separate constant-cache + mutable-nlsolver resize change.

Evidence

Failing before (src stashed; include of pdirk_resize_tests.jl on Julia 1.12.4):

DimensionMismatch: array could not be broadcast to match destination
Test Summary:                    | Error  Total
PDIRK44 resize! grow then shrink |     1      1

Passing after (round 2/3, Julia 1.12, --threads=4):

PDIRK44 resize! grow then shrink (threading=false) | Pass 4
PDIRK44 resize! grow then shrink (threading=true)  | Pass 4
PDIRK44 deleteat! (threading=false)                | Pass 3
PDIRK44 deleteat! (threading=true)                 | Pass 3

Downgrade repro (scratch env, OrdinaryDiffEqNonlinearSolve = "=2.9.1"): FieldError: type Array has no field alg on grow/shrink for both threading values. Same env with =2.9.9: Pass 14.

Logs: job dir before.txt / after.txt (round 1); round 2 resize smoke in scratch/resize_r2.log; round 3 downgrade in scratch/downgrade_fail.log / scratch/downgrade29_pass.log. Also passes on Julia 1.10.12 (round 1/2).

Test-group tails

Core (GROUP=Core Pkg.test, --check-bounds=yes):

PDIRK Resize Cache Tests | Pass 14
Testing OrdinaryDiffEqPDIRK tests passed

QA (GROUP=QA Pkg.test, --check-bounds=yes --threads=4, round 2):

PDIRK Resize Cache Tests | Pass 14
Allocation Tests | Broken 1  (pre-existing AllocCheck broken=true)
JET Tests | Pass 1
Aqua | Pass 21
Testing OrdinaryDiffEqPDIRK tests passed

Not verified

Reviewer pushback

  • Is double-resizing nlsolvers on the resize! path (Core's resize_nlsolver! then this hook) worth avoiding by only resizing k1/k2 here? deleteat! needs the nlsolver resize in this hook because it does not call resize_nlsolver!.
  • Should deleteat! properly deleteat! stage indices instead of truncating via resize! (default Core policy: "ordering doesn't matter in deterministic cache")?
  • Tolerance / dt=1e-3 choice for the coupled-linear exact comparison.
  • Should OOP constant-cache resize land in a follow-up, or block merge until covered?
  • Is requiring NonlinearSolve ≥ 2.9.9 the right trade for supporting Array-of-nlsolver resize, vs. a thinner PDIRK-only workaround?

Please ignore until reviewed by @ChrisRackauckas.

Risk assessment

Independent review: Codex CLI (gpt-6-astra) rated it medium, high confidence: in-place resize correct against exp(At); round 2 adds threading=true coverage and scopes OOP; round 3 raises NonlinearSolve floor to 2.9.9 for downgrade CI (Array nlsolver .alg bug).

🤖 Generated with Cursor Agent 2026.10.01-14929f9 (model: unknown (Cursor auto)), transcript /home/crackauc/sandbox/goals/performance/jobs/pr-pdirk-resize/log.txt on amdci2; orchestrated by Claude Code (claude-opus-5-5[1m]) https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv

Made with Cursor

Risk assessment

  • Risk: low

  • Blast radius: Only OrdinaryDiffEqPDIRK. The code change is a new resize_non_user_cache!(::ODEIntegrator, ::PDIRK44Cache, i) method, so it only runs when someone calls resize! or deleteat! on an in-place PDIRK44 integrator. That case threw DimensionMismatch before this PR. All other paths are unchanged. The compat floors in lib/OrdinaryDiffEqPDIRK/Project.toml go up: OrdinaryDiffEqCore 4.6→4.13, OrdinaryDiffEqDifferentiation 3.3→3.10, OrdinaryDiffEqNonlinearSolve 2.9.1→2.9.9, SciMLBase 3.39→3.46. Users pinned below those floors will not resolve the next PDIRK release. LinearAlgebra is added as a test-only dependency (stdlib, MIT). Public API is unchanged, so no SemVer major bump is needed. The PR does not change the PDIRK version number.

  • Evidence: On head 1f886de, 127 checks pass, 4 fail and 1 is skipped (the matrix-template placeholder). All 4 failures are pre-existing: each also fails on the current master tip 4a5c0e7 and on the PR base 217e0ad.

    • downgrade-sublibraries / test (lib/DiffEqBase): failures in DiffEqBase high_level_solve.jl:94–101, which has nothing to do with PDIRK.
    • downgrade-sublibraries / test (lib/OrdinaryDiffEqDifferentiation)
    • tests / GPU (julia 1, self-hosted Linux X64 gpu) / Tests - GPU (Julia 1)
    • SciMLSensitivity.jl/Core1/1 / Downstream Tests - Core1

    Every PDIRK check passes on head: downgrade-sublibraries / test (lib/OrdinaryDiffEqPDIRK), which confirms the new floors work in CI; sublibrary-ci / lib/OrdinaryDiffEqPDIRK Core on Julia 1, lts and pre; and PDIRK [QA]. downgrade-sublibraries for Core and NonlinearSolve also pass. No regressions.

    Other findings:

    • No weakened tests: nothing was skipped, marked broken or loosened. The new test compares against exact exp(At) at rtol=1e-8 on a coupled system.
    • Internals: the hook reads nls.cache.firstcall and calls resize!(nls, integrator, i). Both are non-public, but they live in sibling packages in the same monorepo, and the code matches resize_nlsolver! in OrdinaryDiffEqNonlinearSolve and the already-merged SDC hook line for line. ODEIntegrator and isnewton are declared public in OrdinaryDiffEqCore.
    • Double resize (disclosed): on the resize! path the nlsolvers are resized twice, by Core's resize_nlsolver! and then by this hook. The second call resizes to the same length, so it is harmless.
    • Out-of-date description: it lists "fresh GitHub downgrade-sublibraries re-run" as not verified, but that check has now run and passed. It does not mention the new ODEIntegrator/isnewton imports. Nothing material is left out.
    • Reviews: none posted.
  • Independent review: Devin CLI (Mac) / fusion-claude-opus-5-5-high-sidekick-swe-2-medium rated it low, high confidence: the new method only runs on a resize path that threw before, it copies the merged SDC resize pattern, and every PDIRK check including downgrade passes, with all 4 head failures also red on master.

  • Merge: auto-merge candidate. It is still a draft and the body says "Please ignore until reviewed by @ChrisRackauckas", so it has to be marked ready first. The design questions the description raises (OOP/constant-cache resize as a follow-up, the double nlsolver resize) do not block merging.


🤖 Risk assessment posted by an AI agent (fleet master) — harness: Devin CLI (Mac) / fusion-claude-opus-5-5-high-sidekick-swe-2-medium; dispatched by Devin CLI 3000.11.3 (Mac) fleet-master caretaker, model Fusion (claude-opus-5-5 medium + swe-2 medium)
Conversation: local transcript ~/.local/share/devin/cli/transcripts/speckle-whale.json (Chris's Mac)

ChrisRackauckas and others added 3 commits October 2, 2026 21:59
k1/k2 are Array{rateType} so full_cache never reaches the stage vectors;
add resize_non_user_cache! (and cover deleteat! via the same hook).

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent 2026.10.01-14929f9
Agent-Model: unknown (Cursor auto)
Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/pr-pdirk-resize/log.txt on amdci2
Parameterize grow/shrink and deleteat! regressions over both Boolean
threading modes so the default two-nlsolver path is protected.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent 2026.10.01-14929f9
Agent-Model: unknown (Cursor auto)
Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/pr-pdirk-resize/log.txt on amdci2
…resize

PDIRK stores nlsolver as an Array; pre-2.9.9 resize_nlsolver! still accessed
.alg on the container after resizing elements, so downgrade CI failed the
new resize regression. Align Core/Differentiation/SciMLBase floors with 2.9.9.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent 2026.10.01-14929f9
Agent-Model: unknown (Cursor auto)
Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/pr-pdirk-resize/log.txt on amdci2
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 7, 2026 04:54
@ChrisRackauckas
ChrisRackauckas merged commit ad92a33 into SciML:master Oct 7, 2026
130 of 134 checks passed
ChrisRackauckas referenced this pull request Oct 14, 2026
…inaryDiffEqBDF, OrdinaryDiffEqExplicitRK, OrdinaryDiffEqFIRK, OrdinaryDiffEqFeagin, OrdinaryDiffEqHighOrderRK, OrdinaryDiffEqPDIRK, OrdinaryDiffEqRKN, OrdinaryDiffEqSDIRK, StochasticDiffEqHighOrder, StochasticDiffEqLowOrder, and StochasticDiffEqMilstein for release (#4871)

Agent-Harness: Devin CLI 3000.11.3
Agent-Model: Fusion (Claude Opus 5.5 Medium + SWE-2 Medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/flash-hour.json

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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