Best-of-N
Give the LLM N valid attempts at the same parent before committing to the global best, then repeat.
"""Best-of-N Population component — a keep-all archive sorted by combined_score.
One file per component (see scaffold.py). SkyDiscover's ``BestOfNDatabase`` stores every program and
re-derives the global best on demand; the parent-reuse logic itself lives in the SelectionPolicy.
"""
from __future__ import annotations
from ...components.population import InMemoryPopulation
class BestOfNPopulation(InMemoryPopulation):
"""SkyDiscover ``BestOfNDatabase`` store: keep-all, fitness-sorted. Used both to find the current
global best (when the parent-reuse budget is spent) and to draw the fresh context sample."""
def __init__(self, capacity: int | None = None):
# None = uncapped; drop_invalid mirrors SkyDiscover skipping database.add() on result.error, so a
# failed attempt never enters the pool (the reuse counter, advanced in observe(), is unaffected).
super().__init__(capacity=capacity, drop_invalid=True)