DiffEqBase.jl icon indicating copy to clipboard operation
DiffEqBase.jl copied to clipboard

User defined termination condition

Open axla-io opened this issue 2 years ago • 4 comments

Hi, how can I define my own termination condition with the current API? It doesn't look like it's possible but I might be wrong...

For instance, I'd like the solver to terminate when a certain energy is below a tolerance or only check a subset of the state vector.

axla-io avatar Apr 06 '23 13:04 axla-io

@avik-pal I don't think there is a way to give an arbitrary function in the new termination conditions?

ChrisRackauckas avatar Apr 08 '23 11:04 ChrisRackauckas

Alright. If I'd like to add this, two options come to mind:

  1. Changing the callback handling so that the solve function checks if a user defined TerminateSteadyState callback is passed as an argument. If yes, use it. If not, use the one from the alg .
  2. Adding a dispatch to _has_converged for a custom termination mode

I think option 1 might be easier to implement, but would maybe not be so consistent with the API? If you think it's an alright idea, I would know how to write up a PR for option 1.

axla-io avatar Apr 22 '23 14:04 axla-io

But I don't know if adding this would have any benefits over just using ODEProblem with infinite timespan and a TerminateSteadyState condition...

axla-io avatar Apr 27 '23 14:04 axla-io

I think it's reasonable to allow for a function form in the new termination conditions. See https://docs.sciml.ai/NonlinearSolve/stable/basics/TerminationCondition/ . But they are much more comprehensive now, so do try and see if the new conditions better suit your problem.

ChrisRackauckas avatar Aug 09 '23 01:08 ChrisRackauckas