Skip to content

Add default SDE algorithm with type-stable approach #626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ChrisRackauckas
Copy link
Member

Summary

This PR adds a default solver algorithm for StochasticDiffEq.jl similar to OrdinaryDiffEq.jl's OrdinaryDiffEqDefault's DefaultSolverAlg, using a type-stable sumtype approach as requested.

Key Features

  • DefaultSDEAlgorithm(): Basic default algorithm that switches between SOSRI (non-stiff) and ImplicitRKMil (stiff)
  • DefaultAdaptiveSDEAlgorithm(): Adaptive algorithm that selects solvers based on problem characteristics
  • Automatic algorithm selection based on:
    • Stiffness detection
    • Noise type (additive, commutative, general)
    • Problem interpretation (Ito vs Stratonovich)
    • Mass matrix presence
  • solve(prob, nothing) now uses the default algorithm automatically

Implementation Details

  • Uses EnumX for defining solver choices (similar to OrdinaryDiffEq.jl)
  • Leverages existing AutoAlgSwitch mechanism for automatic switching
  • Type-stable implementation avoiding runtime dispatch
  • Based on the algorithm selection logic from DifferentialEquations.jl's sde_default_alg.jl

Algorithm Mappings

The default algorithm selection follows this logic:

Problem Type Non-stiff Algorithm Stiff Algorithm
Default SOSRI ImplicitRKMil
Additive noise SOSRA ISSEM
Commutative noise RKMilCommute ImplicitRKMil
Stratonovich Appropriate variant ImplicitRKMil with Stratonovich

Tests

Added comprehensive test suite (test/default_alg_test.jl) covering:

  • Basic default algorithm usage with solve(prob, nothing)
  • Algorithm hints and adaptive selection
  • Various problem types (scalar, system, stiff)
  • Algorithm selection logic
  • isdefaultalg checks

All tests pass successfully.

Example Usage

using StochasticDiffEq

# Simple SDE - will use default algorithm
f(u, p, t) = 1.01 * u
g(u, p, t) = 0.87 * u
prob = SDEProblem(f, g, 1.0, (0.0, 1.0))

# These all use the default algorithm
sol = solve(prob)  # or
sol = solve(prob, nothing)  # or
sol = solve(prob, DefaultSDEAlgorithm())

# Use hints for better algorithm selection
sol = solve(prob, DefaultAdaptiveSDEAlgorithm(alg_hints = [:stiff]))

Process Documentation

This implementation was created following the pattern from OrdinaryDiffEq.jl's DefaultODEAlgorithm:

  1. Analyzed OrdinaryDiffEq.jl's type-stable sumtype approach
  2. Studied DifferentialEquations.jl's sde_default_alg.jl for algorithm selection logic
  3. Adapted the approach for StochasticDiffEq.jl's existing infrastructure
  4. Used existing AutoAlgSwitch mechanism for type stability
  5. Added EnumX dependency for solver choice enumeration
  6. Formatted code with JuliaFormatter using SciMLStyle

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

This PR adds a default solver algorithm for StochasticDiffEq.jl similar to
OrdinaryDiffEq.jl's OrdinaryDiffEqDefault's DefaultSolverAlg, using a
type-stable sumtype approach.

## Key Features

- `DefaultSDEAlgorithm()`: Basic default algorithm that switches between SOSRI (non-stiff) and ImplicitRKMil (stiff)
- `DefaultAdaptiveSDEAlgorithm()`: Adaptive algorithm that selects solvers based on problem characteristics
- Automatic algorithm selection based on:
  - Stiffness detection
  - Noise type (additive, commutative, general)
  - Problem interpretation (Ito vs Stratonovich)
  - Mass matrix presence

## Implementation Details

- Uses EnumX for defining solver choices (similar to OrdinaryDiffEq.jl)
- Leverages existing `AutoAlgSwitch` mechanism for automatic switching
- Type-stable implementation avoiding runtime dispatch
- Hooks into `solve(prob, nothing)` to use default algorithm

## Algorithm Mappings

Based on DifferentialEquations.jl's sde_default_alg.jl logic:
- Default: SOSRI (non-stiff) / ImplicitRKMil (stiff)
- Additive noise: SOSRA (non-stiff) / ISSEM (stiff)
- Commutative noise: RKMilCommute (non-stiff) / ImplicitRKMil (stiff)
- Stratonovich: RKMil variants with Stratonovich interpretation

## Tests

Added comprehensive test suite covering:
- Basic default algorithm usage
- Algorithm hints and adaptive selection
- Various problem types (scalar, system, stiff)
- Algorithm selection logic
- `isdefaultalg` checks

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

Co-Authored-By: Claude <[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.

1 participant