Repository navigation
RKMilCommute/RKMilGeneral: in-place Ito diagonal update (no UniformScaling alloc; scalar iip) - #4823
Merged
ChrisRackauckas merged 2 commits intoOct 9, 2026
Conversation
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
force-pushed
the
sde-rkmilcommute-diag-update
branch
from
October 9, 2026 08:17
bd4081b to
fbee7fc
Compare
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
marked this pull request as ready for review
October 9, 2026 13:01
This was referenced Oct 13, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Non-diagonal Ito
RKMilCommute/RKMilGeneraldidJ -= 1//2 .* UniformScaling(abs(dt)), which allocates a fresh matrix every step (~124 B/step). Replace withview(J, diagind(J)) .-= abs(dt) / 2. Separately, scalar-noise IIP hit@.. J -=on aFloat64J(fill!(::Float64, ::Float64)); split adW isa Numberbranch that doesJ -= abs(dt) / 2. Same pattern applied at LowOrder:254/:327and Milstein:278/:357.Before / after (amdci2, Julia 1.12.4,
JULIA_NUM_THREADS=1,OPENBLAS_NUM_THREADS=1,taskset -c 64, stepbytes = mean@allocatedover 200 warm steps)MethodError fill!(::Float64, ::Float64)Fixed-dt nondiag/diag
u_endidentical 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 (@allocatedafter warmup: 0 B on 1.12, 96 B on 1.10; threshold< 110vs master’s ~112 B UniformScaling).Test-group tails
StochasticDiffEqLowOrder Core (Julia 1.12,
--check-bounds=auto):StochasticDiffEqLowOrder QA:
StochasticDiffEqMilstein Core:
StochasticDiffEqMilstein QA:
Julia 1.10.12 regression (standalone):
Runic + typos on changed files: clean.
Not verified
StochasticDiffEqInterface/Adaptive/commutative CI groups.u_end(OOP already allocatedJfromget_iterated_I; only the UniformScaling temporary is removed).@benchmarkwall-time minima (claim is allocation B/step via stepbytes, matching the audit).Reviewer pushback
1 // 2 * abs(dt)vsabs(dt) / 2should stay rational for Float32/BigFloat promotion consistency on the diagind path.< 110allocation threshold is the right long-term guard (1.10 still shows ~96 B residual from other step machinery).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
JinRKMilCommute(StochasticDiffEqLowOrder) andRKMilGeneral(StochasticDiffEqMilstein), in both the OOP ConstantCache and IIP Cacheperform_step!. Non-diagonal Ito now subtractsdt/2fromdiag(J)in place, and scalar-noise IIP Ito gets its ownJ -= abs(dt)/2branch. No public API change.downgrade-sublibrariesfor DiffEqBase and OrdinaryDiffEqDifferentiation also fail on master Downgrade Sublibraries run https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/37889760391 (91d6ffa).SciMLSensitivity.jl/Core1fails at the sameconcrete_solve_derivatives.jl:451as master IntegrationTest run https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/37889760310.GPU (julia 1)shows the same 3 QNDFdae_tests.jl:481failures 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-identicalsol.tandsol.uon the PR. Scalar-noise IIP Ito fails on master withMethodError: 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. MutatingJalg.Jin place in the IIP path is safe becauseget_iterated_I!andJalg.J .= J_coeffsrewrite all of it every step. Regression: RKMilCommute OOP Ito withSVectorstate and non-diagonalSMatrixnoise solves on master but on the PR throwssetindex!(::SVector{4, Float64}, value, ::Int) is not defined. For a StaticArraysdW,get_iterated_I(::JCommute_oop)returns an immutableSMatrix, andview(J, diagind(J)) .-=cannot write to it. RKMilGeneral with SVector input still works, because itsJis aMatrix. No CI test covers this case.J) breaks RKMilCommute for StaticArrays non-diagonal Ito problems.J -= ...UniformScalingor an equivalent out-of-place form, and add an SVector non-diagonal Ito test. (2)lib/StochasticDiffEqLowOrder/test/runtests.jlconflicts 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: theallocs < 110guard 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
JinRKMilCommute(StochasticDiffEqLowOrder) andRKMilGeneral(StochasticDiffEqMilstein). In the OOP ConstantCache path, the non-diagonal update is now the non-mutatingJ = J - UniformScaling(abs(dt) / 2). In the IIP Cache path, scalar noise gets its ownJ -= abs(dt)/2branch, and non-diagonal noise subtractsdt/2fromdiag(J)in place: a scalar loop whenArrayInterface.fast_scalar_indexing(J), otherwise a broadcast overview(J, diagind(J)). The PR addsArrayInterface(MIT, already a transitive dependency) as a direct dependency of both sublibraries, with compat7.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:
SVector/SMatrixnon-diagonal Ito solve, fixed dt for both methods plus adaptive for RKMilCommute, and that solve would have hit the earliersetindex!error.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.
sol.t,sol.uand retcode on the PR. This includes RKMilCommute SVector non-diagonal Ito, which failed on the earlier head.MethodError: fill!(::Float64, ::Float64)and solve on the PR.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@allocatedfor RKMilCommute non-diagonal IIP is 112 B on master and 0 B on the PR, soallocs < 48fails 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-sublibrariesfor DiffEqBase and for OrdinaryDiffEqDifferentiation.SciMLSensitivity.jl/Core1, with the Mooncake error atconcrete_solve_derivatives.jl:451.GPU (julia 1), with 3 QNDF failures atdae_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 adaptiveInexactErrorexists 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)