32 """Search only distinct canonical representatives in a best-only Grid or CVTGrid.
34 :param archive: Empty reporting archive with scalar fitness.
35 :param canonicalize: Callback (genome_tuple) producing a canonical
36 genome iterable with hashable entries. It must be deterministic and
37 idempotent, and preserve fitness, descriptors, and feasibility.
38 :param propose: Callback (rng) producing an initial iterable genome.
39 :param mutate: Callback (parent_tuple, rng) producing an offspring genome.
40 :param seed: Private proposal and parent selection seed.
42 The search owns a cache of successfully evaluated representatives,
43 including measurements outside the reporting domain. Keep the
44 evaluator, geometry, and canonicalization fixed across calls.
47 def __init__(self, archive, *, canonicalize, propose, mutate, seed=0):
48 _validate_grid(archive)
49 if not all(map(callable, (canonicalize, propose, mutate))):
50 raise TypeError(
"Supply callable canonicalize, propose, and mutate functions.")
53 self.
_rng = np.random.default_rng(seed)
59 """Return an immutable snapshot of proposal and evaluation costs."""
63 def run(self, evaluate, *, proposals, max_evaluations=None):
64 """Return cumulative stats. The optional evaluation limit applies to this call.
66 Evaluate the canonical tuple and return ((fitness,), descriptors).
67 Failed or invalid measurements propagate and leave the candidate
68 eligible for a later attempt.
70 if not callable(evaluate):
71 raise TypeError(
"evaluate must be callable.")
72 proposals = _positive_int(proposals,
"proposals")
73 limit = (
None if max_evaluations
is None
74 else self.
_counts[
"evaluations"] + _positive_int(max_evaluations,
"max_evaluations"))
75 for _
in range(proposals):
76 if limit
is not None and self.
_counts[
"evaluations"] >= limit:
85 if canonical
in self.
_seen:
88 self.
_counts[
"evaluations"] += 1
89 measurement = _measurement(self.
archive, evaluate(canonical), canonical)
91 _offer(self.
archive, measurement)
92 self.
_seen.add(canonical)
run(self, evaluate, *, proposals, max_evaluations=None)
Run additional proposals, skipping evaluation of repeated canonical designs.