Skip to content

Commit 5dc5155

Browse files
committed
add unit test where APOSMM class ingests first
1 parent a354339 commit 5dc5155

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

libensemble/tests/unit_tests/test_persistent_aposmm.py

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_standalone_persistent_aposmm():
122122
assert min_found >= 6, f"Found {min_found} minima"
123123

124124

125-
def _evaluate_aposmm_instance(my_APOSMM):
125+
def _evaluate_aposmm_instance(my_APOSMM, minimum_minima=6):
126126
from libensemble.message_numbers import FINISHED_PERSISTENT_GEN_TAG
127127
from libensemble.sim_funcs.six_hump_camel import six_hump_camel_func
128128
from libensemble.tests.regression_tests.support import six_hump_camel_minima as minima
@@ -166,7 +166,7 @@ def _evaluate_aposmm_instance(my_APOSMM):
166166
print(np.min(np.sum((H[H["local_min"]]["x"] - m) ** 2, 1)), flush=True)
167167
if np.min(np.sum((H[H["local_min"]]["x"] - m) ** 2, 1)) < tol:
168168
min_found += 1
169-
assert min_found >= 6, f"Found {min_found} minima"
169+
assert min_found >= minimum_minima, f"Found {min_found} minima"
170170

171171

172172
@pytest.mark.extra
@@ -256,6 +256,61 @@ def test_asktell_with_persistent_aposmm():
256256
_evaluate_aposmm_instance(my_APOSMM)
257257

258258

259+
@pytest.mark.extra
260+
def test_asktell_ingest_first():
261+
from math import gamma, pi, sqrt
262+
263+
from gest_api.vocs import VOCS
264+
265+
import libensemble.gen_funcs
266+
from libensemble.gen_classes import APOSMM
267+
from libensemble.sim_funcs.six_hump_camel import six_hump_camel_func
268+
from libensemble.tests.regression_tests.support import six_hump_camel_minima as minima
269+
270+
libensemble.gen_funcs.rc.aposmm_optimizers = "nlopt"
271+
272+
n = 2
273+
274+
variables = {"core": [-3, 3], "edge": [-2, 2], "core_on_cube": [0, 1], "edge_on_cube": [0, 1]}
275+
objectives = {"energy": "MINIMIZE"}
276+
277+
variables_mapping = {
278+
"x": ["core", "edge"],
279+
"x_on_cube": ["core_on_cube", "edge_on_cube"],
280+
"f": ["energy"],
281+
}
282+
283+
vocs = VOCS(variables=variables, objectives=objectives)
284+
285+
my_APOSMM = APOSMM(
286+
vocs,
287+
max_active_runs=6,
288+
initial_sample_size=6,
289+
variables_mapping=variables_mapping,
290+
localopt_method="LN_BOBYQA",
291+
rk_const=0.5 * ((gamma(1 + (n / 2)) * 5) ** (1 / n)) / sqrt(pi),
292+
xtol_abs=1e-6,
293+
ftol_abs=1e-6,
294+
dist_to_bound_multiple=0.5,
295+
do_not_produce_sample_points=True,
296+
)
297+
298+
# local_H["x_on_cube"][-num_pts:] = (pts - lb) / (ub - lb)
299+
initial_sample = [
300+
{
301+
"core": minima[i][0],
302+
"edge": minima[i][1],
303+
"core_on_cube": (minima[i][0] - variables["core"][0]) / (variables["core"][1] - variables["core"][0]),
304+
"edge_on_cube": (minima[i][1] - variables["edge"][0]) / (variables["edge"][1] - variables["edge"][0]),
305+
"energy": six_hump_camel_func(np.array([minima[i][0], minima[i][1]])),
306+
}
307+
for i in range(6)
308+
]
309+
310+
my_APOSMM.ingest(initial_sample)
311+
_evaluate_aposmm_instance(my_APOSMM, minimum_minima=4)
312+
313+
259314
def _run_aposmm_export_test(variables_mapping):
260315
"""Helper function to run APOSMM export tests with given variables_mapping"""
261316
from gest_api.vocs import VOCS
@@ -343,4 +398,5 @@ def test_aposmm_export():
343398
test_standalone_persistent_aposmm()
344399
test_standalone_persistent_aposmm_combined_func()
345400
test_asktell_with_persistent_aposmm()
401+
test_asktell_ingest_first()
346402
test_aposmm_export()

0 commit comments

Comments
 (0)