Repository navigation
OrdinaryDiffEqExplicitRK: make indexed dense interpolation generic over Θ type - #4704
Conversation
…er Θ type generic_rk_interpolant! staged per-stage interpolation weights through a Float64 buffer (ExplicitRKConstantCache.bi), so sol(t; idxs) and sol(out, t; idxs) threw Float64(::Dual) when Θ or the state carried ForwardDiff partials. Evaluate each weight with eval_poly_derivative at the point of use, as fused_rk_interpolant_fallback! already does, and drop the now-unused bi buffer from the constant cache. The indexed in-place kernel also replaces per-stage k[i][idxs] views with scalar loops; Float64 results are bitwise identical and allocations unchanged. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> Agent-Harness: Devin CLI 3000.11.3 Agent-Model: swe-2-high Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/pr-erk-dual-interp/log.txt on amdci2
…ernel The scalar-indexed loops read y₀[idx] and k[i][idx] under @inbounds; with OrdinaryDiffEqCore < 4.18.1 there is no upstream idxs validation, so an out-of-range idxs silently read out-of-bounds memory where master threw BoundsError. Validate idxs against y₀ (and assert each stage shares its axes) before the loops. Also folds the duplicated order-0/order-N loop bodies into indexed_rk_interpolant_stages! via a Val flag that compiles to the original expressions. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> Agent-Harness: Devin CLI 3000.11.3 Agent-Model: swe-2-high Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/pr-erk-dual-interp/log.txt on amdci2
Run the direct out-of-range kernel call in a child Julia process with bounds checks set to auto, and require the explicit guard to raise BoundsError. Remove the duplicate validation comment. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Codex <[email protected]> Agent-Harness: Codex CLI codex-cli 0.159.3 Agent-Model: gpt-6-luna Agent-Session: local codex session (log /home/crackauc/sandbox/goals/performance/jobs/pr-erk-dual-interp/log3c.txt on amdci2)
b14e91c to
141ab03
Compare
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-4704/log.txt
Merged the default branch into this PR (clean merge, no conflicts; head eb05871) 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 |
Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a1983b-1c97-7862-8c6a-1d2fb917efac, reviewed head 4443036
Review written by the reviewer named above in a session other than the PR author's, and copied here by the posting agent without change to its findings. The posting agent did not re-run the reviewer's commands. Summary: The PR preserves Dual-valued interpolation weights for indexed ExplicitRK dense output and removes their shared scratch buffer. The added ForwardDiff regression fails on base and passes on head; independent polynomial probes pass with no blocking defect found. Blast radius: ExplicitRK indexed dense interpolation, derivative orders 0–3, and its internal constant cache; the dedicated Tsit5 algorithm and default solver selection are untouched. Evidence: Head: 42/42 in-process assertions from the PR test file; independent polynomial and JLArray probes: 65/65. Base: the identical added ForwardDiff testset has 2 passes and 5 errors; head has 7/7 passes. The analytic decay derivative and separate closed-form polynomial provide G1 evidence; ForwardDiff and the changed JLArray fallback were exercised (G2), and repeated calls with changing time/derivative types exercise removal of the shared weight buffer (G3). CI: 127 successful, three skipped, one failed; the same failed Enzyme threaded-ensemble assertion occurs in completed master CI. Blocking findingsNone. Non-blocking findingsNone. What I ranGit inspection (exit 0): Read-only GitHub checks: Three Julia invocations, sequential, Julia 1.13.2 on aarch64. Each used
CI logs inspected: ExplicitRK Core, Julia 1 reports What I did not verifyNo whole-package, downstream or QA suites were run locally, and no performance benchmark or broad bitwise-identity sweep was repeated. Physical CUDA/ROCm hardware, reverse-mode AD, Reactant, MPI, other platforms and older OrdinaryDiffEqCore versions were not tested locally; the changed array fallback was exercised with JLArray and the changed AD behavior with ForwardDiff. The subprocess assertion ran in CI, not in the local review. The added direct-helper bounds testset was not run on base because its helper signature changes in this PR; failing-before evidence targets the public ForwardDiff interpolation regression. No upstream writes were performed. 🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5 |
Summary
generic_rk_interpolant!staged per-stage interpolation weights through aFloat64scratch buffer (ExplicitRKConstantCache.bi), sosol(t; idxs)andsol(out, t; idxs)threwFloat64(::ForwardDiff.Dual)wheneverΘ(or the state) carried dual partials — i.e. differentiating the interpolation point throughForwardDiffbroke on the indexed path only. Each weight is now evaluated inline witheval_poly_derivative, matchingfused_rk_interpolant_fallback!, and the unusedbibuffer is removed from the constant cache. The indexed in-place kernel replaces the per-stagek[i][idxs]SubArrayviews with scalar loops forArrayoutputs with integer index vectors; a broadcast/view fallback is retained for otherout/idxstypes.Round 2: the scalar loops now validate
idxswithcheckbounds(y₀, idxs)plus anaxes(ki) == axes(y₀)check per stage before their@inboundsreads, so out-of-rangeidxsthrowsBoundsErroreven under OrdinaryDiffEqCore < 4.18.1, where the upstream_check_interpolant_idxscheck (#4607) is absent. The order-0/order-N loop bodies are folded intoindexed_rk_interpolant_stages!via aValflag, which folds to the exact original expressions.Regression tests
New testsets in
lib/OrdinaryDiffEqExplicitRK/test/interpolation_tests.jl:idxs interpolation under ForwardDiff Dual timesdifferentiates throughsol(t; idxs),sol(out, t; idxs), andsol(t, Val{1}; idxs)for scalar and vector indices. On the unfixed code it reports2 passed, 5 erroredwithFloat64(::ForwardDiff.Dual)MethodErrors; with the fix7 passed, 7 total.generic_rk_interpolant! validates idxscalls the kernel directly withidxs = [1, 4]on a length-3 state and expectsBoundsErrorfororder0 and 1, plusDimensionMismatchfor a wrong-lengthout. A child Julia process runs the out-of-range call with--check-bounds=auto; the test passes only when the explicitcheckboundsguard throwsBoundsError. With that guard removed, the child exits without observingBoundsError, and the Core group fails (35 passed, 1 failed). With the guard restored, Core passes 36/36.Performance (same machine,
JULIA_NUM_THREADS=1 taskset -c 12,@benchmarkminima, 1000 interpolation points, round-2 head with the bounds check)sol(out,t; idxs=[1,2])sol(out,t,Val{1}; idxs=[1,2])sol(t; idxs=[1,2])loopsol(out,t)controlCorrection to the round-1 table: the indexed kernel allocates zero bytes per call —
@allocatedover the 1000-point loop withidxshoisted is0 Bon both master and head; the 80 B above is the one-time[1,2]literal inside each benchmarked call. Scalar-idxsand control timings move between runs on this shared box (the unchanged control drifted ~40% here), so treat non-indexed deltas as noise.Float64 results are bitwise identical to master:
reinterpret(UInt64, …)over 1369 values coveringsol(t;idxs),sol(out,t;idxs),Val{0..3}orders, scalar/range/vector/duplicateidxs, in-place and OOP problems, and Tsit5 + DormandPrince tableaus (independent of the reviewer's 3198-case sweep). Under an OrdinaryDiffEqCore 4.18.0 pin,sol(zeros(2), t; idxs=[1,5000000])throwsBoundsErroron this head (it returned garbage before thecheckbounds);sol(out,t;idxs=[1,4])→BoundsError; wrong-lengthout→DimensionMismatch.Test tails
GROUP=Core julia +1.12 --project -e 'using Pkg; Pkg.test()'(fromlib/OrdinaryDiffEqExplicitRK):GROUP=QA julia +1.12 --project -e 'using Pkg; Pkg.test()'(withJULIA_REVISE_POLL=1for this machine's inotify exhaustion):Julia 1.10.12, the package test harness
test/runtests.jlrun in the fresh resolvedscratch/env110environment (Pkg.teston 1.10 cannot use this checkout’s 1.12-resolved package manifest):Runic
--inplaceclean on all changed files;typosclean.Not verified
Arrayout,Boolmaskidxs) is type-corrected but only exercised via scalar-idxscalls; GPU/StaticArrayoutputs were not benchmarked.JULIA_REVISE_POLL=1on this machine (inotify exhaustion); behavior is equivalent, but that flag isn't the CI default.[extras]/thetesttarget inlib/OrdinaryDiffEqExplicitRK/Project.toml(ForwardDiff vs JLArrays) and append a testset at the end oftest/interpolation_tests.jl; whichever merges second rebases keeping both sides. Fix ExplicitRK tableau c eltype for Float32 time #4702 merges cleanly.For reviewers to push back on
axes(ki) == axes(y₀)guard assumes stage derivatives share the state's axes — true for every solver-internal caller; a direct caller with mismatchedknow getsDimensionMismatchinstead of a garbage read.generic_rk_interpolant(!)lose theirbipositional argument andExplicitRKConstantCachea field — internal, non-exported APIs; the reviewer grepped the monorepo and all installed SciML packages and found no outside callers.Please ignore until reviewed by @ChrisRackauckas.
Risk assessment
sol(t; idxs)/sol(out, t; idxs)forExplicitRKonly; full-state and non-indexed paths unchanged.Pkg.testgreen on 1.12 (35/35), 1.10 green; bitwise check 1369/1369; BoundsError restored under Core 4.18.0.Independent review: Claude Code (claude-opus-5-5) rated it medium, high confidence: bitwise identical to master over 3198 interpolation cases, indexed paths 25-50% faster; unchecked @inbounds reads under older Core (fixed in round 2). Re-review pending.
Round 2 (Claude Code claude-opus-5-5): risk low, high confidence. The OOB fix is verified with Core pinned to 4.18.0 (BoundsError), all 3198 cases are bitwise identical, and there is no perf regression. The one should-fix (the bounds test did not discriminate under Pkg.test's --check-bounds=yes) is fixed in round 3 (b14e91c) with a --check-bounds=auto subprocess test, which fails without the check and passes with it. The orchestrator checked that delta.
🤖 Original implementation by Devin CLI 3000.11.3 (model: swe-2-high), transcript /log.txt; round 3 update by Codex CLI codex-cli 0.159.3 (model: gpt-6-luna), local session log /log3c.txt. Independent review by Claude Code (model: claude-opus-5-5[1m]): https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv
Risk assessment (independent review, codex-cli gpt-6-astra, reviewed head 4443036)
GROUP=Core JULIA_NUM_THREADS=4 JULIA_NUM_PRECOMPILE_TASKS=4 julia +release --project=pr-4704/lib/OrdinaryDiffEqExplicitRK -e 'using Pkg; Pkg.test()'with a workspace depot: Generic RK Tests 43/43 passed, Julia 1.13.2. This includes Dual interpolation, explicit bounds checks, and existing JLArrays tests. Log:evidence/4704-test.log. CI snapshot: 21 pass, 106 pending, one skipped, one failed. I read the failed job log: EnzymeAssertionError: mi2 !== nothingin SciMLSensitivity threaded ensemble differentiation using Tsit5, outside ExplicitRK. Latest completed master Core4 passed; latest master runs are queued, so this is inferred unrelated, not a confirmed master reproduction. Failure: https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/38859058853/job/116836959423 ; completed master: https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/38561320093/job/115842815127 . No PR-caused regression found; pending ExplicitRK CI remains relevant.🤖 Posted by an AI agent — harness: codex-cli · model: gpt-6-astra (independent reviewer; appended by Claude Code 2.1.301 · claude-opus-5-5)
Conversation: https://claude.ai/code/session_01VZjwf7Ux9YtTzwHGHMqnsq