-
Notifications
You must be signed in to change notification settings - Fork 505
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
New add_column() method for appsi solvers #2804
base: main
Are you sure you want to change the base?
Conversation
This method adds a variable along with its coefficients in the objective and in constraints, all in a single call. Provides the opportunity for more efficient changes to an existing model.
@michaelbynum, This is a PR you will probably want to review. One thing I'd like to note is that I had to comment out some lines in the test for this PR (see these commented out lines). Those lines were intended to verify that the pyomo model components were modified as expected, but I could never get the comparisons to consistently work as expected, even though the string representation of the expressions showed they were equivalent. If there's a preferred way to make those comparisons, great, I'd love to have them added to the test. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2804 +/- ##
=======================================
Coverage 87.98% 87.99%
=======================================
Files 770 770
Lines 90242 90310 +68
=======================================
+ Hits 79400 79465 +65
- Misses 10842 10845 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@michaelbynum, can you take a look at this? |
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.
A couple minor comments below.
# Add the variable to the objective | ||
if obj_coef != 0.0 and self._objective is not None: | ||
# Add variable to the pyomo objective | ||
self._objective.expr = self._objective.expr + obj_coef * var |
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.
This is certainly convenient, but I'm not sure the solver interface should ever modify the pyomo model...
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.
Having said that, I don't think there is a better way to do this. At least the doc string is clear.
The column will have already been added to the Pyomo model before | ||
this method is called, such that the variable is already incorporated | ||
into the passed in constraints. |
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.
Is this correct?
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.
we are pondering the above questions a bit
I think we should move this method into a "helper function" that takes in a model and a solver and modifies both. This way, we maintain that solver interfaces do not modify models as a "side effect". |
@darrylmelander @michaelbynum this PR has been open for a while, any updates or plans for finishing this? |
If @darrylmelander is unavailable I could pick this up. It would still be a useful thing for APPSI (or any of our "in memory") solver interfaces to have. |
@michaelbynum would the function signature we currently use for persistent solvers be better? pyomo/pyomo/solvers/plugins/solvers/persistent_solver.py Lines 197 to 214 in b5825e9
|
Summary/Motivation:
This PR adds a new add_column() method to the solvers in the pyomo.contrib.appsi.solvers package. Like the add_column() method in the persistent solvers in the main pyomo.solvers package, this function allows you to add a new variable, and add it to the objective and to existing constraints, all in a single function call. This gives persistent solvers an opportunity to add the new variable more efficiently than is possible when modifying existing constraints one by one.
Changes proposed in this PR:
add_column()
method to appsi solvers.Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: