diff --git a/docs/data_structures/alloc_specs.rst b/docs/data_structures/alloc_specs.rst index 074c6a152..159b9eaca 100644 --- a/docs/data_structures/alloc_specs.rst +++ b/docs/data_structures/alloc_specs.rst @@ -19,7 +19,7 @@ Can be constructed and passed to libEnsemble as a Python class or a dictionary. * libEnsemble uses the following defaults if the user doesn't provide their own ``alloc_specs``: .. literalinclude:: ../../libensemble/specs.py - :start-at: alloc_f: Callable = give_sim_work_first + :start-at: alloc_f: Callable = start_only_persistent :end-before: end_alloc_tag :caption: Default settings for alloc_specs diff --git a/docs/examples/alloc_funcs.rst b/docs/examples/alloc_funcs.rst index f54f4bf3c..3734d7cb0 100644 --- a/docs/examples/alloc_funcs.rst +++ b/docs/examples/alloc_funcs.rst @@ -10,14 +10,31 @@ Many users use these unmodified. .. IMPORTANT:: See the API for allocation functions :ref:`here`. + **The default allocation function changed in libEnsemble v2.0 from `give_sim_work_first` to `start_only_persistent `.** + .. note:: - The default allocation function (for non-persistent generators) is :ref:`give_sim_work_first`. - The most commonly used (for persistent generators) is :ref:`start_only_persistent`. + The default allocation function for persistent generators is :ref:`start_only_persistent`. + + The most commonly used allocation function for non-persistent generators is :ref:`give_sim_work_first`. .. role:: underline :class: underline +.. _start_only_persistent_label: + +start_only_persistent +--------------------- +.. automodule:: start_only_persistent + :members: + :undoc-members: + +.. dropdown:: :underline:`start_only_persistent.py` + + .. literalinclude:: ../../libensemble/alloc_funcs/start_only_persistent.py + :language: python + :linenos: + .. _gswf_label: give_sim_work_first @@ -44,20 +61,6 @@ fast_alloc :language: python :linenos: -.. _start_only_persistent_label: - -start_only_persistent ---------------------- -.. automodule:: start_only_persistent - :members: - :undoc-members: - -.. dropdown:: :underline:`start_only_persistent.py` - - .. literalinclude:: ../../libensemble/alloc_funcs/start_only_persistent.py - :language: python - :linenos: - start_persistent_local_opt_gens ------------------------------- .. automodule:: start_persistent_local_opt_gens diff --git a/docs/function_guides/allocator.rst b/docs/function_guides/allocator.rst index a65c404ab..062010582 100644 --- a/docs/function_guides/allocator.rst +++ b/docs/function_guides/allocator.rst @@ -128,8 +128,8 @@ The remaining values above are useful for efficient filtering of H values Descriptions of included allocation functions can be found :doc:`here<../examples/alloc_funcs>`. The default allocation function is -``give_sim_work_first``. During its worker ID loop, it checks if there's unallocated +``start_only_persistent``. During its worker ID loop, it checks if there's unallocated work and assigns simulations for that work. Otherwise, it initializes generators for up to ``"num_active_gens"`` instances. Other settings like ``batch_mode`` are also supported. See -:ref:`here` for more information about ``give_sim_work_first``. +:ref:`here` for more information. diff --git a/libensemble/specs.py b/libensemble/specs.py index dac1baae4..ca02586dd 100644 --- a/libensemble/specs.py +++ b/libensemble/specs.py @@ -5,7 +5,7 @@ import pydantic from pydantic import BaseModel, Field, model_validator -from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first +from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens __all__ = ["SimSpecs", "GenSpecs", "AllocSpecs", "ExitCriteria", "LibeSpecs", "_EnsembleSpecs"] @@ -265,10 +265,14 @@ class AllocSpecs(BaseModel): Specifications for configuring an Allocation Function. """ - alloc_f: object = give_sim_work_first + alloc_f: object = only_persistent_gens """ Python function matching the ``alloc_f`` interface. Decides when simulator and generator functions should be called, and with what resources and parameters. + + .. note:: + For libEnsemble v2.0, the default allocation function is now ``only_persistent_gens``, instead + of ``give_sim_work_first``. """ user: dict | None = {"num_active_gens": 1} diff --git a/libensemble/tests/functionality_tests/1d_sampling.json b/libensemble/tests/functionality_tests/1d_sampling.json index 6066cdd69..0acb17252 100644 --- a/libensemble/tests/functionality_tests/1d_sampling.json +++ b/libensemble/tests/functionality_tests/1d_sampling.json @@ -28,5 +28,8 @@ "user": { "gen_batch_size": 500 } + }, + "alloc_specs": { + "alloc_f": "libensemble.alloc_funcs.give_sim_work_first.give_sim_work_first" } } diff --git a/libensemble/tests/functionality_tests/1d_sampling.toml b/libensemble/tests/functionality_tests/1d_sampling.toml index 6618019a6..bd1ddb8aa 100644 --- a/libensemble/tests/functionality_tests/1d_sampling.toml +++ b/libensemble/tests/functionality_tests/1d_sampling.toml @@ -20,3 +20,6 @@ size = 1 [gen_specs.user] gen_batch_size = 500 + +[alloc_specs] + alloc_f = "libensemble.alloc_funcs.give_sim_work_first.give_sim_work_first" diff --git a/libensemble/tests/functionality_tests/1d_sampling.yaml b/libensemble/tests/functionality_tests/1d_sampling.yaml index 3e82548ae..904c55403 100644 --- a/libensemble/tests/functionality_tests/1d_sampling.yaml +++ b/libensemble/tests/functionality_tests/1d_sampling.yaml @@ -22,3 +22,6 @@ gen_specs: size: 1 user: gen_batch_size: 500 + +alloc_specs: + alloc_f: libensemble.alloc_funcs.give_sim_work_first.give_sim_work_first diff --git a/libensemble/tests/functionality_tests/test_1d_sampling_no_comms_given.py b/libensemble/tests/functionality_tests/test_1d_sampling_no_comms_given.py index 563ee920e..0a3594587 100644 --- a/libensemble/tests/functionality_tests/test_1d_sampling_no_comms_given.py +++ b/libensemble/tests/functionality_tests/test_1d_sampling_no_comms_given.py @@ -17,11 +17,12 @@ import numpy as np from libensemble import Ensemble +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import latin_hypercube_sample as gen_f # Import libEnsemble items for this test from libensemble.sim_funcs.simple_sim import norm_eval as sim_f -from libensemble.specs import ExitCriteria, GenSpecs, LibeSpecs, SimSpecs +from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, LibeSpecs, SimSpecs from libensemble.tools import check_npy_file_exists # Main block is necessary only when using local comms with spawn start method (default on macOS and Windows). @@ -55,6 +56,7 @@ ) sampling.add_random_streams() + sampling.alloc_specs = AllocSpecs(alloc_f=give_sim_work_first) H, persis_info, flag = sampling.run() if sampling.is_manager: diff --git a/libensemble/tests/functionality_tests/test_1d_sampling_with_profile.py b/libensemble/tests/functionality_tests/test_1d_sampling_with_profile.py index 645228d13..8ca5fca76 100644 --- a/libensemble/tests/functionality_tests/test_1d_sampling_with_profile.py +++ b/libensemble/tests/functionality_tests/test_1d_sampling_with_profile.py @@ -19,6 +19,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import latin_hypercube_sample as gen_f from libensemble.libE import libE from libensemble.sim_funcs.simple_sim import norm_eval as sim_f @@ -50,10 +51,16 @@ persis_info = add_unique_random_streams({}, nworkers + 1) + alloc_specs = { + "alloc_f": give_sim_work_first, + } + exit_criteria = {"sim_max": 501} # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs=alloc_specs, libE_specs=libE_specs + ) if is_manager: assert len(H) >= 501 diff --git a/libensemble/tests/functionality_tests/test_1d_splitcomm.py b/libensemble/tests/functionality_tests/test_1d_splitcomm.py index de73660d7..d0c47129b 100644 --- a/libensemble/tests/functionality_tests/test_1d_splitcomm.py +++ b/libensemble/tests/functionality_tests/test_1d_splitcomm.py @@ -15,6 +15,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import latin_hypercube_sample as gen_f # Import libEnsemble items for this test @@ -51,12 +52,18 @@ }, } + alloc_specs = { + "alloc_f": give_sim_work_first, + } + persis_info = add_unique_random_streams({}, nworkers + 1, seed=1234) exit_criteria = {"gen_max": 501} # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs=alloc_specs, libE_specs=libE_specs + ) if is_manager: assert len(H) >= 501 diff --git a/libensemble/tests/functionality_tests/test_1d_subcomm.py b/libensemble/tests/functionality_tests/test_1d_subcomm.py index 7f607c31c..0810f12e8 100644 --- a/libensemble/tests/functionality_tests/test_1d_subcomm.py +++ b/libensemble/tests/functionality_tests/test_1d_subcomm.py @@ -15,6 +15,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import latin_hypercube_sample as gen_f # Import libEnsemble items for this test @@ -55,12 +56,18 @@ }, } + alloc_specs = { + "alloc_f": give_sim_work_first, + } + persis_info = add_unique_random_streams({}, nworkers + 1, seed=1234) exit_criteria = {"gen_max": 501} # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs=alloc_specs, libE_specs=libE_specs + ) if is_manager: assert len(H) >= 501 diff --git a/libensemble/tests/functionality_tests/test_1d_super_simple.py b/libensemble/tests/functionality_tests/test_1d_super_simple.py index e84255714..326e6abce 100644 --- a/libensemble/tests/functionality_tests/test_1d_super_simple.py +++ b/libensemble/tests/functionality_tests/test_1d_super_simple.py @@ -15,6 +15,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import latin_hypercube_sample as gen_f # Import libEnsemble items for this test @@ -55,7 +56,13 @@ def sim_f_noreturn(In): exit_criteria = {"gen_max": 501} - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + alloc_specs = { + "alloc_f": give_sim_work_first, + } + + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs=alloc_specs, libE_specs=libE_specs + ) if is_manager: assert len(H) >= 501 diff --git a/libensemble/tests/functionality_tests/test_1d_uniform_sampling_with_comm_dup.py b/libensemble/tests/functionality_tests/test_1d_uniform_sampling_with_comm_dup.py index 7d2d9f588..98b738e69 100644 --- a/libensemble/tests/functionality_tests/test_1d_uniform_sampling_with_comm_dup.py +++ b/libensemble/tests/functionality_tests/test_1d_uniform_sampling_with_comm_dup.py @@ -19,6 +19,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f # Import libEnsemble items for this test @@ -62,8 +63,12 @@ exit_criteria = {"gen_max": 501} + alloc_specs = { + "alloc_f": give_sim_work_first, + } + # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info) + H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs=alloc_specs) if is_manager: # assert libE_specs["comms"] == "mpi", "MPI default comms should be set" diff --git a/libensemble/tests/functionality_tests/test_calc_exception.py b/libensemble/tests/functionality_tests/test_calc_exception.py index 361e1be3a..d435be283 100644 --- a/libensemble/tests/functionality_tests/test_calc_exception.py +++ b/libensemble/tests/functionality_tests/test_calc_exception.py @@ -13,6 +13,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f from libensemble.libE import libE from libensemble.manager import LoggedException @@ -47,6 +48,10 @@ def six_hump_camel_err(H, persis_info, sim_specs, _): persis_info = add_unique_random_streams({}, nworkers + 1) + alloc_specs = { + "alloc_f": give_sim_work_first, + } + exit_criteria = {"wallclock_max": 10} libE_specs["abort_on_exception"] = False @@ -54,7 +59,9 @@ def six_hump_camel_err(H, persis_info, sim_specs, _): # Perform the run return_flag = 1 try: - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs=alloc_specs, libE_specs=libE_specs + ) except LoggedException as e: print(f"Caught deliberate exception: {e}") return_flag = 0 diff --git a/libensemble/tests/functionality_tests/test_comms.py b/libensemble/tests/functionality_tests/test_comms.py index 52c3e0771..ca31f18e0 100644 --- a/libensemble/tests/functionality_tests/test_comms.py +++ b/libensemble/tests/functionality_tests/test_comms.py @@ -16,6 +16,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.executors.mpi_executor import MPIExecutor # Only used to get workerID in float_x1000 from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f @@ -55,8 +56,14 @@ exit_criteria = {"sim_max": sim_max, "wallclock_max": 300} + alloc_specs = { + "alloc_f": give_sim_work_first, + } + # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs=alloc_specs, libE_specs=libE_specs + ) if is_manager: assert flag == 0 diff --git a/libensemble/tests/functionality_tests/test_evaluate_existing_plus_gen.py b/libensemble/tests/functionality_tests/test_evaluate_existing_plus_gen.py index fe3d8dad8..474aa18f9 100644 --- a/libensemble/tests/functionality_tests/test_evaluate_existing_plus_gen.py +++ b/libensemble/tests/functionality_tests/test_evaluate_existing_plus_gen.py @@ -18,9 +18,10 @@ # Import libEnsemble items for this test from libensemble import Ensemble +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import latin_hypercube_sample as gen_f from libensemble.sim_funcs.six_hump_camel import six_hump_camel as sim_f -from libensemble.specs import ExitCriteria, GenSpecs, SimSpecs +from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, SimSpecs from libensemble.tools import add_unique_random_streams @@ -59,6 +60,7 @@ def create_H0(persis_info, gen_specs, H0_size): sampling.exit_criteria = ExitCriteria(sim_max=100) sampling.persis_info = add_unique_random_streams({}, sampling.nworkers + 1) sampling.H0 = create_H0(sampling.persis_info, gen_specs, 50) + sampling.alloc_specs = AllocSpecs(alloc_f=give_sim_work_first) sampling.run() if sampling.is_manager: diff --git a/libensemble/tests/functionality_tests/test_executor_hworld_pass_fail.py b/libensemble/tests/functionality_tests/test_executor_hworld_pass_fail.py index 1b61bf8d2..b59f9b27b 100644 --- a/libensemble/tests/functionality_tests/test_executor_hworld_pass_fail.py +++ b/libensemble/tests/functionality_tests/test_executor_hworld_pass_fail.py @@ -15,6 +15,7 @@ import numpy as np import libensemble.sim_funcs.six_hump_camel as six_hump_camel +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.executors.mpi_executor import MPIExecutor from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f from libensemble.libE import libE @@ -88,8 +89,12 @@ # num sim_ended_count conditions in executor_hworld exit_criteria = {"sim_max": nworkers * 5} + alloc_specs = { + "alloc_f": give_sim_work_first, + } + # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs=libE_specs) if is_manager: print("\nChecking expected task status against Workers ...\n") diff --git a/libensemble/tests/functionality_tests/test_executor_hworld_timeout.py b/libensemble/tests/functionality_tests/test_executor_hworld_timeout.py index 496eced31..16e74e300 100644 --- a/libensemble/tests/functionality_tests/test_executor_hworld_timeout.py +++ b/libensemble/tests/functionality_tests/test_executor_hworld_timeout.py @@ -15,6 +15,7 @@ import numpy as np import libensemble.sim_funcs.six_hump_camel as six_hump_camel +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.executors.mpi_executor import MPIExecutor from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f @@ -85,6 +86,10 @@ }, } + alloc_specs = { + "alloc_f": give_sim_work_first, + } + persis_info = add_unique_random_streams({}, nworkers + 1) exit_criteria = {"wallclock_max": 10} @@ -97,7 +102,9 @@ for i in range(iterations): # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs=libE_specs + ) if is_manager: print("\nChecking expected task status against Workers ...\n") diff --git a/libensemble/tests/functionality_tests/test_executor_simple.py b/libensemble/tests/functionality_tests/test_executor_simple.py index ac4c201a7..729b1ddf6 100644 --- a/libensemble/tests/functionality_tests/test_executor_simple.py +++ b/libensemble/tests/functionality_tests/test_executor_simple.py @@ -12,6 +12,7 @@ import numpy as np import libensemble.sim_funcs.six_hump_camel as six_hump_camel +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.executors.mpi_executor import MPIExecutor from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f from libensemble.libE import libE @@ -61,8 +62,12 @@ # num sim_ended_count conditions in executor_hworld exit_criteria = {"sim_max": nworkers * 5} + alloc_specs = { + "alloc_f": give_sim_work_first, + } + # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs=libE_specs) if is_manager: print("\nChecking expected task status against Workers ...\n") diff --git a/libensemble/tests/functionality_tests/test_local_sine_tutorial.py b/libensemble/tests/functionality_tests/test_local_sine_tutorial.py index e05a49c96..26a38b3e3 100644 --- a/libensemble/tests/functionality_tests/test_local_sine_tutorial.py +++ b/libensemble/tests/functionality_tests/test_local_sine_tutorial.py @@ -3,7 +3,8 @@ from sine_sim import sim_find_sine from libensemble import Ensemble -from libensemble.specs import ExitCriteria, GenSpecs, LibeSpecs, SimSpecs +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first +from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, LibeSpecs, SimSpecs if __name__ == "__main__": # Python-quirk required on macOS and windows libE_specs = LibeSpecs(nworkers=4, comms="local") @@ -27,6 +28,7 @@ exit_criteria = ExitCriteria(sim_max=80) # Stop libEnsemble after 80 simulations ensemble = Ensemble(sim_specs, gen_specs, exit_criteria, libE_specs) + ensemble.alloc_specs = AllocSpecs(alloc_f=give_sim_work_first) ensemble.add_random_streams() # setup the random streams unique to each worker ensemble.run() # start the ensemble. Blocks until completion. diff --git a/libensemble/tests/functionality_tests/test_local_sine_tutorial_2.py b/libensemble/tests/functionality_tests/test_local_sine_tutorial_2.py index 11911f343..75291ac44 100644 --- a/libensemble/tests/functionality_tests/test_local_sine_tutorial_2.py +++ b/libensemble/tests/functionality_tests/test_local_sine_tutorial_2.py @@ -3,7 +3,8 @@ from sine_sim import sim_find_sine from libensemble import Ensemble -from libensemble.specs import ExitCriteria, GenSpecs, LibeSpecs, SimSpecs +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first +from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, LibeSpecs, SimSpecs if __name__ == "__main__": libE_specs = LibeSpecs(nworkers=4, comms="local") @@ -24,9 +25,11 @@ out=[("y", float)], # sim_f output. "y" = sine("x") ) + alloc_specs = AllocSpecs(alloc_f=give_sim_work_first) + exit_criteria = ExitCriteria(gen_max=160) - ensemble = Ensemble(sim_specs, gen_specs, exit_criteria, libE_specs) + ensemble = Ensemble(sim_specs, gen_specs, exit_criteria, libE_specs, alloc_specs) ensemble.add_random_streams() ensemble.run() diff --git a/libensemble/tests/functionality_tests/test_local_sine_tutorial_3.py b/libensemble/tests/functionality_tests/test_local_sine_tutorial_3.py index d57a0f842..6672feb9f 100644 --- a/libensemble/tests/functionality_tests/test_local_sine_tutorial_3.py +++ b/libensemble/tests/functionality_tests/test_local_sine_tutorial_3.py @@ -3,7 +3,8 @@ from sine_sim import sim_find_sine from libensemble import Ensemble -from libensemble.specs import ExitCriteria, GenSpecs, SimSpecs +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first +from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, SimSpecs if __name__ == "__main__": # Python-quirk required on macOS and windows # libE_specs = LibeSpecs(nworkers=4, comms="local") @@ -26,8 +27,10 @@ exit_criteria = ExitCriteria(sim_max=80) # Stop libEnsemble after 80 simulations + alloc_specs = AllocSpecs(alloc_f=give_sim_work_first) + # replace libE_specs with parse_args=True. Detects MPI runtime - ensemble = Ensemble(sim_specs, gen_specs, exit_criteria, parse_args=True) + ensemble = Ensemble(sim_specs, gen_specs, exit_criteria, alloc_specs=alloc_specs, parse_args=True) ensemble.add_random_streams() ensemble.run() # start the ensemble. Blocks until completion. diff --git a/libensemble/tests/functionality_tests/test_mpi_runners.py b/libensemble/tests/functionality_tests/test_mpi_runners.py index af00471d5..7c69e240c 100644 --- a/libensemble/tests/functionality_tests/test_mpi_runners.py +++ b/libensemble/tests/functionality_tests/test_mpi_runners.py @@ -12,6 +12,7 @@ import numpy as np from libensemble import logger +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.executors.mpi_executor import MPIExecutor from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f from libensemble.libE import libE @@ -233,8 +234,10 @@ def run_tests(mpi_runner, runner_name, test_list_exargs, exp_list): "tests": test_list, } + alloc_specs = {"alloc_f": give_sim_work_first} + # Perform the run - H, pinfo, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, pinfo, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs=libE_specs) # for run_set in ['mpich', 'openmpi', 'aprun', 'srun', 'jsrun', 'rename_mpich', 'custom']: for run_set in ["mpich", "aprun", "srun", "jsrun", "rename_mpich", "custom"]: diff --git a/libensemble/tests/functionality_tests/test_mpi_runners_subnode.py b/libensemble/tests/functionality_tests/test_mpi_runners_subnode.py index 7266678ff..223c4dfb3 100644 --- a/libensemble/tests/functionality_tests/test_mpi_runners_subnode.py +++ b/libensemble/tests/functionality_tests/test_mpi_runners_subnode.py @@ -16,6 +16,7 @@ import numpy as np from libensemble import logger +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.executors.mpi_executor import MPIExecutor from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f from libensemble.libE import libE @@ -91,6 +92,8 @@ }, } + alloc_specs = {"alloc_f": give_sim_work_first} + persis_info = add_unique_random_streams({}, nworkers + 1) exit_criteria = {"sim_max": (nsim_workers) * rounds} @@ -118,6 +121,6 @@ } # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs=libE_specs) # All asserts are in sim func diff --git a/libensemble/tests/functionality_tests/test_mpi_runners_subnode_uneven.py b/libensemble/tests/functionality_tests/test_mpi_runners_subnode_uneven.py index a5145965b..941733996 100644 --- a/libensemble/tests/functionality_tests/test_mpi_runners_subnode_uneven.py +++ b/libensemble/tests/functionality_tests/test_mpi_runners_subnode_uneven.py @@ -14,6 +14,7 @@ import numpy as np from libensemble import logger +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.executors.mpi_executor import MPIExecutor from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f from libensemble.libE import libE @@ -92,6 +93,8 @@ }, } + alloc_specs = {"alloc_f": give_sim_work_first} + persis_info = add_unique_random_streams({}, nworkers + 1) exit_criteria = {"sim_max": (nsim_workers) * rounds} @@ -137,6 +140,6 @@ } # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs=libE_specs) # All asserts are in sim func diff --git a/libensemble/tests/functionality_tests/test_mpi_runners_supernode_uneven.py b/libensemble/tests/functionality_tests/test_mpi_runners_supernode_uneven.py index 77975e200..329a2aa1b 100644 --- a/libensemble/tests/functionality_tests/test_mpi_runners_supernode_uneven.py +++ b/libensemble/tests/functionality_tests/test_mpi_runners_supernode_uneven.py @@ -11,6 +11,7 @@ import numpy as np from libensemble import logger +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.executors.mpi_executor import MPIExecutor from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f from libensemble.libE import libE @@ -131,7 +132,9 @@ "expect": exp_list, } + alloc_specs = {"alloc_f": give_sim_work_first} + # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs=libE_specs) # All asserts are in sim func diff --git a/libensemble/tests/functionality_tests/test_mpi_runners_zrw_subnode_uneven.py b/libensemble/tests/functionality_tests/test_mpi_runners_zrw_subnode_uneven.py index cc73d0e42..aa2a1a8eb 100644 --- a/libensemble/tests/functionality_tests/test_mpi_runners_zrw_subnode_uneven.py +++ b/libensemble/tests/functionality_tests/test_mpi_runners_zrw_subnode_uneven.py @@ -21,7 +21,6 @@ import numpy as np from libensemble import logger -from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f from libensemble.executors.mpi_executor import MPIExecutor from libensemble.gen_funcs.persistent_sampling import persistent_uniform as gen_f from libensemble.libE import libE @@ -100,7 +99,6 @@ }, } - alloc_specs = {"alloc_f": alloc_f} exit_criteria = {"sim_max": (nsim_workers) * rounds} test_list_base = [ @@ -161,5 +159,5 @@ persis_info = add_unique_random_streams({}, nworkers + 1) # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs) + H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) # Run-line asserts are in sim func diff --git a/libensemble/tests/functionality_tests/test_mpi_runners_zrw_supernode_uneven.py b/libensemble/tests/functionality_tests/test_mpi_runners_zrw_supernode_uneven.py index 640d613bf..f52aced21 100644 --- a/libensemble/tests/functionality_tests/test_mpi_runners_zrw_supernode_uneven.py +++ b/libensemble/tests/functionality_tests/test_mpi_runners_zrw_supernode_uneven.py @@ -11,7 +11,6 @@ import numpy as np from libensemble import logger -from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f from libensemble.executors.mpi_executor import MPIExecutor from libensemble.gen_funcs.persistent_sampling import persistent_uniform as gen_f from libensemble.libE import libE @@ -86,7 +85,6 @@ }, } - alloc_specs = {"alloc_f": alloc_f} persis_info = add_unique_random_streams({}, nworkers + 1) exit_criteria = {"sim_max": (nsim_workers) * rounds} @@ -139,6 +137,6 @@ } # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs) + H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) # All asserts are in sim func diff --git a/libensemble/tests/functionality_tests/test_mpi_warning.py b/libensemble/tests/functionality_tests/test_mpi_warning.py index daf6125b6..ab7ac3664 100644 --- a/libensemble/tests/functionality_tests/test_mpi_warning.py +++ b/libensemble/tests/functionality_tests/test_mpi_warning.py @@ -17,11 +17,12 @@ import numpy as np from libensemble import Ensemble, logger +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import latin_hypercube_sample as gen_f # Import libEnsemble items for this test from libensemble.sim_funcs.simple_sim import norm_eval as sim_f -from libensemble.specs import ExitCriteria, GenSpecs, SimSpecs +from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, SimSpecs # Main block is necessary only when using local comms with spawn start method (default on macOS and Windows). if __name__ == "__main__": @@ -41,6 +42,7 @@ "ub": np.array([3, 2]), }, ) + sampling.alloc_specs = AllocSpecs(alloc_f=give_sim_work_first) sampling.exit_criteria = ExitCriteria(sim_max=100) sampling.add_random_streams() diff --git a/libensemble/tests/functionality_tests/test_new_field.py b/libensemble/tests/functionality_tests/test_new_field.py index c130b1d6e..bb7365c67 100644 --- a/libensemble/tests/functionality_tests/test_new_field.py +++ b/libensemble/tests/functionality_tests/test_new_field.py @@ -15,6 +15,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import latin_hypercube_sample as gen_f # Import libEnsemble items for this test @@ -48,11 +49,17 @@ def sim_f(In): }, } + alloc_specs = { + "alloc_f": give_sim_work_first, + } + persis_info = add_unique_random_streams({}, nworkers + 1, seed=1234) exit_criteria = {"gen_max": 501} - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs=alloc_specs, libE_specs=libE_specs + ) if is_manager: assert len(H) >= 501 diff --git a/libensemble/tests/functionality_tests/test_persistent_uniform_sampling.py b/libensemble/tests/functionality_tests/test_persistent_uniform_sampling.py index 81a18a528..50c9fd9ce 100644 --- a/libensemble/tests/functionality_tests/test_persistent_uniform_sampling.py +++ b/libensemble/tests/functionality_tests/test_persistent_uniform_sampling.py @@ -20,7 +20,6 @@ import numpy as np -from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f from libensemble.gen_funcs.persistent_sampling import batched_history_matching as gen_f2 from libensemble.gen_funcs.persistent_sampling import persistent_uniform as gen_f1 @@ -56,8 +55,6 @@ }, } - alloc_specs = {"alloc_f": alloc_f} - exit_criteria = {"gen_max": num_batches * batch, "wallclock_max": 300} libE_specs["kill_canceled_sims"] = False @@ -93,7 +90,7 @@ libE_specs["gen_workers"] = [2] # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs) + H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) if is_manager: assert len(np.unique(H["gen_ended_time"])) == num_batches diff --git a/libensemble/tests/functionality_tests/test_persistent_uniform_sampling_nonblocking.py b/libensemble/tests/functionality_tests/test_persistent_uniform_sampling_nonblocking.py index 542557884..c9e92a6c4 100644 --- a/libensemble/tests/functionality_tests/test_persistent_uniform_sampling_nonblocking.py +++ b/libensemble/tests/functionality_tests/test_persistent_uniform_sampling_nonblocking.py @@ -20,7 +20,6 @@ import numpy as np -from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f from libensemble.gen_funcs.persistent_sampling import uniform_nonblocking as gen_f # Import libEnsemble items for this test @@ -53,8 +52,6 @@ }, } - alloc_specs = {"alloc_f": alloc_f} - persis_info = add_unique_random_streams({}, nworkers + 1) for i in persis_info: persis_info[i]["get_grad"] = True @@ -62,7 +59,7 @@ exit_criteria = {"gen_max": 40, "wallclock_max": 300} # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs) + H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) if is_manager: assert len(np.unique(H["gen_ended_time"])) == 2 diff --git a/libensemble/tests/functionality_tests/test_persistent_uniform_sampling_running_mean.py b/libensemble/tests/functionality_tests/test_persistent_uniform_sampling_running_mean.py index 9cc92dadd..9c915c82a 100644 --- a/libensemble/tests/functionality_tests/test_persistent_uniform_sampling_running_mean.py +++ b/libensemble/tests/functionality_tests/test_persistent_uniform_sampling_running_mean.py @@ -20,7 +20,6 @@ import numpy as np -from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f from libensemble.gen_funcs.persistent_sampling import persistent_uniform_final_update as gen_f from libensemble.libE import libE from libensemble.sim_funcs.six_hump_camel import six_hump_camel_simple as sim_f @@ -57,8 +56,6 @@ }, } - alloc_specs = {"alloc_f": alloc_f} - sim_max = 120 exit_criteria = {"sim_max": sim_max} libE_specs["final_gen_send"] = True @@ -72,7 +69,7 @@ } persis_info = add_unique_random_streams({}, nworkers + 1) - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs) + H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) if is_manager: # Check that last saved history agrees with returned history. diff --git a/libensemble/tests/functionality_tests/test_sim_dirs_per_calc.py b/libensemble/tests/functionality_tests/test_sim_dirs_per_calc.py index b4c30f9d2..9e1362b27 100644 --- a/libensemble/tests/functionality_tests/test_sim_dirs_per_calc.py +++ b/libensemble/tests/functionality_tests/test_sim_dirs_per_calc.py @@ -18,6 +18,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f from libensemble.libE import libE from libensemble.tests.regression_tests.support import write_sim_func as sim_f @@ -61,11 +62,17 @@ }, } + alloc_specs = { + "alloc_f": give_sim_work_first, + } + persis_info = add_unique_random_streams({}, nworkers + 1) exit_criteria = {"sim_max": 21} - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs=alloc_specs, libE_specs=libE_specs + ) if is_manager: assert os.path.isdir(c_ensemble), f"Ensemble directory {c_ensemble} not created." diff --git a/libensemble/tests/functionality_tests/test_sim_dirs_per_worker.py b/libensemble/tests/functionality_tests/test_sim_dirs_per_worker.py index 69bb34ab8..249a3e9e1 100644 --- a/libensemble/tests/functionality_tests/test_sim_dirs_per_worker.py +++ b/libensemble/tests/functionality_tests/test_sim_dirs_per_worker.py @@ -18,6 +18,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f from libensemble.libE import libE from libensemble.tests.regression_tests.support import write_sim_func as sim_f @@ -60,11 +61,17 @@ }, } + alloc_specs = { + "alloc_f": give_sim_work_first, + } + persis_info = add_unique_random_streams({}, nworkers + 1) exit_criteria = {"sim_max": 21} - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs=alloc_specs, libE_specs=libE_specs + ) if is_manager: assert os.path.isdir(w_ensemble), f"Ensemble directory {w_ensemble} not created." diff --git a/libensemble/tests/functionality_tests/test_sim_dirs_with_exception.py b/libensemble/tests/functionality_tests/test_sim_dirs_with_exception.py index 229f6d5f5..b3f951ab0 100644 --- a/libensemble/tests/functionality_tests/test_sim_dirs_with_exception.py +++ b/libensemble/tests/functionality_tests/test_sim_dirs_with_exception.py @@ -18,6 +18,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f from libensemble.libE import libE from libensemble.manager import LoggedException @@ -53,13 +54,19 @@ }, } + alloc_specs = { + "alloc_f": give_sim_work_first, + } + persis_info = add_unique_random_streams({}, nworkers + 1) exit_criteria = {"sim_max": 21} return_flag = 1 try: - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs=libE_specs + ) except LoggedException as e: print(f"Caught deliberate exception: {e}") return_flag = 0 diff --git a/libensemble/tests/functionality_tests/test_sim_dirs_with_gen_dirs.py b/libensemble/tests/functionality_tests/test_sim_dirs_with_gen_dirs.py index c73eeabad..cbf8d5244 100644 --- a/libensemble/tests/functionality_tests/test_sim_dirs_with_gen_dirs.py +++ b/libensemble/tests/functionality_tests/test_sim_dirs_with_gen_dirs.py @@ -18,6 +18,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.libE import libE from libensemble.tests.regression_tests.support import write_sim_func as sim_f from libensemble.tests.regression_tests.support import write_uniform_gen_func as gen_f @@ -76,7 +77,13 @@ exit_criteria = {"sim_max": 20} - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + alloc_specs = { + "alloc_f": give_sim_work_first, + } + + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs=alloc_specs, libE_specs=libE_specs + ) def check_copied(type): input_copied = [] diff --git a/libensemble/tests/functionality_tests/test_sim_input_dir_option.py b/libensemble/tests/functionality_tests/test_sim_input_dir_option.py index 7dc4da705..906d4d8c1 100644 --- a/libensemble/tests/functionality_tests/test_sim_input_dir_option.py +++ b/libensemble/tests/functionality_tests/test_sim_input_dir_option.py @@ -18,6 +18,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f from libensemble.libE import libE from libensemble.tests.regression_tests.support import write_sim_func as sim_f @@ -60,7 +61,13 @@ exit_criteria = {"sim_max": 21} - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + alloc_specs = { + "alloc_f": give_sim_work_first, + } + + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs=alloc_specs, libE_specs=libE_specs + ) if is_manager: assert os.path.isdir(o_ensemble), f"Ensemble directory {o_ensemble} not created." diff --git a/libensemble/tests/functionality_tests/test_uniform_sampling.py b/libensemble/tests/functionality_tests/test_uniform_sampling.py index 2867f94df..ba327c684 100644 --- a/libensemble/tests/functionality_tests/test_uniform_sampling.py +++ b/libensemble/tests/functionality_tests/test_uniform_sampling.py @@ -19,6 +19,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import uniform_random_sample # Import libEnsemble items for this test @@ -59,6 +60,10 @@ exit_criteria = {"gen_max": 501, "wallclock_max": 300} + alloc_specs = { + "alloc_f": give_sim_work_first, + } + for run in range(2): if run == 1: # Test running a mock sim using previous history file @@ -67,7 +72,9 @@ sim_specs["user"] = {"history_file": hfile} # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs=libE_specs + ) if is_manager: assert flag == 0 diff --git a/libensemble/tests/functionality_tests/test_worker_exceptions.py b/libensemble/tests/functionality_tests/test_worker_exceptions.py index 435e621e1..88cb6fcb0 100644 --- a/libensemble/tests/functionality_tests/test_worker_exceptions.py +++ b/libensemble/tests/functionality_tests/test_worker_exceptions.py @@ -16,6 +16,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f from libensemble.libE import libE from libensemble.manager import LoggedException @@ -52,10 +53,16 @@ # Tell libEnsemble when to stop exit_criteria = {"wallclock_max": 10} + alloc_specs = { + "alloc_f": give_sim_work_first, + } + # Perform the run return_flag = 1 try: - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs=alloc_specs, libE_specs=libE_specs + ) except LoggedException as e: print(f"Caught deliberate exception: {e}") return_flag = 0 diff --git a/libensemble/tests/functionality_tests/test_workflow_dir.py b/libensemble/tests/functionality_tests/test_workflow_dir.py index 1abbc10bc..6c7550ac3 100644 --- a/libensemble/tests/functionality_tests/test_workflow_dir.py +++ b/libensemble/tests/functionality_tests/test_workflow_dir.py @@ -18,6 +18,7 @@ import numpy as np +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f from libensemble.libE import libE from libensemble.tests.regression_tests.support import write_sim_func as sim_f @@ -58,6 +59,10 @@ }, } + alloc_specs = { + "alloc_f": give_sim_work_first, + } + persis_info = add_unique_random_streams({}, nworkers + 1) exit_criteria = {"sim_max": 21} @@ -70,7 +75,9 @@ "./test_workflow" + str(i) + "_nworkers" + str(nworkers) + "_comms-" + libE_specs["comms"] ) - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) + H, persis_info, flag = libE( + sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs=alloc_specs, libE_specs=libE_specs + ) assert os.path.isdir(libE_specs["workflow_dir_path"]), "workflow_dir not created" assert all( diff --git a/libensemble/tests/regression_tests/test_1d_sampling.py b/libensemble/tests/regression_tests/test_1d_sampling.py index edecabb66..7009a329b 100644 --- a/libensemble/tests/regression_tests/test_1d_sampling.py +++ b/libensemble/tests/regression_tests/test_1d_sampling.py @@ -16,7 +16,7 @@ import numpy as np from libensemble import Ensemble -from libensemble.gen_funcs.sampling import latin_hypercube_sample as gen_f +from libensemble.gen_funcs.persistent_sampling import persistent_uniform # Import libEnsemble items for this test from libensemble.sim_funcs.simple_sim import norm_eval as sim_f @@ -29,10 +29,10 @@ sampling.libE_specs = LibeSpecs(save_every_k_gens=300, safe_mode=False, disable_log_files=True) sampling.sim_specs = SimSpecs(sim_f=sim_f) sampling.gen_specs = GenSpecs( - gen_f=gen_f, + gen_f=persistent_uniform, outputs=[("x", float, (1,))], user={ - "gen_batch_size": 100, + "initial_batch_size": 100, "lb": np.array([-3]), "ub": np.array([3]), }, diff --git a/libensemble/tests/regression_tests/test_2d_sampling.py b/libensemble/tests/regression_tests/test_2d_sampling.py index 8164c2844..a852a4a8b 100644 --- a/libensemble/tests/regression_tests/test_2d_sampling.py +++ b/libensemble/tests/regression_tests/test_2d_sampling.py @@ -16,11 +16,12 @@ import numpy as np from libensemble import Ensemble +from libensemble.alloc_funcs.give_sim_work_first import give_sim_work_first from libensemble.gen_funcs.sampling import latin_hypercube_sample as gen_f # Import libEnsemble items for this test from libensemble.sim_funcs.simple_sim import norm_eval as sim_f -from libensemble.specs import ExitCriteria, GenSpecs, LibeSpecs, SimSpecs +from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, LibeSpecs, SimSpecs # Main block is necessary only when using local comms with spawn start method (default on macOS and Windows). if __name__ == "__main__": @@ -37,6 +38,8 @@ }, ) + sampling.alloc_specs = AllocSpecs(alloc_f=give_sim_work_first) + sampling.exit_criteria = ExitCriteria(sim_max=200) sampling.add_random_streams() diff --git a/libensemble/tests/regression_tests/test_asktell_aposmm_nlopt.py b/libensemble/tests/regression_tests/test_asktell_aposmm_nlopt.py index 83e3bf625..9aba020a2 100644 --- a/libensemble/tests/regression_tests/test_asktell_aposmm_nlopt.py +++ b/libensemble/tests/regression_tests/test_asktell_aposmm_nlopt.py @@ -34,9 +34,8 @@ from gest_api.vocs import VOCS from libensemble import Ensemble -from libensemble.alloc_funcs.persistent_aposmm_alloc import persistent_aposmm_alloc as alloc_f from libensemble.gen_classes import APOSMM -from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, SimSpecs +from libensemble.specs import ExitCriteria, GenSpecs, SimSpecs from libensemble.tests.regression_tests.support import six_hump_camel_minima as minima # Main block is necessary only when using local comms with spawn start method (default on macOS and Windows). @@ -53,7 +52,6 @@ sys.exit("Cannot run with a persistent worker if only one worker -- aborting...") n = 2 - workflow.alloc_specs = AllocSpecs(alloc_f=alloc_f) vocs = VOCS( variables={"core": [-3, 3], "edge": [-2, 2], "core_on_cube": [-3, 3], "edge_on_cube": [-2, 2]}, diff --git a/libensemble/tests/regression_tests/test_asktell_gpCAM.py b/libensemble/tests/regression_tests/test_asktell_gpCAM.py index b093a0df7..f59fc135d 100644 --- a/libensemble/tests/regression_tests/test_asktell_gpCAM.py +++ b/libensemble/tests/regression_tests/test_asktell_gpCAM.py @@ -24,7 +24,6 @@ import numpy as np from gest_api.vocs import VOCS -from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f from libensemble.gen_classes.gpCAM import GP_CAM, GP_CAM_Covar # Import libEnsemble items for this test @@ -65,8 +64,6 @@ vocs = VOCS(variables={"x0": [-3, 3], "x1": [-2, 2], "x2": [-1, 1], "x3": [-1, 1]}, objectives={"f": "MINIMIZE"}) - alloc_specs = {"alloc_f": alloc_f} - gen = GP_CAM_Covar(vocs) for inst in range(3): @@ -89,7 +86,7 @@ exit_criteria = {"sim_max": num_batches * batch_size, "wallclock_max": 300} # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, {}, alloc_specs, libE_specs) + H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, {}, libE_specs=libE_specs) if is_manager: assert len(np.unique(H["gen_ended_time"])) == num_batches diff --git a/libensemble/tests/regression_tests/test_gpCAM.py b/libensemble/tests/regression_tests/test_gpCAM.py index 218ecfc91..b5074ac61 100644 --- a/libensemble/tests/regression_tests/test_gpCAM.py +++ b/libensemble/tests/regression_tests/test_gpCAM.py @@ -28,7 +28,6 @@ import numpy as np -from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f from libensemble.gen_funcs.persistent_gpCAM import persistent_gpCAM, persistent_gpCAM_covar # Import libEnsemble items for this test @@ -67,8 +66,6 @@ }, } - alloc_specs = {"alloc_f": alloc_f} - for inst in range(3): if inst == 0: gen_specs["gen_f"] = persistent_gpCAM_covar @@ -91,7 +88,7 @@ persis_info = add_unique_random_streams({}, nworkers + 1) # Perform the run - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs) + H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) if is_manager: assert len(np.unique(H["gen_ended_time"])) == num_batches diff --git a/libensemble/tests/regression_tests/test_optimas_grid_sample.py b/libensemble/tests/regression_tests/test_optimas_grid_sample.py index 57c6c8fed..c390be8ca 100644 --- a/libensemble/tests/regression_tests/test_optimas_grid_sample.py +++ b/libensemble/tests/regression_tests/test_optimas_grid_sample.py @@ -24,8 +24,7 @@ from optimas.generators import GridSamplingGenerator from libensemble import Ensemble -from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f -from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, LibeSpecs, SimSpecs +from libensemble.specs import ExitCriteria, GenSpecs, LibeSpecs, SimSpecs def eval_func(input_params: dict): @@ -73,13 +72,11 @@ def eval_func(input_params: dict): vocs=vocs, ) - alloc_specs = AllocSpecs(alloc_f=alloc_f) exit_criteria = ExitCriteria(sim_max=n_evals) workflow = Ensemble( libE_specs=libE_specs, sim_specs=sim_specs, - alloc_specs=alloc_specs, gen_specs=gen_specs, exit_criteria=exit_criteria, ) diff --git a/libensemble/tests/regression_tests/test_persistent_tasmanian.py b/libensemble/tests/regression_tests/test_persistent_tasmanian.py index 269c4ba59..c45adaca2 100644 --- a/libensemble/tests/regression_tests/test_persistent_tasmanian.py +++ b/libensemble/tests/regression_tests/test_persistent_tasmanian.py @@ -22,7 +22,6 @@ import numpy as np -from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f from libensemble.gen_funcs.persistent_tasmanian import sparse_grid_batched as gen_f_batched # Import libEnsemble items for this test @@ -74,8 +73,6 @@ def tasmanian_init_localp(): "out": [("x", float, num_dimensions)], } - alloc_specs = {"alloc_f": alloc_f} - grid_files = [] for run in range(3): @@ -116,7 +113,7 @@ def tasmanian_init_localp(): gen_specs["user"]["sCriteria"] = "classic" gen_specs["user"]["iOutput"] = 0 - H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs, libE_specs) + H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs) if is_manager: grid_files.append(gen_specs["user"]["tasmanian_checkpoint_file"]) diff --git a/libensemble/tests/regression_tests/test_xopt_EI.py b/libensemble/tests/regression_tests/test_xopt_EI.py index bf114b38f..38a0cecd2 100644 --- a/libensemble/tests/regression_tests/test_xopt_EI.py +++ b/libensemble/tests/regression_tests/test_xopt_EI.py @@ -22,8 +22,7 @@ from xopt.generators.bayesian.expected_improvement import ExpectedImprovementGenerator from libensemble import Ensemble -from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f -from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, LibeSpecs, SimSpecs +from libensemble.specs import ExitCriteria, GenSpecs, LibeSpecs, SimSpecs # Adapted from Xopt/xopt/resources/testing.py @@ -83,13 +82,11 @@ def xtest_sim(H, persis_info, sim_specs, _): vocs=vocs, ) - alloc_specs = AllocSpecs(alloc_f=alloc_f) exit_criteria = ExitCriteria(sim_max=20) workflow = Ensemble( libE_specs=libE_specs, sim_specs=sim_specs, - alloc_specs=alloc_specs, gen_specs=gen_specs, exit_criteria=exit_criteria, ) diff --git a/libensemble/tests/regression_tests/test_xopt_EI_xopt_sim.py b/libensemble/tests/regression_tests/test_xopt_EI_xopt_sim.py index f2ff1453c..7d3ec5b87 100644 --- a/libensemble/tests/regression_tests/test_xopt_EI_xopt_sim.py +++ b/libensemble/tests/regression_tests/test_xopt_EI_xopt_sim.py @@ -22,8 +22,7 @@ from xopt.generators.bayesian.expected_improvement import ExpectedImprovementGenerator from libensemble import Ensemble -from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f -from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, LibeSpecs, SimSpecs +from libensemble.specs import ExitCriteria, GenSpecs, LibeSpecs, SimSpecs # From Xopt/xopt/resources/testing.py @@ -77,13 +76,11 @@ def xtest_callable(input_dict: dict, a=0) -> dict: vocs=vocs, ) - alloc_specs = AllocSpecs(alloc_f=alloc_f) exit_criteria = ExitCriteria(sim_max=20) workflow = Ensemble( libE_specs=libE_specs, sim_specs=sim_specs, - alloc_specs=alloc_specs, gen_specs=gen_specs, exit_criteria=exit_criteria, ) diff --git a/libensemble/tests/regression_tests/test_xopt_nelder_mead.py b/libensemble/tests/regression_tests/test_xopt_nelder_mead.py index 56e0daada..edefcd80e 100644 --- a/libensemble/tests/regression_tests/test_xopt_nelder_mead.py +++ b/libensemble/tests/regression_tests/test_xopt_nelder_mead.py @@ -20,8 +20,7 @@ from xopt.generators.sequential.neldermead import NelderMeadGenerator from libensemble import Ensemble -from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f -from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, LibeSpecs, SimSpecs +from libensemble.specs import ExitCriteria, GenSpecs, LibeSpecs, SimSpecs def rosenbrock_callable(input_dict: dict) -> dict: @@ -65,13 +64,11 @@ def rosenbrock_callable(input_dict: dict) -> dict: vocs=vocs, ) - alloc_specs = AllocSpecs(alloc_f=alloc_f) exit_criteria = ExitCriteria(sim_max=30) workflow = Ensemble( libE_specs=libE_specs, sim_specs=sim_specs, - alloc_specs=alloc_specs, gen_specs=gen_specs, exit_criteria=exit_criteria, ) diff --git a/libensemble/tests/unit_tests/test_ensemble.py b/libensemble/tests/unit_tests/test_ensemble.py index 271932573..501b14104 100644 --- a/libensemble/tests/unit_tests/test_ensemble.py +++ b/libensemble/tests/unit_tests/test_ensemble.py @@ -86,45 +86,6 @@ def test_bad_func_loads(): assert flag == 0 -def test_full_workflow(): - """Test initializing a workflow via Specs and Ensemble.run()""" - from libensemble.ensemble import Ensemble - from libensemble.gen_funcs.sampling import latin_hypercube_sample - from libensemble.sim_funcs.simple_sim import norm_eval - from libensemble.specs import ExitCriteria, GenSpecs, LibeSpecs, SimSpecs - - LS = LibeSpecs(comms="local", nworkers=4) - - # parameterizes and validates everything! - ens = Ensemble( - libE_specs=LS, - sim_specs=SimSpecs(sim_f=norm_eval), - gen_specs=GenSpecs( - gen_f=latin_hypercube_sample, - user={ - "gen_batch_size": 100, - "lb": np.array([-3]), - "ub": np.array([3]), - }, - ), - exit_criteria=ExitCriteria(gen_max=101), - ) - - ens.add_random_streams() - ens.run() - if ens.is_manager: - assert len(ens.H) >= 101 - - # test a dry run - ens.libE_specs.dry_run = True - flag = 1 - try: - ens.run() - except SystemExit: - flag = 0 - assert not flag, "Ensemble didn't exit after specifying dry_run" - - def test_flakey_workflow(): """Test initializing a workflow via Specs and Ensemble.run()""" from pydantic import ValidationError @@ -235,7 +196,6 @@ def test_local_comms_without_nworkers(): test_ensemble_parse_args_false() test_from_files() test_bad_func_loads() - test_full_workflow() test_flakey_workflow() test_ensemble_specs_update_libE_specs() test_ensemble_prevent_comms_overwrite()