54 def __init__(self, archive, encodings, *, initial_samples=8, seed=0):
55 _validate_grid(archive)
56 encodings = tuple(encodings)
57 if not encodings
or any(
58 not isinstance(encoding, GenomeEncoding)
or not isinstance(encoding.name, str)
59 or not encoding.name
or not all(map(callable, (encoding.sample, encoding.mutate, encoding.decode)))
60 for encoding
in encodings):
61 raise ValueError(
"Supply named encodings with sampling, mutation, and decoding callables.")
62 if len({encoding.name
for encoding
in encodings}) != len(encodings):
63 raise ValueError(
"Encoding names must be unique.")
64 self.
_initial = _attempt_budget(initial_samples) * len(encodings)
65 self.
_rng = np.random.default_rng(seed)
67 if archive.fitness_weights
is None:
68 archive._set_fitness_weights((1.,))
91 def run(self, evaluate, budget):
92 if not callable(evaluate):
93 raise ValueError(
"evaluate must be callable.")
94 for _
in range(_attempt_budget(budget)):
100 genome = tuple(self.
encodings[slot].mutate(tuple(parent), self.
_rng))
104 if phenotype
is None:
108 measurement = evaluate(phenotype)
109 if measurement
is not None:
110 quality, descriptors = measurement
112 _offer(self.
archive, _measurement(self.
archive, ((quality,), descriptors), (slot, *genome)))