Designating specific pool from within Python program
AnsweredHi all,
I'm working with a Python script that calls the gurobi optimizer. I need to run many iterations of the script with different parameters. As far as I can tell, the best way to do this is to create different files containing the script, each with a unique set of parameters, and then to have each file run using a unique Gurobi cloud pool.
The guide for using instant cloud in a program says "the Gurobi client libraries provide you with dedicated environment constructors to specify the access ID, the secret key and optionally the pool." Thus, it seems possible for each file to specify a different pool.
My question is how to implement this in my program. My program calls gurobi via pyomo's SolverFactory (see abbreviated code below). The example here is the closest I've come to a solution, but I'm not sure how to implement it. Could I replace solver = 'gurobi' below with solver = Env.CloudEnv(...)?
Margaret
-
Hi Margaret,
I'm not sure that there is a way to do this programmatically with Pyomo (short of modifying the Pyomo source), since Pyomo doesn't appear to give you access to the Gurobi environment. This would be straightforward to do with the \( \texttt{gurobipy} \) interface.
Instead, you could download the separate licenses for each cloud pool in the Pools menu of the Cloud Manager. Save the files separately as, e.g., \( \texttt{gurobi.lic.pool1} \), \( \texttt{gurobi.lic.pool2} \), etc. Then, each time the script runs, make sure the \( \texttt{GRB_LICENSE_FILE} \) environment variable points to the license file corresponding to the cloud pool you want to use.
Does this help?
Thanks,
Eli
0 -
Hi Eli,
Thanks for your reply! That's very helpful.
One follow-up question (and apologies for my ignorance--I haven't spent much time dealing with back-end issues in Python). Is there a way to make GRB_LICENSE_FILE point to many different files (e.g., gurobi.lic.pool1, gurobi.lic.pool2) for different scripts within a single virtual environment? My goal is to be able to run these different scripts simultaneously, in case that wasn't clear.
Thanks again for your help,
Margaret
0 -
Hi Margaret,
If you want to use different cloud pools within a single Python script, you can set the \( \texttt{GRB_LICENSE_FILE} \) environment variable inside of the script, immediately before solving the model:
import os
# Build Pyomo model here...
with SolverFactory('gurobi') as opt:
# Solve model with first cloud pool
os.environ['GRB_LICENSE_FILE'] = '/home/margaret/gurobi.lic.pool1'
results = opt.solve(model)
# Solve model with second cloud pool
os.environ['GRB_LICENSE_FILE'] = '/home/margaret/gurobi.lic.pool2'
results = opt.solve(model)If you are running several different scripts simultaneously, you can set the environment variable before running the script:
export GRB_LICENSE_FILE=/home/margaret/gurobi.lic.pool1
python solve_model.pyDoes this help?
Thanks,
Eli
0 -
That seems to work great! Thanks so much.
Margaret
0
Please sign in to leave a comment.
Comments
4 comments