cc_staff
1,857
edits
mNo edit summary |
mNo edit summary |
||
Line 13: | Line 13: | ||
===Academic Usage Agreement=== <!--T:4--> | ===Academic Usage Agreement=== <!--T:4--> | ||
<!--T: | <!--T:41--> | ||
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 publicly available article(s). | 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 publicly available article(s). | ||
===Configuring your account=== <!--T: | ===Configuring your account=== <!--T:43--> | ||
You do NOT need to create a <code>~/.licenses/gurobi.lic</code> file. The required settings to use the Compute Canada Gurobi license are configured by default when you load a gurobi module on any cluster. To verify your username has been added to the Compute Canada Gurobi license and is working properly run the following command. If it returns "Fail" then open a ticket to request help. | You do NOT need to create a <code>~/.licenses/gurobi.lic</code> file. The required settings to use the Compute Canada Gurobi license are configured by default when you load a gurobi module on any cluster. To verify your username has been added to the Compute Canada Gurobi license and is working properly run the following command. If it returns "Fail" then open a ticket to request help. | ||
Line 22: | Line 22: | ||
$ gurobi_cl 1> /dev/null && echo Success || echo Fail | $ gurobi_cl 1> /dev/null && echo Success || echo Fail | ||
== Interactive Allocations == <!--T: | == Interactive Allocations == <!--T:5--> | ||
===Gurobi Command-Line Tools=== <!--T: | ===Gurobi Command-Line Tools=== <!--T:51--> | ||
<!--T:42--> | <!--T:42--> | ||
Line 32: | Line 32: | ||
[gra800:~] gurobi_cl --help | [gra800:~] gurobi_cl --help | ||
===Gurobi Interactive Shell === <!--T: | ===Gurobi Interactive Shell === <!--T:53--> | ||
[gra-login2:~] salloc --time=1:00:0 --cpus-per-task=8 --mem=1G --account=def-xyz | [gra-login2:~] salloc --time=1:00:0 --cpus-per-task=8 --mem=1G --account=def-xyz | ||
Line 49: | Line 49: | ||
gurobi> help() | gurobi> help() | ||
<!--T: | <!--T:55--> | ||
where | where | ||
* https://www.gurobi.com/documentation/8.1/refman/recording_api_calls.html | * https://www.gurobi.com/documentation/8.1/refman/recording_api_calls.html | ||
Line 56: | Line 56: | ||
**** https://www.gurobi.com/documentation/8.1/refman/attributes.html | **** https://www.gurobi.com/documentation/8.1/refman/attributes.html | ||
===Replaying API calls=== <!--T: | ===Replaying API calls=== <!--T:6--> | ||
You can record API calls and repeat them with command | You can record API calls and repeat them with command | ||
<!--T:61--> | |||
[gra800:~] gurobi_cl recording000.grbr | [gra800:~] gurobi_cl recording000.grbr | ||
<!--T: | <!--T:63--> | ||
Reference: https://www.gurobi.com/documentation/8.1/refman/recording_api_calls.html | Reference: https://www.gurobi.com/documentation/8.1/refman/recording_api_calls.html | ||
== Batch Jobs == <!--T: | == Batch Jobs == <!--T:7--> | ||
=== Model in LP-format === <!--T: | === Model in LP-format === <!--T:71--> | ||
<!--T: | <!--T:73--> | ||
This is an example job script for an optimization model written in the [https://www.gurobi.com/documentation/8.1/refman/lp_format.html LP format]. | This is an example job script for an optimization model written in the [https://www.gurobi.com/documentation/8.1/refman/lp_format.html LP format]. | ||
{{File | {{File | ||
Line 80: | Line 80: | ||
#SBATCH --mem-per-cpu=1000M # memory per CPU (in MB) | #SBATCH --mem-per-cpu=1000M # memory per CPU (in MB) | ||
<!--T: | <!--T:75--> | ||
# use a version >= 9.0.3 | # use a version >= 9.0.3 | ||
module load StdEnv/2020 | module load StdEnv/2020 | ||
module load gurobi/9.1.0 | module load gurobi/9.1.0 | ||
<!--T: | <!--T:77--> | ||
# Create environment file in current directory setting the number of threads: | # Create environment file in current directory setting the number of threads: | ||
echo "Threads ${SLURM_CPUS_ON_NODE:-1}" > gurobi.env | echo "Threads ${SLURM_CPUS_ON_NODE:-1}" > gurobi.env | ||
<!--T: | <!--T:79--> | ||
gurobi_cl ${GUROBI_HOME}/examples/data/coins.lp | gurobi_cl ${GUROBI_HOME}/examples/data/coins.lp | ||
}} | }} | ||
=== Job using Gurobi Python === <!--T: | === Job using Gurobi Python === <!--T:8--> | ||
<!--T: | <!--T:81--> | ||
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]. | ||
{{File | {{File | ||
Line 107: | Line 107: | ||
#SBATCH --mem-per-cpu=1000M # memory per CPU (in MB) | #SBATCH --mem-per-cpu=1000M # memory per CPU (in MB) | ||
<!--T: | <!--T:83--> | ||
# use a version <= 9.0.2 | # use a version <= 9.0.2 | ||
module load StdEnv/2016.4 # or StdEnv/2018.3 | module load StdEnv/2016.4 # or StdEnv/2018.3 | ||
module load gurobi/9.0.2 | module load gurobi/9.0.2 | ||
<!--T: | <!--T:85--> | ||
# Create environment file in current directory setting the number of threads: | # Create environment file in current directory setting the number of threads: | ||
echo "Threads ${SLURM_CPUS_ON_NODE:-1}" > gurobi.env | echo "Threads ${SLURM_CPUS_ON_NODE:-1}" > gurobi.env | ||
<!--T: | <!--T:87--> | ||
gurobi.sh ${GUROBI_HOME}/examples/python/facility.py | gurobi.sh ${GUROBI_HOME}/examples/python/facility.py | ||
}} | }} | ||
== Using Gurobi in Python virtual environments == <!--T: | == Using Gurobi in Python virtual environments == <!--T:9--> | ||
<!--T: | <!--T:91--> | ||
Gurobi brings it's own version of Python but that one does not contain any 3rd-party Python packages except Gurobi. In order to use Gurobi together with popular Python | Gurobi brings it's own version of Python but that one does not contain any 3rd-party Python packages except Gurobi. In order to use Gurobi together with popular Python | ||
packages like NumPy, Matplotlib, Pandas and others, we need to create a [[Python#Creating_and_using_a_virtual_environment|virtual Python environment]] in which we can install both <code>gurobipy</code> and e.g. <code>pandas</code>. | packages like NumPy, Matplotlib, Pandas and others, we need to create a [[Python#Creating_and_using_a_virtual_environment|virtual Python environment]] in which we can install both <code>gurobipy</code> and e.g. <code>pandas</code>. | ||
<!--T: | <!--T:93--> | ||
Before we start, we need to decide which combination of versions for Gurobi and Python to use. | Before we start, we need to decide which combination of versions for Gurobi and Python to use. | ||
Line 147: | Line 147: | ||
<translate> | <translate> | ||
<!--T: | <!--T:95--> | ||
We see that <code>gurobi/8.1.1</code> brings it's own installation of <code>python2.7/</code> and Python packages for Python 2.7, 3.5, 3.6 and 3.7 (<code>pythonX.Y_utf32/</code>), | We see that <code>gurobi/8.1.1</code> brings it's own installation of <code>python2.7/</code> and Python packages for Python 2.7, 3.5, 3.6 and 3.7 (<code>pythonX.Y_utf32/</code>), | ||
while <code>gurobi/9.0.1</code> by default uses <code>python3.7/</code> and brings Python packages for Python 2.7, 3.5, 3.6, 3.7 and 3.8 (<code>pythonX.Y_utf32/</code>). | while <code>gurobi/9.0.1</code> by default uses <code>python3.7/</code> and brings Python packages for Python 2.7, 3.5, 3.6, 3.7 and 3.8 (<code>pythonX.Y_utf32/</code>). | ||
<!--T: | <!--T:97--> | ||
In this example we want to create a Python environment based on <code>python/3.7</code> in which we want to use <code>gurobi/9.0.1</code> and install the Pandas package. | In this example we want to create a Python environment based on <code>python/3.7</code> in which we want to use <code>gurobi/9.0.1</code> and install the Pandas package. | ||
=== Creating a Python virtual environments with Gurobi === <!--T: | === Creating a Python virtual environments with Gurobi === <!--T:10--> | ||
<!--T: | <!--T:101--> | ||
These steps need to be done only once per system. | These steps need to be done only once per system. | ||
<!--T: | <!--T:103--> | ||
The first step is to load the modules to [[Python#Creating_and_using_a_virtual_environment|create the virtual environment]] and activate it. | The first step is to load the modules to [[Python#Creating_and_using_a_virtual_environment|create the virtual environment]] and activate it. | ||
<!--T: | <!--T:105--> | ||
{{Commands|prompt=[name@server ~] $ | {{Commands|prompt=[name@server ~] $ | ||
| module load gurobi/9.0.1 python/3.7 | | module load gurobi/9.0.1 python/3.7 | ||
Line 173: | Line 173: | ||
}} | }} | ||
<!--T: | <!--T:107--> | ||
Now that the environment has been activated we can install the Python packages we want to use, in this case <code>pandas</code>. | Now that the environment has been activated we can install the Python packages we want to use, in this case <code>pandas</code>. | ||
<!--T: | <!--T:108--> | ||
{{Commands|prompt=(env_gurobi) [name@server ~] $ | {{Commands|prompt=(env_gurobi) [name@server ~] $ | ||
| pip install --no-index pandas | | pip install --no-index pandas | ||
Line 187: | Line 187: | ||
}} | }} | ||
<!--T: | <!--T:110--> | ||
The third step is to install gurobipy into the environment: | The third step is to install gurobipy into the environment: | ||
<!--T: | <!--T:112--> | ||
{{Commands|prompt=(env_gurobi) [name@server ~] $ | {{Commands|prompt=(env_gurobi) [name@server ~] $ | ||
| cd $EBROOTGUROBI | | cd $EBROOTGUROBI | ||
Line 212: | Line 212: | ||
}} | }} | ||
=== Using the Gurobi-enabled virtual environment === <!--T: | === Using the Gurobi-enabled virtual environment === <!--T:120--> | ||
<!--T: | <!--T:122--> | ||
Python scripts can now import both Pandas and Gurobi: | Python scripts can now import both Pandas and Gurobi: | ||
<!--T: | <!--T:124--> | ||
import pandas as pd | import pandas as pd | ||
import numpy as np | import numpy as np | ||
Line 224: | Line 224: | ||
# [...] | # [...] | ||
<!--T: | <!--T:126--> | ||
Once created we can activate Gurobi and the environment with: | Once created we can activate Gurobi and the environment with: | ||
<!--T: | <!--T:128--> | ||
module load gurobi/9.0.1 | module load gurobi/9.0.1 | ||
source ~/env_gurobi/bin/activate | source ~/env_gurobi/bin/activate | ||
python my_gurobi_script.py | python my_gurobi_script.py | ||
<!--T: | <!--T:130--> | ||
Note that we now use <code>python</code> instead of <code>gurobi.sh</code>! | Note that we now use <code>python</code> instead of <code>gurobi.sh</code>! | ||
<!--T: | <!--T:132--> | ||
And this is an example job script that we can use: | And this is an example job script that we can use: | ||
</translate> | </translate> | ||
Line 259: | Line 259: | ||
<translate> | <translate> | ||
== Cite Gurobi == <!--T: | == Cite Gurobi == <!--T:140--> | ||
<!--T: | <!--T:142--> | ||
Please see [https://support.gurobi.com/hc/en-us/articles/360013195592-How-do-I-cite-Gurobi-software-for-an-academic-publication- How do I cite Gurobi software for an academic publication?] | Please see [https://support.gurobi.com/hc/en-us/articles/360013195592-How-do-I-cite-Gurobi-software-for-an-academic-publication- How do I cite Gurobi software for an academic publication?] | ||
</translate> | </translate> |