Skip to content

Commit bd86e21

Browse files
committed
Added test for slurm integration
1 parent 9133e15 commit bd86e21

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

test_pbs_slurm.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import time
2+
import unittest
3+
4+
5+
from subprocess import Popen, PIPE
6+
from nose.tools import assert_equal, assert_true
7+
8+
pbs_string = """\
9+
#!/usr/bin/env /bin/bash
10+
11+
#PBS -N arrayJob
12+
#PBS -o arrayJob_%A_%a.out
13+
#PBS -t 1-5
14+
#PBS -l walltime=01:00:00
15+
#PBS -l naccelerators=1
16+
#PBS -l proc={cons}
17+
#PBS -M {mail}
18+
#SBATCH --qos {priority}
19+
20+
######################
21+
# Begin work section #
22+
######################
23+
24+
echo "My SLURM_ARRAY_JOB_ID:" $SLURM_ARRAY_JOB_ID
25+
echo "My SLURM_ARRAY_TASK_ID: " $SLURM_ARRAY_TASK_ID
26+
nvidia-smi
27+
"""
28+
29+
sbatch_string = """\
30+
#!/usr/bin/env -i /bin/zsh
31+
32+
#SBATCH --job-name=arrayJob
33+
#SBATCH --output=arrayJob_%A_%a.out
34+
#SBATCH --array=0-5
35+
#SBATCH --time=01:00:00
36+
#SBATCH --gres=gpu
37+
#SBATCH --constraint=gpu6gb
38+
39+
######################
40+
# Begin work section #
41+
######################
42+
43+
echo "My SLURM_ARRAY_JOB_ID:" $SLURM_ARRAY_JOB_ID
44+
echo "My SLURM_ARRAY_TASK_ID: " $SLURM_ARRAY_TASK_ID
45+
nvidia-smi
46+
"""
47+
48+
class TestSlurm(unittest.TestCase):
49+
50+
def test_pbs_slurm(self):
51+
priorities = ['unkillable', 'high', 'low']
52+
# doesn't test 12 and 24 to avoid killing jobs just for testing
53+
constraints = ['gpulowmem', 'gpu6gb', 'gpu8gb']
54+
mem = ['2G', '4G', '6G']
55+
mail = 'adrien.alitaiga@gmail.com'
56+
# gpus = ['titanblack']
57+
58+
for priority in priorities:
59+
for cons in constraints:
60+
for m in mem:
61+
string = pbs_string.format(**{
62+
'cons': cons,
63+
'mail': mail,
64+
'priority': priority
65+
})
66+
with open("test.pbs", "w") as text_file:
67+
text_file.write(string)
68+
process = Popen("sbatch test.pbs", stdout=PIPE, stderr=PIPE, shell=True)
69+
time.sleep(1)
70+
71+
stdout, stderr = process.communicate()
72+
print stdout
73+
assert_true("Submitted batch job" in stdout)

0 commit comments

Comments
 (0)