Integration¤
First, there are a lot of available package to use to train/integrate Neural ODEs, torchdiffeq (not maintained anymore) in Pytorch and Diffrax (which is the gold standard here). This means that this library doesn't have any many features since it focuses more on DDEs.
Regarless, the only entry point to integrate ODEs/DDEs is the integrate
function.
What essentially differentiates DDEs with ODEs are :
- the vector field definition.
- the
delays
argument specification.
What changes in an ODE compared to a DDE ?
In practice, your function will be defined like this :
def f_ode(t,y,args):
return ...
def f_dde(t,y,args, history):
return ...
and your ODE's initial condition y0
will become a history function history_fn = lambda t : ...
torchdde.integrate.integrate(func: Union[torch.nn.modules.module.Module, Callable], solver: AbstractOdeSolver, t0: Float[Tensor, ''], t1: Float[Tensor, ''], ts: Float[Tensor, 'time'], y0: Union[Float[Tensor, 'batch ...'], Callable[[Float[Tensor, '']], Float[Tensor, 'batch ...']]], args: Any, stepsize_controller: AbstractStepSizeController = <torchdde.step_size_controller.constant.ConstantStepSizeController object at 0x7f10c1e330d0>, dt0: Optional[Float[Tensor, '']] = None, delays: Optional[Float[Tensor, 'delays']] = None, discretize_then_optimize: bool = False, max_steps: int = 2048) -> Float[Tensor, 'batch time ...']
¤
Solves a system of ODEs or DDEs. See the Getting started page for example usage.
Main arguments:
These are the arguments most commonly used day-to-day.
func
: The terms of the differential equation. This specifies the vector field.solver
: The solver for the differential equation. See the available solvers.t0
: The start of the region of integration.t1
: The end of the region of integration.ts
: The time points at which to return the solution.y0
: The initial value. This is either a tensor (for ODEs) or a history function callable (for DDEs)args
: Any additional arguments to pass to the vector field.stepsize_controller
: How to change the step size as the integration progresses. See the list of stepsize controllers. Defaults set toConstantStepSizeController
.dt0
: The step size to use for the first step. If you are using a fixed step sizes then this will also be the step size for all other steps. If set asNone
then the initial step size will be determined automatically, only available fortorchdde.AdaptiveStepSizeController
.delays
: The initial values given to the constant delays for the DDE. If set toNone
then the system is treated as an ODE.discretize_then_optimize
: If set toFalse
, the adjoint method will be used for training. If set toTrue
, regular backpropagation will be used for training.max_steps
: The maximum number of steps to take before quitting the computation unconditionally.
Returns:
Returns the solution of the differential equation.