-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathtest_lsf_settings.py
285 lines (229 loc) · 9.02 KB
/
test_lsf_settings.py
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# BSD 2-Clause License
#
# Copyright (c) 2021-2024, Hewlett Packard Enterprise
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import pytest
from smartsim.error import SSUnsupportedError
from smartsim.settings import BsubBatchSettings, JsrunSettings
# The tests in this file belong to the group_b group
pytestmark = pytest.mark.group_b
# ------ Jsrun ------------------------------------------------
def test_jsrun_settings():
settings = JsrunSettings("python")
settings.set_num_rs(8)
settings.set_cpus_per_rs(2)
settings.set_gpus_per_rs(1)
settings.set_rs_per_host(4)
settings.set_tasks_per_rs(12)
settings.set_tasks(96)
settings.set_binding("packed:2")
formatted = settings.format_run_args()
result = [
"--nrs=8",
"--cpu_per_rs=2",
"--gpu_per_rs=1",
"--rs_per_host=4",
"--tasks_per_rs=12",
"--np=96",
"--bind=packed:2",
]
assert formatted == result
settings.set_cpus_per_rs("ALL_CPUS")
settings.set_gpus_per_rs("ALL_GPUS")
settings.set_num_rs("ALL_HOSTS")
formatted = settings.format_run_args()
result = [
"--nrs=ALL_HOSTS",
"--cpu_per_rs=ALL_CPUS",
"--gpu_per_rs=ALL_GPUS",
"--rs_per_host=4",
"--tasks_per_rs=12",
"--np=96",
"--bind=packed:2",
]
assert formatted == result
def test_jsrun_args():
"""Test the possible user overrides through run_args"""
run_args = {
"latency_priority": "gpu-gpu",
"immediate": None,
"d": "packed", # test single letter variables
"nrs": 10,
"np": 100,
}
settings = JsrunSettings("python", run_args=run_args)
formatted = settings.format_run_args()
result = [
"--latency_priority=gpu-gpu",
"--immediate",
"-d",
"packed",
"--nrs=10",
"--np=100",
]
assert formatted == result
def test_jsrun_args_mutation():
"""Ensure re-using ERF settings doesn't mutate existing run settings"""
run_args = {
"latency_priority": "gpu-gpu",
"immediate": None,
"d": "packed", # test single letter variables
"nrs": 10,
"np": 100,
}
settings = JsrunSettings("python", run_args=run_args)
erf_settings = {"foo": "1", "bar": "2"}
settings.set_erf_sets(erf_settings)
assert settings.erf_sets["foo"] == "1"
assert settings.erf_sets["bar"] == "2"
erf_settings["foo"] = "111"
erf_settings["bar"] = "111"
assert settings.erf_sets["foo"] == "1"
assert settings.erf_sets["bar"] == "2"
def test_jsrun_update_env():
env_vars = {"OMP_NUM_THREADS": 20, "LOGGING": "verbose"}
settings = JsrunSettings("python", env_vars=env_vars)
num_threads = 10
settings.update_env({"OMP_NUM_THREADS": num_threads})
assert settings.env_vars["OMP_NUM_THREADS"] == str(num_threads)
def test_jsrun_format_env():
# Test propagation (no value setting)
env_vars = {"OMP_NUM_THREADS": None, "LOGGING": "verbose"}
settings = JsrunSettings("python", env_vars=env_vars)
formatted = settings.format_env_vars()
assert formatted == ["-E", "OMP_NUM_THREADS", "-E", "LOGGING=verbose"]
def test_jsrun_mpmd():
settings = JsrunSettings("python")
settings.set_mpmd_preamble(["launch_distribution : packed"])
assert settings.mpmd_preamble_lines == ["launch_distribution : packed"]
def test_catch_colo_mpmd():
settings = JsrunSettings("python")
settings.colocated_db_settings = {"port": 6379, "cpus": 1}
settings_2 = JsrunSettings("python")
with pytest.raises(SSUnsupportedError):
settings.make_mpmd(settings_2)
@pytest.mark.parametrize("reserved_arg", ["chdir", "h"])
def test_no_set_reserved_args(reserved_arg):
srun = JsrunSettings("python")
srun.set(reserved_arg)
assert reserved_arg not in srun.run_args
def test_set_tasks():
rs = JsrunSettings("python")
rs.set_tasks(6)
assert rs.run_args["np"] == 6
with pytest.raises(ValueError):
rs.set_tasks("not an int")
def test_set_tasks_per_node():
rs = JsrunSettings("python")
rs.set_tasks_per_node(6)
assert rs.run_args["tasks_per_rs"] == 6
with pytest.raises(ValueError):
rs.set_tasks_per_node("not an int")
def test_set_cpus_per_task():
rs = JsrunSettings("python")
rs.set_cpus_per_task(6)
assert rs.run_args["cpu_per_rs"] == 6
with pytest.raises(ValueError):
rs.set_cpus_per_task("not an int")
def test_set_memory_per_node():
rs = JsrunSettings("python")
rs.set_memory_per_node(8000)
assert rs.run_args["memory_per_rs"] == 8000
with pytest.raises(ValueError):
rs.set_memory_per_node("not_an_int")
# ---- Bsub Batch ---------------------------------------------------
def test_bsub_batch_settings():
sbatch = BsubBatchSettings(
nodes=1,
time="10:00:00",
project="A3123",
smts=4,
batch_args={"alloc_flags": "nvme"},
)
formatted = sbatch.format_batch_args()
result = ['-alloc_flags "nvme smt4"', "-nnodes 1"]
assert formatted == result
def test_bsub_batch_manual():
sbatch = BsubBatchSettings(batch_args={"alloc_flags": "gpumps smt4"})
sbatch.set_nodes(5)
sbatch.set_project("A3531")
sbatch.set_walltime("10:00:00")
sbatch._format_alloc_flags()
# Enclose in quotes if user did not
assert sbatch.batch_args["alloc_flags"] == '"gpumps smt4"'
sbatch.set_smts("2") # This should have no effect as per our docs
sbatch.set_hostlist(["node1", "node2", "node5"])
sbatch.set_tasks(5)
formatted = sbatch.format_batch_args()
result = [
'-alloc_flags "gpumps smt4"',
"-nnodes 5",
'-m "node1 node2 node5"',
"-n 5",
]
assert formatted == result
sbatch.add_preamble("module load gcc")
sbatch.add_preamble(["module load openmpi", "conda activate smartsim"])
assert list(sbatch.preamble) == [
"module load gcc",
"module load openmpi",
"conda activate smartsim",
]
with pytest.raises(TypeError):
sbatch.add_preamble(1)
def test_bsub_batch_alloc_flag_formatting_by_smt():
"""Ensure that alloc_flags are formatted correctly when smts is changed"""
# Check when no smt is set in the constructor
sbatch = BsubBatchSettings()
sbatch._format_alloc_flags()
assert "alloc_flags" not in sbatch.batch_args
# check when using set_smts
sbatch = BsubBatchSettings(smts=2)
sbatch._format_alloc_flags()
assert "alloc_flags" in sbatch.batch_args
assert sbatch.batch_args["alloc_flags"] == "smt2"
# Check when passing alloc_flags in constructor
sbatch = BsubBatchSettings(batch_args={"alloc_flags": "unittest-smt"}, smts=0)
sbatch._format_alloc_flags()
assert sbatch.batch_args["alloc_flags"] == "unittest-smt"
# if smts=(non-zero), smt is *not* prepended to alloc_flags
sbatch = BsubBatchSettings(batch_args={"alloc_flags": "unittest-smt"})
sbatch._format_alloc_flags()
assert sbatch.batch_args["alloc_flags"] == "unittest-smt"
# Check when passing only SMT in constructor
sbatch = BsubBatchSettings(smts=1)
sbatch._format_alloc_flags()
assert sbatch.batch_args["alloc_flags"] == "smt1"
# Check prepending smt to alloc_flags value
sbatch = BsubBatchSettings(atch_args={"alloc_flags": "3"}, smts=3)
sbatch._format_alloc_flags()
assert sbatch.batch_args["alloc_flags"] == "smt3"
# check multi-smt flag, with prefix
sbatch = BsubBatchSettings(batch_args={"alloc_flags": '"smt3 smt4"'}, smts=4)
sbatch._format_alloc_flags()
assert sbatch.batch_args["alloc_flags"] == '"smt3 smt4"' # <-- wrap in quotes
# show that mismatched alloc_flags and smts are NOT touched
sbatch = BsubBatchSettings(batch_args={"alloc_flags": "smt10"}, smts=2)
sbatch._format_alloc_flags()
assert sbatch.batch_args["alloc_flags"] == "smt10" # <-- not smt2