Manually reject step from ODE function with adaptive step solvers #210
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.