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

Suggestion: return status of integration as part of tuple / values.

Open RebelMoogle opened this issue 9 years ago • 3 comments

I would like to be able to get the status when I need to check on it, rather than as a println or an exception. Status like "success", "break: minimum step size", "outside of domain", etc.

This would make it easier to handle or ignore different statuses.

If this status was somehow optionally accessible, that would be perfect.

I would also be willing to help out with coding this, if needed.

RebelMoogle avatar Dec 21 '15 13:12 RebelMoogle

+1 It would also be great if the solvers would return the integration up to the point where an error was thrown.

mauro3 avatar Dec 21 '15 14:12 mauro3

If we stop throwing errors for failed integrations, this is a severely breaking change for users who rely on errors to inform them that the integration wasn't successful. To have the code just silently return an integrated result that isn't complete and not notice that something wen't wrong unless you remember to check the status flag seems like an API regression to difficult-to-use C libraries. Not something I'd vote for.

We could, however, add a few exception types that signal what went wrong, and carry any interesting data, and throw them instead of generic ones. For example, consider

immutable StepSizeError <: Exception
    step_size_at_end
    tout_so_far
    yout_so_far
end

# and in the solver
if step < threshold
    throw(StepSizeError(step, tout, yout))
end

Now, the caller can wrap the solver in try ... catch, and handle some or all possible faults at will, without breaking the API for users who rely on errors to signal that tout, yout should not be entirely trusted.

tomasaschan avatar Dec 21 '15 15:12 tomasaschan

Yeah I can see what you are saying, better exceptions / errors would probably be the way to go.

This would still let me handle errors as they appear and let me decide if I want to use the integration up to the point or not.

I'm all for not breaking anyone else's code. :)

RebelMoogle avatar Dec 21 '15 15:12 RebelMoogle