Gurobi: Difference between revisions

Jump to navigation Jump to search
552 bytes added ,  5 months ago
m
no edit summary
mNo edit summary
mNo edit summary
Line 227: Line 227:


<!--T:126-->
<!--T:126-->
Once its been created we can activate our Gurobi environment at any time by doing :
Once its been created we can activate our Gurobi environment at any time.  Before doing so we will also load gurobi so the $EBROOTGUROBI is defined and also load the <code>scipy-stack</code> module since the matrix1 example requires scipy in addition to numpy which we already pip installed into the environment via pandas :


<!--T:203-->
<!--T:203-->
{{Commands|prompt=[name@server ~] $
{{Commands|prompt=[name@server ~] $
| module load gurobi/11.0.1
| module load gurobi/11.0.1 scipy-stack
   source ~/env_gurobi/bin/activate
   source ~/env_gurobi/bin/activate
   (env_gurobi) [name@server ~]
   (env_gurobi) [name@server ~]
Line 237: Line 237:


<!--T:205-->
<!--T:205-->
Example python scripts provided by gurobi can now be run (within the virtual environment) using python directly instead of [https://support.gurobi.com/hc/en-us/articles/14078206742801-What-is-the-Gurobi-Interactive-Shell-gurobi-sh-or-gurobi-bat|<code>gurobi.sh</code>] such as :
Example python scripts provided with the gurobi module can now be run (within the virtual environment) using python  


{{Commands|prompt=(env_gurobi) [name@server ~] $
{{Commands|prompt=(env_gurobi) [name@server ~] $
| cp -r $EBROOTGUROBI/examples/python .
| python $EBROOTGUROBI/examples/python/matrix1.py
| python matrix1.py
}}
}}


<!--T:122-->
<!--T:122-->
Likewise python scripts you write can be run in the queue using the virtual environment as shown in the slurm script below :
Likewise custom python scripts such as the following can be run as jobs in the queue by writing slurm scripts that load your virtual environment.


{{Commands|prompt=[name@server ~] $
{{Commands|prompt=[name@server ~] $
Line 255: Line 254:
   etc
   etc
}}
}}
Submit your script to the queue by running <code>sbatch my_slurm_script.sh</code> as per usual :


<!--T:204-->
<!--T:204-->
{{File
{{File
   |name=gurobi-py_example.sh
   |name=my_slurm_script.sh
   |lang="sh"
   |lang="sh"
   |contents=
   |contents=
#!/bin/bash
#!/bin/bash
#SBATCH --time=0-00:30       # time limit (D-HH:MM)
#SBATCH --account=def-somegrp  # specify an account
#SBATCH --cpus-per-task=4     # number of CPUs to use
#SBATCH --time=0-00:30         # time limit (D-HH:MM)
#SBATCH --mem-per-cpu=1000M  # memory per CPU (in MB)
#SBATCH --nodes=1              # run job on one node
#SBATCH --cpus-per-task=4     # specify number of CPUS
#SBATCH --mem=4000M            # specify total MB memory


module load StdEnv/2023
module load StdEnv/2023
module load gurobi/11.0.1
module load gurobi/11.0.1
# module load scipy-stack      # uncomment if needed


echo "Threads ${SLURM_CPUS_ON_NODE:-1}" > gurobi.env  # set number of threads
echo "Threads ${SLURM_CPUS_ON_NODE:-1}" > gurobi.env  # set number of threads


source ~/env_gurobi/bin/activate
source ~/env_gurobi/bin/activate
python my_gurobi_script.py
python my_gurobi_script.py
}}
}}
<!--T:205-->
Further details about submitting jobs with python virtual environments is given [https://docs.alliancecan.ca/wiki/Python#Creating_virtual_environments_inside_of_your_jobs|here].


== Using Gurobi with Java == <!--T:210-->
== Using Gurobi with Java == <!--T:210-->
cc_staff
1,857

edits

Navigation menu