Repository navigation
Avoid per-step deepcopy in ExplicitTaylorAdaptiveOrder - #4766
ChrisRackauckas merged 9 commits into
Conversation
Order-selection trials cloned the whole controller cache and grew order_history every step. Snapshot only the restored fields into preallocated storage and drop the unused history. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.10.01-14929f9 Agent-Model: unknown (Cursor auto) Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/pr-taylor-deepcopy/log.txt on amdci2
Order-selection restore was converting every controller field through typeof(t), which MethodError'd Dual tspan and rounded Float32-t PID history. Snapshot the cache's own isbits/array values as a NamedTuple. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.10.01-14929f9 Agent-Model: unknown (Cursor auto) Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/pr-taylor-deepcopy/log.txt on amdci2
isbits-only NamedTuple snapshots dropped BigFloat PIController q11/errold, so order trials leaked state. Include every scalar scratch field and make array history length-generic; tighten Float32 PID and add BigFloat regressions. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.10.01-14929f9 Agent-Model: unknown (Cursor auto) Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/pr-taylor-deepcopy/log.txt on amdci2
Runtime-length ntuple boxed the length-3 err history (~1 KB/step). Specialize on Val(3) after an explicit length check and add a PID allocation regression. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.10.01-14929f9 Agent-Model: unknown (Cursor auto) Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/pr-taylor-deepcopy/log.txt on amdci2
Julia 1.10/1.11 step! has a fixed 16-byte infrastructure allocation for every solver, so == 0 fails CI while the PID snapshot path is still 0 extra bytes. Keep the bound tight against the round-3 1 KB ntuple regression. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent 2026.10.01-14929f9 Agent-Model: unknown (Cursor auto) Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/pr-taylor-deepcopy/log.txt on amdci2
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-4766/log.txt
Merged the default branch into this PR (clean merge, no conflicts; head 66db7bc) 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 |
…ptiveOrder The allocation-free field snapshot assumed every array field was a length-3 history (PIDControllerCache.err), so a user-defined AbstractControllerCache with, e.g., a length-4 Vector threw an ArgumentError on the first step. Restrict the field snapshot to OrdinaryDiffEqCore's I/PI/PID/Predictive caches, whose sync_controllers! copies exactly the walked fields, and send every other controller cache through the documented protocol: deepcopy before the order trial, sync_controllers! after. Adds a Core regression test with a custom controller holding a length-4 history and an accept counter, run IIP and OOP; it errors before this change and checks that the counter equals stats.naccept after it. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Agent-Harness: Claude Code 2.1.301 Agent-Model: claude-opus-5-5 Agent-Session: local session ID bf8d6de7-a858-41b2-b438-bc6101c93513 (headless claude -p, no URL)
…qCore ExplicitTaylorAdaptiveOrder pseudo-steps the step-size controller once per candidate order and rolls it back. The allocation-free rollback depended on four non-public OrdinaryDiffEqCore cache types and their field layouts, with matching ExplicitImports exemptions in the Taylor QA test. OrdinaryDiffEqCore now owns that protocol as documented public API: snapshot_controller(cache) / restore_controller!(cache, snapshot). The default is deepcopy + sync_controllers!, so every custom controller that implements sync_controllers! keeps working. The I/PI/PID/Predictive caches get allocation-free NamedTuple methods next to their sync_controllers!. OrdinaryDiffEqTaylorSeries calls only the public pair, its local snapshot code and the four QA exemptions are gone, and its QA environment resolves the in-repo OrdinaryDiffEqCore like the other sublibrary QA environments. OrdinaryDiffEqCore 4.19.0 -> 4.20.0 (new public API). OrdinaryDiffEqTaylorSeries 2.4.0 -> 2.5.0 with OrdinaryDiffEqCore compat raised to 4.20, since it needs the new functions. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Agent-Harness: Claude Code 2.1.301 Agent-Model: claude-opus-5-5 Agent-Session: local session ID bf8d6de7-a858-41b2-b438-bc6101c93513 (headless claude -p, no URL)
Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a1983c-7a7b-7972-abf8-91bb0fe6ee2d, reviewed head 3da8de7
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: Adds public controller snapshot/restore hooks to reduce adaptive-order Taylor allocations and removes unused order history. Focused before/after tests and independent analytic probes support merging with minor documentation repairs. Blast radius: ExplicitTaylorAdaptiveOrder IIP/OOP order-selection trials and its internal history storage; new OrdinaryDiffEqCore extension hooks. Existing Tsit5, Vern, Rodas, FBDF, default selection, callbacks and interpolation implementations are unchanged. Evidence: Blind diff assessment frozen in INITIAL.md and INITIAL.sha256 before author context. On Julia 1.13.2, Core snapshot tests passed 28/28; the six added Taylor testsets passed 16/16 on head and failed 2/16 on base, specifically both allocation assertions. Independent probes passed 28/28. CI recorded 258 successes, two failures and three skips; both failures match completed master runs. Blocking findingsNone. Non-blocking findings
What I ran
What I did not verifyI did not run whole package suites, Pkg.test(), local QA, the full documentation build, or downstream suites. I did not reproduce the author's wall-clock benchmark table or Lorenz/Kepler trajectory comparisons; I verified allocation regressions and the added mixed-precision/BigFloat baseline fixtures instead. The Dual-time and custom-cache tests pass on base, so they do not demonstrate fixes relative to the merge-base; the discriminating regressions here are the allocation tests. I did not run predictive-controller Taylor solves, GPU, MPI, Reactant, or Enzyme/Mooncake/Zygote-specific probes locally. No such specialized implementation is changed; the changed ForwardDiff/Dual-time path ran locally. The initial temporary-environment setup error prevented Taylor execution in run 1 and was resolved for runs 2 and 3. 🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5 |
Summary
ExplicitTaylorAdaptiveOrderwasdeepcopyingintegrator.controller_cacheon every order-selection trial (several times per step) andpush!ing onto an unusedorder_history. That dominated the AdaptiveOrder hot path: on this machine a warmed Lorenz IIPstep!was 13.8 µs / 144 allocs / 6432 B, andsolveat 1e-8 was 18.7 ms vs Taylor10 at 0.206 ms.This PR snapshots only the controller-cache scratch fields into a per-trial
NamedTupleof each field's own type (noconvertthroughtypeof(t)), and dropsorder_history. The snapshot is generated from the cache's isbits fields (skippingcontroller/EEst) plus array history copied elementwise as a 3-tuple (PIDControllerCache.err), so it trackssync_controllers!scratch without a hardcoded field-name list. Lorenz/Kepler IIP trajectories (sol.t,sol.u, and the per-step chosen orders) at 1e-8 and 1e-12 are bitwise identical to master, as is Float32-t/ Float64-uwithPIDController.Test plan
@allocated step!bound< 2048. Master (src stashed): 3360 bytes, FAIL. After: 144 bytes, PASS. Julia 1.10.12: 16 bytes, PASS.abstol=reltolin{1e-8, 1e-12}.t(ForwardDiff derivative throughtspan): unfixed snapshot MethodErrorFloat64(::Dual)FAIL (before.txt); after PASS (after.txt,d ≈ -0.5*exp(-0.5)).t/ Float64u+PIDController(0.7, -0.4)at 1e-6:sol.tandsol.ubitwise==mastere70688847(43 steps).JULIA_NUM_THREADS=1 taskset -c 12@benchmarkminima (Julia 1.12.4, 5 solve samples / 40 step samples,evals=1):@allocated step!on the Lorenz bench was 3216–6432 B on master (order-loop deepcopy) vs 0 B after. The Core regression test uses a 2-eq linear RHS and still sees 144 B fromstep!'s return on 1.12 (16 B on 1.10).Core group tail (
GROUP=Core Pkg.test, round 2)QA group tail (
GROUP=QA Pkg.test, round 2)AdaptiveOrder remains
broken=truein AllocCheck static analysis (5 sites); runtimestep!is 0-alloc on Lorenz/Kepler after this change.What I did not verify
nlsolveras on master).@benchmark(identity was IIP Lorenz/Kepler; Float32 PID is IIP).OrdinaryDiffEqumbrella tests and GPU.broken=trueafter further cleanup of the remaining static sites.t(same convert path as Dual; Dual is the regression).Reviewer pushback
NamedTuplevs a mutable snapshot parameterized on the controller-cache field types (NamedTuple is 0-alloc for the in-tree isbits caches).PIDControllerCache.err).order_historyif anyone was poking it as an unofficial diagnostic (it was written and never read in-tree).broken=truefor AdaptiveOrder even though runtimestep!is now 0-alloc on the measured problems.Please ignore until reviewed by @ChrisRackauckas.
Risk assessment
Independent review: Devin SWE-2 round 1 CHANGES (snapshot types); round 2 preserves field types
🤖 Generated with Cursor Agent 2026.10.01-14929f9 (model: unknown (Cursor auto)), transcript /log.txt; orchestrated by Claude Code (claude-opus-5-5[1m]) https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv
Made with Cursor
Review findings addressed
ArgumentError: AdaptiveOrder controller array snapshot expects length 3, got 4). Fixed in e7353fc. The allocation-free field snapshot now only applies to OrdinaryDiffEqCore'sIControllerCache,PIControllerCache,PIDControllerCacheandPredictiveControllerCache. Theirsync_controllers!copies exactly the fields the snapshot walks, and their only array is PID'serr, which is alwaysones(QT, 3). Every other controller cache (user-definedAbstractControllerCaches, composite caches) uses master's protocol:deepcopybefore the order trial,sync_controllers!after. That covers arbitrary array lengths, matrices, and any other scratch state a customsync_controllers!restores. The four cache types are owner-internal in OrdinaryDiffEqCore, so they are imported and added to the ExplicitImports ignore list intest/qa/qa.jl. OrdinaryDiffEqFIRK handlesPredictiveControllerCachethe same way.AdaptiveOrder custom controller cache with length-4 history, run IIP and OOP. It uses a custom controller whose cache has aVector{Float64}history of length 4, an accept counter, and async_controllers!override. It checks the retcode and solution, and checks that the counter equalsstats.naccept, which shows the order-selection pseudo-steps were rolled back.Error During Test ... ArgumentError: AdaptiveOrder controller array snapshot expects length 3, got 4.AdaptiveOrder custom controller cache with length-4 history | 6 6on Julia 1.13.0 and 1.10.12. The same controller on the merge base (59ba40e) gives identical output to the fixed branch:Success,u_end=[0.9048374198048081, 1.8096748396096163], counter 55 ==stats.naccept55, for both IIP and OOP.GROUP=Core Pkg.test()(Julia 1.13.0): all 26 testsets pass, including the master-identity Float32 PID and BigFloat PI tests and bothstep!allocation bounds, and the run ends withOrdinaryDiffEqTaylorSeries tests passed.GROUP=QA: Allocation 2 pass / 1 broken (the AdaptiveOrder AllocCheck entry was already marked broken), JET 1/1, Aqua 17/17. AllocCheck reports 8 static sites on Julia 1.13.0 both with and without this commit; the 5 quoted above were measured on 1.12.4. Runic 1.10.0--checkandtyposare clean on the changed files.🤖 Posted by an AI agent — harness: Claude Code 2.1.301 · model: claude-opus-5-5
Conversation: local session ID bf8d6de7-a858-41b2-b438-bc6101c93513 (headless, no URL)
Review findings addressed (round 2)
OrdinaryDiffEqCore.snapshot_controller(cache)andrestore_controller!(cache, snapshot). Both have docstrings and@docsentries plus a table row indocs/src/api/controllers.md, under "Optional methods".deepcopy(cache), written back withsync_controllers!, which is the protocol master used. So any custom controller that implementssync_controllers!keeps working, whatever its fields.IController,PIController,PIDControllerandPredictiveControllercaches have allocation-freeNamedTuplemethods, placed next to theirsync_controllers!in Core.IControllerCache/PIControllerCache/PIDControllerCache/PredictiveControllerCache, and the four ExplicitImports exemptions are removed.test/qa/Project.toml) gains[sources] OrdinaryDiffEqCore = {path = "../../../OrdinaryDiffEqCore"}, as the Tsit5, Verner, SymplecticRK and other sublibrary QA envs have. Without it the QA env resolved OrdinaryDiffEqCore from the registry, so QA did not test the in-repo Core.GROUP=QA:all_explicit_imports_are_publicerrors with "IControllerCacheis not public inOrdinaryDiffEqCorebut it was imported fromOrdinaryDiffEqCore", and the same for the other three types.GROUP=QA: Allocation 2 pass / 1 broken (the AdaptiveOrder AllocCheck entry was already marked broken), JET 1/1, Aqua 17/17 with no new exemptions.Base.ispublic(OrdinaryDiffEqCore, :snapshot_controller)andBase.ispublic(OrdinaryDiffEqCore, :restore_controller!)returntrue.lib/OrdinaryDiffEqCore/test/controller_snapshot_tests.jl(in the Core group), 28/28. For each built-in cache it checks a snapshot/restore round trip, that the snapshot covers every fieldsync_controllers!transfers, and a 0-byte@allocatedround trip. It also checks that a custom cache falls back todeepcopyplus itssync_controllers!.GROUP=Corestill passes all 26 testsets, including the bitwise master-identity Float32 PID and BigFloat PI trajectories, bothstep!allocation bounds, and the length-4 custom-controller regression.Breaking change
None: no public name is removed, renamed or changed in behavior. The required bumps, both made in this PR as earlier Core API additions such as b1d788586 did:
snapshot_controller/restore_controller!.4to4.20because it calls the new functions. OrdinaryDiffEqCore 4.20.0 must be registered before this Taylor release.Verification (round 2)
Every command was run locally with
JULIA_NUM_THREADS=4.GROUP=Coreinlib/OrdinaryDiffEqCore, Julia 1.13.0:Controller snapshot/restore | 28 28, thenTesting OrdinaryDiffEqCore tests passed.GROUP=QAinlib/OrdinaryDiffEqCore, Julia 1.13.0: AllocCheck 1/1; JET 30 pass / 1 broken (an existingbroken = trueintest/qa/jet.jl); Aqua 26/26.GROUP=Coreinlib/OrdinaryDiffEqTaylorSeries, Julia 1.13.0: 26 testsets, 0 failures or errors,tests passed.test/runtests.jlwithGROUP=Coreon Julia 1.10.12, run in an env with the in-repo packages developed: 26 testsets, 0 failures or errors. The new Core test file also passes on 1.10.12: 28/28.GROUP=QAinlib/OrdinaryDiffEqTaylorSeries, Julia 1.13.0, resolving OrdinaryDiffEqCore v4.20.0 from the repo: Allocation 2 pass / 1 broken (already broken before this PR), JET 1/1, Aqua 17/17. The before/after ExplicitImports result is given above.makedocsofdocs/src/api/controllers.mdagainst the in-repo OrdinaryDiffEqCore.snapshot_controllerandrestore_controller!render with anchors, with no@refor docs-block errors. For this local check, the page's "Algorithm-integrated controllers"@docsblock was dropped from the scratch copy, because it names BDF, Nordsieck and ImplicitDiscreteSolve types that were not loaded.--checkandtyposare clean on every changed file.Not verified: the full
docs/make.jlbuild, Core and Taylor QA on Julia 1.10, the umbrella/downstream groups, and GPU.🤖 Posted by an AI agent — harness: Claude Code 2.1.301 · model: claude-opus-5-5
Conversation: local session ID bf8d6de7-a858-41b2-b438-bc6101c93513 (headless, no URL)
Risk assessment (independent review, codex-cli gpt-6.1-sol, reviewed head 3da8de7)
ExplicitTaylorAdaptiveOrdercontroller rollback and internal order-history storage; two additive public OrdinaryDiffEqCore controller hooks. Existing custom caches retain deepcopy plussync_controllers!. Other solvers do not call the new hooks.3da8de7199529cfd6b8a26d9109c20539a3eba5a, unchanged at the final check. On Julia 1.13.0 withJULIA_NUM_THREADS=4, Taylor Core passed 148/148 assertions across 26 testsets; Core snapshot tests passed 28/28; Taylor Aqua/ExplicitImports passed 16/16. The same Taylor regression test fails against the unmodified merge base with3216 < 2048. Independent warmed-step probes measured PI/PID allocations of 2144/7200 bytes on base and 0/0 on head. Six Lorenz trajectory comparisons passed 19/19 assertions for identical saved times, states, and orders. CI was checked at the start and end: 22 pending, no failures, at both checks. Sublibrary CI, main CI, docs. The latest default-branch runs inspected were also queued, including default-branch sublibrary CI; there were no failed PR jobs requiring log comparison.🤖 Posted by an AI agent — harness: codex-cli · model: gpt-6.1-sol (independent reviewer; appended by Claude Code 2.1.301 · claude-opus-5-5)
Conversation: https://claude.ai/code/session_01VZjwf7Ux9YtTzwHGHMqnsq