Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle function evaluation errors #210

Closed
Robbybp opened this issue Jul 5, 2023 · 3 comments · Fixed by #215
Closed

Handle function evaluation errors #210

Robbybp opened this issue Jul 5, 2023 · 3 comments · Fixed by #215

Comments

@Robbybp
Copy link
Contributor

Robbybp commented Jul 5, 2023

Ipopt function/derivative callbacks should return false if there was a problem with the evaluation. This way Ipopt can try to recover by cutting the step size and trying again.

This does not appear to be supported in CyIpopt. For example, here in the constraint callback, True is returned even if an exception is encountered. I'm not sure how this exception is then processed. When my callback Python code raises an exception, I get "Stopping optimization at current point as requested by user" and my Python exception is re-raised.

I propose that there should be a particular type of exception, e.g. CyIpoptEvaluationError, that will cause CyIpopt evaluation callbacks to return False to Ipopt (and are otherwise ignored by CyIpopt).

Does this sound like a reasonable way to handle evaluation errors? If so, I'm happy to try to implement this.

@Robbybp
Copy link
Contributor Author

Robbybp commented Jul 8, 2023

In an initial test, returning False in an evaluation callback causes Ipopt to halt with the message "Invalid number in NLP function or derivative detected". Looking at the code for the AMPL interface, which handles evaluation errors routinely, we might be missing a call to ipopt_application->RethrowNonIpoptException(false);? From the documentation, this does not appear to control behavior on callbacks returning False, but it is the only thing that stands out to me in a quick glance at the AMPL interface.

@moorepants
Copy link
Collaborator

We'll definitely review pull requests that try to address this. Feel free to submit something though if you are digging into it.

@Robbybp
Copy link
Contributor Author

Robbybp commented Jul 25, 2023

In an initial test, returning False in an evaluation callback causes Ipopt to halt with the message "Invalid number in NLP function or derivative detected".

This appears to be because Ipopt only handles function evaluation errors in the objective and constraint callbacks, and I was testing an error in the Jacobian callback. This is a little inconvenient for the user, but there is nothing to stop us from returning false and letting Ipopt handle this how it chooses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants