Pyomo / pyomo

An object-oriented algebraic modeling language in Python for structured optimization problems.
https://www.pyomo.org
Other
1.98k stars 508 forks source link

Manage Gurobi environments explicitly in GurobiDirect #2408

Closed simonbowly closed 1 year ago

simonbowly commented 2 years ago

Summary

It would be useful to add some capability to manage Gurobi environments (gurobipy.Env objects) in the GurobiDirect solver.

I'm happy to submit a PR for the changes described below, but could use some guidance as to the best option that fits with pyomo's style & API.

Rationale

Some Gurobi customers using pyomo to build their models have run into issues with locking up shared resources (compute servers, floating licenses, etc). When using gurobipy directly the solution is to use context managers to explicitly free those resources once they are done with. This is tricky to achieve in pyomo since Gurobi environments are not used explicitly (the global 'default' environment is used).

Additionally, some parameters cannot be set without explicitly creating Gurobi environments e.g. ISV keys (see #2401), or MemLimit added in a recent release.

Description

Several possible solutions:

Some technical points to fix:

Additional information

I've written some test cases to try to make the above points clear.

mrmundt commented 2 years ago

Hello, @simonbowly. We appreciate your suggestion! We will discuss this request and add it to our backlog for future efforts.

NOTE: There is no guarantee that we will implement all suggestions. We do, however, accept external contributions. If you are interested in expediting this request, we encourage you to review our Contribution Guide. Feel free to ask us for more details on contributing to Pyomo as well.