Skip to content

Commit

Permalink
run settings input to string conversion typehint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ankona committed Jun 5, 2023
1 parent e7ac4f4 commit fde3291
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
2 changes: 0 additions & 2 deletions smartsim/database/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,6 @@ def _initialize_entities(self, **kwargs: t.Any) -> None:
db_node_name, port, cluster
)

# exe_args = " ".join(start_script_args)

# if only launching 1 db per command, we don't need a list of exe args lists
run_settings = self._build_run_settings(
sys.executable, [start_script_args], **kwargs
Expand Down
5 changes: 3 additions & 2 deletions smartsim/entity/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,15 @@ def _read_model_parameters(self) -> t.Tuple[t.List[str], t.List[t.List[str]]]:
)

param_names: t.List[str] = []
parameters: t.List[t.List[t.Union[int, str]]] = []
parameters: t.List[t.List[str]] = []
for name, val in self.params.items():
param_names.append(name)

if isinstance(val, list):
val = [str(v) for v in val]
parameters.append(val)
elif isinstance(val, (int, str)):
parameters.append([val])
parameters.append([str(val)])
else:
raise TypeError(
"Incorrect type for ensemble parameters\n"
Expand Down
28 changes: 14 additions & 14 deletions tests/test_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def test_all_perm():
params = {"h": [5, 6]}
ensemble = Ensemble("all_perm", params, run_settings=rs, perm_strat="all_perm")
assert len(ensemble) == 2
assert ensemble.entities[0].params["h"] == 5
assert ensemble.entities[1].params["h"] == 6
assert ensemble.entities[0].params["h"] == "5"
assert ensemble.entities[1].params["h"] == "6"


def test_step():
Expand All @@ -84,10 +84,10 @@ def test_step():
ensemble = Ensemble("step", params, run_settings=rs, perm_strat="step")
assert len(ensemble) == 2

model_1_params = {"h": 5, "g": 7}
model_1_params = {"h": "5", "g": "7"}
assert ensemble.entities[0].params == model_1_params

model_2_params = {"h": 6, "g": 8}
model_2_params = {"h": "6", "g": "8"}
assert ensemble.entities[1].params == model_2_params


Expand All @@ -104,7 +104,7 @@ def test_random():
)
assert len(ensemble) == len(random_ints)
assigned_params = [m.params["h"] for m in ensemble.entities]
assert all([x in random_ints for x in assigned_params])
assert all([int(x) in random_ints for x in assigned_params])

ensemble = Ensemble(
"random_test",
Expand All @@ -115,7 +115,7 @@ def test_random():
)
assert len(ensemble) == len(random_ints) - 1
assigned_params = [m.params["h"] for m in ensemble.entities]
assert all([x in random_ints for x in assigned_params])
assert all([int(x) in random_ints for x in assigned_params])


def test_user_strategy():
Expand All @@ -124,10 +124,10 @@ def test_user_strategy():
ensemble = Ensemble("step", params, run_settings=rs, perm_strat=step_values)
assert len(ensemble) == 2

model_1_params = {"h": 5, "g": 7}
model_1_params = {"h": "5", "g": "7"}
assert ensemble.entities[0].params == model_1_params

model_2_params = {"h": 6, "g": 8}
model_2_params = {"h": "6", "g": "8"}
assert ensemble.entities[1].params == model_2_params


Expand Down Expand Up @@ -181,10 +181,10 @@ def test_arg_and_model_params_step():
exe_args_1 = rs_orig_args + ["-H", "6", "--g_param=b"]
assert ensemble.entities[1].run_settings.exe_args == exe_args_1

model_1_params = {"H": 5, "g_param": "a", "h": 5, "g": 7}
model_1_params = {"H": "5", "g_param": "a", "h": "5", "g": "7"}
assert ensemble.entities[0].params == model_1_params

model_2_params = {"H": 6, "g_param": "b", "h": 6, "g": 8}
model_2_params = {"H": "6", "g_param": "b", "h": "6", "g": "8"}
assert ensemble.entities[1].params == model_2_params


Expand Down Expand Up @@ -214,13 +214,13 @@ def test_arg_and_model_params_all_perms():
assert ensemble.entities[1].run_settings.exe_args == exe_args_1
assert ensemble.entities[3].run_settings.exe_args == exe_args_1

model_0_params = {"g_param": "a", "h": 5}
model_0_params = {"g_param": "a", "h": "5"}
assert ensemble.entities[0].params == model_0_params
model_1_params = {"g_param": "b", "h": 5}
model_1_params = {"g_param": "b", "h": "5"}
assert ensemble.entities[1].params == model_1_params
model_2_params = {"g_param": "a", "h": 6}
model_2_params = {"g_param": "a", "h": "6"}
assert ensemble.entities[2].params == model_2_params
model_3_params = {"g_param": "b", "h": 6}
model_3_params = {"g_param": "b", "h": "6"}
assert ensemble.entities[3].params == model_3_params


Expand Down

0 comments on commit fde3291

Please sign in to comment.