38,892
edits
No edit summary |
(Updating to match new version of source page) |
||
Line 11: | Line 11: | ||
===Academic Usage Agreement=== | ===Academic Usage Agreement=== | ||
<div class="mw-translate-fuzzy"> | |||
== Allocations interactives == | |||
</div> | |||
<div class="mw-translate-fuzzy"> | |||
où | |||
* 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 | |||
</div> | |||
$ module load gurobi | |||
$ gurobi_cl 1> /dev/null && echo Success || echo Fail | |||
<div class="mw-translate-fuzzy"> | |||
===Ligne de commande=== | ===Ligne de commande=== | ||
</div> | |||
<div class="mw-translate-fuzzy"> | |||
=== Gurobi-Python === | |||
</div> | |||
[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 22: | Line 39: | ||
[gra800:~] gurobi_cl --help | [gra800:~] gurobi_cl --help | ||
<div class="mw-translate-fuzzy"> | |||
# Create environment file in current directory setting the number of threads: | |||
echo "Threads ${SLURM_CPUS_ON_NODE:-1}" > gurobi.env | |||
</div> | |||
<div class="mw-translate-fuzzy"> | |||
== Environnements virtuels Python == | |||
</div> | |||
<div class="mw-translate-fuzzy"> | |||
=== Interpréteur interactif === | === Interpréteur interactif === | ||
Line 38: | Line 65: | ||
gurobi> m.runtime see **** | gurobi> m.runtime see **** | ||
gurobi> help() | gurobi> help() | ||
</div> | |||
<div class="mw-translate-fuzzy"> | |||
Cette procédure est effectuée une seule fois pour chaque système. | |||
</div> | |||
<div class="mw-translate-fuzzy"> | |||
{{Commands|prompt=[name@server ~] $ | |||
| module load gurobi/9.0.1 python/3.7 | |||
| virtualenv --no-download ~/env_gurobi | |||
Using base prefix '/cvmfs/soft.computecanada.ca/easybuild/software/2017/Core/python/3.7.4' | |||
New python executable in /home/name/env_gurobi/bin/python | |||
Installing setuptools, pip, wheel... | |||
done. | |||
| source ~/env_gurobi/bin/activate | |||
}} | |||
</div> | |||
<div class="mw-translate-fuzzy"> | |||
===Répéter des appels API=== | ===Répéter des appels API=== | ||
Il est possible d'enregistrer des appels API et de rejouer l'enregistrement avec la commande | Il est possible d'enregistrer des appels API et de rejouer l'enregistrement avec la commande | ||
</div> | |||
<div class="mw-translate-fuzzy"> | |||
Nous pouvons maintenant activer Gurobi et l'environnement avec | |||
</div> | |||
<div class="mw-translate-fuzzy"> | |||
Remarquez que nous utilisons maintenant <code>python</code> plutôt que <code>gurobi.sh</code>. | |||
</div> | |||
= | <div class="mw-translate-fuzzy"> | ||
== Comment citer Gurobi == | |||
</div> | |||
<div class="mw-translate-fuzzy"> | |||
# 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 | ||
</div> | |||
gurobi_cl ${GUROBI_HOME}/examples/data/coins.lp | gurobi_cl ${GUROBI_HOME}/examples/data/coins.lp | ||
}} | }} | ||
=== Gurobi | === 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]. | |||
{{File | {{File | ||
|name=gurobi-py_example.sh | |name=gurobi-py_example.sh | ||
Line 99: | Line 132: | ||
}} | }} | ||
== | == Using Gurobi in Python virtual environments == | ||
Gurobi | 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>. | |||
Before we start, we need to decide which combination of versions for Gurobi and Python to use. | |||
{{Commands|prompt=[name@server ~] $ | {{Commands|prompt=[name@server ~] $ | ||
Line 121: | Line 155: | ||
}} | }} | ||
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>). | |||
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 === | ||
These steps need to be done only once per system. | |||
The first step is to load the modules to [[Python#Creating_and_using_a_virtual_environment|create the virtual environment]] and activate it. | |||
{{Commands|prompt=[name@server ~] $ | {{Commands|prompt=[name@server ~] $ | ||
Line 142: | Line 176: | ||
}} | }} | ||
Now that the environment has been activated we can install the Python packages we want to use, in this case <code>pandas</code>. | |||
{{Commands|prompt=(env_gurobi) [name@server ~] $ | {{Commands|prompt=(env_gurobi) [name@server ~] $ | ||
Line 154: | Line 188: | ||
}} | }} | ||
The third step is to install gurobipy into the environment: | |||
{{Commands|prompt=(env_gurobi) [name@server ~] $ | {{Commands|prompt=(env_gurobi) [name@server ~] $ | ||
Line 177: | Line 211: | ||
}} | }} | ||
=== | === Using the Gurobi-enabled virtual environment === | ||
Python scripts can now import both Pandas and Gurobi: | |||
import pandas as pd | import pandas as pd | ||
Line 187: | Line 221: | ||
# [...] | # [...] | ||
Once created we can activate Gurobi and the environment with: | |||
module load gurobi/9.0.1 | module load gurobi/9.0.1 | ||
Line 193: | Line 227: | ||
python my_gurobi_script.py | python my_gurobi_script.py | ||
Note that we now use <code>python</code> instead of <code>gurobi.sh</code>! | |||
And this is an example job script that we can use: | |||
{{File | {{File | ||
|name=gurobi-py_example.sh | |name=gurobi-py_example.sh | ||
Line 216: | Line 250: | ||
}} | }} | ||
== | == Cite Gurobi == | ||
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?] |