Events¤
Events allow for interrupting a differential equation solve, and changing its internal state, or terminating the solve before t1
is reached.
At the moment a single kind of event is supported: discrete events which are checked at the end of every step, and which halt the integration once they become true.
diffrax.AbstractDiscreteTerminatingEvent
diffrax.AbstractDiscreteTerminatingEvent
¤
Evaluated at the end of each integration step. If true then the solve is stopped at that time.
__call__(self, state, **kwargs)
abstractmethod
¤
Arguments:
state
: a dataclass of the evolving state of the system, including in particular the solutionstate.y
at timestate.tprev
.**kwargs
: the integration options held constant throughout the solve are passed as keyword arguments:terms
,solver
,args
. etc.
Returns
A boolean. If true then the solve is terminated.
¤
¤
diffrax.DiscreteTerminatingEvent (AbstractDiscreteTerminatingEvent)
¤
Terminates the solve if its condition is ever active.
__init__(self, cond_fn: Callable[..., bool])
¤
Arguments:
cond_fn
: A function(state, **kwargs) -> bool
that is evaluated on every step of the differential equation solve. If it returnsTrue
then the solve is finished at that timestep.state
is a dataclass of the evolving state of the system, including in particular the solutionstate.y
at timestate.tprev
. Passed as keyword arguments are theterms
,solver
,args
etc. that are constant throughout the solve.
diffrax.SteadyStateEvent (AbstractDiscreteTerminatingEvent)
¤
Terminates the solve once it reaches a steady state.
__init__(self, rtol: Optional[float] = None, atol: Optional[float] = None, norm: Callable[[PyTree], Scalar] = <function rms_norm>)
¤
Arguments:
rtol
: The relative tolerance for determining convergence. Defaults to the samertol
as passed to an adaptive step controller if one is used.atol
: The absolute tolerance for determining convergence. Defaults to the sameatol
as passed to an adaptive step controller if one is used.norm
: A functionPyTree -> Scalar
, which is called to determine whether the vector field is close to zero.