Handling prematurely terminated ODE integration in parameter estimation

Hi,

I’m trying to estimate parameters of an ODE model using DifferentialEquations, SciMLSensitivity, and Optimization packages. In particular, I’ve found that Ipopt works quite well for my problem.
Sometimes, though, the ODE cannot be solved up to the final time during the course of the optimization. That is, the ODE solver terminates somewhere in the middle such that the residual / loss cannot be computed.

At the moment, an exception is raised since some arithmetics doesn’t work out (due to different vector dimensions). This crashes the optimizer as well.

Is there a general practice how to handle this problem with derivative-based optimizers?
For example, can I signal the optimizer to try a different step size in its line search or can I let it abort and return the best point encountered so far?

Have you looked at Handling Divergent and Unstable Trajectories · SciMLSensitivity.jl?

Thanks for the pointer, I’ve tried that. Unfortunately, Ipopt doesn’t like it:

EXIT: Invalid number in NLP function or derivative detected.

That just means you didn’t do it correctly. You need to make sure you capture the solution, check the retcode, and change the loss calculation instead of letting it error. Do you have an MWE?