Numerical Solvers¤
ODE Solvers¤
Only some explicit solvers are available to use but adding new ones is rather simple with torchdde.AbstractOdeSolver
.
torchdde.AbstractOdeSolver
¤
Base class for creating ODE solvers. All solvers should inherit from it.
To create new solvers users must implement the init
, step
and order
method.
init(self, func: Union[torch.nn.modules.module.Module, Callable], t0: Float[Tensor, ''], y0: Float[Tensor, 'batch ...'], dt0: Float[Tensor, ''], func_args: Any, *args: Any, **kwargs: Any) -> Optional[Tuple[Any, ...]]
abstractmethod
¤
Initializes the solver state. This method is called before the integration starts.
Arguments:
func
: Pytorch model or callable function, i.e vector fieldt0
: Start of the integration timet0
y0
: Initial statey0
dt0
: Initial step sizedt0
func_args
: Arguments to be passed along tofunc
when it's called (e.g., func(t, y, func_args)).*args
: Additional positional arguments passed to init (use rarely).**kwargs
: Additional keyword arguments passed to init.
Returns
The initial solver state, which should be used the first time step
is called.
order(self) -> int
abstractmethod
¤
Returns the order of the solver.
step(self, func: Union[torch.nn.modules.module.Module, Callable], t: Float[Tensor, ''], y: Float[Tensor, 'batch ...'], dt: Float[Tensor, ''], solver_state: Optional[Tuple[Any, ...]], func_args: Any) -> Tuple[Float[Tensor, 'batch ...'], Optional[Float[Tensor, 'batch ...']], dict[str, Float[Tensor, 'batch order']], Optional[Tuple[Any, ...]], Union[Float[Tensor, 'batch'], Any]]
abstractmethod
¤
ODE's solver stepping method
Arguments:
func
: Pytorch model or callable function, i.e vector fieldt
: Current time stept
y
: Current statey
dt
: Step sizedt
solver_state
: State of the solver. It is the output of the previousstep
method.func_args
: Arguments to be passed along tofunc
when it's called (e.g., func(t, y, func_args)).
Returns:
- The value of the solution at
t+dt
. - A local error estimate made during the step. (Used by
torchdde.AdaptiveStepSizeController
controllers to change the step size.) It may beNone
for constant stepsize solvers for example. - Dictionary that holds all the information needed to properly
build the interpolation between
t
andt+dt
. - None if the model doesn't have an auxiliary output.
build_interpolation(self, t0: Float[Tensor, ''], t1: Float[Tensor, ''], dense_info: Dict[str, Float[Tensor, '...']]) -> AbstractLocalInterpolation
abstractmethod
¤
Interpolator building method based on the solver used.
Arguments:
t0
: The start of the interval over which the interpolation is defined.t1
: The end of the interval over which the interpolation is defined.dense_info
: Dictionary that hold all the information needed to properly build the interpolation betweent
andt+dt
.
Returns:
A Callable
that can be used to interpolate the solution between t0
and t1
.
Explicit Solvers¤
torchdde.Euler (AbstractOdeSolver)
¤
Euler's method
torchdde.RK2 (AbstractOdeSolver)
¤
Second-order explicit Runge-Kutta method (RK2's method).
This implementation uses the 2-stage Butcher Tableau for Heun's method (also known as the improved Euler method or trapezoidal rule). It does not inherently provide error estimation for adaptive step sizing.
torchdde.RK4 (AbstractOdeSolver)
¤
Classic fourth-order explicit Runge-Kutta method.
This implementation uses the standard Butcher Tableau for RK4. It does not inherently provide error estimation for adaptive step sizing.
torchdde.Bosh3 (AbstractOdeSolver)
¤
Bogacki--Shampine's 3/2 method.
3rd order explicit Runge--Kutta method. Has an embedded 2nd order method for adaptive step sizing. Uses 4 stages with FSAL. Uses 3rd order Hermite interpolation for dense/ts output.
torchdde.Dopri5 (AbstractOdeSolver)
¤
Dormand-Prince 5(4) explicit Runge-Kutta method.
Uses a 7-stage, 5th-order method with an embedded 4th-order method for error estimation and adaptive step sizing. Features the FSAL property.
Implicit Solvers¤
torchdde.ImplicitEuler (AbstractOdeSolver)
¤
ImplicitEuler Euler's method