Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

58

59

60

61

62

63

64

65

#alloc_func 

 

from __future__ import division 

from __future__ import absolute_import 

import numpy as np 

 

from libensemble.alloc_funcs.support import \ 

avail_worker_ids, sim_work, gen_work, count_persis_gens 

 

 

def only_persistent_gens_for_inverse_bayes(W, H, sim_specs, gen_specs, persis_info): 

""" 

Starts up to gen_count number of persistent generators. 

These persistent generators produce points (x) in batches and subbatches. 

The points x are given in subbatches to workers to perform a calculation. 

When all subbatches have returned, their output is given back to the 

corresponding persistent generator. 

 

The first time called there are no persis_w 1st for loop is not done 

""" 

 

Work = {} 

gen_count = count_persis_gens(W) 

 

# If i is idle, but in persistent mode, and generated work has all returned 

# give output back to i. Otherwise, give nothing to i 

for i in avail_worker_ids(W, persistent=True): 

 

# if > 1 persistant generator, assign the correct work to it 

inds_generated_by_i = (H['gen_worker'] == i) 

if np.all(H['returned'][inds_generated_by_i]): 

 

# Has sim_f completed everything from this persistent worker? 

# Then give back everything in the last batch 

batch_ids = H['batch'][inds_generated_by_i] 

last_batch_inds = (batch_ids == np.max(batch_ids)) 

inds_to_send_back = np.where(np.logical_and(inds_generated_by_i, 

last_batch_inds))[0] 

if H['batch'][-1] > 0: 

n = gen_specs['subbatch_size']*gen_specs['num_subbatches'] 

k = H['batch'][-1] 

H['weight'][(n*(k-1)):(n*k)] = H['weight'][(n*k):(n*(k+1))] 

 

gen_work(Work, i, ['like'], persis_info[i], 

np.atleast_1d(inds_to_send_back), persistent=True) 

 

task_avail = ~H['given'] 

for i in avail_worker_ids(W, persistent=False): 

if np.any(task_avail): 

 

# perform sim evaluations (if any point hasn't been given). 

sim_subbatches = H['subbatch'][task_avail] 

sim_inds = (sim_subbatches == np.min(sim_subbatches)) 

sim_ids_to_send = np.nonzero(task_avail)[0][sim_inds] 

sim_work(Work, i, sim_specs['in'], np.atleast_1d(sim_ids_to_send)) 

task_avail[sim_ids_to_send] = False 

 

elif gen_count == 0: 

 

# Finally, generate points since there is nothing else to do. 

gen_count += 1 

gen_work(Work, i, gen_specs['in'], persis_info[i], 

[], persistent=True) 

 

return Work, persis_info