Skip to content

Extension Guide

The multi-fidelity active learning framework is designed for extension. Every component in the active-learning loop can be replaced independently:

graph LR
    D([Dataset]) -- fit --> S([Surrogate])
    S -- inform --> A([Acquisition])
    A -- guide --> Sa([Sampler])
    Sa -- propose --> Se([Selector])
    Se -- query --> O([Oracle])
    O -- append --> D

Extending the framework — replacing or adding oracles, surrogates, samplers, selectors, or acquisitions — is the primary intended use; all other loop components operate without modification.

The common extension recipe

Every component follows the same four-step pattern:

1. Implement your class by subclassing the relevant abstract base.

# src/activelearning/oracle/my_oracle.py
from activelearning.oracle.oracle import Oracle

class MyOracle(Oracle):
    def get_fidelity_confidences(self) -> dict[int, float]: ...
    def get_costs(self, candidates): ...
    def query(self, candidates): ...

2. Add a Pydantic config model with a type literal and a build() method.

# src/activelearning/oracle/config.py  (additions)
from activelearning.oracle.my_oracle import MyOracle

class MyOracleConfig(BaseModel):
    type: Literal["MyOracle"] = "MyOracle"
    # your parameters here

    def build(self) -> Oracle:
        return MyOracle(...)

3. Register that config model in the component's config.py by adding it to the Union type alias.

OracleConfig = Annotated[
    Union[..., MyOracleConfig],
    Field(discriminator="type"),
]

4. Point your YAML at the new type.

# config.yaml
oracle:
  type: MyOracle

Runtime context

All components inherit from ALRuntimeMixin. The runtime context (device, dtype, logger) is bound after build() — avoid using it in __init__(). Access it inside your methods instead:

class MyOracle(Oracle):
    def query(self, candidates):
        x = torch.tensor([c.x for c in candidates], dtype=self.dtype, device=self.device)
        self.logger.info("querying %d candidates", len(candidates))
        ...

The sampler is the only component whose build() receives runtime directly (see Sampler guide).

Quick reference: what to extend

If you need to change… Extend… Key method(s)
Evaluation rule, simulator, benchmark, fidelity levels Oracle get_fidelity_confidences(), get_costs(), query()
Candidate proposal strategy, search space Sampler sample()
Predictive model (GP, NN, ensemble…) Surrogate updates_from_latest(), is_fitted(), fit() / update(), predict()
Information criterion, scoring function Acquisition update(), score()
Per-round budget allocation and budget cost schedule Budget get_round_budget(), consume(), can_afford()
Candidate selection policy (ranking/constraints within the round budget) Selector __call__()
Observation storage/retrieval semantics Dataset add_observations(), get_observations_iterable(), get_latest_observations_iterable(), get_best_candidates()
Experiment tracking backend(s) Logger log_config(), log_metric(), log_figure(), log_step(), end()

Detailed guides

  • Oracle — add a new evaluation mechanism
  • Sampler — add a new candidate proposal strategy
  • Surrogate — add a new predictive model
  • Acquisition — add a new information criterion
  • Selector — add a new candidate selection policy