Handling Gurobi licenses through the APPSI interface
In order to obtain performance benefits when re-solving a Pyomo model
with Gurobi repeatedly, Pyomo has to keep a reference to a gurobipy
model between calls to
solve(). Depending
on the Gurobi license type, this may “consume” a license as long as
any APPSI-Gurobi interface exists (i.e., has not been garbage
collected). To release a Gurobi license for other processes, use the
release_license()
method as shown below. Note that
release_license()
must be called on every instance for this to actually release the
license. However, releasing the license will delete the gurobipy model
which will have to be reconstructed from scratch the next time
solve() is
called, negating any performance benefit of the persistent solver
interface.
>>> opt = appsi.solvers.Gurobi()
>>> results = opt.solve(model)
>>> opt.release_license()
Also note that both the
available() and
solve() methods
will construct a gurobipy model, thereby (depending on the type of
license) “consuming” a license. The
available()
method has to do this so that the availability does not change between
calls to
available() and
solve(), leading
to unexpected errors.