Gurobi can be run a number of ways, including from it’s own command line interpreter, from Python, and from Matlab. See below for the section that interests you.

Installing and running the Gurobi Python libraries

To use the Gurobi Python interface, you must first install the Gurobi Python library. This is most easily accomplished by using the option to install it into the Python library collection in your home directory. The setup procedure expects to be able to write to the directory from which it is run, so the following procedure is needed.

A script to install the Gurobi Python libraries is available on Great Lakes at /sw/examples/gurobi/python/install_gurobi_python. That script presumes you will use the python3.8-anaconda/2020.07 and the gurobi/9.0.2 modules.

Copy that script to your home directory, modify the modules being loaded if needed, and run it. The commands are described here.

The modules need to be loaded, and you need to make a copy of the libraries to install. The commands below create a temporary directory, change to it, then copy the library files to it and run the setup program. It then changes back to the directory you started from and removes the copied library files. Finally, it runs a simple example file to make sure that the installation is usable.

The following example shows what it would look like from the command line, where the $ indicates the prompt.

$ module load python3.8-anaconda/2020.07 gurobi/9.0.2

$ build=$(mktemp -d)
$ cd $build
$ cp -rp ${GUROBI_HOME}/lib .
$ python ${GUROBI_HOME}/setup.py install --user
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/gurobipy
copying lib/python3.8_utf32/gurobipy/__init__.py -> build/lib/gurobipy
copying lib/python3.8_utf32/gurobipy/gurobipy.so -> build/lib/gurobipy
running install_lib
creating /home/grundoon/.local/lib/python3.8/site-packages/gurobipy
copying build/lib/gurobipy/__init__.py -> /home/grundoon/.local/lib/python3.8/site-packages/gurobipy
copying build/lib/gurobipy/gurobipy.so -> /home/grundoon/.local/lib/python3.8/site-packages/gurobipy
byte-compiling /home/grundoon/.local/lib/python3.8/site-packages/gurobipy/__init__.py to __init__.cpython-38.pyc
running install_egg_info
Writing /home/grundoon/.local/lib/python3.8/site-packages/gurobipy-9.0.2-py3.8.egg-info
removing /tmp/grundoon/build

$ cd $OLDPWD
$ rm -rf $build
$python /sw/examples/gurobi/python/diet.py
Using license file /sw/arc/centos7/gurobi/gurobi902/linux64/gurobi.lic
Set parameter TokenServer to value flux-license1.miserver.it.umich.edu
Set parameter TSPort to value 16325
Gurobi Optimizer version 9.0.2 build v9.0.2rc0 (linux64)
Optimize a model with 4 rows, 13 columns and 40 nonzeros
Model fingerprint: 0xff20f824
Coefficient statistics:
  Matrix range     [1e+00, 2e+03]
  Objective range  [9e-01, 3e+00]
  Bounds range     [6e+01, 2e+03]
  RHS range        [0e+00, 0e+00]
Presolve removed 0 rows and 3 columns
Presolve time: 0.00s
Presolved: 4 rows, 10 columns, 37 nonzeros

Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    0.0000000e+00   1.472500e+02   0.000000e+00      0s
       4    1.1828861e+01   0.000000e+00   0.000000e+00      0s

Solved in 4 iterations and 0.00 seconds
Optimal objective  1.182886111e+01

Cost: 11.8289

Buy:
hamburger 0.604514
milk 6.97014
ice cream 2.59132

Nutrition:
calories 1800
protein 91
fat 59.0559
sodium 1779

Adding constraint: at most 6 servings of dairy
Gurobi Optimizer version 9.0.2 build v9.0.2rc0 (linux64)
Optimize a model with 5 rows, 13 columns and 42 nonzeros
Coefficient statistics:
  Matrix range     [1e+00, 2e+03]
  Objective range  [9e-01, 3e+00]
  Bounds range     [6e+01, 2e+03]
  RHS range        [6e+00, 6e+00]
Iteration    Objective       Primal Inf.    Dual Inf.      Time
       0    1.1828861e+01   5.698333e+01   0.000000e+00      0s

Solved in 0 iterations and 0.00 seconds
Infeasible model
No solution

Running Gurobi from the command line

Gurobi comes with a command line batch interpreter, gurobi_cl, that can be used to run models set up using Gurobi’s LP model specification syntax. Please refer to the Gurobi web page Solving a Simple Model – The Gurobi Command Line for more details.

To run the Gurobi command line using an LP format file, simply use the gurobi_cl command followed by the name of the LP file, as shown in this example. The coins.lp file can be found on Great Lakes as /sw/examples/gurobi/coins.lp, and you can copy it to your home directory (or use the full path).

$ gurobi_cl coins.lp
Using license file /sw/arc/centos7/gurobi/gurobi902/linux64/gurobi.lic
Set parameter TokenServer to value flux-license1.miserver.it.umich.edu
Set parameter TSPort to value 16325
Set parameter LogFile to value gurobi.log

Gurobi Optimizer version 9.0.2 build v9.0.2rc0 (linux64)
Copyright (c) 2020, Gurobi Optimization, LLC

Read LP format model from file coins.lp
Reading time = 0.00 seconds
: 4 rows, 9 columns, 16 nonzeros
Optimize a model with 4 rows, 9 columns and 16 nonzeros
Model fingerprint: 0x5ce1d538
Variable types: 4 continuous, 5 integer (0 binary)
Coefficient statistics:
  Matrix range     [6e-02, 7e+00]
  Objective range  [1e-02, 1e+00]
  Bounds range     [5e+01, 1e+03]
  RHS range        [0e+00, 0e+00]
Found heuristic solution: objective -0.0000000
Presolve removed 1 rows and 5 columns
Presolve time: 0.00s
Presolved: 3 rows, 4 columns, 9 nonzeros
Variable types: 0 continuous, 4 integer (0 binary)

Root relaxation: objective 1.134615e+02, 2 iterations, 0.00 seconds

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0  113.46154    0    1   -0.00000  113.46154      -     -    0s
H    0     0                     113.4500000  113.46154  0.01%     -    0s
     0     0  113.46154    0    1  113.45000  113.46154  0.01%     -    0s

Explored 1 nodes (2 simplex iterations) in 0.00 seconds
Thread count was 32 (of 36 available processors)

Solution count 2: 113.45 -0 

Optimal solution found (tolerance 1.00e-04)
Best objective 1.134500000000e+02, best bound 1.134500000000e+02, gap 0.0000%
[bennet@gl-build gurobi]$ cat coins.lp 
Maximize
  .01 Pennies + .05 Nickels + .1 Dimes + .25 Quarters + 1 Dollars
Subject To
  Copper: .06 Pennies + 3.8 Nickels + 2.1 Dimes + 5.2 Quarters + 7.2 Dollars -
     Cu = 0
  Nickel: 1.2 Nickels + .2 Dimes + .5 Quarters + .2 Dollars -
     Ni = 0
  Zinc: 2.4 Pennies + .5 Dollars - Zi = 0
  Manganese: .3 Dollars - Mn = 0
Bounds
  Cu <= 1000
  Ni <= 50
  Zi <= 50
  Mn <= 50
Integers
  Pennies Nickels Dimes Quarters Dollars
End

.