Remove deprecated gurobipy addConstr call#3350
Conversation
|
Hi, I am currently testing this PR by running: python examples/pyomo/columngeneration/cutting_stock.py gurobi_persistent File "d:\dev\pyomo\pyomo\solvers\plugins\solvers\GUROBI.py", line 38, in |
| gurobi_expr, referenced_vars, degree = self._get_expr_from_pyomo_repn( | ||
| con.canonical_form(), self._max_constraint_degree | ||
| ) | ||
| # elif isinstance(con, LinearCanonicalRepn): |
There was a problem hiding this comment.
Is this commented block something that should be kept ? Happy to leave it as is to minimize the diff
There was a problem hiding this comment.
I think that is completely removable (looking back, I think LinearCanonicalRepn disappeared from Pyomo more than 7 years ago).
Yes - the problem is your definition of the class GurobiModel(gurobipy.Model):Parsing / compiling this definition (during module import) accesses the The simplest "workaround" might be something like: class GurobiModel(gurobipy.Model if gurobipy_available else object):However, that will run afoul of another test in the Pyomo unittest system: this solution still triggers the gurobipy import - when you implicitly cast The better solution is probably to define an |
|
Thank you so much for your help @jsiirola, I have implemented your suggestion, and it works great! |
|
@quantresearch1 I removed the [WIP] marking from the title to check the test status on this PR. Is this ready for review or still work in progress? |
|
@blnicho thanks, let me fix the unit tests first before asking for a review |
|
@blnicho I think I have fixed it. The issue was that for NumericConstant expression, the degree is 0. I would incorrectly raise a DegreeError as I was expecting _get_expr_from_pyomo_repn to only give me degrees 1 or 2 |
|
@jsiirola The win/3.9 build failed with a segmentation in conda, should I just give the CI another run ? Sorry I am not sure how to debug this issue. Platform: win-64 |
|
@quantresearch1: the windows failure is an issue with conda that crops up with surprising regularity (the error is happening while trying to set up the conda environment and has nothing to do with Pyomo). Usually waiting a couple hours and re-running that job will clear it. |
|
Great to see all checks are now passing. May I merge it ? |
Summary/Motivation:
With both the previous and latest major gurobi versions, we get a deprecation warning when calling model.addConstr.
Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Changes proposed in this PR:
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: