Skip to content

Exception of Lazy parameter not set with cbLazy and Gurobi #3637

Open
@noamgold

Description

@noamgold

Summary

Working with the gurobi_persistent interface and setting the
opt.set_gurobi_param('LazyConstraints', 1)
I get an exception when calling
cbLazy from Pyomo callback indicating that the parameter hasn't been set

I run Pyomo setting a callback using Gurobi.

Steps to reproduce the issue

$ command1 [options]
$ command2 [options]
...
# example.py
import pyomo.environ
...

def my_callback(cb_m, cb_opt, cb_where):
model = cb_m
mmodel = opt._solver_model

if cb_where == GRB.Callback.MIPSOL: # and not cb_m.theta.value is None:

....
cb_opt.cbLazy(add_cut_two(Z,a_bar,a,V,c,model))

opt = pe.SolverFactory('gurobi_persistent')
opt.set_instance(model,symbolic_solver_labels=True)
opt.set_gurobi_param('PreCrush', 1)
opt.set_gurobi_param('LazyConstraints', 1)
opt.set_callback(my_callback)

Error Message

Traceback (most recent call last):
File "src\gurobipy\callback.pxi", line 101, in gurobipy._core.CallbackClass.callback
File "C:..\pyomo\solvers\plugins\solvers\gurobi_persistent.py", line 482, in f
self._callback_func(self._pyomo_model, self, where)
File "C:..\src\rebpp.py", line 333, in my_callback
cb_opt.cbLazy(add_cut_two(Z,a_bar,a,V,c,model))
File "C:..\pyomo\solvers\plugins\solvers\gurobi_persistent.py", line 685, in cbLazy
self._solver_model.cbLazy(
File "src\gurobipy\_model.pyx", line 7798, in gurobipy._model.Model.cbLazy
File "src\gurobipy\_model.pyx", line 7842, in gurobipy._model.Model._cbCutOrLazy
gurobipy._exception.GurobiError: Must set LazyConstraints parameter to use lazy constraints
Exception ignored in: 'gurobipy._core.callbackstub'
Traceback (most recent call last):
File "src\gurobipy\callback.pxi", line 101, in gurobipy._core.CallbackClass.callback
File "C:..\pyomo\solvers\plugins\solvers\gurobi_persistent.py", line 482, in f
self._callback_func(self._pyomo_model, self, where)
File "C:..\src\rebpp.py", line 333, in my_callback
cb_opt.cbLazy(add_cut_two(Z,a_bar,a,V,c,model))
File "C:..\pyomo\solvers\plugins\solvers\gurobi_persistent.py", line 685, in cbLazy
self._solver_model.cbLazy(
File "src\gurobipy\_model.pyx", line 7798, in gurobipy._model.Model.cbLazy
File "src\gurobipy\_model.pyx", line 7842, in gurobipy._model.Model._cbCutOrLazy
gurobipy._exception.GurobiError: Must set LazyConstraints parameter to use lazy constraints

$ # Output message here, including entire stack trace, if available

Information on your system

Pyomo version: 6.8.2
Python version: 3.13.5
Operating system: Windows 11
How Pyomo was installed (PyPI, conda, source): PyPI
Solver (if applicable): Gurobi 12.0.0

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions