Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/data_structures/alloc_specs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
35 changes: 19 additions & 16 deletions docs/examples/alloc_funcs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,31 @@ Many users use these unmodified.
.. IMPORTANT::
See the API for allocation functions :ref:`here<api_alloc_f>`.

**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<gswf_label>`.

The most commonly used (for persistent generators) is :ref:`start_only_persistent<start_only_persistent_label>`.
The default allocation function for persistent generators is :ref:`start_only_persistent<start_only_persistent_label>`.

The most commonly used allocation function for non-persistent generators is :ref:`give_sim_work_first<gswf_label>`.

.. 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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/function_guides/allocator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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<gswf_label>` for more information about ``give_sim_work_first``.
:ref:`here<start_only_persistent_label>` for more information.
8 changes: 6 additions & 2 deletions libensemble/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pydantic
from pydantic import BaseModel, Field

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"]

Expand Down Expand Up @@ -126,10 +126,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}
Expand Down
3 changes: 3 additions & 0 deletions libensemble/tests/functionality_tests/1d_sampling.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
"user": {
"gen_batch_size": 500
}
},
"alloc_specs": {
"alloc_f": "libensemble.alloc_funcs.give_sim_work_first.give_sim_work_first"
}
}
3 changes: 3 additions & 0 deletions libensemble/tests/functionality_tests/1d_sampling.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions libensemble/tests/functionality_tests/1d_sampling.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion libensemble/tests/functionality_tests/test_1d_splitcomm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion libensemble/tests/functionality_tests/test_1d_subcomm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion libensemble/tests/functionality_tests/test_comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Loading