coin-or / python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Eclipse Public License 2.0
518 stars 92 forks source link

`GUROBI_HOME` check does not work with pip installation of Gurobi #185

Closed RichardOberdieck closed 2 years ago

RichardOberdieck commented 3 years ago

Describe the bug If Gurobi is installed via pip (see e.g. here), then the .so file does not conform to the current style set out in mip/gurobi.py.

To Reproduce

  1. pip install mip
  2. pip install -i https://pypi.gurobi.com gurobipy
  3. `setenv GUROBI_HOME='xxx'
  4. It doesn't work

Expected behavior I think it would be nice if it happened.

Desktop (please complete the following information):

Additional context I think a possible fix would look like this, i.e. to add this after the first is not libfile:

if not libfile: # For pip installer
            libfile = glob(
                os.path.join(os.environ["GUROBI_HOME"], "gurobipy.*.so")
            )

For Linux, the .so file is named: gurobipy.cpython-37m-x86_64-linux-gnu.so. This would though mean that the version number deduction with major_ver and minor_ver in gurobi.py does not work and the subsequent definition of lib_path does not work either. Not sure how to handle this, which is why I did not make a PR.

sebheger commented 2 years ago

@RichardOberdieck

as experiment, I tried it under windows by setting the libfile directly as absolute path to the gurobi.dll which comes with pip installation. So far, the linkage for cffi is fine. But it won't accept the size-limited trial license. Always get 10009 on GRBloadenv on C side. I tried to copy around the gurobi.lic to the default directorys and setting GRB_LICENSE_FILE. It seems to me, that the special PIP Trial-License could not be "universally" used. As I have no "full" license available on my personal computer, I cannot test if it would work otherwise. Any ideas on that?

RichardOberdieck commented 2 years ago

Yes, this is unfortunately to be expected since the trial license only works for gurobipy or our command-line interface (gurobi_cl); it will not work with any other API, including the C API.

I will ask internally whether we can change this, and will let you know if I hear anything back.

RichardOberdieck commented 2 years ago

We are discussing this in the team, but I doubt that we will take a quick decision on this. If we gave you a full license for a few days, would that be enough for you to test this?

sebheger commented 2 years ago

With a trial license for let's say 2 weeks, I could do some more tests and see if and how we can fix/additionally search for gurobipy installed gurobi.

One more thing: Would it be possible to get some license to be integrated into our CI workflow? To make the development more "sustainable" regarding the gurobi implementation part. My initial thought was, that we install gurobi via gurobipy and pip and reuse the size-limited license within our CI after stripping down the tests to smaller examples (at the moment the CI runs a lot of larger models). But then I recognized this issue ...

RichardOberdieck commented 2 years ago

How exactly does your workflow look like? Do you run your CI on a fixed, local machine, GH actions or something else?

sebheger commented 2 years ago

The CI is based on GH actions

RichardOberdieck commented 2 years ago

Ok.

We've discussed this internally and I don't think we'll make the size-limited license that ships with the installation from the PyPI server generally available for all APIs.

However, I have been thinking about something: if you have a working integration with the PyPI installed gurobipy, then you are good to go to use the size-limited license. The only part that it does not cover is the current installation method via the GUROBI_HOME environment variable.

Maybe we can have a quick call to discuss the details and set everything up? You can reach me at oberdieck@gurobi.com.

sebheger commented 2 years ago

@RichardOberdieck Would you take a look at #271?

DavidWalz commented 2 years ago

A workaround for windows is to copy the gurobiXX.dll file inside a folder called /bin because of this line https://github.com/coin-or/python-mip/blob/14466736d92ea13182d18c61c64642aff4a5a2e8/mip/gurobi.py#L55