Skip to main content

Designating specific pool from within Python program

Answered

Comments

4 comments

  • Eli Towle
    Gurobi Staff Gurobi Staff

    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
  • Margaret McCall
    Gurobi-versary
    Curious
    Conversationalist

    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
  • Eli Towle
    Gurobi Staff Gurobi Staff

    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.py

    Does this help?

    Thanks,

    Eli

    0
  • Margaret McCall
    Gurobi-versary
    Curious
    Conversationalist

    That seems to work great! Thanks so much.

    Margaret

    0

Please sign in to leave a comment.