Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link
Contributor

Summary

This PR addresses issue #2557 by refactoring the monolithic __init function in OrdinaryDiffEqCore into smaller, more focused helper functions. This improves code maintainability and makes the initialization flow easier to understand.

Changes

Added the following helper functions extracted from __init:

  • validate_prob_alg_compat: Validates problem-algorithm compatibility
  • validate_dt_requirements: Validates timestep requirements
  • prepare_algorithm: Prepares algorithm (converts AutoSwitch to AutoSwitchCache)
  • resolve_aliases: Resolves ODEAliasSpecifier from kwargs
  • extract_state_variables: Extracts f, p, u, du, duprev from problem
  • compute_tolerances: Computes abstol/reltol with defaults
  • compute_rate_prototype: Computes rate and residual prototypes
  • setup_callback_cache: Sets up callback cache for vector callbacks
  • setup_controller: Sets up step size controller with deprecation handling
  • finalize_integrator_init!: Performs final initialization steps

The __init function now delegates to these helpers, making the code flow clearer while maintaining full backward compatibility.

Notes on init codepath architecture

Added documentation explaining the full dispatch chain:

CommonSolve.init -> DiffEqBase.init -> DiffEqBase.init_up -> DiffEqBase.init_call -> SciMLBase.__init

The init_up layer exists to support ChainRules differentiation (since kwargs can't be differentiated). Currently only solve_up has AD rules defined, but the structure is maintained for consistency and future AD support for init.

Test plan

  • All basic ODE solve tests pass
  • init/solve! workflow works correctly
  • Edge cases tested (saveat, tstops, tolerances, composite algorithms, etc.)
  • OrdinaryDiffEqCore package tests pass

Fixes #2557

cc @ChrisRackauckas

🤖 Generated with Claude Code

This PR addresses issue SciML#2557 by refactoring the monolithic `__init` function
in OrdinaryDiffEqCore into smaller, more focused helper functions. This improves
code maintainability and makes the initialization flow easier to understand.

## Summary of changes

Added the following helper functions extracted from `__init`:

- `validate_prob_alg_compat`: Validates problem-algorithm compatibility
- `validate_dt_requirements`: Validates timestep requirements
- `prepare_algorithm`: Prepares algorithm (converts AutoSwitch to AutoSwitchCache)
- `resolve_aliases`: Resolves ODEAliasSpecifier from kwargs
- `extract_state_variables`: Extracts f, p, u, du, duprev from problem
- `compute_tolerances`: Computes abstol/reltol with defaults
- `compute_rate_prototype`: Computes rate and residual prototypes
- `setup_callback_cache`: Sets up callback cache for vector callbacks
- `setup_controller`: Sets up step size controller with deprecation handling
- `finalize_integrator_init!`: Performs final initialization steps

The `__init` function now delegates to these helpers, making the code flow
clearer while maintaining full backward compatibility.

## Notes on init codepath architecture

Added documentation explaining the full dispatch chain:
`CommonSolve.init -> DiffEqBase.init -> DiffEqBase.init_up -> DiffEqBase.init_call -> SciMLBase.__init`

The `init_up` layer exists to support ChainRules differentiation (since kwargs
can't be differentiated). Currently only `solve_up` has AD rules defined,
but the structure is maintained for consistency and future AD support for `init`.

Fixes SciML#2557

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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.

refactor init codepaths

2 participants