Gurobi

Overview

Gurobi is an optimization solver, documentation is available here.

Executing

Modules

This application is available using the modules command.

Version 6.5.1

[user@mercury ~]$ module load gurobi/6.5/6.5.1
[user@mercury ~]$ gurobi_cl --help
Gurobi command line optimizer, version 6.5.1 build v6.5.1rc3 (linux64).
Copyright (c) 2016, Gurobi Optimization, Inc.

Usage: gurobi_cl [--command]* [param=value]* filename

Gurobi parameters are documented in the Gurobi Reference Manual.

Accepted commands are:
   --version: version information
   --license: license information
   --tokens:  details on tokens currently in use
   --status:  current Gurobi Services status
   --adminpassword, --joblimit, --killjob, --server: Gurobi Services
         administrative commands

A few usage examples:
  gurobi_cl Method=2 ResultFile=afiro.sol afiro.mps
  gurobi_cl --server=localhost --status

Visit www.gurobi.com/doc/65 for further details on how to use this program.

Version 7.5.2

[user@mercury ~]$ module load gurobi/7.5/7.5.2
[user@mercury ~]$ gurobi_cl --help
Gurobi command line optimizer, version 7.5.2 build v7.5.2rc1 (linux64).
Copyright (c) 2017, Gurobi Optimization, Inc.

Usage: gurobi_cl [--command]* [param=value]* filename

Gurobi parameters are documented in the Gurobi Reference Manual.

Accepted commands are:
   --version: version information
   --license: license information
   --tokens:  details on tokens currently in use
   --status:  current Gurobi Services status
   --newadminpassword, --joblimit, --killjob, --server: Gurobi Services
         administrative commands

A few usage examples:
    gurobi_cl misc07.mps
    gurobi_cl Record=1 Method=2 ResultFile=p0033.sol InputFile=p0033.mst InputFile=p0033.hnt.gz LogFile=p0033.log p0033.mps
    gurobi_cl --server=localhost --status

Visit www.gurobi.com/documentation/7.5 for further details on how to use this program.

Submitting Batch

Code examples can be found by visiting the Gurobi Optimizer Example Tour. In addition, the code examples are hosted on the compute nodes at $GUROBI_HOME/examples. The following shows how to use Gurobi to solve a simple quadratically constrained program (QCP) in Python.

Python

Code

qcp.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
# Copyright 2017, Gurobi Optimization, Inc.
# This example formulates and solves the following simple QCP model:
#     maximize    x
#     subject to  x + y + z = 1
#                 x^2 + y^2 <= z^2 (second-order cone)
#                 x^2 <= yz        (rotated second-order cone)

from gurobipy import *

# The gurobi log file, this will be placed in the same directory as the code being run if you use the -cwd option on the grid engine
env = Env("model-out.log")

# Create a new model
m = Model("qcp", env)

# Create variables
x = m.addVar(name="x")
y = m.addVar(name="y")
z = m.addVar(name="z")

# Set objective: x
obj = 1.0*x
m.setObjective(obj, GRB.MAXIMIZE)

# Add constraint: x + y + z = 1
m.addConstr(x + y + z == 1, "c0")

# Add second-order cone: x^2 + y^2 <= z^2
m.addConstr(x*x + y*y <= z*z, "qc0")

# Add rotated cone: x^2 <= yz
m.addConstr(x*x <= y*z, "qc1")

# Optimize
m.optimize()

# dump output
for v in m.getVars():
print('%s %g' % (v.varName, v.x))
print('Obj: %g' % obj.getValue())

Submission script

Create a job submission script in the same directory as your code:

submit_qcp.qsub
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#!/bin/bash

#SBATCH --job-name gurobi_qcp

# load the module
module load python/booth/3.6/3.6.3
module load gurobi/7.5/7.5.2

# Run the Python code
python qcp.py

Submission

Submit the job to the Slurm scheduler

[username@mercury gurobi]$ sbatch submit_qcp.sh

Output

There should now be stdout, stderr and a model-out.log file in the same directory as the code.

[username@mercury gurobi]$ more model-out.log
Gurobi 7.5.2 (linux64, Python) logging started Fri Dec  8 12:32:52 2017

Optimize a model with 1 rows, 3 columns and 3 nonzeros

Model has 2 quadratic constraints

Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  QMatrix range    [1e+00, 1e+00]
  Objective range  [1e+00, 1e+00]
  Bounds range     [0e+00, 0e+00]
  RHS range        [1e+00, 1e+00]

Presolve time: 0.00s
Presolved: 6 rows, 6 columns, 13 nonzeros
Presolved model has 2 second-order cone constraints
Ordering time: 0.00s

Barrier statistics:
 AA' NZ     : 1.500e+01
 Factor NZ  : 2.100e+01
 Factor Ops : 9.100e+01 (less than 1 second per iteration)
 Threads    : 1
                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   2.38095238e-01  2.38095238e-01  8.33e-17 4.33e-01  9.23e-02     0s
   1   3.20481543e-01  3.62123302e-01  2.78e-17 1.39e-02  7.95e-03     0s
   2   3.26649101e-01  3.28651430e-01  1.11e-14 5.44e-04  3.46e-04     0s
   3   3.26797051e-01  3.27019441e-01  5.69e-13 5.98e-10  2.78e-05     0s
   4   3.26990986e-01  3.26994814e-01  2.91e-13 3.48e-13  4.78e-07     0s
   5   3.26992304e-01  3.26992876e-01  8.91e-11 2.63e-14  7.15e-08     0s
Barrier solved model in 5 iterations and 0.00 seconds

Optimal objective 3.26992304e-01

Errata and Miscellany

  • The Python modules for Gurobi 7.5.2 are installed on the Booth Python versions 2.7.5, 2.7.14, 3.6.2 and 3.6.3 which are available using the module command.
  • The Python modules for Gurobi 6.5.1 are NOT installed and are NOT useable by any Python on Mercury. The Gurobi Python modules are not versioned and therefore CANNOT be installed along side the 7.5.2 version. Do not ask to have it installed, it does NOT work.
  • Note that in ALL version of Gurobo installed on Mercury, the Gurobi shell (gurobi.sh) will use the Gurobi internally included Python version 2.7.13 and not the ones supplied by Booth on Mercury. If you wish to use the shell with another version of Python, copy the gurobi.sh script to your home directory, modify it to use another Python and execute it from there. We will not support this alternate version, the one that comes with is the one that Gurobi is meant to be used with.Gurobi