Skip to content

Fix type inference regression with PIController on Julia 1.10 LTS#3033

Closed
ChrisRackauckas-Claude wants to merge 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:fix-controller-type-inference
Closed

Fix type inference regression with PIController on Julia 1.10 LTS#3033
ChrisRackauckas-Claude wants to merge 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:fix-controller-type-inference

Conversation

@ChrisRackauckas-Claude
Copy link
Contributor

Summary

  • Fixes type inference failure in @inferred init() tests on Julia 1.10 LTS
  • Return type was being inferred as Union{..PIController.., ..PIControllerCache..} instead of a concrete type
  • This was a pre-existing issue affecting BS3, Tsit5, RK4, and Vern6 solvers

Root Cause

Two code paths existed for creating controllers:

  1. default_controller_v7 returning new-style controllers (NewPIControllerPIControllerCache)
  2. legacy_default_controller returning legacy controllers (PIController)

Julia 1.10's type inference couldn't determine at compile time which path would be taken, resulting in a Union type.

Changes

lib/OrdinaryDiffEqCore/src/solve.jl:

  • Always use default_controller_v7 for the controller default parameter
  • Replace legacy_default_controller call with new_controller_from_legacy_params

lib/OrdinaryDiffEqCore/src/alg_utils.jl:

  • Enable CompositeController for composite algorithms (instead of returning nothing)
  • Add _default_controller_v7_tuple generated function for type-stable tuple creation
  • Add new_controller_from_legacy_params to create new-style controllers from legacy parameters

Test plan

  • Verified @inferred init(prob, BS3()) passes on Julia 1.10.10
  • Verified @inferred init(prob, Tsit5()) passes on Julia 1.10.10
  • Verified @inferred init(prob, RK4()) passes on Julia 1.10.10
  • Verified @inferred init(prob, Vern6()) passes on Julia 1.10.10
  • Verified solve() still works correctly for all above solvers
  • CI tests

🤖 Generated with Claude Code

…ia 1.10 LTS

The `@inferred init()` tests were failing on Julia 1.10 LTS because the
return type was inferred as Union{..PIController.., ..PIControllerCache..}
instead of a concrete type.

Root cause: Two code paths for creating controllers existed:
1. `default_controller_v7` returning new-style controllers
2. `legacy_default_controller` returning legacy controllers

Julia 1.10's type inference couldn't determine at compile time which
path would be taken, resulting in a Union type.

Changes:
- Always use `default_controller_v7` for the controller default parameter
- Enable `CompositeController` for composite algorithms instead of returning
  `nothing` (which triggered the legacy fallback)
- Add `new_controller_from_legacy_params` to create new-style controllers
  when legacy parameters are provided, ensuring type stability
- Replace `legacy_default_controller` call with new controller constructors

This fixes the Regression_II (LTS) test failure without breaking backwards
compatibility for users who specify legacy controller parameters.

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

2 participants