Skip to content

Adding a New Selector

Selectors choose the final subset of candidates from the pool the sampler produces. A selector implements the within-round candidate selection policy under the round budget provided by Budget. Implement a new selector to:

  • Apply custom constraints (diversity, domain rules, batch coverage).
  • Implement a new feasibility/ranking policy under a round budget (fractional fidelity spending, risk thresholds).
  • Mix cost awareness with acquisition scoring in a custom way.

Before implementing a new selector, verify that TopKAcquisitionSelector or CostAwareSelector does not already meet your requirements.

What to implement

Subclass activelearning.selector.selector.Selector and implement one method:

Method Required? Notes
__call__(candidates, acquisition=None, cost_fn=None, round_budget=None) Yes Returns list[Candidate] — a subset of the input candidates

Return a subset of the input candidates — including an empty list if no candidates are feasible. Never query the oracle, compute observations, or modify the budget inside the selector.

Reference implementations

Review the built-in selectors as concrete examples before writing your own:

  • TopKAcquisitionSelector — picks the top-K candidates by acquisition score; the simplest selector.
  • CostAwareSelector — selects candidates by score-per-unit-cost within the round budget; the default for multi-fidelity experiments.

Source: src/activelearning/selector/.

Config model and registration

Add a Pydantic config model in src/activelearning/selector/config.py and extend the SelectorConfig union. See the existing models in that file as reference.

class MySelectorConfig(BaseModel):
    type: Literal["MySelector"] = "MySelector"
    # your parameters here

    def build(self) -> Selector:
        return MySelector(...)

SelectorConfig = Annotated[
    Union[..., MySelectorConfig],
    Field(discriminator="type"),
]

Then in your YAML:

selector:
  type: MySelector

Fidelity preservation

Selected candidates must carry their fidelity ids unchanged. Do not modify Candidate.fidelity inside the selector — the oracle and dataset use it to route and record observations correctly. Since Candidate is a frozen dataclass, accidental mutation will raise an AttributeError.

Using acquisition.score() inside the selector

Call acquisition.score() with the full candidate sequence. Always guard with a None check and check supports_singleton_scoring before calling:

if acquisition is not None and acquisition.supports_singleton_scoring:
    scores = acquisition.score(candidates)
else:
    scores = [0.0] * len(candidates)

For cost-aware policies, compute costs with cost_fn and divide scores by cost:

if cost_fn is not None:
    costs = cost_fn(candidates)
    scores = [s / c for s, c in zip(scores, costs)]

This selector-side division is a separate mechanism from any acquisition-level cost weighting that may already be built into the values returned by acquisition.score(candidates). In particular, BoTorch multi-fidelity acquisitions configured with cost_aware_utility bake that weighting into the acquisition object during update() — so the scores returned by score() already penalize expensive candidates. If you then divide by cost again in the selector, both penalties compound. This is usually undesirable. To avoid double-counting, either:

  • Rely on the acquisition-level cost_aware_utility (which also influences samplers that use acquisition scores), or
  • Use selector-side division (e.g., CostAwareSelector) and configure the acquisition without cost_aware_utility.

See the Acquisition guide for more details.

Common pitfalls

Do not query the oracle — the selector only allocates from a pre-built pool. Any oracle call inside the selector corrupts budget accounting.

Do not double-count budget — the loop deducts costs after oracle query. The selector's job is to check feasibility, not to deduct.