Skip to content

Fix Unitful ODE_DEFAULT_NORM to compute RMS (#4596) - #4609

Merged
ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/4596-unitful-rms-norm
Sep 27, 2026
Merged

ChrisRackauckas merged 3 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/4596-unitful-rms-norm

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

Summary

The Unitful ODE_DEFAULT_NORM for arrays was sqrt(mean(abs(value(x)))) because the scalar method is abs, not abs2. It now uses sqrt(mean(abs2(value(x)))), matching the plain-array RMS (e.g. [3,4]u"m" → ≈3.5355 instead of ≈1.8708). This is a numerical change (error control / step counts for Unitful adaptive solves can change); it is not an API break and no version bump is included. @fastmath was not touched.

Verification

Fail before (buggy master behavior) / negative control

cd scratch/unitful-norm-test  # DiffEqBase developed + Unitful
# with reverted DiffEqBaseUnitfulExt.jl:
julia +1.12 --project=. lib/DiffEqBase/test/unitful_ext.jl

Tail:

Unitful ODE_DEFAULT_NORM is RMS: Test Failed
  Expression: ODE_DEFAULT_NORM(u_arr, 0.0) ≈ ODE_DEFAULT_NORM(plain, 0.0)
   Evaluated: 1.8708286933869707 ≈ 3.5355339059327378
...
Test Summary:                   | Pass  Fail  Total  Time
Unitful ODE_DEFAULT_NORM is RMS |    5     4      9  6.3s
ERROR: LoadError: Some tests did not pass: 5 passed, 4 failed, 0 errored, 0 broken.

Pass after fix

julia +1.12 --project=scratch/unitful-norm-test lib/DiffEqBase/test/unitful_ext.jl
Test Summary:                   | Pass  Total  Time
Unitful ODE_DEFAULT_NORM is RMS |    9      9  0.7s

DiffEqBase Core suite

cd lib/DiffEqBase && GROUP=Core julia +1.12 --project=. -e 'using Pkg; Pkg.test()'
Test Summary:     | Pass  Total  Time
Unitful extension |    9      9  1.4s
...
156.947259 seconds (...)
     Testing DiffEqBase tests passed

Unitful ODE solve still works (scratch env; not downstream/)

julia +1.12 --project=scratch/unitful-ode-solve -e '... solve(ODEProblem(...), Tsit5()) ...'
retcode=Success nsteps=7 u_end=...[40.17088400355386 m]
step_ok t=0.02 s u=...[2.1236730930936423 m]

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

Not verified

  • Full DiffEqBase Downstream / Downstream2 groups (intentionally avoided instantiating test/downstream).
  • FlexUnits extension (same zip/ODE_DEFAULT_NORM pattern may exist; out of scope for this issue).
  • Performance (no instruction-count / allocation evidence claimed).
  • Broader Unitful solver matrix beyond a single Tsit5 solve.

Reviewer pushback

  • Whether FlexUnits should get the same fix in a follow-up.
  • Whether empty-array max(length(u), 1) (aligned with plain Array norm) is desired vs historical / length(u).
  • Whether other extensions (Tracker, Measurements, …) with the same sum(ODE_DEFAULT_NORM)-on-scalars pattern need the same treatment.

Fixes #4596

Please ignore this draft until reviewed by @ChrisRackauckas.

Harness: Cursor Agent CLI 2026.09.18-9a7762b; model: auto; transcript: /home/crackauc/sandbox/agent-jobs/OrdinaryDiffEq.jl/jobs/4596-cursor/log.txt on amdci2.julia.csail.mit.edu

Adoption update

Adopted the stalled PR on 2026-09-26 (Cursor Agent CLI 2026.09.26-dd393fe).

Rebase / branch

  • git fetch fork: nobody else pushed; HEAD..fork/agent/4596-unitful-rms-norm was empty before rebase.
  • Rebased the two original commits onto current origin/master (f9ce35da…); no conflicts. Authorship preserved (no squash).
  • Pushed with git push --force-with-lease fork agent/4596-unitful-rms-norm.
  • No code changes beyond the rebase were required (no review comments; no PR-caused CI failures).

Fail-before / pass-after (regression lib/DiffEqBase/test/unitful_ext.jl)

With DiffEqBaseUnitfulExt.jl reverted to master:

Test Summary:                   | Pass  Fail  Total  Time
Unitful ODE_DEFAULT_NORM is RMS |    5     4      9  8.9s
ERROR: LoadError: Some tests did not pass: 5 passed, 4 failed, 0 errored, 0 broken.

(Evaluated: 1.8708286933869707 ≈ 3.5355339059327378.)

With the fix restored:

Test Summary:                   | Pass  Total  Time
Unitful ODE_DEFAULT_NORM is RMS |    9      9  0.5s

Affected test group

cd lib/DiffEqBase && GROUP=Core julia +1.12 --project=. -e 'using Pkg; Pkg.test()' → Unitful extension | 9 9 and Testing DiffEqBase tests passed.

Runic --check on the three touched files: clean.

CI classification (pre-rebase failures on PR)

All four red checks also fail on current master (or share the same unrelated root cause); none are caused by this Unitful RMS change:

  1. SciMLSensitivity.jl/Core1 — Mooncake MethodError: no constructors have been defined for Any in concrete_solve_derivatives.jl. Same on master: https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/36242489986/job/108415150951
  2. downgrade-sublibraries / test (lib/DiffEqBase) — high_level_solve.jl:94 despecialized callback kwargs (unrelated). Same on master: https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/36242489922/job/108422524630
  3. downgrade-sublibraries / test (lib/OrdinaryDiffEqDifferentiation) — diag(::ScalarOperator) MethodError. Same on master: https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/36242489922/job/108422524661
  4. sublibrary-ci / lib/DiffEqBase / Julia lts / Core — same high_level_solve.jl:94 failure as (2). Master Sublibrary CI does not schedule DiffEqBase unless those paths change (e.g. https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/36242490111); Julia 1 DiffEqBase Core on this PR already passed. Treated as master-preexisting / out of scope.

Not verified

Risk assessment

  • Risk: low
  • Blast radius: ODE_DEFAULT_NORM for Unitful arrays in DiffEqBase's Unitful extension. It computed sqrt(mean(abs(value(x)))) and now computes the RMS sqrt(mean(abs2(value(x)))), consistent with the unitless default norm. Adaptive step control for Unitful problems changes to match the unitless solve of the same problem. Non-Unitful code paths are untouched, and there is no public API change.
  • Evidence: the regression test fails on master and passes here, with expected values derived analytically. The rebase was clean and the original commits and authorship are kept. The red CI jobs were classified against master in the adoption update above.
  • Independent review: Codex CLI (gpt-6-astra; the adopter is Cursor Auto) rated it low with high confidence, verdict MERGE. One comment nit was sent back to the adopter. A separate, pre-existing issue: empty Unitful arrays still error in the mapped reduction, on master too.
  • Merge: auto-merge candidate once the nit commit lands and CI is green.

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

ChrisRackauckas and others added 2 commits September 26, 2026 14:13
Assert Unitful Array and AbstractArray norms match plain RMS of
stripped values, currently wrong as sqrt(mean(abs)).

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/4596-cursor/log.txt on amdci2.julia.csail.mit.edu
Scalar ODE_DEFAULT_NORM is abs, so summing it then taking sqrt gave
sqrt(mean(|x|)). Use abs2 of stripped values to match plain-array 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/4596-cursor/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-4609/log.txt on amdci2.julia.csail.mit.edu
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 27, 2026 12:14
@ChrisRackauckas
ChrisRackauckas merged commit a3b7a4a into SciML:master Sep 27, 2026
134 of 139 checks passed
ChrisRackauckas referenced this pull request Sep 29, 2026
* Bump DiffEqBase to 7.21.3

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqBDF to 2.4.12

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqSDIRK to 2.9.7

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqRosenbrock to 2.7.5

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqLowOrderRK to 2.2.6

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqTsit5 to 2.1.5

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqVerner to 2.4.2

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json

* Bump OrdinaryDiffEqSymplecticRK to 2.2.3

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.11.3 (Mac)
Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.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.

DiffEqBase: Unitful ODE_DEFAULT_NORM computes sqrt(mean(|x|)), not RMS

2 participants