-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathfast_alloc.py
More file actions
57 lines (45 loc) · 2.43 KB
/
fast_alloc.py
File metadata and controls
57 lines (45 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from libensemble.tools.alloc_support import AllocSupport, InsufficientFreeResources
def give_sim_work_first(W, H, sim_specs, gen_specs, alloc_specs, persis_info, libE_info):
"""
This allocation function gives (in order) entries in ``H`` to idle workers
to evaluate in the simulation function. The fields in ``sim_specs["in"]``
are given. If all entries in `H` have been given a be evaluated, a worker
is told to call the generator function, provided this wouldn't result in
more than ``alloc_specs["user"]["num_active_gen"]`` active generators.
This fast_alloc variation of give_sim_work_first is useful for cases that
simply iterate through H, issuing evaluations in order and, in particular,
is likely to be faster if there will be many short simulation evaluations,
given that this function contains fewer column length operations.
tags: alloc, simple, fast
.. seealso::
`test_fast_alloc.py <https://github.com/Libensemble/libensemble/blob/develop/libensemble/tests/functionality_tests/test_fast_alloc.py>`_ # noqa
"""
if libE_info["sim_max_given"] or not libE_info["any_idle_workers"]:
return {}, persis_info
user = alloc_specs.get("user", {})
manage_resources = libE_info["use_resource_sets"]
support = AllocSupport(W, manage_resources, persis_info, libE_info)
gen_count = support.count_gens()
Work = {}
gen_in = gen_specs.get("in", [])
# Give sim work if possible
for wid in support.avail_worker_ids(gen_workers=False):
persis_info = support.skip_canceled_points(H, persis_info)
if persis_info["next_to_give"] < len(H):
try:
Work[wid] = support.sim_work(wid, H, sim_specs["in"], [persis_info["next_to_give"]], [])
except InsufficientFreeResources:
break
persis_info["next_to_give"] += 1
# Give gen work if possible
if persis_info["next_to_give"] >= len(H):
for wid in support.avail_worker_ids(gen_workers=True):
if wid not in Work and gen_count < user.get("num_active_gens", gen_count + 1):
return_rows = range(len(H)) if gen_in else []
try:
Work[wid] = support.gen_work(wid, gen_in, return_rows, persis_info.get(wid))
except InsufficientFreeResources:
break
gen_count += 1
persis_info["total_gen_calls"] += 1
return Work, persis_info