Examples¶
Simple Python program using virtualenv and pip¶
First we need to create a working directory and move there
mkdir python_test
cd python_test
Next we load the python 3 module and use python 3 to create a python virtualenv. This way we can install pip packages which are not installed on the cluster
module load python/3.6.6
python3 -m venv mytest
Activate the mytest
virtualenv and use pip to install the webcolors
package
source mytest/bin/activate
pip install webcolors
Create the file test.py with the following contents using nano
import webcolors
from random import randint
from socket import gethostname
colour_list = list(webcolors.css3_hex_to_names.items())
requested_colour = randint(0,len(colour_list))
colour_name = colour_list[requested_colour][1]
print("Random colour name:", colour_name, " on host: ", gethostname())
Alternatively download it with wget:
wget https://raw.githubusercontent.com/vuw-research-computing/raapoi-tools/master/examples/python_venv/test.py
Using nano create the submissions script called python_submit.sh with the following content - change me@email.com
to your email address.
#!/bin/bash
#
#SBATCH --job-name=python_test
#SBATCH -o python_test.out
#SBATCH -e python_test.err
#
#SBATCH --cpus-per-task=1
#SBATCH --mem-per-cpu=1G
#SBATCH --time=10:00
#
#SBATCH --mail-type=BEGIN,END,FAIL
#SBATCH --mail-user=me@email.com
module load python/3.6.6
source mytest/bin/activate
python test.py
Alternatively download it with wget
wget https://raw.githubusercontent.com/vuw-research-computing/raapoi-tools/master/examples/python_venv/python_submit.sh
To submit your job to the Slurm scheduler
sbatch python_submit.sh
Check for your job on the queue with squeue
though it might finish very fast. The output files will appear in your working directory.