66 """Adapt OMNI-EPIC's successful/failed task archive to deterministic benchmarks.
68 Use a one-elite Grid or CVTGrid. The evaluator measures the result of a
69 fixed solver or solver panel. An optional post-generation reviewer checks
70 a solved candidate against its nearest measured tasks. This workflow
71 leaves policy training and task representation to the caller.
73 :param archive: Empty best-only, scalar maximizing Grid or CVTGrid.
74 :param neighbors: Maximum nearby examples passed to proposal and review callbacks.
75 :param failure_memory: Maximum measured unsolved tasks passed back to the proposer.
76 :param seed: Seed for parent selection and proposal callbacks.
79 def __init__(self, archive, *, neighbors=3, failure_memory=8, seed=0):
80 _validate_grid(archive)
81 if (archive.fitness_weights
is not None and archive.fitness_weights[0] <= 0
82 or archive.fitness_score_names
or archive.features_score_names):
83 raise ValueError(
"Use a maximizing grid with native fitness and descriptors.")
84 low, high = np.asarray(archive.features_domain, dtype=float).T
85 self.
_span = high - low
86 if not (np.isfinite(self.
_span).all()
and (self.
_span > 0).all()):
87 raise ValueError(
"Use finite increasing descriptor intervals.")
88 archive._set_fitness_weights((1.,))
90 self.
_neighbors = _positive_int(neighbors,
"neighbors")
91 self.
_failed = deque(maxlen=_positive_int(failure_memory,
"failure_memory"))
92 self.
_rng = np.random.default_rng(seed)
98 """Return a snapshot of the retained measured tasks."""
100 tuple(entry.features.values),
True,
101 entry.scores[
"task_feedback"]))
106 """Return bounded memory of tasks that the evaluator could not solve."""
111 """Return cumulative search calls and outcomes."""
114 def _nearby(self, descriptor, entries):
115 point = np.asarray(descriptor)
116 return tuple(sorted(entries, key=
lambda row: np.linalg.norm(
119 def _measure(self, task, evaluate, review):
123 if task
in self.
_seen:
124 self.
_counts[
"duplicates"] += 1
126 self.
_counts[
"evaluations"] += 1
127 measured = evaluate(task)
131 if not isinstance(measured, TaskAssessment)
or type(measured.solved)
is not bool:
132 raise ValueError(
"Return a TaskAssessment with a Boolean solved value, or None.")
133 genome, cell = _measurement(self.
archive, ((measured.quality,), measured.descriptors), (task,))
135 raise ValueError(
"Return task quality and descriptors within the archive domains.")
137 measured.solved, measured.feedback))
138 if not measured.solved:
142 self.
_place(entry, genome, cell, review)
145 def _place(self, entry, genome, cell, review):
146 if review
is not None:
148 if not review(entry, self.
_nearby(entry.assessment.descriptors, self.
entries)):
151 genome.scores[
"task_feedback"] = entry.assessment.feedback
153 _offer(self.
archive, (genome, cell))
157 def run(self, propose, evaluate, *, budget, review=None):
158 """Spend up to budget new proposals, counting failed and duplicate proposals.
160 :param propose: Callback (TaskRequest, rng) returning an immutable,
161 hashable task or None.
162 :param evaluate: Callback (task) returning TaskAssessment, or None for
163 an invalid encoding. A complete solver panel counts as one call.
164 :param review: Optional callback (TaskEntry, nearby_entries) returning
165 whether a solved task qualifies for admission.
166 :param budget: Maximum additional calls to propose.
168 if not callable(propose)
or not callable(evaluate)
or review
is not None and not callable(review):
169 raise ValueError(
"Supply proposal and evaluation callbacks and an optional reviewer.")
170 for _
in range(_positive_int(budget,
"budget")):
172 parent = entries[int(self.
_rng.integers(len(entries)))]
if entries
else None
173 examples = self.
_nearby(parent.assessment.descriptors, entries)
if parent
else ()
176 self.
_measure(task, evaluate, review)
Pair an immutable task encoding with its measured outcome.