Skip to content

Commit e9d6ed8

Browse files
committed
PR review comments addressed
1 parent bb04488 commit e9d6ed8

File tree

7 files changed

+51
-14
lines changed

7 files changed

+51
-14
lines changed

smartsim/settings/arguments/batch/lsf.py

+9
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ def set_smts(self, smts: int) -> None:
7676
7777
:param smts: SMT (e.g on Summit: 1, 2, or 4)
7878
:raises TypeError: if not an int
79+
:raises ValueError: if not positive int
7980
"""
8081
if not isinstance(smts, int):
8182
raise TypeError("smts argument was not of type int")
83+
if smts <= 0:
84+
raise ValueError("smts must be a positive value")
8285
self.set("alloc_flags", str(smts))
8386

8487
def set_project(self, project: str) -> None:
@@ -112,9 +115,12 @@ def set_nodes(self, num_nodes: int) -> None:
112115
113116
:param nodes: number of nodes
114117
:raises TypeError: if not an int
118+
:raises ValueError: if not positive int
115119
"""
116120
if not isinstance(num_nodes, int):
117121
raise TypeError("num_nodes argument was not of type int")
122+
if num_nodes <= 0:
123+
raise ValueError("Number of nodes must be a positive value")
118124
self.set("nnodes", str(num_nodes))
119125

120126
def set_hostlist(self, host_list: t.Union[str, t.List[str]]) -> None:
@@ -139,9 +145,12 @@ def set_tasks(self, tasks: int) -> None:
139145
140146
:param tasks: number of tasks
141147
:raises TypeError: if not an int
148+
:raises ValueError: if not positive int
142149
"""
143150
if not isinstance(tasks, int):
144151
raise TypeError("tasks argument was not of type int")
152+
if tasks <= 0:
153+
raise ValueError("Number of tasks must be a positive value")
145154
self.set("n", str(tasks))
146155

147156
def set_queue(self, queue: str) -> None:

smartsim/settings/arguments/batch/pbs.py

+6
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ def set_nodes(self, num_nodes: int) -> None:
6363
6464
:param num_nodes: number of nodes
6565
:raises TypeError: if not an int
66+
:raises ValueError: if not positive int
6667
"""
6768
if not isinstance(num_nodes, int):
6869
raise TypeError("num_nodes argument was not of type int")
70+
if num_nodes <= 0:
71+
raise ValueError("Number of nodes must be a positive value")
6972

7073
self.set("nodes", str(num_nodes))
7174

@@ -124,9 +127,12 @@ def set_ncpus(self, num_cpus: int) -> None:
124127
125128
:param num_cpus: number of cpus per node in select
126129
:raises TypeError: if not an int
130+
:raises ValueError: if not positive int
127131
"""
128132
if not isinstance(num_cpus, int):
129133
raise TypeError("num_cpus argument was not of type int")
134+
if num_cpus <= 0:
135+
raise ValueError("Number of CPUs must be a positive value")
130136
self.set("ppn", str(num_cpus))
131137

132138
def set_account(self, account: str) -> None:

smartsim/settings/arguments/batch/slurm.py

+6
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ def set_nodes(self, num_nodes: int) -> None:
7474
7575
:param num_nodes: number of nodes
7676
:raises TypeError: if not an int
77+
:raises ValueError: if not positive int
7778
"""
7879
if not isinstance(num_nodes, int):
7980
raise TypeError("num_nodes argument was not of type int")
81+
if num_nodes <= 0:
82+
raise ValueError("Number of nodes must be a positive value")
8083
self.set("nodes", str(num_nodes))
8184

