diffrax icon indicating copy to clipboard operation
diffrax copied to clipboard

Event tracking for continuous functions

Open nikolas-claussen opened this issue 1 year ago • 6 comments

This is a feature request. At the moment, Diffrax only supports two types of events, DiscreteTerminatingEvent and SteadyStateEvent. For many applications (ODEs with collision or reflection, first passage problems for SDEs) it would be very convenient to have an event tracker as in SciPy's scipy.integrate.solve_ivp. This would allow the user to provide a real-valued, continuous function (state, **kwargs) -> float and use a root finder to determine precisely when this function crosses 0. At the moment, DiscreteTerminatingEvent will significantly overshoot the zero-crossing and I have to use additional post-processing. SciPy also allows the user to specify which directionality (i.e. from negative to postive or positive to negative) of a zero-crossing should terminate integration, which is very helpful in practice.

nikolas-claussen avatar Feb 23 '24 19:02 nikolas-claussen

Haha, this is good timing! As it turns out this is something that we're working on at the moment. Keep your eyes peeled :)

patrick-kidger avatar Feb 23 '24 22:02 patrick-kidger

Regarding this continuous time event feature: Will the output of the ODE/SDE be differentiable wrt. to parameters in the cond_fn of the Event? If one wants to implement this functionality with the current version of diffrax how would you suggest them to proceed? Thanks for the help :)

LuggiStruggi avatar Apr 29 '24 08:04 LuggiStruggi

We now have a prototype of this feature in #387! It's very much a work-in-progress but folks should feel free to try it out and offer feedback.

Indeed we definitely should be differentiable with respect to the condition function for the event.

(Tagging also @cholberg here for visibility.)

patrick-kidger avatar May 04 '24 12:05 patrick-kidger

Excellent, this looks like precisely what I need. Looking forward to trying it out!

nikolas-claussen avatar May 04 '24 12:05 nikolas-claussen

Hi @patrick-kidger! I see that https://github.com/patrick-kidger/diffrax/pull/387 was just closed, I'm wondering what the status of the new Event functionality is? This is something that is being tabled for now, but may be reopened soon?

dkweiss31 avatar Jun 14 '24 13:06 dkweiss31

Closed by mistake only! :D

patrick-kidger avatar Jun 14 '24 14:06 patrick-kidger