Generator Specs
Used to specify the generator function, its inputs and outputs, and user data.
Can be constructed and passed to libEnsemble as a Python class or a dictionary.
1...
2import numpy as np
3from libensemble import GenSpecs
4from generator import gen_random_sample
5
6...
7
8gen_specs = GenSpecs(
9 gen_f=gen_random_sample,
10 out=[("x", float, (1,))],
11 user={
12 "lower": np.array([-3]),
13 "upper": np.array([3]),
14 "gen_batch_size": 5,
15 },
16)
17...
- pydantic model libensemble.specs.GenSpecs
- Fields:
1...
2import numpy as np
3from generator import gen_random_sample
4
5...
6
7gen_specs = {
8 "gen_f": gen_random_sample,
9 "out": [("x", float, (1,))],
10 "user": {
11 "lower": np.array([-3]),
12 "upper": np.array([3]),
13 "gen_batch_size": 5,
14 },
15}
See also
test_uniform_sampling.py: the generator function
uniform_random_sample
in sampling.py will generate 500 random points uniformly over the 2D domain defined bygen_specs["ub"]
andgen_specs["lb"]
.
gen_specs = {
"gen_f": uniform_random_sample, # Function generating sim_f input
"out": [("x", float, (2,))], # Tell libE gen_f output, type, size
"user": {
"gen_batch_size": 500, # Used by this specific gen_f
"lb": np.array([-3, -2]), # Used by this specific gen_f
"ub": np.array([3, 2]), # Used by this specific gen_f
},
}
See also
test_persistent_aposmm_nlopt.py shows an example where
gen_specs["in"]
is empty, butgen_specs["persis_in"]
specifies values to return to the persistent generator.test_persistent_aposmm_with_grad.py shows a similar example where an
H0
is used to provide points from a previous run. In this case,gen_specs["in"]
is populated to provide the generator with data for the initial points.In some cases you might be able to give different (perhaps fewer) fields in
"persis_in"
than"in"
; you may not need to givex
for example, as the persistent generator already hasx
for those points. See more example uses ofpersis_in
.
Note
In all interfaces, custom fields should only be placed in
"user"
Generator
"out"
fields typically match Simulation"in"
fields, and vice-versa.