Skip to content

Commit cd27017

Browse files
authored
creates validator that enables sim_dirs_make when sim_input_dir is enabled. slightly adjusts docs and corresponding test (#1266)
1 parent 9510cc2 commit cd27017

6 files changed

Lines changed: 26 additions & 6 deletions

File tree

docs/data_structures/libE_specs.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ libEnsemble is primarily customized by setting options within a ``LibeSpecs`` cl
128128

129129
**sim_input_dir** [str]:
130130
Copy this directory's contents into the working directory upon calling the simulation function.
131+
Forms the base of a simulation directory.
131132

132133
.. tab-item:: Gens
133134

@@ -145,6 +146,7 @@ libEnsemble is primarily customized by setting options within a ``LibeSpecs`` cl
145146

146147
**gen_input_dir** [str]:
147148
Copy this directory's contents into the working directory upon calling the generator function.
149+
Forms the base of a generator directory.
148150

149151
.. tab-item:: Profiling
150152

libensemble/specs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ class LibeSpecs(BaseModel):
257257
sim_input_dir: Optional[Union[str, Path]] = None
258258
"""
259259
Copy this directory's contents into the working directory upon calling the simulation function.
260+
Forms the base of a simulation directory.
260261
"""
261262

262263
gen_dirs_make: Optional[bool] = False
@@ -279,6 +280,7 @@ class LibeSpecs(BaseModel):
279280
gen_input_dir: Optional[Union[str, Path]] = None
280281
"""
281282
Copy this directory's contents into the working directory upon calling the generator function.
283+
Forms the base of a generator directory.
282284
"""
283285

284286
calc_dir_id_width: Optional[int] = 4

libensemble/tests/functionality_tests/test_sim_input_dir_option.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
libE_specs["sim_input_dir"] = sim_input_dir
3939
libE_specs["ensemble_dir_path"] = o_ensemble
40-
libE_specs["sim_dirs_make"] = False
4140
libE_specs["sim_dir_symlink_files"] = ["./test_sim_input_dir_option.py"] # to cover FileExistsError catch
4241
libE_specs["ensemble_copy_back"] = True
4342

@@ -65,8 +64,6 @@
6564

6665
if is_manager:
6766
assert os.path.isdir(o_ensemble), f"Ensemble directory {o_ensemble} not created."
68-
assert os.path.basename(dir_to_copy) in os.listdir(o_ensemble), "Input file not copied over."
69-
with open(os.path.join(o_ensemble, "test_sim_out.txt"), "r") as f:
70-
lines = f.readlines()
71-
72-
assert len(lines) == exit_criteria["sim_max"], "Sim output not written to ensemble dir for each sim call"
67+
assert all(
68+
[("copy_this" in os.listdir(os.path.join(o_ensemble, i))) for i in os.listdir(o_ensemble)]
69+
), "Sim input dir not copied to each sim dir."

libensemble/utils/pydantic_bindings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
check_valid_out,
2424
enable_save_H_when_every_K,
2525
genf_set_in_out_from_attrs,
26+
set_calc_dirs_on_input_dir,
2627
set_platform_specs_to_class,
2728
set_workflow_dir,
2829
simf_set_in_out_from_attrs,
@@ -117,6 +118,7 @@ class Config:
117118
"check_any_workers_and_disable_rm_if_tcp": check_any_workers_and_disable_rm_if_tcp,
118119
"enable_save_H_when_every_K": enable_save_H_when_every_K,
119120
"set_workflow_dir": set_workflow_dir,
121+
"set_calc_dirs_on_input_dir": set_calc_dirs_on_input_dir,
120122
},
121123
)
122124

libensemble/utils/specs_checkers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ def _check_set_workflow_dir(values):
104104
return values
105105

106106

107+
def _check_set_calc_dirs_on_input_dir(values):
108+
if scg(values, "sim_input_dir") and not scg(values, "sim_dirs_make"):
109+
scs(values, "sim_dirs_make", True)
110+
if scg(values, "gen_input_dir") and not scg(values, "gen_dirs_make"):
111+
scs(values, "gen_dirs_make", True)
112+
return values
113+
114+
107115
def _check_logical_cores(values):
108116
if scg(values, "cores_per_node") and scg(values, "logical_cores_per_node"):
109117
assert (

libensemble/utils/validators.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
_check_H0,
1212
_check_logical_cores,
1313
_check_output_fields,
14+
_check_set_calc_dirs_on_input_dir,
1415
_check_set_workflow_dir,
1516
)
1617

@@ -111,6 +112,10 @@ def enable_save_H_when_every_K(cls, values):
111112
def set_workflow_dir(cls, values):
112113
return _check_set_workflow_dir(values)
113114

115+
@root_validator
116+
def set_calc_dirs_on_input_dir(cls, values):
117+
return _check_set_calc_dirs_on_input_dir(values)
118+
114119
@root_validator
115120
def check_exit_criteria(cls, values):
116121
return _check_exit_criteria(values)
@@ -202,6 +207,10 @@ def enable_save_H_when_every_K(self):
202207
def set_workflow_dir(self):
203208
return _check_set_workflow_dir(self)
204209

210+
@model_validator(mode="after")
211+
def set_calc_dirs_on_input_dir(self):
212+
return _check_set_calc_dirs_on_input_dir(self)
213+
205214
@model_validator(mode="after")
206215
def check_exit_criteria(self):
207216
return _check_exit_criteria(self)

0 commit comments

Comments
 (0)