-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_backend.py
More file actions
176 lines (157 loc) · 6 KB
/
Copy pathtest_backend.py
File metadata and controls
176 lines (157 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import os
import sys
import unittest
from executorlib.standalone.interactive.backend import parse_arguments
from executorlib.standalone.interactive.spawner import MpiExecSpawner
from executorlib.task_scheduler.interactive.spawner_slurm import SrunSpawner
try:
from executorlib.task_scheduler.interactive.spawner_pysqa import PysqaSpawner, create_pysqa_block_allocation_scheduler
skip_pysqa_test = False
except ImportError:
skip_pysqa_test = True
class TestParser(unittest.TestCase):
def test_command_local(self):
result_dict = {
"host": "localhost",
"worker_id": 0,
"zmqport": "22",
}
command_lst = [
"mpiexec",
"-n",
"2",
"--oversubscribe",
sys.executable,
"/",
"--zmqport",
result_dict["zmqport"],
]
interface = MpiExecSpawner(cwd=None, cores=2, openmpi_oversubscribe=True)
self.assertEqual(
command_lst,
interface.generate_command(
command_lst=[sys.executable, "/", "--zmqport", result_dict["zmqport"]]
),
)
self.assertEqual(result_dict, parse_arguments(command_lst))
def test_command_slurm(self):
result_dict = {
"host": "127.0.0.1",
"worker_id": 0,
"zmqport": "22",
}
command_lst = [
"srun",
"-n",
"2",
"-D",
os.path.abspath("."),
"--gpus-per-task=1",
"--oversubscribe",
sys.executable,
"/",
"--host",
result_dict["host"],
"--zmqport",
result_dict["zmqport"],
]
interface = SrunSpawner(
cwd=os.path.abspath("."),
cores=2,
gpus_per_core=1,
openmpi_oversubscribe=True,
)
self.assertEqual(
command_lst,
interface.generate_command(
command_lst=[
sys.executable,
"/",
"--host",
result_dict["host"],
"--zmqport",
result_dict["zmqport"],
]
),
)
self.assertEqual(result_dict, parse_arguments(command_lst))
def test_command_slurm_user_command(self):
result_dict = {
"host": "127.0.0.1",
"worker_id": 0,
"zmqport": "22",
}
command_lst = [
"srun",
"-n",
"2",
"-D",
os.path.abspath("."),
"--mpi=pmi2",
"--gpus-per-task=1",
"--oversubscribe",
"--account=test",
"--job-name=executorlib",
sys.executable,
"/",
"--host",
result_dict["host"],
"--zmqport",
result_dict["zmqport"],
]
interface = SrunSpawner(
cwd=os.path.abspath("."),
cores=2,
gpus_per_core=1,
openmpi_oversubscribe=True,
slurm_cmd_args=["--account=test", "--job-name=executorlib"],
pmi_mode="pmi2",
)
self.assertEqual(
command_lst,
interface.generate_command(
command_lst=[
sys.executable,
"/",
"--host",
result_dict["host"],
"--zmqport",
result_dict["zmqport"],
]
),
)
self.assertEqual(result_dict, parse_arguments(command_lst))
@unittest.skipIf(skip_pysqa_test, "pysqa is not installed, so the pysqa tests are skipped.")
def test_command_pysqa(self):
interface_slurm = PysqaSpawner(backend="slurm", cores=2, pmi_mode="pmix", num_nodes=2, threads_per_core=2, gpus_per_core=1, exclusive=True, openmpi_oversubscribe=True, slurm_cmd_args=["test"])
output = ['srun', '-n', '2', '--mpi=pmix', '-N', '2', '--cpus-per-task=2', '--gpus-per-task=1', '--exact', '--oversubscribe', 'test']
self.assertEqual(interface_slurm.generate_command(command_lst=[]), output)
with self.assertRaises(FileNotFoundError):
interface_slurm.bootup(command_lst=["sleep", "1"])
interface_flux = PysqaSpawner(backend="flux", cores=2, pmi_mode="pmix")
output = ['flux', 'run', '-n', '2', '-o', 'pmi=pmix']
self.assertEqual(interface_flux.generate_command(command_lst=[]), output)
interface_flux = PysqaSpawner(backend="flux", cores=2, pmi_mode="pmix", num_nodes=2)
with self.assertRaises(ValueError):
interface_flux.generate_command(command_lst=[])
interface_flux = PysqaSpawner(backend="flux", cores=2, pmi_mode="pmix", threads_per_core=2)
with self.assertRaises(ValueError):
interface_flux.generate_command(command_lst=[])
interface_flux = PysqaSpawner(backend="flux", cores=2, pmi_mode="pmix", gpus_per_core=1)
with self.assertRaises(ValueError):
interface_flux.generate_command(command_lst=[])
interface_flux = PysqaSpawner(backend="flux", cores=2, pmi_mode="pmix", exclusive=True)
with self.assertRaises(ValueError):
interface_flux.generate_command(command_lst=[])
interface_flux = PysqaSpawner(backend="flux", cores=2, pmi_mode="pmix", openmpi_oversubscribe=True)
with self.assertRaises(ValueError):
interface_flux.generate_command(command_lst=[])
interface_nobackend = PysqaSpawner(cores=2)
with self.assertRaises(ValueError):
interface_nobackend.generate_command(command_lst=[])
with self.assertRaises(RuntimeError):
interface_nobackend._check_process_helper(command_lst=[])
with self.assertRaises(ValueError):
create_pysqa_block_allocation_scheduler()
with self.assertRaises(ValueError):
create_pysqa_block_allocation_scheduler(resource_dict={"cwd": "."})