Skip to content

RKMilCommute/RKMilGeneral: in-place Ito diagonal update (no UniformScaling alloc; scalar iip) - #4823

Merged
ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:sde-rkmilcommute-diag-update
Oct 9, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:masterfrom
ChrisRackauckas-Claude:sde-rkmilcommute-diag-update

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Summary

Non-diagonal Ito RKMilCommute / RKMilGeneral did J -= 1//2 .* UniformScaling(abs(dt)), which allocates a fresh matrix every step (~124 B/step). Replace with view(J, diagind(J)) .-= abs(dt) / 2. Separately, scalar-noise IIP hit @.. J -= on a Float64 J (fill!(::Float64, ::Float64)); split a dW isa Number branch that does J -= abs(dt) / 2. Same pattern applied at LowOrder :254/:327 and Milstein :278/:357.

Before / after (amdci2, Julia 1.12.4, JULIA_NUM_THREADS=1, OPENBLAS_NUM_THREADS=1, taskset -c 64, stepbytes = mean @allocated over 200 warm steps)

case before after
RKMilCommute nondiag IIP Ito 123.76 B/step 5.6 B/step
RKMilCommute diag IIP Ito 3.76 B/step 3.76 B/step (unchanged)
RKMilCommute scalar IIP Ito MethodError fill!(::Float64, ::Float64) succeeds; 44.76 B/step

Fixed-dt nondiag/diag u_end identical to master (seed 7, dt=1/64). Scalar is a bug fix (master crashes).

Regression (stash src): 1 error (fill!(::Float64,…) on scalar iip). With fix: 3 pass (@allocated after warmup: 0 B on 1.12, 96 B on 1.10; threshold < 110 vs master’s ~112 B UniformScaling).

Test-group tails

StochasticDiffEqLowOrder Core (Julia 1.12, --check-bounds=auto):

Test Summary:                                                 | Pass  Total   Time
RKMilCommute Ito diagonal update (scalar iip + nondiag alloc) |    3      3  16.0s
     Testing StochasticDiffEqLowOrder tests passed

StochasticDiffEqLowOrder QA:

Test Summary:     | Pass  Broken  Total     Time
QA (Aqua and JET) |   18       3     21  1m29.2s
     Testing StochasticDiffEqLowOrder tests passed

StochasticDiffEqMilstein Core:

