Skip to content

Gurobi warning due to improper cleanup order #41

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

Closed
staadecker opened this issue May 30, 2025 · 2 comments
Closed

Gurobi warning due to improper cleanup order #41

staadecker opened this issue May 30, 2025 · 2 comments

Comments

@staadecker
Copy link

staadecker commented May 30, 2025

from pyoptinterface import gurobi

def make_model():
    env = gurobi.Env(empty=True)
    # env.set_raw_parameter("some_key", "some_value")
    env.start()
    return gurobi.Model(m)

m = make_model()
# m.close() ## Uncommenting this line fixes the issue.

The above code outputs the following warning when the program exits:

Warning: environment still referenced so free is deferred (Continue to use WLS)

This could be avoided by closing the model before the environment is freed. It would be nice for pyoptinterface to do this so that users don't need to.

Note: this only happens with using Gurobi's Web License Server (WLS) not when using a named academic license.

@metab0t
Copy link
Owner

metab0t commented May 31, 2025

import gurobipy as gp

options = {
    "WLSACCESSID": "",
    "WLSSECRET": "",
    "LICENSEID": 0,
}

# use wls
# env = gp.Env(params=options)

# use local license
env = gp.Env()

model = gp.Model(env=env)

env.dispose()

The problem is that Gurobi chooses to keep the environment alive if its created model is still alive only for WLS. I do not think we should add more complexity to deal with this issue like recording the models created by which environment and destroy them before the env.

Like the official docs said: "Users should dispose of all models created in this environment before disposing of this Env object."

@staadecker
Copy link
Author

Fair enough!

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

No branches or pull requests

2 participants