Skip to content

Commit

Permalink
Merge pull request #481 from Libensemble/feature/updated_vtmop
Browse files Browse the repository at this point in the history
Adding example call showing how to re-start vtmop
  • Loading branch information
jmlarson1 committed Jun 19, 2020
2 parents 4fa93c9 + 55000b0 commit 1d323a0
Showing 1 changed file with 54 additions and 15 deletions.
69 changes: 54 additions & 15 deletions libensemble/tests/regression_tests/test_vtmop.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
# TESTSUITE_NPROCS:

import numpy as np
import os
import time
from libensemble.utils.timer import Timer

# Import libEnsemble items for this test
from libensemble.libE import libE
Expand All @@ -32,6 +35,8 @@
from libensemble.alloc_funcs.only_one_gen_alloc import ensure_one_active_gen as alloc_f
from libensemble.tools import parse_args, save_libE_output, add_unique_random_streams

timer = Timer()

# Set the problem dimensions here
num_dims = 5
num_objs = 3
Expand Down Expand Up @@ -103,41 +108,75 @@ def sim_f(H, *unused):
# Set up the allocator
alloc_specs = {'alloc_f': alloc_f, 'out': []}

for run in range(2):
if run == 1:
s1 = []
H = []

for run in range(3):
if run == 0:
H0 = None
# Run for 1100 evaluations or 300 seconds
exit_criteria = {'sim_max': 1100, 'elapsed_wallclock_time': 300}

elif run == 1:
# In the second run, we initialize VTMOP with an initial sample:
np.random.seed(0)
sample_size = 1000
X = np.random.uniform(gen_specs['user']['lb'], gen_specs['user']['ub'], (sample_size, num_dims))
f = np.zeros((sample_size, num_objs))
size = 1000
X = np.random.uniform(gen_specs['user']['lb'], gen_specs['user']['ub'], (size, num_dims))
f = np.zeros((size, num_objs))

H0 = np.zeros(sample_size, dtype=[('x', float, num_dims), ('f', float, num_objs), ('sim_id', int),
('returned', bool), ('given', bool)])
H0 = np.zeros(size, dtype=[('x', float, num_dims), ('f', float, num_objs), ('sim_id', int),
('returned', bool), ('given', bool)])
H0['x'] = X
H0['sim_id'] = range(sample_size)
H0['sim_id'] = range(size)
H0[['given', 'returned']] = True

for i in range(sample_size):
for i in range(size):
Out, _ = sim_f(H0[[i]])
H0['f'][i] = Out['f']

gen_specs['user']['first_batch_size'] = 0
else:
H0 = None
# Run for 1100 evaluations or 300 seconds
exit_criteria = {'sim_max': 1100, 'elapsed_wallclock_time': 300}

elif run == 2:
# In the third run, we restart VTMOP by loading in the history array saved in run==1
gen_specs['user']['use_chkpt'] = True

if is_master:
os.rename('vtmop.chkpt_finishing_' + s1, 'vtmop.chkpt')
np.save('H_for_vtmop_restart.npy', H)
open('manager_done_file', 'w').close()
else:
while not os.path.isfile('manager_done_file'):
time.sleep(0.1)
H = np.load('H_for_vtmop_restart.npy')

size = sum(H['returned'])
H0 = np.zeros(size, dtype=[('x', float, num_dims), ('f', float, num_objs), ('sim_id', int),
('returned', bool), ('given', bool)])
H0['x'] = H['x'][:size]
H0['sim_id'] = range(size)
H0[['given', 'returned']] = True
H0['f'] = H['f'][:size]

# Run for 100 more evaluations or 300 seconds
exit_criteria = {'sim_max': size+100, 'elapsed_wallclock_time': 300}

# Persistent info between iterations
persis_info = add_unique_random_streams({}, nworkers + 1)
persis_info['next_to_give'] = 0
persis_info['total_gen_calls'] = 0

# Run for 2000 evaluations or 300 seconds
exit_criteria = {'sim_max': 1100, 'elapsed_wallclock_time': 300}

# Perform the run
H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info,
alloc_specs=alloc_specs, libE_specs=libE_specs, H0=H0)

# The master takes care of checkpointint/output
# The master takes care of checkpointing/output
if is_master:
# Renaming vtmop checkpointing file, if needed for later use.
timer.start()
s1 = timer.date_start.replace(' ', '_')
os.rename('vtmop.chkpt', 'vtmop.chkpt_finishing_' + s1)

assert flag == 0
save_libE_output(H, persis_info, __file__, nworkers)

0 comments on commit 1d323a0

Please sign in to comment.