Skip to content

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) abstractmethod ¤

Initializes the solver. This method is called before the integration starts.

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, ''], args: Any, has_aux = False) -> tuple[Float[Tensor, 'batch ...'], Float[Tensor, 'batch ...'], dict[str, Float[Tensor, 'batch order']], Union[Float[Tensor, 'batch'], Any]] abstractmethod ¤

ODE's solver stepping method

Arguments:

  • func: Pytorch model or callable function, i.e vector field
  • t: Current time step t
  • y: Current state y
  • dt: Step size dt
  • has_aux: Whether the model/callable has an auxiliary output.
has_aux ?

A function with an auxiliary output can look like

def f(t,y,args):
    return -y, ("Hello World",1)
The has_aux kwargs argument is used to compute the adjoint method

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 be None for constant stepsize solvers for example.
  • Dictionary that holds all the information needed to properly build the interpolation between t and t+dt.
  • None if the model doesn't have an auxiliary output.
build_interpolation(self, t0, t1, dense_info) -> Any abstractmethod ¤

Interpolator building method based on the solver's order.

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 between t and t+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) ¤

2nd order explicit Runge-Kutta method

torchdde.RK4 (AbstractOdeSolver) ¤

4th order explicit Runge-Kutta method

torchdde.Dopri5 (AbstractOdeSolver) ¤

5th order order explicit Runge-Kutta method Dormand Prince

Implicit Solvers¤

torchdde.ImplicitEuler (AbstractOdeSolver) ¤

ImplicitEuler Euler's method