8285
def set_account(self, account: str) -> None:
@@ -122,9 +125,12 @@ def set_cpus_per_task(self, cpus_per_task: int) -> None:
122125
123126
:param num_cpus: number of cpus to use per task
124127
:raises TypeError: if not int
128+
:raises ValueError: if not positive int
125129
"""
126130
if not isinstance(cpus_per_task, int):
127131
raise TypeError("cpus_per_task argument was not of type int")
132+
if cpus_per_task <= 0:
133+
raise ValueError("CPUs per task must be a positive value")
128134
self.set("cpus-per-task", str(cpus_per_task))
129135

130136
def set_hostlist(self, host_list: t.Union[str, t.List[str]]) -> None:

smartsim/settings/batch_settings.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,13 @@ def __init__(
121121
if batch_args is not None:
122122
if not (
123123
isinstance(batch_args, dict)
124-
and all(isinstance(key, str) for key, val in batch_args.items())
124+
and all(
125+
isinstance(key, str) and isinstance(val, (str, type(None)))
126+
for key, val in batch_args.items()
127+
)
125128
):
126129
raise TypeError(
127-
"batch_args argument was not of type mapping of str and str"
130+
"batch_args argument was not of type dict of str and str or None"
128131
)
129132
self._arguments = self._get_arguments(batch_args)
130133
"""The BatchSettings child class based on scheduler type"""
@@ -151,10 +154,13 @@ def env_vars(self, value: t.Dict[str, str | None]) -> None:
151154
"""Set the environment variables."""
152155

153156
if not (
154-
isinstance(value, t.Mapping)
155-
and all(isinstance(key, str) for key, val in value.items())
157+
isinstance(value, t.Dict)
158+
and all(
159+
isinstance(key, str) and isinstance(val, (str, type(None)))
160+
for key, val in value.items()
161+
)
156162
):
157-
raise TypeError("env_vars argument was not of type dic of str and str")
163+
raise TypeError("env_vars argument was not of type dict of str and str")
158164

159165
self._env_vars = copy.deepcopy(value)
160166

smartsim/settings/launch_settings.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,14 @@ def __init__(
129129

130130
if launch_args is not None:
131131
if not (
132-
isinstance(launch_args, t.Mapping)
133-
and all(isinstance(key, str) for key, val in launch_args.items())
132+
isinstance(launch_args, t.Dict)
133+
and all(
134+
isinstance(key, str) and isinstance(val, (str, type(None)))
135+
for key, val in launch_args.items()
136+
)
134137
):
135138
raise TypeError(
136-
"batch_args argument was not of type mapping of str and str"
139+
"launch_args argument was not of type dict of str and str or None"
137140
)
138141
self._arguments = self._get_arguments(launch_args)
139142
"""The LaunchSettings child class based on launcher type"""
@@ -176,9 +179,12 @@ def env_vars(self, value: dict[str, str | None]) -> None:
176179
"""
177180
if not (
178181
isinstance(value, dict)
179-
and all(isinstance(key, str) for key, val in value.items())
182+
and all(
183+
isinstance(key, str) and isinstance(val, (str, type(None)))
184+
for key, val in value.items()
185+
)
180186
):
181-
raise TypeError("env_vars argument was not of type dic of str and str")
187+
raise TypeError("env_vars argument was not of type dict of str and str")
182188

183189
self._env_vars = copy.deepcopy(value)
184190

tests/temp_tests/test_settings/test_batchSettings.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ def test_type_batch_scheduler():
9797
pytest.param("", id="empty string"),
9898
pytest.param(0, id="0"),
9999
pytest.param([], id="empty list"),
100+
pytest.param({"valid": 1}, id="value not str or None"),
100101
],
101102
)
102103
def test_type_batch_args(batch_args):
103104
with pytest.raises(
104-
TypeError, match="batch_args argument was not of type mapping of str and str"
105+
TypeError,
106+
match="batch_args argument was not of type dict of str and str or None",
105107
):
106108
BatchSettings(
107109
batch_scheduler="slurm",
@@ -113,7 +115,7 @@ def test_type_batch_args(batch_args):
113115
def test_type_env_vars():
114116
env_vars = "invalid"
115117
with pytest.raises(
116-
TypeError, match="env_vars argument was not of type dic of str and str"
118+
TypeError, match="env_vars argument was not of type dict of str and str"
117119
):
118120
BatchSettings(batch_scheduler="slurm", env_vars=env_vars)
119121

tests/temp_tests/test_settings/test_launchSettings.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,13 @@ def test_type_launcher():
104104
pytest.param("", id="empty string"),
105105
pytest.param(0, id="0"),
106106
pytest.param([], id="empty list"),
107+
pytest.param({"valid", 2}, id="val not str or None"),
107108
],
108109
)
109110
def test_type_launch_args(launch_args):
110111
with pytest.raises(
111-
TypeError, match="batch_args argument was not of type mapping of str and str"
112+
TypeError,
113+
match="launch_args argument was not of type dict of str and str or None",
112114
):
113115
LaunchSettings(
114116
launcher="local", launch_args=launch_args, env_vars={"ENV": "VAR"}
@@ -118,6 +120,6 @@ def test_type_launch_args(launch_args):
118120
def test_type_env_vars():
119121
env_vars = "invalid"
120122
with pytest.raises(
121-
TypeError, match="env_vars argument was not of type dic of str and str"
123+
TypeError, match="env_vars argument was not of type dict of str and str"
122124
):
123125
LaunchSettings(launcher="local", env_vars=env_vars)

0 commit comments

Comments
 (0)