Skip to content

Fix FlexUnits/ReverseDiff/Tracker/Measurements/MCM ODE_DEFAULT_NORM to RMS (#4610) - #4611

Merged
ChrisRackauckas merged 7 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/4610-ext-norms-rms
Oct 31, 2026
Merged

ChrisRackauckas merged 7 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/4610-ext-norms-rms

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

Summary

Five DiffEqBase extensions copied the Unitful bug from #4596: array ODE_DEFAULT_NORM called the scalar method (abs) on stripped values, computing sqrt(mean(|x|)) instead of RMS. They now use sqrt(sum(abs2(value(x))) / max(length(u), 1)) (MonteCarloMeasurements value is the particle mean). This is a numerical change only (adaptive step counts for these element types); not an API break; Unitful left untouched (see #4609).

Behaviour change

With Tsit5 at default tolerances, adaptive step counts for these element types move toward the Float64 baseline instead of taking 25–33% more steps:

Problem Element type master this PR Float64 baseline
Lotka–Volterra Measurements 44 33 33
Lotka–Volterra MonteCarloMeasurements 44 35 33
Exponential decay Measurements 27 18 18
Exponential decay MonteCarloMeasurements 27 18 18

Verification

Fail before / negative control

Scratch env with DiffEqBase developed; extension sources reverted to pre-fix:

julia +1.12 --project=scratch/norm-ext-test -e 'include("lib/DiffEqBase/test/measurements_norm_ext.jl")'
# and the other four *_norm_ext.jl files similarly

Tails:

Evaluated: 1.8708286933869707 ≈ 3.5355339059327378
Test Summary:                     | Pass  Fail  Total  Time
FlexUnits ODE_DEFAULT_NORM is RMS |    5     4      9  6.0s
Test Summary:                        | Pass  Fail  Total  Time
Measurements ODE_DEFAULT_NORM is RMS |    5     4      9  0.4s
Test Summary:                                  | Pass  Fail  Total  Time
MonteCarloMeasurements ODE_DEFAULT_NORM is RMS |    7     4     11  0.6s
Test Summary:                       | Pass  Fail  Total  Time
ReverseDiff ODE_DEFAULT_NORM is RMS |    7     5     12  4.3s
Test Summary:                   | Pass  Fail  Total  Time
Tracker ODE_DEFAULT_NORM is RMS |    7     5     12  1.5s

Pass after fix

julia +1.12 --project=scratch/norm-ext-test -e 'include.(["flexunits","measurements","montecarlomeasurements","reversediff","tracker"] .* "_norm_ext.jl")'
Test Summary:                     | Pass  Total  Time
FlexUnits ODE_DEFAULT_NORM is RMS |    9      9  0.7s
Test Summary:                        | Pass  Total  Time
Measurements ODE_DEFAULT_NORM is RMS |    9      9  0.6s
Test Summary:                                  | Pass  Total  Time
MonteCarloMeasurements ODE_DEFAULT_NORM is RMS |   11     11  0.6s
Test Summary:                       | Pass  Total  Time
ReverseDiff ODE_DEFAULT_NORM is RMS |   12     12  7.5s
Test Summary:                   | Pass  Total  Time
Tracker ODE_DEFAULT_NORM is RMS |   12     12  1.5s
ALL PASSED

DiffEqBase Core suite

cd lib/DiffEqBase && GROUP=Core julia +1.12 --project=. -e 'using Pkg; Pkg.test()'

Tail:

Test Summary:              | Pass  Total  Time
FlexUnits ODE_DEFAULT_NORM |    9      9  3.6s
Test Summary:                 | Pass  Total  Time
Measurements ODE_DEFAULT_NORM |    9      9  0.6s
Test Summary:                           | Pass  Total  Time
MonteCarloMeasurements ODE_DEFAULT_NORM |   11     11  9.7s
Test Summary:                | Pass  Total  Time
ReverseDiff ODE_DEFAULT_NORM |   12     12  6.4s
Test Summary:            | Pass  Total  Time
Tracker ODE_DEFAULT_NORM |   12     12  3.9s
...
200.543611 seconds (...);
     Testing DiffEqBase tests passed

Runic --check and typos on touched files: clean.

Not verified

  • Downstream / Downstream2 groups (intentionally did not instantiate test/downstream).
  • Full ODE solves with these element types (norm-only unit tests).
  • Performance (no instruction-count / allocation evidence claimed).
  • Unitful (out of scope; Fix Unitful ODE_DEFAULT_NORM to compute RMS (#4596) #4609).

Points to weigh

  • Whether TrackedReal-time AoS methods should keep returning a tracked residual via sum(abs2, u) (done here) vs always stripping.
  • Whether MonteCarloMeasurements should keep historical mean(...) spelling vs sum/max(length,1) (functionally same for non-empty).
  • Adding MonteCarloMeasurements + Tracker to DiffEqBase test targets (needed so Core CI loads the extensions).

Fixes #4610

Please ignore this draft until reviewed by @ChrisRackauckas.

Harness: Cursor Agent CLI 2026.09.18-9a7762b; model: auto; transcript: /log.txt

Adoption update

Rebased the original two Cursor commits plus the prior Codex cleanup commit onto current origin/master at 85110ac2a6 (Reuse W across the sweeps of an adaptive SDC step), preserving authorship and commit separation (no squash). Force-pushed to fork with --force-with-lease. Draft status unchanged; not merged.

No unresolved review comments or review threads. Issue #4610 remains open; master still has the buggy sqrt(mean(|x|)) extension norms (confirmed via git show origin/master:lib/DiffEqBase/ext/DiffEqBaseMeasurementsExt.jl). No other open PR duplicates this fix (related: #4609 Unitful-only, #4600 @fastmath).

Fail before / pass after

With the five extension sources reverted to master and the regression tests retained (scratch/norm-ext-test):

Evaluated: 1.8708286933869707 ≈ 3.5355339059327378
FlexUnits ODE_DEFAULT_NORM is RMS |    5     4      9
Measurements ODE_DEFAULT_NORM is RMS |    5     4      9
MonteCarloMeasurements ODE_DEFAULT_NORM is RMS |    7     4     11
ReverseDiff ODE_DEFAULT_NORM is RMS |    7     5     12
Tracker ODE_DEFAULT_NORM is RMS |    7     5     12

With the fix restored:

FlexUnits ODE_DEFAULT_NORM is RMS |    9      9
Measurements ODE_DEFAULT_NORM is RMS |    9      9
MonteCarloMeasurements ODE_DEFAULT_NORM is RMS |   11     11
ReverseDiff ODE_DEFAULT_NORM is RMS |   12     12
Tracker ODE_DEFAULT_NORM is RMS |   12     12
PASS_AFTER_OK

GROUP=Core DiffEqBase (Pkg.test()): Testing DiffEqBase tests passed (133.2 s); extension suites 9/9, 9/9, 11/11, 12/12, 12/12. Runic --check on touched .jl files: clean. PR CI DiffEqBase Julia 1 Core: pass.

CI classification

All seven red checks are inherited from master / unrelated packages (this PR only changes DiffEqBase extension norms + tests; DiffEqBase Julia 1/pre/Downstream/QA/Static/Sundials are green):

Check Classification Evidence
DiffEqBase downgrade also on master PR / master — same high_level_solve.jl:94 despecialized_solved !== despecialized_default_problem
OrdinaryDiffEqDifferentiation downgrade also on master PR / master — same diag(::ScalarOperator) MethodError
SciMLSensitivity Core1 also on master PR / master — Mooncake/Any constructor, ComplexF64 dual, SIGSEGV
DiffEqBase LTS Core also on master (local) PR — same high_level_solve failure; reproduced on clean master tree under LTS locally; master Sublibrary CI still queued (f9ce35, 85110ac)
OrdinaryDiffEqDifferentiation Core also on master (same as downgrade) PR — diag(::ScalarOperator); identical to master Differentiation downgrade
GlobalDiffEq Core unrelated / present on original PR CI PR — GlobalErrorEstimation does not currently support callbacks in companion_tests.jl (untouched by this PR); same signature on pre-adoption PR runs
OrdinaryDiffEqNonlinearSolve Core unrelated / present on original PR CI PR — Trapezoid non-diagonal mass matrix ArgumentError in mass_matrix_tests.jl (untouched); same on pre-adoption PR; NonlinearSolve downgrade on this PR passes

GPU jobs were still pending on the pre-rebase CI matrix; not re-run locally.

Not verified

  • Full ODE solves with these element types (norm-only unit tests).
  • Performance / allocations.
  • Unitful (out of scope; Fix Unitful ODE_DEFAULT_NORM to compute RMS (#4596) #4609).
  • Independent human review of the numerical change.
  • Fresh post-rebase CI completion on 85110ac tip (push will retrigger).

🤖 Adoption work by Cursor Agent CLI 2026.09.26-dd393fe (model: auto).
Session: local transcript at <local>/log.txt.

Independent review

Review follow-up (Opus 5.5 MERGE)

Addressed the three small asks from the independent review:

  1. Added the Behaviour change section above with measured Tsit5 step counts.
  2. MonteCarloMeasurements cases now use varied particles ([1,2,3,4,5] / [0,2,4,6,8]) with hand-checked means 3 and 4, so the suite exercises value (= particle mean) rather than constant fills.
  3. Merged the five *_norm_ext.jl files into extension_norm_ext.jl with a loop over the five types; dropped the redundant expected ≈ 3.5355… lines.

Merged-suite verification (extension sources reverted → restored):

# fail-before
Extension ODE_DEFAULT_NORM is RMS |   20    14     34
  FlexUnits / Measurements / MCM / ReverseDiff / Tracker all fail (1.8708… ≈ 3.5355…)

# pass-after
Extension ODE_DEFAULT_NORM is RMS |   34     34
PASS_AFTER_OK

Runic --check on extension_norm_ext.jl and runtests.jl: clean. Pushed 91fdb5d9f5.

Risk assessment

  • Risk: low
  • Blast radius: ODE_DEFAULT_NORM in five optional DiffEqBase extensions (FlexUnits, ReverseDiff, Tracker, Measurements, MonteCarloMeasurements). Each now computes the same RMS as the Float64 default on primal values; tracked methods keep tracked abs2, so AD behaviour is unchanged. Adaptive stepping for these element types now matches Float64: for example, Lotka-Volterra with Measurements goes from 44 to 33 steps, equal to Float64. No public API change.
  • Evidence: the merged test suite fails with the extension sources reverted and passes with them. The DiffEqBase downgrade red (high_level_solve.jl:94) also fails on master. The PR is consistent with the sibling Unitful fix Fix Unitful ODE_DEFAULT_NORM to compute RMS (#4596) #4609.
  • Independent review: Claude Code (Opus 5.5; adopted by Codex Luna then Cursor Auto) rated it low with high confidence, verdict MERGE. Its test-merge and PR-body asks landed afterwards and were checked by the head session.
  • Merge: auto-merge candidate once CI finishes.

Risk assessment and review coordination by 🤖 Claude Code (model: claude-opus-5-5[1m]), https://claude.ai/code/session_01NdFVhANTF4nepTbqYxjfRP

Adoption update: rebased onto master 7393799

Rebased onto 739379950d (Bump OrdinaryDiffEqSDC to 1.0.0), preserving the five PR commits and their authorship. Force-pushed to fork with --force-with-lease.

Conflicts

Only file: lib/DiffEqBase/test/runtests.jl (twice during the rebase).

  1. Commit “Add failing RMS norm tests…” — master had added @safetestset "Unitful extension" include("unitful_ext.jl") (Fix Unitful ODE_DEFAULT_NORM to compute RMS (#4596) #4609); the PR added the five *_norm_ext.jl includes in the same place. Kept both: Unitful include from master, then the five PR includes.
  2. Commit “Merge … into one looping suite” — HEAD still had Unitful + five includes; the commit replaced the five with extension_norm_ext.jl. Kept Unitful from master and the merged Extension ODE_DEFAULT_NORM include from the PR.

lib/DiffEqBase/Project.toml auto-merged cleanly (PR adds MonteCarloMeasurements/Tracker to test targets atop master’s Unitful extras).

Re-verify tails

# extension_norm_ext.jl
Test Summary:                     | Pass  Total   Time
Extension ODE_DEFAULT_NORM is RMS |   34     34  10.3s
EXTENSION_NORM_OK

# GROUP=Core DiffEqBase
Unitful extension |    9      9  1.9s
Extension ODE_DEFAULT_NORM |   34     34  2m06.0s
...
     Testing DiffEqBase tests passed

# Runic --check on changed .jl files
(exit 0)

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Risk assessment (independent review, Codex gpt-6.1-sol, head ce79ecd)

  • Verdict: MERGE
  • Risk: medium-low (ML2: numerical step-control correction on peripheral optional-element-type paths, with independent analytic RMS evidence and failing-before tests; ordinary floating-point methods are unchanged). ML1 and L2 also apply; this does not change the ordinary main-lane solver defaults, introduce API, or change the documented RMS contract.
  • Blast radius: Adaptive integration of arrays of FlexUnits quantities, Measurements, MonteCarloMeasurements particles, ReverseDiff tracked scalars and Tracker tracked scalars can take different steps. Tracked-time ReverseDiff and Tracker paths preserve differentiation through the corrected RMS calculation. Plain floating-point and existing TrackedArray implementations are untouched.
  • Evidence: Read pr.txt first, the complete risk rules, and git diff origin/HEAD...HEAD. Exported HEAD and origin/HEAD (0139bdc) into scratch; installed a local scratch environment with the requested depot, JULIA_NUM_THREADS=4 and JULIA_NUM_PRECOMPILE_TASKS=4. Ran timeout 3600 julia --project=<scratch/env> -e 'include("<scratch/head/lib/DiffEqBase/test/extension_norm_ext.jl>")' with each exported DiffEqBase selected in the manifest: head exited 0 with 34/34 passes; base exited 1 with 20 passes and 14 assertion failures covering all five extensions. Ran timeout 3600 julia --project=<scratch/env> with scratch/ad.jl on head: 5/5 assertions passed, then included the existing test/ode_default_norm.jl, which completed without failures (process exit 0). ReverseDiff.gradient and Tracker.gradient both returned [0.4242640687119285, 0.565685424949238] for arrays and views, matching the analytic derivative u/(2*sqrt(12.5)); the particle-valued-time overload returned sqrt(12.5). G1 PASS: independent RMS formula for [3,4] and analytic derivatives, not solver-generated reference values. G2 PASS for affected AD paths: forward values and actual ReverseDiff/Tracker gradients exercised locally; GPU/Reactant/MPI not applicable to this diff. G3 NOT APPLICABLE: no mutable shared state, cache, threading, or global-default configuration is changed. Diff inspection found no skipped or loosened assertions, new production dependency, new public name, or dependency-internal access introduced by the patch.
  • Merge: merge (no actionable findings; medium-low still requires the separate reviews specified by fleet policy).

🤖 Posted by an AI agent — harness: Codex CLI 0.162.1 · model: gpt-6.1-sol
Conversation: local headless review run (no public session URL); transcript kept by the fleet master.

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Independent review

Risk assessment (independent review, Claude Opus 5.5 (claude-opus-5-5), head ce79ecd)

  • Verdict: MERGE
  • Risk: medium (M2: results change on paths that already worked. Default-solver step control for arrays of Measurement, Particles, FlexUnits Quantity, and Array{TrackedReal} (in-place ReverseDiffAdjoint) now takes different steps, with independent evidence of accuracy. I did not rate it H2 because only these peripheral element types are affected; Float64, ForwardDiff, TrackedArray and Unitful paths are unchanged. A stricter reading of "default step control in a core package" would give H2. Either way it is not auto-mergeable.)
  • Blast radius: DiffEqBase extensions only, with no public signature changes. Affected: anyone solving with Measurements, MonteCarloMeasurements, FlexUnits, Array-of-ReverseDiff.TrackedReal or Array-of-Tracker.TrackedReal state. They get fewer steps, equal to the Float64 count, at the same tolerances. Results move within tolerance, and in-place ReverseDiffAdjoint gradients at default tolerances change visibly (below). ReverseDiff.TrackedArray and Tracker.TrackedArray keep their own existing RMS methods and are untouched, so out-of-place ReverseDiffAdjoint/TrackerAdjoint gradients are bit-identical.
  • Evidence:
    • New test lib/DiffEqBase/test/extension_norm_ext.jl run against the merge-base 59ba40e (base) and against the head, each in its own env with the base or head lib/ developed. Base: 20 pass, 14 fail, each failure Evaluated: 1.8708286933869707 ≈ 3.5355339059327378, i.e. sqrt(mean(|[3,4]|)) against RMS. Head: 34/34 pass.
    • End-to-end Tsit5 at default tolerances, Lotka–Volterra on (0, 10), naccept/nreject. Float64: 33/2. Base: Measurement 44/0, Particles 44/0, FlexUnits 44/0. Head: all three 33/2. Exponential decay with 5 components against the analytic solution, maximum error. Float64: 18 steps, 9.79e-8. Base Measurement: 24 steps, 1.64e-8. Head Measurement: 18 steps, 9.79e-8, identical to Float64.
    • AD (SciMLSensitivity v7.119.13 + Zygote): out-of-place decay gradients against the analytic gradient are identical on base and head (3.26e-12 tight, 1.13e-7 default) for ReverseDiffAdjoint and TrackerAdjoint. In-place Lotka–Volterra ReverseDiffAdjoint at default tolerances, relative error against a 1e-12 ForwardDiff reference: base 0.0256, head 0.1975. The head value equals the out-of-place/TrackedArray result exactly, so the in-place path now uses the same norm as the TrackedArray path. In-place TrackerAdjoint with Zygote errors identically on base and head ("convert tracked TrackedReal{Float64} to tracked Float64"), which predates this PR.
    • SciMLSensitivity GROUP=Core1 via Pkg.test, with DiffEqBase developed from the base and from the head: both pass, 242 pass / 6 broken / 248 total.
    • DiffEqBase GROUP=Core on the head: passes, including the new testset at 34/34. GROUP=QA (Aqua) on the head: 9/9 pass. Runic --check clean, typos clean.
    • G1 pass: the test asserts against hand-computed RMS (sqrt((9+16)/2)), not code output. The end-to-end runs match the analytic decay solution and the Float64 step counts.
    • G2 pass (by reviewer run): these are not AD rules, but the ReverseDiff/Tracker paths are AD-adjacent. I ran ReverseDiffAdjoint and TrackerAdjoint gradients and SciMLSensitivity Core1, output above.
    • G3 not applicable: no shared state, caches or global defaults.
  • Merge: merge, at medium, so it needs Chris's decision. No code changes required. The PR body should state the in-place ReverseDiffAdjoint gradient shift (finding 1).

🤖 Posted by an AI agent — harness: Claude Code · model: claude-opus-5-5
Conversation: local headless review run (no public session URL); transcript kept by the fleet master.

@ChrisRackauckas-Claude
ChrisRackauckas-Claude force-pushed the agent/4610-ext-norms-rms branch 3 times, most recently from 6f7d541 to 710ca4f Compare September 26, 2026 22:47
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/OrdinaryDiffEq.jl that referenced this pull request Sep 26, 2026
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/adopt/SciML_OrdinaryDiffEq.jl-4611/log.txt on amdci2.julia.csail.mit.edu
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 27, 2026 12:14
ChrisRackauckas and others added 5 commits September 30, 2026 07:22
Regression tests for SciML#4610: FlexUnits, Measurements, MonteCarloMeasurements,
ReverseDiff, and Tracker array ODE_DEFAULT_NORM must match plain RMS.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.18-9a7762b
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/OrdinaryDiffEq.jl/jobs/4610-cursor/log.txt on amdci2.julia.csail.mit.edu
Array norms in FlexUnits, Measurements, MonteCarloMeasurements, ReverseDiff,
and Tracker extensions used abs via the scalar ODE_DEFAULT_NORM, yielding
sqrt(mean(|x|)) instead of RMS. Match the Unitful fix: abs2 of value(x).

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.18-9a7762b
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/agent-jobs/OrdinaryDiffEq.jl/jobs/4610-cursor/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI 0.157.1
Agent-Model: gpt-6-luna
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/adopt/SciML_OrdinaryDiffEq.jl-4611/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/adopt/SciML_OrdinaryDiffEq.jl-4611/log.txt on amdci2.julia.csail.mit.edu
Address review: varied MCM particles with known means, drop hardcoded
3.5355 checks, and keep every element type covered in a single testset.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/adopt/SciML_OrdinaryDiffEq.jl-4611/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.11.3 (conflict resolution), Claude Code 2.1.285 (orchestration)
Agent-Model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Agent-Session: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master); Devin log /Users/chrisrackauckas/sandbox/master/fusion-fixes/SciML_OrdinaryDiffEq.jl-4611/log.txt
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Merged the default branch into this PR (clean merge, no conflicts; head efbb97b) so CI runs on current master. Its earlier failures in SciMLSensitivity Core1 and the downgrade jobs were fixed on master after this PR's last CI run.


🤖 Posted by an AI agent — harness: Devin CLI 3000.11.3 (merge), Claude Code 2.1.285 (posting) · model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Conversation: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master)

@ChrisRackauckas
ChrisRackauckas merged commit fd74cf9 into SciML:master Oct 31, 2026
274 of 276 checks passed
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.

DiffEqBase: FlexUnits, ReverseDiff, Tracker, Measurements, MonteCarloMeasurements ODE_DEFAULT_NORM compute sqrt(mean(|x|)), not RMS

3 participants