cc_staff
1,857
edits
mNo edit summary |
mNo edit summary |
||
Line 153: | Line 153: | ||
python3.11 | python3.11 | ||
=== HowTo Install Gurobi for Python === | |||
=== | As explained at the bottom of [[https://support.gurobi.com/hc/en-us/articles/360044290292-How-do-I-install-Gurobi-for-Python|How-do-I-install-Gurobi-for-Python]] the previous recommended approach for installing gurobi for python with setup.py has been deprecated as of version Gurobi 11. For continuity a modified version of the instruction (usable under StdEnv/2023) is provided in the following section for Gurobi 10 and older. Following this a new section is provided showing how to install gurobi for python from a wheel for version Gurobi 11 and greater. | ||
=== Gurobi Versions 10.0.3 (and older) === <!--T:10--> | |||
<!--T:97--> | <!--T:97--> | ||
The following steps need to be done once per system and are usable with StdEnv/2023 and older. First load the modules to [[Python#Creating_and_using_a_virtual_environment|create the virtual environment]] and activate it: | |||
<!--T:105--> | <!--T:105--> | ||
{{Commands|prompt=[name@server ~] $ | {{Commands|prompt=[name@server ~] $ | ||
| module load gurobi/ | | module load gurobi/10.0.3 python | ||
| virtualenv --no-download ~/env_gurobi | | virtualenv --no-download ~/env_gurobi | ||
| source ~/env_gurobi/bin/activate | | source ~/env_gurobi/bin/activate | ||
}} | }} | ||
Now | Now install any Python packages we want to use (in this case <code>pandas</code>) for example: | ||
<!--T:110--> | <!--T:110--> | ||
{{Commands|prompt=(env_gurobi) [name@server ~] $ | {{Commands|prompt=(env_gurobi) [name@server ~] $ | ||
| pip install --no-index pandas | | pip install --no-index pandas | ||
}} | }} | ||
Next install gurobipy into the environment. Note that as of StdEnv/2023 the install can no longer be done under $EBROOTGUROBI as previously documented using the command <code>python setup.py build --build-base /tmp/${USER} install</code> since a fatal <code>error: could not create 'gurobipy.egg-info': Read-only file system</code> crash message will occur. Instead the required files need to copied to elsewhere (such as /tmp/$USER) and installed from there, for example: | |||
<!--T:113--> | |||
{{Commands|prompt=(env_gurobi) [name@server ~] $ | |||
| mkdir /tmp/$USER | |||
| cp -r $EBROOTGUROBI/{lib,setup.py} /tmp/$USER | |||
| cd /tmp/$USER | |||
| python setup.py install | |||
(env_gurobi) [roberpj@gra-login1:/tmp/roberpj] python setup.py install | |||
/home/roberpj/env_gurobi/lib/python3.11/site-packages/setuptools/_core_metadata.py:158: SetuptoolsDeprecationWarning: Invalid config. | |||
!! | |||
******************************************************************************** | |||
newlines are not allowed in `summary` and will break in the future | |||
******************************************************************************** | |||
!! | |||
write_field('Summary', single_line(summary)) | |||
removing /tmp/roberpj/build | |||
(env_gurobi) [roberpj@gra-login1:/tmp/roberpj] | |||
}} | |||
=== Gurobi Versions 11.0.0 (and newer) === <!--T:11--> | |||
<!--T:97--> | |||
Once again, following steps need to be done once per system and are usable with StdEnv/2023 and older. First load the modules to [[Python#Creating_and_using_a_virtual_environment|create the virtual environment]] and activate it. Version 11.0.0 is skipped since it has been observed to seg fault in at least one example versus Version 11.0.1 which runs smoothly. | |||
<!--T:105--> | |||
{{Commands|prompt=[name@server ~] $ | |||
| module load gurobi/11.0.1 python | |||
| virtualenv --no-download ~/env_gurobi | |||
| source ~/env_gurobi/bin/activate | |||
}} | |||
As before, install any needed Python packages (in this case <code>pandas</code>) for example: | |||
<!--T:110--> | |||
{{Commands|prompt=(env_gurobi) [name@server ~] $ | |||
| pip install --no-index pandas | |||
}} | |||
Next install gurobipy into the environment. As mentioned above and in [[https://support.gurobi.com/hc/en-us/articles/360044290292-How-do-I-install-Gurobi-for-Python|this article]] the use of setup.py to install Gurobi for python is deprecated starting with Gurobi 11. Both pip and conda are given as alternatives, however since conda should not be used on alliance systems, the pip approach will be demonstrated here. | |||
The installation is slightly complicated since Alliance linux systems are setup with gentoo prefix. As a result neither A) the recommended command to download and install the gurobipy extension from the public PyPI server <code>pip install gurobipy==11.0.1</code> mentioned in the article line or B) the offline command to install the wheel with <code>python -m pip install --find-links <wheel-dir> --no-index gurobipy</code>, will work. Instead a script available from the alliance maybe utilized to download and modify the existing wheel into an usable format under a new name. There is one caveat which is for each new Gurobi version the researcher must go into https://pypi.org/project/gurobipy/11.0.1/#history, click on the desired version followed by the <code>Download files</code> button in the left hand menu and finally copy the https link for the wheel file named gurobipy-11.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl in the case of Gurobi 11.0.1 and paste its link as the --url argument as shown in the following: | |||
<!--T:112--> | <!--T:112--> | ||
{{Commands|prompt=(env_gurobi) [name@server ~] $ | {{Commands|prompt=(env_gurobi) [name@server ~] $ | ||
| | | wget https://github.com/ComputeCanada/wheels_builder/blob/main/unmanylinuxize.sh | ||
| ./unmanylinuxize.sh --package gurobipy --version 11.0.1 --url | |||
https://files.pythonhosted.org/packages/c5/c6/7cb959ea454c58169ecc6d165c8e3e915769d963df1bab61f5c5bc0052e6/ | |||
gurobipy-11.0.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | |||
'gurobipy-11.0.1-cp312-cp312-linux_x86_64.whl' -> '../gurobipy-11.0.1-cp312-cp312-linux_x86_64.whl' | |||
| python -m pip install --find-links ~/pythonwheels --no-index gurobipy}} | |||
}} | |||
=== Using the virtual environment === <!--T:120--> | === Using the virtual environment === <!--T:120--> | ||
Line 229: | Line 245: | ||
<!--T:203--> | <!--T:203--> | ||
{{Commands|prompt=[name@server ~] $ | {{Commands|prompt=[name@server ~] $ | ||
| module load gurobi/ | | module load gurobi/11.0.1 | ||
source ~/env_gurobi/bin/activate | source ~/env_gurobi/bin/activate | ||
(env_gurobi) python my_gurobi_script.py | (env_gurobi) python my_gurobi_script.py | ||
Line 244: | Line 260: | ||
#!/bin/bash | #!/bin/bash | ||
#SBATCH --time=0-00:30 # time limit (D-HH:MM) | #SBATCH --time=0-00:30 # time limit (D-HH:MM) | ||
#SBATCH --cpus-per-task= | #SBATCH --cpus-per-task=4 # number of CPUs to use | ||
#SBATCH --mem-per-cpu=1000M # memory per CPU (in MB) | #SBATCH --mem-per-cpu=1000M # memory per CPU (in MB) | ||
<!--T:205--> | <!--T:205--> | ||
module load StdEnv/ | module load StdEnv/2023 | ||
module load gurobi/ | module load gurobi/11.0.1 | ||
<!--T:206--> | <!--T:206--> |