|
| 1 | +""" |
| 2 | +Runs libEnsemble with Latin hypercube sampling and check no warning. |
| 3 | +
|
| 4 | +Execute using MPI (e.g. 3 workers): |
| 5 | + mpiexec -np 4 python test_mpi_warning.py |
| 6 | +
|
| 7 | +The number of concurrent evaluations of the objective function will be 4-1=3. |
| 8 | +""" |
| 9 | + |
| 10 | +# Do not change these lines - they are parsed by run-tests.sh |
| 11 | +# TESTSUITE_COMMS: mpi |
| 12 | +# TESTSUITE_NPROCS: 4 |
| 13 | + |
| 14 | +import numpy as np |
| 15 | +import os |
| 16 | +import time |
| 17 | + |
| 18 | +from libensemble import Ensemble |
| 19 | +from libensemble.gen_funcs.sampling import latin_hypercube_sample as gen_f |
| 20 | + |
| 21 | +# Import libEnsemble items for this test |
| 22 | +from libensemble.sim_funcs.simple_sim import norm_eval as sim_f |
| 23 | +from libensemble.specs import ExitCriteria, GenSpecs, SimSpecs |
| 24 | + |
| 25 | +from libensemble import logger |
| 26 | + |
| 27 | +# Main block is necessary only when using local comms with spawn start method (default on macOS and Windows). |
| 28 | +if __name__ == "__main__": |
| 29 | + log_file = "ensemble_check_warning.log" |
| 30 | + logger.set_level("MANAGER_WARNING") |
| 31 | + logger.set_filename(log_file) |
| 32 | + |
| 33 | + sampling = Ensemble() |
| 34 | + sampling.libE_specs.save_every_k_sims = 100 |
| 35 | + sampling.sim_specs = SimSpecs(sim_f=sim_f) |
| 36 | + sampling.gen_specs = GenSpecs( |
| 37 | + gen_f=gen_f, |
| 38 | + outputs=[("x", float, 2)], |
| 39 | + user={ |
| 40 | + "gen_batch_size": 100, |
| 41 | + "lb": np.array([-3, -2]), |
| 42 | + "ub": np.array([3, 2]), |
| 43 | + }, |
| 44 | + ) |
| 45 | + |
| 46 | + sampling.exit_criteria = ExitCriteria(sim_max=100) |
| 47 | + sampling.add_random_streams() |
| 48 | + |
| 49 | + if sampling.is_manager: |
| 50 | + if os.path.exists(log_file): |
| 51 | + os.remove(log_file) |
| 52 | + |
| 53 | + sampling.run() |
| 54 | + if sampling.is_manager: |
| 55 | + print("len:", len(sampling.H)) |
| 56 | + time.sleep(0.2) |
| 57 | + assert os.path.exists(log_file) |
| 58 | + assert os.stat(log_file).st_size == 0, "Unexpected warning" |
0 commit comments