-
Notifications
You must be signed in to change notification settings - Fork 10
Utility to handle errors during optimization #42
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
|
…nto optimization_termination_utility
|
|
||
| LOGGER.info( | ||
| "Added a constraint to ensure that at least 50 percent of the budget is used when the total budget is sufficient to plug all wells." | ||
| "Added a constraint to ensure that at least 50 percent of the \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor but string concatenation when using parenthesis does not require '\'. You can simply close the string and open it again on the next line.
|
|
||
| Returns | ||
| ------- | ||
| 1 : Optimal termination |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we wrap the statuses in an enum class or atleast define them as global parameters somewhere? That way, we are not left with magic numbers (1 or 2) in other places in the code
| # feasible solution - couldn't find a suitable test | ||
| if ( | ||
| results.solver.status == SolverStatus.ok | ||
| and not results.solver.termination_condition == TerminationCondition.other |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure this is safe? Pareto implemented an explicit feasibility checker since solvers like CBC, Highs in general cannot be trusted. https://github.com/project-pareto/project-pareto/blob/b034951418c28d78679ce7a8759337fd7066b329/pareto/utilities/results.py#L2923
ruonanli61
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have additional comments in addition to Yash's.
Fixes/Addresses/Summary/Motivation:
For the web interface, if a job experiences a sub-optimal termination status in PRIMO, we want information about the status to be propagated to the end user in some way. This PR adds a simple OptimizationException to accomplish this. Specifically, the added method passes any optimization run that returns an optimal completion status (i.e., solution status is optimal and the termination condition is "convergenceCriteriaSatisfied"). Any other result from an optimization triggers an OptimizationException, which passes a generic "optimization did not terminate optimally" and the associated results object. All errors that happen before the successful creation of the results object (e.g., feasibility and unboundedness with Highs) will raise an error that will be excepted by some other exception type. If the exception type is an OptimizationException, then all the information regarding the results are in the results object. If the exception type is different (e.g., RunTimeError for Highs detecting infeasibility of the problem before executing), then those exceptions can be handled differently. This PR proposes the simplest way of communicating optimization run errors from PRIMO to the web API, where they can be appropriately handled and information conveyed to the user.
While implementing the handling of optimization errors, it became very cumbersome to use the existing infrastructure with using Highs independent from pyomo (the results objects are different types, structures, etc.). This motivated the switch to using the appsi_highs solver interface with pyomo.
Changes proposed in this PR:
Legal Acknowledgement
By contributing to this software project, I agree to the following terms and conditions for my
contribution:
at the top level of this directory.
rights to intellectual property that includes these contributions, I represent that I have
received permission to make contributions and grant the required license on behalf of that
employer.