Standardized Generator (gest-api)¶
Introduction || Standardized Generator (gest-api) || Legacy Generator Function
Standardized generators are classes that inherit from gest_api.Generator.
They adhere to the gest-api standard and are parameterized by a VOCS
object defining the problem’s variables and objectives.
A basic generator implements the suggest() and ingest() methods, which
operate on lists of dictionaries:
1import numpy as np
2from gest_api import Generator
3from gest_api.vocs import VOCS
4
5
6class UniformSample(Generator):
7 """Samples over the domain specified in the VOCS."""
8
9 def __init__(self, vocs: VOCS):
10 self.vocs = vocs
11 self.rng = np.random.default_rng(1)
12 super().__init__(vocs)
13
14 def _validate_vocs(self, vocs):
15 assert len(self.vocs.variable_names), "VOCS must contain variables."
16
17 def suggest(self, n_trials):
18 output = []
19 for _ in range(n_trials):
20 trial = {}
21 for key in self.vocs.variables:
22 trial[key] = self.rng.uniform(self.vocs.variables[key].domain[0], self.vocs.variables[key].domain[1])
23 output.append(trial)
24 return output
25
26 def ingest(self, calc_in):
27 pass # random sample so nothing to ingest
libEnsemble’s handling of standardized generators is specified using GenSpecs:
gen_specs = GenSpecs(
generator=UniformSample(vocs),
inputs=["sim_id"],
persis_in=["x", "f"],
outputs=[("x", float, 2)],
vocs=vocs,
user={"batch_size": 128},
)
Note
Ensure that gen_specs.inputs or gen_specs.persis_in requests at least one field
(like "sim_id" or "f") to be sent back, even if the generator does not
process them.