Skip to content

Commit 1168e3e

Browse files
committed
New test for priority
1 parent bd86e21 commit 1168e3e

File tree

4 files changed

+148
-73
lines changed

4 files changed

+148
-73
lines changed

array.pbs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env /bin/bash
2+
3+
#PBS -N arrayJob
4+
#PBS -o arrayJob_%A_%a.out
5+
#PBS -t 1-5
6+
#PBS -l walltime=01:00:00
7+
#PBS -l naccelerators=1
8+
#PBS -l proc=gpu6gb
9+
10+
######################
11+
# Begin work section #
12+
######################
13+
14+
echo "My SLURM_ARRAY_JOB_ID:" $SLURM_ARRAY_JOB_ID
15+
echo "My SLURM_ARRAY_TASK_ID: " $SLURM_ARRAY_TASK_ID
16+
nvidia-smi

array.sbatch

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env -i /bin/zsh
2+
3+
#SBATCH --job-name=arrayJob
4+
#SBATCH --output=arrayJob_%A_%a.out
5+
#SBATCH --array=0-5
6+
#SBATCH --time=01:00:00
7+
#SBATCH --gres=gpu
8+
#SBATCH --constraint=gpu6gb
9+
10+
######################
11+
# Begin work section #
12+
######################
13+
14+
echo "My SLURM_ARRAY_JOB_ID:" $SLURM_ARRAY_JOB_ID
15+
echo "My SLURM_ARRAY_TASK_ID: " $SLURM_ARRAY_TASK_ID
16+
nvidia-smi
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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-2
14+
#PBS -l walltime=01:00:00
15+
#PBS -l naccelerators=1
16+
{}
17+
18+
######################
19+
# Begin work section #
20+
######################
21+
22+
echo "My SLURM_ARRAY_JOB_ID:" $SLURM_ARRAY_JOB_ID
23+
echo "My SLURM_ARRAY_TASK_ID: " $SLURM_ARRAY_TASK_ID
24+
nvidia-smi
25+
"""
26+
27+
sbatch_string = """\
28+
#!/usr/bin/env -i /bin/zsh
29+
30+
#SBATCH --job-name=arrayJob
31+
#SBATCH --output=arrayJob_%A_%a.out
32+
#SBATCH --array=0-5
33+
#SBATCH --time=01:00:00
34+
#SBATCH --gres=gpu
35+
#SBATCH --constraint=gpu6gb
36+
37+
######################
38+
# Begin work section #
39+
######################
40+
41+
echo "My SLURM_ARRAY_JOB_ID:" $SLURM_ARRAY_JOB_ID
42+
echo "My SLURM_ARRAY_TASK_ID: " $SLURM_ARRAY_TASK_ID
43+
nvidia-smi
44+
"""
45+
46+
47+
class TestSlurm(unittest.TestCase):
48+
49+
def test_priority(self):
50+
priorities = ['high', 'low']
51+
for priority in priorities:
52+
string = pbs_string.format(
53+
"#SBATCH --qos={priority}".format(priority=priority)
54+
)
55+
with open("test.pbs", "w") as text_file:
56+
text_file.write(string)
57+
process = Popen("sbatch test.pbs", stdout=PIPE, stderr=PIPE, shell=True)
58+
stdout, stderr = process.communicate()
59+
assert_true("Submitted batch job" in stdout)
60+
job_id = stdout.split(" ")[-1]
61+
62+
time.sleep(0.25)
63+
process = Popen("squeue -u $USER -O qos", stdout=PIPE, stderr=PIPE, shell=True)
64+
stdout, stderr = process.communicate()
65+
job_priorities = [prio.strip() for prio in stdout.split("\n")[1:] if prio != '']
66+
assert_true(all(prio == priority for prio in job_priorities))
67+
68+
# def test_pbs_slurm(self):
69+
# priorities = ['unkillable', 'high', 'low']
70+
# # doesn't test 12 and 24 to avoid killing jobs just for testing
71+
# constraints = ['gpulowmem', 'gpu6gb', 'gpu8gb']
72+
# mem = ['2G', '4G', '6G']
73+
# mail = 'adrien.alitaiga@gmail.com'
74+
# # gpus = ['titanblack']
75+
#
76+
# for priority in priorities:
77+
# for cons in constraints:
78+
# for m in mem:
79+
# string = pbs_string.format(**{
80+
# 'cons': cons,
81+
# 'mail': mail,
82+
# 'priority': priority
83+
# })
84+
# with open("test.pbs", "w") as text_file:
85+
# text_file.write(string)
86+
# process = Popen("sbatch test.pbs", stdout=PIPE, stderr=PIPE, shell=True)
87+
# time.sleep(1)
88+
#
89+
# stdout, stderr = process.communicate()
90+
# print stdout
91+
# assert_true("Submitted batch job" in stdout)
92+
93+
94+
pbs_string2 = """\
95+
#!/usr/bin/env /bin/bash
96+
97+
#PBS -N arrayJob
98+
#PBS -o arrayJob_%A_%a.out
99+
#PBS -t 1-5
100+
#PBS -l walltime=01:00:00
101+
#PBS -l naccelerators=1
102+
#PBS -l proc={cons}
103+
#PBS -M {mail}
104+
#SBATCH --qos {priority}
105+
106+
######################
107+
# Begin work section #
108+
######################
109+
110+
echo "My SLURM_ARRAY_JOB_ID:" $SLURM_ARRAY_JOB_ID
111+
echo "My SLURM_ARRAY_TASK_ID: " $SLURM_ARRAY_TASK_ID
112+
nvidia-smi
113+
"""
114+
115+
if __name__ == '__main__':
116+
unittest.main()

test_pbs_slurm.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)