Skip to content

Commit

Permalink
Merge pull request #1007 from Libensemble/testing/coverage
Browse files Browse the repository at this point in the history
Testing/coverage
  • Loading branch information
jmlarson1 committed May 25, 2023
2 parents 7b2a74e + d396d19 commit 10f0262
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libensemble/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,6 @@ def _final_receive_and_kill(self, persis_info: dict) -> (dict, int, int):
self._kill_workers()
return persis_info, exit_flag, self.elapsed()

# --- Main loop

def _sim_max_given(self) -> bool:
if "sim_max" in self.exit_criteria:
return self.hist.sim_started_count >= self.exit_criteria["sim_max"] + self.hist.sim_started_offset
Expand Down Expand Up @@ -606,6 +604,8 @@ def _alloc_work(self, H: npt.NDArray, persis_info: dict) -> dict:

return output

# --- Main loop

def run(self, persis_info: dict) -> (dict, int, int):
"""Runs the manager"""
logger.info(f"Manager initiated on node {socket.gethostname()}")
Expand Down
29 changes: 29 additions & 0 deletions libensemble/tests/unit_tests/test_allocation_funcs_and_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,33 @@ def test_convert_to_rsets():
clear_resources()


def test_check_H_rows():
exp = np.arange(3)
H_rows = AllocSupport._check_H_rows(exp)
assert isinstance(H_rows, np.ndarray), "_check_H_rows returned unexpected type"
assert np.array_equal(H_rows, exp), f"Output {H_rows} is not as expected"

in_rows_list = [0, 1, 2]
H_rows = AllocSupport._check_H_rows(in_rows_list)
assert isinstance(H_rows, np.ndarray), "_check_H_rows returned unexpected type"
assert np.array_equal(H_rows, exp), f"Output {H_rows} is not as expected"

in_rows_list = range(3)
H_rows = AllocSupport._check_H_rows(in_rows_list)
assert isinstance(H_rows, np.ndarray), "_check_H_rows returned unexpected type"
assert np.array_equal(H_rows, exp), f"Output {H_rows} is not as expected"


def test_check_H_fields():
in_fields = ["x", "num_nodes", "procs_per_node"]
H_fields = AllocSupport._check_H_fields(in_fields)
assert H_fields == in_fields, f"H_fields {H_fields} did not match expected"

in_fields = ["x", "num_nodes", "procs_per_node", "x"]
H_fields = AllocSupport._check_H_fields(in_fields)
assert set(H_fields) == set(in_fields), f"H_fields {H_fields} did not match expected"


if __name__ == "__main__":
test_decide_work_and_resources()
test_als_init_normal()
Expand All @@ -468,3 +495,5 @@ def test_convert_to_rsets():
test_als_all_gen_informed()
test_als_points_by_priority()
test_convert_to_rsets()
test_check_H_rows()
test_check_H_fields()

0 comments on commit 10f0262

Please sign in to comment.