|
12 | 12 | #PBS -o arrayJob_%A_%a.out |
13 | 13 | #PBS -t 1-2 |
14 | 14 | #PBS -l walltime=01:00:00 |
15 | | -#PBS -l naccelerators=1 |
16 | 15 | {} |
17 | 16 |
|
18 | 17 | ###################### |
|
43 | 42 | nvidia-smi |
44 | 43 | """ |
45 | 44 |
|
| 45 | +def test_param(self, param_array, command, flag, string=pbs_string): |
| 46 | + for param in param_array: |
| 47 | + command = pbs_string.format( |
| 48 | + string.format(command.format(param)) |
| 49 | + ) |
| 50 | + with open("test.pbs", "w") as text_file: |
| 51 | + text_file.write(command) |
| 52 | + process = Popen("sbatch test.pbs", stdout=PIPE, stderr=PIPE, shell=True) |
| 53 | + stdout, stderr = process.communicate() |
| 54 | + assert_true("Submitted batch job" in stdout) |
| 55 | + job_id = stdout.split(" ")[-1].strip() |
| 56 | + |
| 57 | + time.sleep(0.25) |
| 58 | + process = Popen("squeue -u $USER -j {} -O {}".format(job_id, flag), stdout=PIPE, stderr=PIPE, shell=True) |
| 59 | + stdout, stderr = process.communicate() |
| 60 | + job_params = [c.strip() for c in stdout.split("\n")[1:] if c != ''] |
| 61 | + assert_true(all(p == param for p in job_params)) |
46 | 62 |
|
47 | 63 | class TestSlurm(unittest.TestCase): |
48 | 64 |
|
| 65 | + def tearDown(self): |
| 66 | + process = Popen("rm *.out", stdout=PIPE, stderr=PIPE, shell=True) |
| 67 | + stdout, stderr = process.communicate() |
| 68 | + |
49 | 69 | 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 -j {} -O qos".format(job_id), 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(pri == priority for pri in job_priorities)) |
| 70 | + test_param( |
| 71 | + ['high', 'low'], |
| 72 | + "#SBATCH --qos={}", |
| 73 | + "qos", |
| 74 | + pbs_string |
| 75 | + ) |
67 | 76 |
|
68 | 77 | def test_gres(self): |
69 | | - gress = ['gpu', 'gpu:titanblack'] |
70 | | - for gres in gress: |
71 | | - string = pbs_string.format( |
72 | | - "#PBS -l gpu={gres}".format(gres=gres) |
73 | | - ) |
74 | | - with open("test.pbs", "w") as text_file: |
75 | | - text_file.write(string) |
76 | | - process = Popen("sbatch test.pbs", stdout=PIPE, stderr=PIPE, shell=True) |
77 | | - stdout, stderr = process.communicate() |
78 | | - assert_true("Submitted batch job" in stdout) |
79 | | - job_id = stdout.split(" ")[-1] |
80 | | - |
81 | | - time.sleep(0.25) |
82 | | - process = Popen("squeue -u $USER -j {} -O gres".format(job_id), stdout=PIPE, stderr=PIPE, shell=True) |
83 | | - stdout, stderr = process.communicate() |
84 | | - job_gres = [gre.strip() for gre in stdout.split("\n")[1:] if gre != ''] |
85 | | - assert_true(all(gpu == gres for gpu in job_gres)) |
| 78 | + test_param( |
| 79 | + ['titanblack], |
| 80 | + "#PBS -l naccelerators={}", |
| 81 | + "gres", |
| 82 | + pbs_string |
| 83 | + ) |
86 | 84 |
|
87 | 85 | def test_memory(self): |
88 | | - mems = ['2G', '4G'] |
89 | | - for mem in mems: |
90 | | - string = pbs_string.format( |
91 | | - "#PBS -l mem_free={memory}".format(memory=mem) |
92 | | - ) |
93 | | - with open("test.pbs", "w") as text_file: |
94 | | - text_file.write(string) |
95 | | - process = Popen("sbatch test.pbs", stdout=PIPE, stderr=PIPE, shell=True) |
96 | | - stdout, stderr = process.communicate() |
97 | | - assert_true("Submitted batch job" in stdout) |
98 | | - job_id = stdout.split(" ")[-1] |
99 | | - |
100 | | - time.sleep(0.25) |
101 | | - process = Popen("squeue -u $USER -j {} -O minmemory".format(job_id), stdout=PIPE, stderr=PIPE, shell=True) |
102 | | - stdout, stderr = process.communicate() |
103 | | - job_mems = [m.strip() for m in stdout.split("\n")[1:] if m != ''] |
104 | | - assert_true(all(me == mem for me in job_mems)) |
105 | | - |
106 | | - # def test_pbs_slurm(self): |
107 | | - # priorities = ['unkillable', 'high', 'low'] |
108 | | - # # doesn't test 12 and 24 to avoid killing jobs just for testing |
109 | | - # constraints = ['gpulowmem', 'gpu6gb', 'gpu8gb'] |
110 | | - # mem = ['2G', '4G', '6G'] |
111 | | - # mail = 'adrien.alitaiga@gmail.com' |
112 | | - # # gpus = ['titanblack'] |
113 | | - # |
114 | | - # for priority in priorities: |
115 | | - # for cons in constraints: |
116 | | - # for m in mem: |
117 | | - # string = pbs_string.format(**{ |
118 | | - # 'cons': cons, |
119 | | - # 'mail': mail, |
120 | | - # 'priority': priority |
121 | | - # }) |
122 | | - # with open("test.pbs", "w") as text_file: |
123 | | - # text_file.write(string) |
124 | | - # process = Popen("sbatch test.pbs", stdout=PIPE, stderr=PIPE, shell=True) |
125 | | - # time.sleep(1) |
126 | | - # |
127 | | - # stdout, stderr = process.communicate() |
128 | | - # print stdout |
129 | | - # assert_true("Submitted batch job" in stdout) |
| 86 | + test_param( |
| 87 | + ['2G', '4G'], |
| 88 | + "#PBS -l mem={}", |
| 89 | + "minmemory", |
| 90 | + pbs_string |
| 91 | + ) |
| 92 | + |
| 93 | + def test_nb_cpus(self): |
| 94 | + test_param( |
| 95 | + ["1", "2"], |
| 96 | + "PBS -l ncpus={}", |
| 97 | + "cpuspertask", # or numcpus |
| 98 | + pbs_string |
| 99 | + ) |
130 | 100 |
|
131 | 101 |
|
132 | 102 | pbs_string2 = """\ |
|
0 commit comments