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
Manage Gurobi environments in GurobiDirect #2680
Conversation
Hi @simonbowly - We are very excited about this PR but need to have a more targeted discussion as a dev team to discuss backwards compatibility implications. We will get back to you ASAP and thoroughly appreciate your contribution! |
Thanks @mrmundt! Are the current jenkins test failures relevant? They seem to be only codecov related. Just one note I should add re: the tests. Some of the tests I added are really integration tests that rely on Gurobi single-use license behaviour, so they are skipped in CI. I can look at adding a few more unit tests if the changes seem reasonable. |
@simonbowly: yes: the Jenkins failure is legitimate:
|
Add tests to check environments are closed properly. Requires a single-use Gurobi license to run correctly.
Avoid keeping the default environment open in this test module.
Verifies that parameters are set appropriately on models and environments in gurobi_direct
Include Gurobi error details in ApplicationError message
Avoid re-checking the default environment has been started. Provide a class-level method release_license to dispose of the default environment.
2c4658e
to
7f24d04
Compare
Thanks @jsiirola. I pushed a fix to that test and rebased. |
I took one more pass to hopefully sort out that failing conda test 🤞 |
@blnicho I think the only remaining failing test is unrelated - |
I think the docstring of |
@simonbowly - One more question. Would it be better to allow users to pass in an instance of |
I did think about that initially. The distinction would be: import gurobipy as gp
with gp.Env(params={...}) as env, pyo.SolverFactory("gurobi_direct", env=env) as opt:
opt.solve(model) vs. with pyo.SolverFactory("gurobi_direct", options={...}, manage_env=True) as opt:
opt.solve(model) where
Unless there is a use case for creating one |
Added documentation with 317b8c5. That's everything I wanted to add, please review when time allows :-) |
@blnicho I see this didn't make it into the release, did you want me to make any changes? |
@simonbowly we don't have any change requests at this time. We ran out of time to get a second review on this and needed to move forward with the release to meet a deadline for a downstream project. |
There was a pypy-3.9 test failure. I restarted that job. If it passes, we will merge. Sorry for the delay, @simonbowly. It is my fault. |
No problem at all! I really appreciate the time you all spent discussing & reviewing this PR, thanks again! |
Very great job folks! Thank you! |
Fixes #2408
Summary/Motivation:
There are currently several limitations in the GurobiDirect interface:
Env
object. This includes connection parameters for compute servers, token servers, and instant cloud (can be worked around via a license file, but this isn't always an ideal approach) and special parameters such as MemLimit.Changes proposed in this PR:
Introduces a constructor flag
manage_env
for GurobiDirect (defaults to False), and two public methods.close()
and.close_global()
. If users setmanage_env=True
:.close()
achieves the same result as the context manager:If
manage_env=False
(the default) is set, then users will get the old behaviour, which uses the Gurobi default/global environment. There are some minor changes:.close()
, or exiting the context properly disposes of all models created by the solver.close_global()
disposes of models created by the solver, and disposes the Gurobi default environment. This will free all Gurobi resources assuming the user did not create any other models (e.g. via another GurobiDirect object withmanage_env=False
):Finally, the
available()
call no longer stores errors globally and repeats them back if users retry the check. So users can do the following to queue requests if they are using a shared license (regardless of whether manage_env is set to True or False):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: