Skip to content

Fix type inference for AutoVern7+Rodas5P with autodiff and linsolve - #3202

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/inference-autoswitch-autodiff-3200
Mar 20, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/inference-autoswitch-autodiff-3200

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Summary

Fixes #3200 — @inferred solve(prob, AutoVern7(Rodas5P(autodiff=AutoForwardDiff(chunksize=1), linsolve=GenericLUFactorization()))) now passes on Julia 1.11.

The root cause was a combination of three inference barriers:

  • SciMLBase.remake for implicit algorithms used kwargs splatting (struct_as_namedtuple(thing)... + kwargs...) that exceeded Julia 1.11's inference budget when the algorithm had many type parameters (custom autodiff + custom linsolve). Adding @inline lets the compiler track through the merging.
  • prepare_ADType for AutoForwardDiff branched on standardtag::Bool, producing a Union{AutoForwardDiff{CS,Nothing}, AutoForwardDiff{CS,Tag}} return type. Splitting into Val{true}/Val{false} dispatch eliminates the union.
  • prepare_alg for CompositeAlgorithm updated the algorithm tuple but left the AutoSwitch choice function with unprepped (stale) algorithm types, causing a type mismatch in AutoSwitchCache.

Changes

  • lib/OrdinaryDiffEqCore/src/algorithms.jl: Add @inline to SciMLBase.remake for implicit/DAE algorithms
  • lib/OrdinaryDiffEqDifferentiation/src/alg_utils.jl: Extract ST type parameter in prepare_alg, use Val{ST}() dispatch; split prepare_ADType for AutoForwardDiff into Val{true}/Val{false} methods
  • lib/OrdinaryDiffEqCore/src/alg_utils.jl: Update prepare_alg for CompositeAlgorithm to also prepare algorithms stored in AutoSwitch
  • test/regression/inference.jl: Add regression test

Test plan

  • @inferred solve(prob, AutoVern7(Rodas5P(autodiff=AutoForwardDiff(chunksize=1), linsolve=GenericLUFactorization()))) passes on Julia 1.11.9
  • All previously-passing inference cases still pass (Tsit5, Rodas5P, AutoVern7+Rodas5P, etc.)
  • No regression on Julia 1.12
  • OrdinaryDiffEqCore tests pass
  • OrdinaryDiffEqRosenbrock tests (running)
  • OrdinaryDiffEqDifferentiation tests (running)
  • CI

🤖 Generated with Claude Code

Three changes to fix the inference regression on Julia 1.11:

1. Add @inline to SciMLBase.remake for implicit algorithms
   (OrdinaryDiffEqCore/src/algorithms.jl). The kwargs splatting in remake
   exceeded Julia 1.11's inference budget for algorithms with many type
   parameters. Inlining allows the compiler to track through the
   struct_as_namedtuple + kwargs merging.

2. Use Val{ST}() dispatch in prepare_alg instead of standardtag(alg)::Bool
   (OrdinaryDiffEqDifferentiation/src/alg_utils.jl). Split prepare_ADType
   for AutoForwardDiff into Val{true}/Val{false} methods to eliminate the
   Union{AutoForwardDiff{CS,Nothing}, AutoForwardDiff{CS,Tag}} return type.

3. Update prepare_alg for CompositeAlgorithm to also prepare algorithms
   stored in AutoSwitch (OrdinaryDiffEqCore/src/alg_utils.jl). Previously,
   the algorithms in AutoSwitchCache had unprepped autodiff types while the
   algorithm tuple had prepped types, causing a type mismatch.

Fixes SciML#3200

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@ChrisRackauckas

Copy link
Copy Markdown
Member

The failure is just sources not used on v1.10, which should now be handled by the test infra fixes.

@ChrisRackauckas
ChrisRackauckas merged commit 0667841 into SciML:master Mar 20, 2026
214 of 224 checks passed
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/OrdinaryDiffEq.jl that referenced this pull request Mar 22, 2026
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/OrdinaryDiffEq.jl that referenced this pull request Mar 22, 2026
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/OrdinaryDiffEq.jl that referenced this pull request Mar 22, 2026
The @inferred test from PR SciML#3202 requires Julia 1.11+ compiler
improvements to pass. On Julia 1.10 (LTS), the return type is
not fully inferred for CompositeAlgorithm with AutoSwitch.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
ChrisRackauckas added a commit to ChrisRackauckas-Claude/OrdinaryDiffEq.jl that referenced this pull request May 27, 2026
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
ChrisRackauckas added a commit to ChrisRackauckas-Claude/OrdinaryDiffEq.jl that referenced this pull request May 27, 2026
The @inferred test from PR SciML#3202 requires Julia 1.11+ compiler
improvements to pass. On Julia 1.10 (LTS), the return type is
not fully inferred for CompositeAlgorithm with AutoSwitch.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
ChrisRackauckas added a commit to ChrisRackauckas-Claude/OrdinaryDiffEq.jl that referenced this pull request May 27, 2026
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
ChrisRackauckas added a commit to ChrisRackauckas-Claude/OrdinaryDiffEq.jl that referenced this pull request May 27, 2026
The @inferred test from PR SciML#3202 requires Julia 1.11+ compiler
improvements to pass. On Julia 1.10 (LTS), the return type is
not fully inferred for CompositeAlgorithm with AutoSwitch.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
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.

Solution cannot be inferred anymore on Julia 1.11

2 participants