Skip to content
Merged
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
10 changes: 7 additions & 3 deletions libensemble/alloc_funcs/give_pregenerated_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ def give_pregenerated_sim_work(W, H, sim_specs, gen_specs, alloc_specs, persis_i
"""

Work = {}
if not persis_info:
persis_info['next_to_give'] = 0
# Unless already defined, initialize next_to_give to be the first point in H
persis_info['next_to_give'] = persis_info.get('next_to_give', 0)

assert persis_info['next_to_give'] < len(H), 'No more work to give inside give_pregenerated_sim_work.'
if persis_info['next_to_give'] >= len(H):
return Work, persis_info, 1

for i in avail_worker_ids(W):
# Give sim work
sim_work(Work, i, sim_specs['in'], [persis_info['next_to_give']], [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it check 'given' for the row its on - and increment if True?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That is possible. This allocation function is called give_pregenerated_sample so I think that it's okay to just go through all of the rows of H in order. (But I'm fine with checking given.)

Note that the top of this allocation function is not very robust: If there is persis_info then next_to_give will not be initialized. I hope that such issues will be addressed in our re-working of allocation functions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it just be checking the 'next_to_give' component is initialized? Something like:

persis_info['next_to_give'] = persis_info.get('next_to_give', 0) + 1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initialization is fixed in 8080b1b

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback!

persis_info['next_to_give'] += 1

if persis_info['next_to_give'] >= len(H):
break

return Work, persis_info
25 changes: 15 additions & 10 deletions libensemble/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,28 @@ def __init__(self, alloc_specs, sim_specs, gen_specs, exit_criteria, H0):

# Combine all 'out' fields (if they exist) in sim_specs, gen_specs, or alloc_specs
dtype_list = list(set(libE_fields + sum([k['out'] for k in [sim_specs, alloc_specs, gen_specs] if k], [])))
H = np.zeros(L + len(H0), dtype=dtype_list)
H = np.zeros(L + len(H0), dtype=dtype_list) # This may be more history than is needed if H0 has un-given points

if len(H0):
# Prepend H with H0
fields = H0.dtype.names

for field in fields:
H[field][:len(H0)] = H0[field]
# for ind, val in np.ndenumerate(H0[field]): # Works if H0[field] has arbitrary dimension but is slow
# H[field][ind] = val

# Prepend H with H0
H['sim_id'][:len(H0)] = np.arange(0, len(H0))
H['given'][:len(H0)] = 1
H['returned'][:len(H0)] = 1
if 'given' not in fields:
logger.manager_warning("Marking entries in H0 as having been 'given' and 'returned'")
H['given'][:len(H0)] = 1
H['returned'][:len(H0)] = 1
elif 'returned' not in fields:
logger.manager_warning("Marking entries in H0 as having been 'returned' if 'given'")
H['returned'][:len(H0)] = H0['given']

if 'sim_id' not in fields:
logger.manager_warning("Assigning sim_ids to entries in H0")
H['sim_id'][:len(H0)] = np.arange(0, len(H0))

H['sim_id'][-L:] = -1
H['given_time'][-L:] = np.inf
Expand All @@ -74,12 +82,9 @@ def __init__(self, alloc_specs, sim_specs, gen_specs, exit_criteria, H0):
self.offset = len(H0)
self.index = self.offset

# libE.check_inputs also checks that all points in H0 are 'returned', so gen and sim have been run.
# assert np.all(H0['given']), "H0 contains unreturned points. Exiting"
self.given_count = self.offset
self.given_count = np.sum(H['given'])

# assert np.all(H0['returned']), "H0 contains unreturned points. Exiting"
self.sim_count = self.offset
self.sim_count = np.sum(H['returned'])

def update_history_f(self, D):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
n_samp = 1000
n = 8

H0 = np.zeros(n_samp, dtype=[('x', float, 8), ('sim_id', int)])
H0 = np.zeros(n_samp, dtype=[('x', float, 8), ('sim_id', int), ('given', bool)])

np.random.seed(0)
H0['x'] = gen_borehole_input(n_samp)
H0['sim_id'] = range(n_samp)
H0['given'] = False

alloc_specs = {'alloc_f': alloc_f, 'out': [('x', float, n)]}

Expand Down