Skip to content

Resize FSAL, nlsolver and J/W buffers in deleteat!/addat!, once per array - #4796

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/fsal-deleteat-addat
Oct 8, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/fsal-deleteat-addat

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

deleteat!/addat! on an ODEIntegrator only touched full_cache(integrator). They missed fsallast (and fsalfirst when it doesn't alias a cache field), the nonlinear-solver buffers, and J/W. They also ran twice on any array that appears more than once in full_cache; Vern7Cache, for example, aliases k3/k10 to k2. This PR visits each distinct buffer once (deduplicated by ===, with the FSAL arrays included) and then resizes f's split cache, the nlsolver and J/W the same way resize! does. Only the deleteat!/addat! paths change. The resize! methods that #4763 edits are untouched.

Fixes #4789. The same double-delete-on-aliased-buffers mechanism caused the default-solver failure in #2549. With this change, an adapted version of that reproducer returns Success. The setup I measured was the default solver on du .= 0 with u0 = [1.0, 2.0, 3.0], one step!, then deleteat!(integ, 1) and solve!, giving u = [2.0, 3.0]. The Cursor review ran a decaying right-hand side with five step!s and also got Success, with u ≈ [0.298, 0.447] (the decayed kept components). I have not run the original callback script from #2549, so I am not closing it here.

Verification

The new test test/Integrators_II/deleteat_addat_tests.jl covers Trapezoid, ImplicitEuler, KenCarp4, Tsit5, Vern7 and Rodas5P. For each method it takes 5 fixed steps (dt = 1/64) on a decoupled 6-component decay problem, applies deleteat! or addat!, and continues to t_end. It then asserts Success, the kept components, and agreement within rtol = 1e-12 against a solve of the reduced or extended system started from the same state.

Fail before (master 0fd3326, fix stashed, test wrapped in an outer testset):

Test Summary:                                   | Pass  Error  Total   Time
all                                             |   23      8     31  21.7s
  deleteat!/addat! mid-solve with Trapezoid     |    2      2      4   8.8s
  deleteat!/addat! mid-solve with ImplicitEuler |    2      2      4   2.8s
  deleteat!/addat! mid-solve with KenCarp4      |    2      2      4   2.2s
  deleteat!/addat! mid-solve with Tsit5         |    8             8   1.6s
  deleteat!/addat! mid-solve with Vern7         |    1      2      3   2.3s
  deleteat!/addat! mid-solve with Rodas5P       |    8             8   1.7s

Pass after:

Test Summary: | Pass  Total   Time
all           |   48     48  18.5s

Issue reproducer after the fix: all 12 method×operation combinations print Success. Tsit5 and Rodas5P already passed on master.

GROUP=Integrators_II julia +1.12 --project=. -e 'using Pkg; Pkg.test()' (repo root):

Integrator RNG Tests            |   41     41
Reverse Directioned Event Tests |  170    170
Differentiation Direction Tests |   12     12
Resize Tests                    |   90     90
deleteat!/addat! Tests          |   48     48
Cache Tests                     |  214  4 broken  218
Add Steps Tests                 |    1      1
IMEX Split Function Tests       |   15  1 broken   16
     Testing OrdinaryDiffEq tests passed

Runic (julia +1.12 --project=@runic -e 'using Runic; exit(Runic.main(ARGS))' -- --check on all 3 touched files, at the branch head): exit 0. typos on the touched files: exit 0.

Not verified

  • DelayDiffEq defines its own deleteat!/addat! for DDEIntegrator and is not changed here. Its deleteat! passes an undefined i to deleteat_non_user_cache!, which is a separate bug.
  • addat! on arrays follows SciMLBase's semantics: it appends uninitialized slots at the end and ignores the positions. The test uses addat!(integ, 7:8) and sets the new values explicitly.
  • I did not run other test groups, QA, or GPU tests.

Risk assessment

  • Risk: low
  • Blast radius: only deleteat!(::ODEIntegrator, idxs) and addat!(::ODEIntegrator, idxs) in OrdinaryDiffEqCore. On master these already threw for every in-place implicit FSAL method and for Vern7. For methods that worked (Tsit5, Rodas5P), the only behavior change is that an array aliased in full_cache is no longer edited twice. No public API change.
  • Evidence: the new test fails on master (8 errors) and passes with the fix (48/48). The Integrators_II group passes locally.
  • Independent review: Cursor Agent (auto) first pass rated it low, high confidence, MERGE: fail-before/pass-after reproduced, J/W rebuilt and next implicit step matches a fresh solve, merges cleanly with Zero-fill grown step history after resize! (#4722) #4763. Top-reviewer pass (Astra/Fusion) pending — both out of quota 2026-10-07
  • Merge: needs human review until a top-reviewer pass is in. It is small and self-contained.

🤖 Generated with Claude Code (model: claude-opus-5-5[1m])

https://claude.ai/code/session_01AXwyJDRaMKgnYMG9M1Ut49

Risk assessment

  • Risk: low
  • Blast radius: Only deleteat!(::ODEIntegrator, idxs) and addat!(::ODEIntegrator, idxs) in lib/OrdinaryDiffEqCore/src/integrators/integrator_interface.jl change.
    • Where it fixes things: on master these calls threw for in-place implicit FSAL methods (Trapezoid, ImplicitEuler, KenCarp4) and for Vern7. They now work.
    • Where behavior differs for methods that already worked (Tsit5, Rodas5P):
      • An array that appears more than once in full_cache is now deleted from only once.
      • fsalfirst and fsallast are now edited.
      • nothing entries are skipped.
      • resize_f!, resize_nlsolver! and resize_J_W! now run with the same arguments resize! already uses.
    • Not affected: DelayDiffEq has its own DDEIntegrator methods and never calls these. StochasticDiffEq uses a different integrator type.
    • Downstream: FBDF deleteat!/addat!: edit u, uprev and history arrays (stacked on #4719, #4796) #4807 is stacked on this PR.
    • Gaps the description doesn't mention (none are regressions):
      • On CompositeCache/DefaultCache, resize_J_W! and resize_nlsolver! do nothing, because the J/W/nlsolver fields live in the sub-caches. A stiff switch after deleteat! (for example AutoTsit5(Rosenbrock23())) is probably still broken. resize! has the same limitation.
      • The SplitFunction branch of resize_f! is never exercised by the new test.
      • No test covers the default-solver case from deleteat!(integrator, ind) not working with default solver #2549 that the description cites.
      • Non-aliased nlsolver and linsolve buffers, and J/W, are resized by truncation or similar, not by index deletion. This is safe because firstcall = true and the Rosenbrock check on last_u_length both force a fresh J/W.
  • Evidence: On head 1a07ddb, 250 checks pass, 8 fail and 1 is skipped (a template-named matrix job). Integrators_II passes on Julia 1, lts and pre; the new tests live there. Runic, Typos and OrdinaryDiffEqCore QA also pass. None of the 8 failures is a regression:
    • These four fail on the last 3 master pushes (0fd3326, 6ef1364, cceca42) with the same signature:
      • tests / GPU (julia 1): three QNDF mass=diag_cu failures at test/gpu/dae_tests.jl:481, 170 pass / 3 fail on both head and master.
      • SciMLSensitivity.jl/Core1/1: "Mooncake with MooncakeAdjoint" errors at concrete_solve_derivatives.jl:451, 241 pass / 1 error on both.
      • downgrade-sublibraries / test (lib/DiffEqBase): fails on master too.
      • downgrade-sublibraries / test (lib/OrdinaryDiffEqDifferentiation): fails on master too.
    • These four sublibrary-ci jobs don't run on master pushes. The first three fail on unrelated master-based PRs Skip the step between tstops an ulp apart #4805 and Differentiate with a fitting chunk after resize!/deleteat! shrinks the state below the ForwardDiff chunk #4804; GlobalDiffEq Core fails on Skip the step between tstops an ulp apart #4805. None of the errors involves deleteat or addat:
      • GlobalDiffEq Core: "GlobalErrorEstimation does not currently support callbacks"
      • OrdinaryDiffEqDifferentiation Core: diag(::ScalarOperator) MethodError
      • OrdinaryDiffEqNonlinearSolve Core: LineSearchException in Newton Tests
      • OrdinaryDiffEqRosenbrock QA: "Rosenbrock32 is unstable on DAEs" in inference_tests.jl
  • Independent review: Devin CLI (Mac) / fusion-claude-opus-5-5-high-sidekick-swe-2-medium rated it low, high confidence. The change is a 26-line fix to a path that previously threw. It reuses the package's own resize! helpers (resize_f!, resize_nlsolver!, resize_J_W!) without reaching into any dependency's non-public internals and changes no public API (SemVer patch). It weakens no tests and adds a new test that compares the result against a fresh solve at rtol = 1e-12. There are no review comments on the PR.
  • Merge: auto-merge candidate. No regressions, no weakened tests, no API change. Caveats:

🤖 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 head, model Fusion (claude-opus-5-5 medium + swe-2 medium)
Conversation: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

ChrisRackauckas and others added 2 commits October 7, 2026 11:36
…rray

deleteat!/addat! on an ODEIntegrator only touched full_cache, so
fsallast (and fsalfirst when not aliased), the nonlinear solver buffers and
J/W kept the old length, and the next step! threw. Cache fields that alias
each other were also shortened twice. Visit each distinct buffer once and
resize the solver internals the same way resize! does.

Fixes SciML#4789

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Agent-Harness: Claude Code
Agent-Model: claude-opus-5-5[1m]
Agent-Session: https://claude.ai/code/session_01AXwyJDRaMKgnYMG9M1Ut49
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Agent-Harness: Claude Code
Agent-Model: claude-opus-5-5[1m]
Agent-Session: https://claude.ai/code/session_01AXwyJDRaMKgnYMG9M1Ut49
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 8, 2026 11:14
@ChrisRackauckas
ChrisRackauckas merged commit 1d86051 into SciML:master Oct 8, 2026
253 of 261 checks passed
ChrisRackauckas referenced this pull request Oct 13, 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.

deleteat!/addat! on in-place integrators skip fsallast, nlsolver/J/W, and double-apply to aliased cache arrays

2 participants