pulp icon indicating copy to clipboard operation
pulp copied to clipboard

Gurobi environment handling

Open torressa opened this issue 2 years ago • 1 comments

Details for the issue

What did you do?

Using a single-use token license.

$ python3
>>> import pulp
>>> pulp.list_solvers(onlyAvailable=True)
Set parameter TokenServer to value "localhost"
No parameters matching '_test' found
/Users/david.torres-sanchez/.pyenv/versions/3.10.2/lib/python3.10/site-packages/pulp/apis/gurobi_api.py:357: UserWarning: GUROBI error: Set parameter TokenServer to value "localhost"
Set parameter LogFile to value "gurobi.log"

Failed to set up a license

Error 10009: Request denied: use limit (1) exceeded

.
  warnings.warn("GUROBI error: {}.".format(out))
['GUROBI', 'PULP_CBC_CMD']

Two tokens are required and not released until the python shell is exited (and the object is freed). So when you run the command again, GUROBI is no longer available

What did you expect to see?

What did you see instead?

Useful extra information

It would be good if environment handling was taken care of. This is an issue for Gurobi users using cloud, WLS or token license types. E.g. https://github.com/snakemake/snakemake/issues/1801

Possible solution: WIP:

  • Add some extra arguments to control environment handling
  • Initialise default environment unless user prefers otherwise
  • Context manager for the same purpose

What operating system are you using?

  • [ ] Windows: ( version: ___ )
  • [ ] Linux: ( distro: ___ )
  • [ ] Mac OS: ( version: )
  • [ ] Other: ___

I'm using python version:

  • [ ] 2.7
  • [ ] 3.4
  • [ ] 3.5
  • [ ] 3.6
  • [X] Other: 3.10.2

I installed PuLP via:

  • [X] pypi (python -m pip install pulp)
  • [ ] github (python -m pip install -U git+https://github.com/coin-or/pulp)
  • [X] Other: cloned

Did you also

  • [X] Tried out the latest github version: https://github.com/coin-or/pulp
  • [X] Searched for an existing similar issue: https://github.com/coin-or/pulp/issues?utf8=%E2%9C%93&q=is%3Aissue%20

torressa avatar Aug 08 '22 17:08 torressa

I think the error comes because we needed to call some function of the gurobi python to know if it's correctly licensed. That's why we had gurobipy.setParam("_test", 0) (this is the problematic line in question I'm guessing). Is there a way to check if a valid and licensed version of Gurobi is available without using a license? Or is there a way to return the license after successfully testing any random parameter? If the licensed is "single-use" I understand it's spent once we call it?

Sorry for all the questions but I checked the WIP and was overly complicated. If we can find a simple solution to check for licensing without using a license, that would be great.

pchtsp avatar Aug 22 '22 16:08 pchtsp

Hi both, do we have any update on a fix for this?

Tomkourou avatar Sep 30 '22 11:09 Tomkourou

right @pchtsp Seems we should call

Python: Gurobi 9.0.0 or newer: Call Model.dispose() on all Model objects. Then, if using custom-made environments, call Env.dispose() on all Env objects. Otherwise, call disposeDefaultEnv(). Gurobi 8.1.1 or older: Delete all Model objects, delete all Env objects (if used), then call disposeDefaultEnv().

https://support.gurobi.com/hc/en-us/articles/360013417731-How-do-I-release-a-shared-limited-use-license-

@torressa and @Tomkourou are you able to test this by adding the line

gurobipy.disposeDefaultEnv()

after the line gurobipy.setParam("_test", 0)

stumitchell avatar Oct 02 '22 23:10 stumitchell

Thanks, everyone. Sorry for the delay!

@torressa and @Tomkourou are you able to test this by adding the line gurobipy.disposeDefaultEnv()

That would work for this specific bug. In general, however, the current lack of environment handling still suffers from:

  • Inability to set environment-only parameters (e.g. MemLimit)
  • Inability to use/reuse user-defined environments.
  • Environments are at the mercy of the garbage collector and under certain circumstances (memory leaks, jupyter notebooks, ...) this may lead to them being used-up or locked for long periods of time.

My commit https://github.com/torressa/pulp/commit/c766603fb1502acddc6af6e7cb51c4dfb5c17c6e addresses these points somewhat (still needs double checking).

torressa avatar Oct 03 '22 11:10 torressa

Hi ! I'm still having the same issue. Any news on this ?

tgi-climact avatar Sep 18 '23 11:09 tgi-climact

This has been merged. Will be fixed in the next release.

torressa avatar Sep 28 '23 13:09 torressa