Skip to content

Gate initialization discrete saves on save_discretes - #4753

Merged
ChrisRackauckas merged 5 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/4742-save-discretes-init
Oct 4, 2026
Merged

ChrisRackauckas merged 5 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/4742-save-discretes-init

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

initialize_callbacks! and finalize_endpoint! called SciMLBase discrete-save helpers without checking integrator.opts.save_discretes, so save_discretes=false still recorded discretes at init and (when the endpoint-save path runs) at finalize. Event-time saves in DiffEqBase already use !isdefined(integrator.opts, :save_discretes) || integrator.opts.save_discretes; this PR applies the same guard on those ODE paths and on DelayDiffEq's post-init discrete save. Default save_discretes=true is unchanged.

Verification

Runic (Julia formatter, not the unrelated runic binary):

julia +1.12 --project=@runic -e 'using Runic; exit(Runic.main(ARGS))' -- --check <touched files>
# exit 0

Init gate (OrdinaryDiffEqCore)

Fail-before (src init gate reverted):

Expression: isempty((sol_false.discretes.collection[1]).t)
 Evaluated: isempty([0.0])
save_discretes initialization | 2 Pass, 2 Fail

Pass-after: save_discretes initialization | 4 Pass (init-only subset before finalize test was added).

Finalize gate (OrdinaryDiffEqCore)

Fail-before (finalize_endpoint! gate reverted; save_everystep=false so endpoint path runs):

Expression: isempty((sol_false.discretes.collection[1]).t)
 Evaluated: isempty([0.2])
Expression: isempty((sol_false.discretes.collection[1]).u)
 Evaluated: isempty([[0.0]])

Pass-after (narrowed): save_discretes initialization | 8 Pass (init + finalize).

DelayDiffEq post-init gate

Fail-before (DelayDiffEq src gate reverted; Core init gate kept):

Expression: isempty((sol_false.discretes.collection[1]).t)
 Evaluated: isempty([0.0])
... (solve + reinit! emptiness assertions fail; default non-empty still passes)
save_discretes | 1 Pass, 5 Fail

Pass-after (narrowed): save_discretes | 6 Pass.

Full suites

cd lib/OrdinaryDiffEqCore && GROUP=Core julia +1.12 --project=. -e 'using Pkg; Pkg.test()'
# save_discretes initialization | 8 Pass
# Testing OrdinaryDiffEqCore tests passed

cd lib/DelayDiffEq && GROUP=Integrators julia +1.12 --project=. -e 'using Pkg; Pkg.test()'
# save_discretes | 6 Pass
# Testing DelayDiffEq tests passed

Not verified

  • ModelingToolkit issue reproducer end-to-end (Core/DDE tests use a minimal SymbolCache stand-in).
  • SciMLBase-central fix inside save_discretes_if_enabled! / save_final_discretes!.
  • Other integrator packages outside this monorepo.

Reviewer pushback

  • Prefer fixing inside SciMLBase so every integrator inherits the guards.
  • Whether DelayDiffEq's second post-init save_discretes_if_enabled! should be removed rather than gated.
  • Finalize saves only run when solution_endpoint_match_cur_integrator! appends the endpoint (save_everystep=false in the test); dense every-step solves may not hit that path.

Fixes #4742

Risk assessment

  • Risk: low
  • Blast radius: ODE/DDE discrete-parameter saving when save_discretes=false at init, DelayDiffEq post-init, and endpoint finalize; default true unchanged.
  • Evidence: fail-before/pass-after for init, finalize, and DDE gates; full OrdinaryDiffEqCore GROUP=Core and DelayDiffEq GROUP=Integrators passed.
  • Independent review: Claude Code (claude-opus-5-5[1m]) rated round 1 low, high confidence: init-time gate correct and public-API; round-1 findings (Runic, DDE test, finalize gate) addressed in follow-up commits
  • Merge: needs human review — init/finalize callback paths are shared; small, opt-gated change but discrete-parameter semantics warrant a maintainer look.

🤖 Generated with Cursor Agent CLI (model: auto)
Transcript: /home/crackauc/sandbox/goals/issue-backlog/ibd/OrdinaryDiffEq.jl/jobs/4742-cursor/log.txt on amdci2.julia.csail.mit.edu

