Gurobi: Difference between revisions

From Alliance Doc
Jump to navigation Jump to search
No edit summary
Line 53: Line 53:
== Batch Jobs ==
== Batch Jobs ==


=== Model in LP-format ==  
=== Model in LP-format ===  


This is an example jobscript for an optimization model written in the [https://www.gurobi.com/documentation/8.1/refman/lp_format.html LP format].
This is an example jobscript for an optimization model written in the [https://www.gurobi.com/documentation/8.1/refman/lp_format.html LP format].
Line 73: Line 73:
}}
}}


=== Job using Gurobi Python ==  
=== Job using Gurobi Python ===  


This is an example jobscript for a model using [https://www.gurobi.com/documentation/8.1/refman/py_python_api_overview.html#sec:Python Gurobi-Python].
This is an example jobscript for a model using [https://www.gurobi.com/documentation/8.1/refman/py_python_api_overview.html#sec:Python Gurobi-Python].

Revision as of 15:27, 10 December 2019

Other languages:

Gurobi is a commercial software suite for solving complex optimization problems. This page wiki page describes the non-commercial use of Gurobi software on Compute Canada clusters and is currently a work in progress.

License limitations

Compute Canada supports and provides a free license to use Gurobi Graham, Cedar, Beluga and Niagara clusters. The license provides a total number of 4096 simultaneous uses (tokens in use) and permits distributed usage. A single user can run multiple simultaneous jobs. In order to use Gurobi you must agree to certain conditions. Please contact support with a copy of the following statement. You will then be added into the Compute Canada license file as a permitted user.

My Compute Canada username is "_______" and I am a member of the academic institution "_____________________".  This message confirms that I will only use the Compute Canada Gurobi license provided on Compute Canada systems for the purpose of non-commercial research project(s) to be published in a publicly available article(s).

Interactive Allocations

Gurobi Command-Line Tools

[gra-login2:~] salloc --time=1:00:0 --cpus-per-task=8 --mem=1G --account=def-xyz
[gra800:~] module load gurobi
[gra800:~] gurobi_cl Record=1 Threads=8 Method=2 ResultFile=p0033.sol LogFile=p0033.log $GUROBI_HOME/examples/data/p0033.mps
[gra800:~] gurobi_cl --help

Gurobi Interactive Shell

[gra-login2:~] salloc --time=1:00:0 --cpus-per-task=8 --mem=1G --account=def-xyz
[gra800:~] module load gurobi
[gra800:~] echo "Record 1" > gurobi.env    see *
[gra800:~] gurobi.sh
gurobi> m = read('/cvmfs/restricted.computecanada.ca/easybuild/software/2017/Core/gurobi/8.1.1/examples/data/glass4.mps') 
gurobi> m.Params.Threads = 8               see **
gurobi> m.Params.Method = 2
gurobi> m.Params.ResultFile = "glass4.sol"
gurobi> m.Params.LogFile = "glass4.log"
gurobi> m.optimize()
gurobi> m.write('glass4.lp')
gurobi> m.status                           see ***
gurobi> m.runtime                          see ****
gurobi> help()

where

   * https://www.gurobi.com/documentation/8.1/refman/recording_api_calls.html
  ** https://www.gurobi.com/documentation/8.1/refman/parameter_descriptions.html
 *** https://www.gurobi.com/documentation/8.1/refman/optimization_status_codes.html
**** https://www.gurobi.com/documentation/8.1/refman/attributes.html

Replay API Call Recording

[gra800:~] gurobi_cl recording000.grbr

Reference: https://www.gurobi.com/documentation/8.1/refman/recording_api_calls.html

Batch Jobs

Model in LP-format

This is an example jobscript for an optimization model written in the LP format.


File : gurobi_example.sh

#!/bin/bash
#SBATCH --time=0:30           # time limit (D-HH:MM)
#SBATCH --mem-per-cpu=1000M   # memory per CPU (in MB)
module purge  
module load gurobi

# Create environment file in current directory setting the number of threads:
echo "Threads ${SLURM_CPUS_ON_NODE:-1}" > gurobi.env

gurobi_cl ${EBROOTGUROBI}/examples/data/coins.lp


Job using Gurobi Python

This is an example jobscript for a model using Gurobi-Python.


File : gurobi-py_example.sh

#!/bin/bash
#SBATCH --time=0:30           # time limit (D-HH:MM)
#SBATCH --mem-per-cpu=1000M   # memory per CPU (in MB)
module purge  
module load gurobi

# Create environment file in current directory setting the number of threads:
echo "Threads ${SLURM_CPUS_ON_NODE:-1}" > gurobi.env

gurobi.sh  ${EBROOTGUROBI}/examples/python/facility.py