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

change default behavior in appsi to not care where variables live #2903

Merged
merged 9 commits into from
Aug 8, 2023

Conversation

michaelbynum
Copy link
Contributor

@michaelbynum michaelbynum commented Jul 10, 2023

Fixes #2888.

Summary/Motivation:

This PR

  • changes the default behavior of appsi solver interfaces to match that of the new NL writer so that models can be solved even if using variables that live outside the block being solved.
  • fixes a bug in update where an error was raised when removing variables that were used in the old objective but not the new objective.
  • improves the tests in appsi to test both only_child_vars=True and only_child_vars=False. This is the flag that controls how variables are gathered (by traversing the model or from the active constraints/objective).

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:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has 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.

@michaelbynum michaelbynum marked this pull request as draft July 10, 2023 14:58
@michaelbynum michaelbynum marked this pull request as ready for review July 11, 2023 12:24
@codecov
Copy link

codecov bot commented Jul 11, 2023

Codecov Report

Patch coverage: 90.21% and project coverage change: +0.01% 🎉

Comparison is base (25db781) 87.81% compared to head (4ccf713) 87.82%.
Report is 65 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2903      +/-   ##
==========================================
+ Coverage   87.81%   87.82%   +0.01%     
==========================================
  Files         770      770              
  Lines       89626    89641      +15     
==========================================
+ Hits        78701    78728      +27     
+ Misses      10925    10913      -12     
Flag Coverage Δ
linux 84.86% <89.05%> (+0.01%) ⬆️
osx 74.59% <87.52%> (+0.01%) ⬆️
other 85.04% <89.05%> (+0.01%) ⬆️
win 82.12% <88.46%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
pyomo/core/__init__.py 100.00% <ø> (ø)
pyomo/environ/__init__.py 82.35% <ø> (ø)
pyomo/solvers/plugins/solvers/xpress_direct.py 72.71% <53.33%> (+0.95%) ⬆️
pyomo/contrib/viewer/pyomo_viewer.py 70.96% <80.00%> (ø)
pyomo/core/expr/numeric_expr.py 98.60% <90.86%> (-1.02%) ⬇️
pyomo/common/numeric_types.py 92.40% <93.47%> (+1.49%) ⬆️
pyomo/common/errors.py 100.00% <100.00%> (ø)
pyomo/contrib/appsi/base.py 85.57% <100.00%> (+0.37%) ⬆️
pyomo/contrib/appsi/solvers/cbc.py 82.79% <100.00%> (ø)
pyomo/contrib/appsi/solvers/cplex.py 89.07% <100.00%> (ø)
... and 90 more

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@blnicho blnicho requested a review from emma58 July 11, 2023 18:52
Copy link
Contributor

@emma58 emma58 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very happy! :)

Comment on lines 1463 to 1467
# this has to be done after the objective in case the
# old objective uses old variables
timer.start('vars')
self.remove_variables(old_vars)
timer.stop('vars')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure I'm understanding, it has to be after constraints for the same reason, right? (It just already was.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point. Yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update the comment

@michaelbynum
Copy link
Contributor Author

This is very happy! :)

Haha, good!

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 this pull request may close these issues.

APPSI Solver Error: cannot remove variable q2 - it is still being used by constraints or the objective
3 participants