Test Summary:                                    | Pass  Total   Time
RKMilGeneral diagonal vector noise (issue #3863) |    9      9  27.3s
     Testing StochasticDiffEqMilstein tests passed

StochasticDiffEqMilstein QA:

Test Summary:     | Pass  Broken  Total     Time
QA (Aqua and JET) |   17       4     21  1m31.8s
     Testing StochasticDiffEqMilstein tests passed

Julia 1.10.12 regression (standalone):

nondiag iip @allocated step! = 96 B
Test Summary:                                                 | Pass  Total  Time
RKMilCommute Ito diagonal update (scalar iip + nondiag alloc) |    3      3  9.3s

Runic + typos on changed files: clean.

Not verified

  • Full umbrella StochasticDiffEq Interface/Adaptive/commutative CI groups.
  • Bitwise identity of OOP ConstantCache paths beyond fixed-dt u_end (OOP already allocated J from get_iterated_I; only the UniformScaling temporary is removed).
  • Stratonovich (Ito correction skipped) and complex/GPU noise.
  • @benchmark wall-time minima (claim is allocation B/step via stepbytes, matching the audit).

Reviewer pushback

  • Whether 1 // 2 * abs(dt) vs abs(dt) / 2 should stay rational for Float32/BigFloat promotion consistency on the diagind path.
  • Whether the < 110 allocation threshold is the right long-term guard (1.10 still shows ~96 B residual from other step machinery).
  • Whether Milstein should get its own scalar-iip regression (same Number branch applied; test lives in LowOrder).

Please ignore until reviewed by @ChrisRackauckas.

Risk assessment

Independent review: pending

🤖 Generated with Cursor Agent 2026.10.01-14929f9 (model: unknown (Cursor auto)), transcript /home/crackauc/sandbox/goals/performance/jobs/pr-sde-rkmilcommute/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: medium
  • Blast radius: Ito correction of the iterated-integral matrix J in RKMilCommute (StochasticDiffEqLowOrder) and RKMilGeneral (StochasticDiffEqMilstein), in both the OOP ConstantCache and IIP Cache perform_step!. Non-diagonal Ito now subtracts dt/2 from diag(J) in place, and scalar-noise IIP Ito gets its own J -= abs(dt)/2 branch. No public API change.
  • Evidence: Head bd4081b (base 6072e89). CI: 139 pass, 4 fail. All 4 failures are pre-existing and match master: downgrade-sublibraries for DiffEqBase and OrdinaryDiffEqDifferentiation also fail on master Downgrade Sublibraries run https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/37889760391 (91d6ffa). SciMLSensitivity.jl/Core1 fails at the same concrete_solve_derivatives.jl:451 as master IntegrationTest run https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/37889760310. GPU (julia 1) shows the same 3 QNDF dae_tests.jl:481 failures as master. Locally (Julia 1.12.7, seed 7), I compared master base and PR for RKMilCommute and RKMilGeneral under Ito and Stratonovich, with non-diagonal 4x2, diagonal and scalar noise, IIP and OOP, fixed dt=1/64 and adaptive (52 cases). Every case that solves on master gives bitwise-identical sol.t and sol.u on the PR. Scalar-noise IIP Ito fails on master with MethodError: fill!(::Float64, ::Float64) for both methods. On the PR it solves, and the fixed-dt result is bitwise identical to the OOP scalar Ito result, so the Ito correction is right. Mutating Jalg.J in place in the IIP path is safe because get_iterated_I! and Jalg.J .= J_coeffs rewrite all of it every step. Regression: RKMilCommute OOP Ito with SVector state and non-diagonal SMatrix noise solves on master but on the PR throws setindex!(::SVector{4, Float64}, value, ::Int) is not defined. For a StaticArrays dW, get_iterated_I(::JCommute_oop) returns an immutable SMatrix, and view(J, diagind(J)) .-= cannot write to it. RKMilGeneral with SVector input still works, because its J is a Matrix. No CI test covers this case.
  • Independent review: Claude Code (claude-opus-5-5) rated it medium, high confidence: the IIP fixes are correct and bitwise-neutral, but the OOP edit (which removes no allocation, since the OOP path already allocates J) breaks RKMilCommute for StaticArrays non-diagonal Ito problems.
  • Merge: needs human review. Findings: (1) StaticArrays OOP regression above. Fix it by reverting the two ConstantCache hunks to J -= ...UniformScaling or an equivalent out-of-place form, and add an SVector non-diagonal Ito test. (2) lib/StochasticDiffEqLowOrder/test/runtests.jl conflicts with master since Fix OOP RKMil adaptive error estimate to use ggprime #4821 and SRA1 iip: scale k₁ in-place to drop per-step allocation #4822 merged, so the PR needs a rebase. (3) Nits: the allocs < 110 guard sits just under master's ~112 B, so it only weakly protects against a regression; the test comments narrate what master did ("previously hit…"), which the repo's comment style avoids; no Milstein-side test covers the scalar IIP branch.

🤖 Risk assessment posted by an AI agent (fleet master) — harness: Claude Code 2.1.285 · model: claude-opus-5-5
Conversation: local session 3c311569-dda6-4687-bc9f-65febb212c33 (local transcript)

Risk assessment

  • Risk: low

  • Blast radius: Ito correction of the iterated-integral matrix J in RKMilCommute (StochasticDiffEqLowOrder) and RKMilGeneral (StochasticDiffEqMilstein). In the OOP ConstantCache path, the non-diagonal update is now the non-mutating J = J - UniformScaling(abs(dt) / 2). In the IIP Cache path, scalar noise gets its own J -= abs(dt)/2 branch, and non-diagonal noise subtracts dt/2 from diag(J) in place: a scalar loop when ArrayInterface.fast_scalar_indexing(J), otherwise a broadcast over view(J, diagind(J)). The PR adds ArrayInterface (MIT, already a transitive dependency) as a direct dependency of both sublibraries, with compat 7.28. No public API change.

  • Evidence: I re-reviewed head 5fe5ae6, which is rebased on master 72ee57d (after Fix OOP RKMil adaptive error estimate to use ggprime #4821 and SRA1 iip: scale k₁ in-place to drop per-step allocation #4822) and is mergeable. All three earlier findings are resolved:

    • (1) StaticArrays regression: the OOP hunks now use the out-of-place form above. Both testsets add an SVector/SMatrix non-diagonal Ito solve, fixed dt for both methods plus adaptive for RKMilCommute, and that solve would have hit the earlier setindex! error.
    • (2) The rebase is done.
    • (3) The test comments describe the current behaviour, and the Milstein testset covers the scalar IIP branch with a bitwise IIP==OOP check.

    Locally (Julia 1.12.7, seed 7), I compared master 72ee57d and the PR on 66 cases. They cover RKMilCommute and RKMilGeneral; Ito and Stratonovich; non-diagonal 4x2, diagonal and scalar noise; IIP and OOP; fixed dt=1/64 and adaptive; and SVector OOP with diagonal and non-diagonal noise, fixed and adaptive.

    • All 54 cases that solve on master give bitwise-identical sol.t, sol.u and retcode on the PR. This includes RKMilCommute SVector non-diagonal Ito, which failed on the earlier head.
    • The 4 scalar-noise IIP Ito cases fail on master with MethodError: fill!(::Float64, ::Float64) and solve on the PR.
    • 6 RKMilGeneral non-diagonal adaptive cases throw InexactError: Int64(NaN) on both master and the PR. This is pre-existing and unrelated.

    Allocation guard: I ran the test's setup, with p-based functions, dt=1/2^6 and 5 warmup steps. Per-step @allocated for RKMilCommute non-diagonal IIP is 112 B on master and 0 B on the PR, so allocs < 48 fails on master and passes on the PR. I could not run Julia 1.10 locally because of a manifest mismatch. The LTS Core jobs pass in CI.

    I found no weakened tests: the diff only adds testsets and changes no existing assertion or tolerance.

    CI on 5fe5ae6: 139 pass, 4 fail, 1 skipped. All four failures are the pre-existing ones from master:

    • downgrade-sublibraries for DiffEqBase and for OrdinaryDiffEqDifferentiation.
    • SciMLSensitivity.jl/Core1, with the Mooncake error at concrete_solve_derivatives.jl:451.
    • GPU (julia 1), with 3 QNDF failures at dae_tests.jl:481.

    These jobs pass on the PR: StochasticDiffEqLowOrder and StochasticDiffEqMilstein Core on Julia 1, lts and pre, QA, and downgrade.

  • Independent review: Claude Code (claude-opus-5-5) rated it low, high confidence: every master-solvable case is bitwise unchanged, the scalar IIP Ito crash is fixed, the earlier StaticArrays regression is gone and now tested, and the allocation guard fails on master and passes on the PR (re-review at 5fe5ae6)

  • Merge: auto-merge candidate. Non-blocking notes: the view(J, diagind(J)) GPU branch has no test here. The RKMilGeneral non-diagonal adaptive InexactError exists on master too and is worth its own issue.


🤖 Risk assessment posted by an AI agent (fleet master) — harness: Claude Code 2.1.285 · model: claude-opus-5-5
Conversation: local session 3c311569-dda6-4687-bc9f-65febb212c33 (local transcript)

Use view(J, diagind(J)) .-= abs(dt)/2 on IIP caches; keep OOP
non-mutating (UniformScaling) so SMatrix J stays valid. Scalar-noise
IIP uses a dW isa Number branch instead of @.. on Float64.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
@ChrisRackauckas-Claude
ChrisRackauckas-Claude force-pushed the sde-rkmilcommute-diag-update branch from bd4081b to fbee7fc Compare October 9, 2026 08:17
view(J, diagind(J)) .-= allocates ~80 B on Julia 1.10; a plain loop
brings the LTS step under the allocs < 48 guard while keeping the
broadcasted view for GPU / non-scalar-indexable arrays.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 9, 2026 13:01
@ChrisRackauckas
ChrisRackauckas merged commit eadfcff into SciML:master Oct 9, 2026
142 of 146 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