cc_staff
1,857
edits
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 | 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 | 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 ~] $ | ||
| | | python $EBROOTGUROBI/examples/python/matrix1.py | ||
}} | }} | ||
<!--T:122--> | <!--T:122--> | ||
Likewise python scripts | 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= | |name=my_slurm_script.sh | ||
|lang="sh" | |lang="sh" | ||
|contents= | |contents= | ||
#!/bin/bash | #!/bin/bash | ||
#SBATCH --time=0-00:30 | #SBATCH --account=def-somegrp # specify an account | ||
#SBATCH --cpus-per-task=4 | #SBATCH --time=0-00:30 # time limit (D-HH:MM) | ||
#SBATCH --mem | #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 | 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--> |