-
Notifications
You must be signed in to change notification settings - Fork 81
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
Reusing Gurobi environment doesn't work inside package #388
Comments
It seems like there's a weird interaction with Revise.jl (v3.1.11) going on. After executing the first set of REPL commands in my previous post (before "However, curiously..."), if I add an additional line
Alternatively, if I rename the constant |
I can reproduce this. I'll take a look. |
You can't initialize C variables like this. You need to use an module TestGurobi
using Gurobi
const GRB_ENV = Ref{Gurobi.Env}()
function __init__()
global GRB_ENV[] = Gurobi.Env()
end
end Then using TestGurobi
env = TestGurobi.GRB_ENV[] Here are the docs: https://docs.julialang.org/en/v1/manual/modules/#Module-initialization-and-precompilation |
Closing because this is not an issue with Gurobi.jl. |
Thanks for the quick response! This worked great for me. |
In the past week, reusing a Gurobi environment has stopped working for me inside packages but not modules. I'm using Julia v1.5.3, Gurobi v9.1.1, and Gurobi.jl v0.9.7. As a MWE, I create a package using
pkg> generate TestGurobi
,add Gurobi
as a dependency, and editsrc/TestGurobi.jl
to beThen, in the REPL, the
Gurobi.Optimizer
constructor works with a new Gurobi environment but not withGRB_ENV
:However, curiously (in a new REPL session) if I
include
the module file instead ofusing
the package,GRB_ENV
works fine:Defining the constant
GRB_ENV
in the REPL (again in a new session) directly also works:Am I doing something wrong? I had been using the constant
GRB_ENV
inside a package for months now without any problems, so I'm not sure what could have changed. I tried updating Gurobi.jl and Gurobi itself, both to the newest versions, to no avail.The text was updated successfully, but these errors were encountered: