Repository navigation
Fix CompositeAlgorithm switching with 3+ algorithms (#4648) - #4652
Merged
ChrisRackauckas merged 1 commit intoSep 28, 2026
Merged
Conversation
Add a choose_algorithm! method for general CompositeCache so composites
with three or more algorithms switch correctly. Previously only the
2-tuple CompositeCache{Tuple{T1,T2},F} had a switching method; longer
tuples hit the no-op choose_algorithm!(::OrdinaryDiffEqCache) and never
left their first algorithm.
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: opencode <[email protected]>
Agent-Harness: opencode 1.18.31
Agent-Model: opencode/longcat-2.5-preview-free
Agent-Session: local opencode session in /home/crackauc/sandbox/goals/performance/jobs/pr-4648/repo (log /home/crackauc/sandbox/goals/performance/jobs/pr-4648/log.txt)
ChrisRackauckas
marked this pull request as ready for review
September 28, 2026 11:54
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>
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.
Fix
CompositeAlgorithmnever switching with 3+ algorithms.Fixes #4648
What changed and why
choose_algorithm!had a switching method only for 2-algorithm composites (CompositeCache{Tuple{T1,T2},F}) and a no-opchoose_algorithm!(integrator, cache::OrdinaryDiffEqCache) = nothing. SinceCompositeCache <: OrdinaryDiffEqCache, composites with 3+ algorithms matched the no-op instead of the generic switching fallback and never left their first algorithm.Add a
choose_algorithm!(integrator, cache::CompositeCache)method that handles tuples of any length: unrolled type-stable dispatch for indices 1 and 2 (fast-path parity with the 2-tuple method), a dynamic branch for 3+ (the same patterninitialize!/perform_step!already use for generalCompositeCache), then the existing switching machinery (reset_alg_dependent_opts!,transfer_cache!) for the transition. The 2-tuple fast path,DefaultCache, and non-composite caches are untouched.StochasticCompositeCacheis unaffected: it is not anOrdinaryDiffEqCacheand still uses theis_composite_cachegeneric fallback.Also add a regression test in
test/InterfaceI/composite_algorithm_test.jl: a 3-algorithm composite with a cycling choice function must visit all three algorithms.Verification
--checkon both changed files: clean.typosover the diff: clean.GROUP=Core julia --project -e 'using Pkg; Pkg.test()'inlib/OrdinaryDiffEqCore: all testsets pass.GROUP=Core julia --project -e 'using Pkg; Pkg.test()'inlib/OrdinaryDiffEqDefault: all 56 Default Solver tests pass.lib/StochasticDiffEq/test/composite_algorithm_test.jlrun directly against the fixed tree: exit 0 (StochasticCompositeCache path unaffected).2 algs: unique alg_choice = [1, 2]/3 algs: unique alg_choice = [1]2 algs: unique alg_choice = [1, 2]/3 algs: unique alg_choice = [1, 2, 3]CompositeAlgorithm((Tsit5(), Vern7(), BS3()), mod(iter,3)+1)returnsSuccess, visits[1,2,3], final state within 0.012 of aTsit5reference (expected spread when a low-order method takes cyclic steps).Failing-before/passing-after
New test
CompositeAlgorithm with 3+ algorithms (#4648)intest/InterfaceI/composite_algorithm_test.jl, run directly against master sources:Same test with the fix applied:
Equivalence check
2-algorithm composite (
CompositeAlgorithm((Tsit5(), Vern7()), mod(iter,2)+1)) andDefaultODEAlgorithm()onprob_ode_lorenzandprob_ode_vanderpol_stiff(mu=1e6):sol.t,sol.u,sol.stats, andsol.alg_choiceserialized on master and on this branch, then compared withcmp— bitwise identical.What was not verified
InterfaceI/Everythingtop-level suite viaPkg.test()(the composite test file was run directly instead).Risk assessment
CompositeCachedispatch; no existing method modified. Public API unchanged.DefaultCache, 2-tuple composites, stochastic composites, and non-composite caches keep their exact prior behavior (bitwise-identical results above).DefaultODEAlgorithmon Lorenz and Van der Pol mu=1e6;GROUP=Corepasses for OrdinaryDiffEqCore and OrdinaryDiffEqDefault; stochastic composite tests pass.sol.t/u/stats/alg_choicevs master on 10 cases (AutoTsit5(Rosenbrock23), DefaultODEAlgorithm, 2-alg cyclic; Lorenz and VdP μ=1e6). The switch sequence mirrors the 2-tuple method line by line;which/morespecificconfirm unambiguous dispatch; JET reports 0 runtime dispatch for n=2..5; the new test fails on master; no conflict with Unroll CompositeControllerCache dispatch (non-stiff Default step! allocation-free) #4647. One optional nit: the unrolled 1/2 arms duplicate theelsearm.Please ignore until reviewed by @ChrisRackauckas.
🤖 Generated with opencode (model: opencode/longcat-2.5-preview-free), orchestrated by Claude Code (claude-opus-5-5[1m]) session https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv
Risk assessment
diag(::ScalarOperator); master); DelayDiffEq Regression, GlobalDiffEq Core, OrdinaryDiffEqDifferentiation Core, and OrdinaryDiffEqNonlinearSolve Core, all Julia 1 (respectively NaN matrix, unsupported callbacks, missingdiag, and Trapezoid mass-matrix errors; master); top-level GPU Julia 1 (QNDFgpu_mismatch; master). All four InterfaceI configurations pass. No GitHub reviews or review comments exist. The description omits the still-queued OrdinaryDiffEqDefault GPU check and does not enumerate the pre-existing failures; these are actual test errors, not merely infrastructure failures.🤖 Risk assessment posted by an AI agent (fleet master) — harness: Codex CLI 0.156.1 (Mac) / gpt-6-astra; dispatched by Claude Code head, model claude-opus-5-5[1m]
Conversation: local Claude Code session 3cd6500a-1f81-46b5-ac0b-c466e15b6a53 on Chris's Mac (session ID, no URL)