torchdiffeq icon indicating copy to clipboard operation
torchdiffeq copied to clipboard

Manually reject step from ODE function with adaptive step solvers

Open slishak opened this issue 3 years ago • 0 comments

For some ODE functions, there are certain feasible regions of state values, and states outside this region result in undefined derivatives. In this situation, it is helpful to be able to communicate to an adaptive solver that it should try a smaller step instead.

This PR adds a RejectStepError exception class that can be raised by an ODE function. If this happens, an adaptive step solver will reject the step and reduce the step size. If the step size is already at the minimum, the exception will be re-raised to avoid an infinite loop.

I've fixed the error ratio to 10 for the new step size calculation, but open to other ideas as this is somewhat arbitrary.

If you think this contribution is worth merging, I can add some documentation and tests.

slishak avatar Sep 01 '22 17:09 slishak