Risk assessment

  • Risk: low
  • Blast radius: Only ODE and DDE solves called with save_discretes=false and a callback that has saved_clock_partitions. In practice that means ModelingToolkit models with @discretes or discrete events. Those solves no longer save discretes at initialization, at DelayDiffEq's post-init save, or at the endpoint in finalize_endpoint!. Code that relied on the old behaviour, where sol.ps[h] held exactly one value ([t0], or the endpoint) even with save_discretes=false, will now get an empty timeseries. This is the documented intent of the flag and fixes save_discretes = false still saves the discretes at initialization #4742, so it is a patch-level bug fix, not a SemVer break. With the default save_discretes=true, the code path is unchanged. The fix lives in the OrdinaryDiffEq monorepo only. Other integrators that call SciMLBase.save_discretes_if_enabled! directly don't get it, which the description discloses.
  • Evidence: On head 5d0eaae9, 261 checks pass, 1 is skipped and 8 fail. I compared every failure against master and none is a regression:
    • SciMLSensitivity.jl/Core1/1 / Downstream Tests - Core1: the same 2 errors (Mooncake with MooncakeAdjoint at concrete_solve_derivatives.jl:451, and Complex Adjoints) with an identical count (231 passed, 2 errored, 6 broken) on master head 4a5c0e71. Also fails on bd6cfb3c, e7068884 (the base) and 75bc9dfc. Pre-existing.
    • downgrade-sublibraries / test (lib/DiffEqBase) and downgrade-sublibraries / test (lib/OrdinaryDiffEqDifferentiation): both fail on 4a5c0e71, bd6cfb3c, e7068884 and 75bc9dfc. Pre-existing.
    • tests / GPU (julia 1, self-hosted Linux X64 gpu): fails on 4a5c0e71, e7068884 and 75bc9dfc. Pre-existing.
    • Four sublibrary-ci jobs fail with the same error and count on master 75bc9dfc. Later master commits only run the touched sublibraries, so they have no newer runs of these jobs. Pre-existing:
      • lib/GlobalDiffEq Core: companion_tests.jl:49 errors.
      • lib/OrdinaryDiffEqDifferentiation Core: ScalarOperator mass matrix fails with MethodError: diag(::ScalarOperator).
      • lib/OrdinaryDiffEqNonlinearSolve Core: Newton Tests fails with LineSearchException.
      • lib/OrdinaryDiffEqRosenbrock [QA]: Rosenbrock32 perform_step! inference errors at inference_tests.jl:58.
    • The relevant suites all pass:
      • OrdinaryDiffEqCore Core on Julia 1, lts and pre, plus its QA job.
      • Every DelayDiffEq group, including QA.
      • The ModelingToolkit downstream jobs (Initialization, InterfaceI, InterfaceII, SymbolicIndexingInterface) and the in-repo tests / ModelingToolkit jobs on Julia 1, lts and pre.
      • DiffEqCallbacks downstream, and SciMLSensitivity Core2 through Core5.
  • Independent review: Devin CLI (Mac) / fusion-claude-opus-5-5-high-sidekick-swe-2-medium rated it low, high confidence: three call sites get the same !isdefined(opts, :save_discretes) || opts.save_discretes guard that DiffEqBase already applies to event-time saves; the default path is untouched; no tests were weakened. It adds 2 new testsets (Core: init and finalize; DDE: solve and reinit!), and the description shows each failing before the fix and passing after.
  • Merge: needs human review. Nothing in the code blocks a merge. The findings are:
    1. The PR text asks reviewers to ignore it until @ChrisRackauckas has reviewed it, and no reviews or comments exist yet.
    2. It calls the non-public SciMLBase internals save_discretes_if_enabled! and save_final_discretes!. Both calls predate this PR and are on the ExplicitImports allowlist in lib/OrdinaryDiffEqCore/test/qa/qa.jl, so nothing new is introduced.
    3. The PR doesn't mention that sol.ps[h] changes from one value to empty under save_discretes=false. Users who depended on that will see the difference.
    4. The MTK reproducer from the issue wasn't run end-to-end; the tests use a SymbolCache stand-in. The description discloses this.
    5. There is an open design question whether the guard belongs inside SciMLBase so that every integrator gets it.
    6. The attribution in the PR's embedded risk section is vague ("Cursor Agent CLI (model: auto)").

🤖 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 5 commits October 3, 2026 01:48
Event-time discrete saves already respect save_discretes; the init path did not, so save_discretes=false still recorded the initial discrete value.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/OrdinaryDiffEq.jl/jobs/4742-cursor/log.txt on amdci2.julia.csail.mit.edu
Asserts that a never-firing callback with saved_clock_partitions leaves discrete storage empty when save_discretes=false, while still saving once at t0 when true.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/OrdinaryDiffEq.jl/jobs/4742-cursor/log.txt on amdci2.julia.csail.mit.edu
DelayDiffEq calls save_discretes_if_enabled! again after initialize_callbacks!; without the same guard, DDE solves would still save discretes at start when save_discretes=false.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/OrdinaryDiffEq.jl/jobs/4742-cursor/log.txt on amdci2.julia.csail.mit.edu
save_final_discretes! at the endpoint path ignored opts.save_discretes; apply the same DiffEqBase-style guard, Runic-format the SymbolCache call, and assert finalize-only saves respect save_discretes=false.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/OrdinaryDiffEq.jl/jobs/4742-cursor/log.txt on amdci2.julia.csail.mit.edu
Cover MethodOfSteps(Tsit5()) solve and reinit! paths so the post-init DelayDiffEq discrete-save gate is exercised.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/OrdinaryDiffEq.jl/jobs/4742-cursor/log.txt on amdci2.julia.csail.mit.edu
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 4, 2026 14:23
@ChrisRackauckas
ChrisRackauckas merged commit be2e640 into SciML:master Oct 4, 2026
264 of 272 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.

save_discretes = false still saves the discretes at initialization

2 participants