/
call_6-hump_camel_test_elapsed_time.py
63 lines (52 loc) · 2.25 KB
/
call_6-hump_camel_test_elapsed_time.py
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
# """
# Runs libEnsemble on the 6-hump camel problem. Documented here:
# https://www.sfu.ca/~ssurjano/camel6.html
#
# Execute via the following command:
# mpiexec -np 4 python3 call_6-hump_camel_test_elapsed_time.py
# The number of concurrent evaluations of the objective function will be 4-1=3.
# """
from __future__ import division
from __future__ import absolute_import
from mpi4py import MPI # for libE communicator
import sys, os # for adding to path
import numpy as np
# Import libEnsemble main
#sys.path.append('../../src')
from libensemble.libE import libE
# Import sim_func
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../examples/sim_funcs'))
from libensemble.sim_funcs.six_hump_camel import six_hump_camel
# Import gen_func
#sys.path.append(os.path.join(os.path.dirname(__file__), '../../examples/gen_funcs'))
from libensemble.gen_funcs.uniform_sampling import uniform_random_sample
#State the objective function, its arguments, output, and necessary parameters (and their sizes)
sim_specs = {'sim_f': [six_hump_camel], # This is the function whose output is being minimized
'in': ['x'], # These keys will be given to the above function
'out': [('f',float), # This is the output from the function being minimized
],
'pause_time': 1,
# 'save_every_k': 10
}
# State the generating function, its arguments, output, and necessary parameters.
gen_specs = {'gen_f': uniform_random_sample,
'in': ['sim_id'],
'out': [('x',float,2),
],
'lb': np.array([-3,-2]),
'ub': np.array([ 3, 2]),
'gen_batch_size': 5,
'num_inst': 1,
'batch_mode': False,
# 'save_every_k': 10
}
# Tell libEnsemble when to stop
exit_criteria = {'elapsed_wallclock_time': 0.1}
np.random.seed(1)
# Perform the run
H, flag = libE(sim_specs, gen_specs, exit_criteria)
filename = '6-hump_camel_results_History_length=' + str(len(H)) + '_evals=' + str(sum(H['returned'])) + '_ranks=' + str(MPI.COMM_WORLD.Get_size())
print("\n\n\nRun completed.\nSaving results to file: " + filename)
if flag == 2:
print("\n\n\nKilling COMM_WORLD")
MPI.COMM_WORLD.Abort()