Base Task

The BaseTask class is an abstract base class that defines the common interface for all task types in the framework. It provides the basic structure for setting up experiments, running tasks, and managing task state.

class alf_core.tasks.base_task.BaseTask(task_type, acq_batch_size=0, num_acq_rounds=0, save_round_predictions=False)[source]

Bases: ABC

Base class for all tasks.

Provides common functionality for different types of experiments/tasks, including setup, evaluation, and saving predictions.

evaluate(state)[source]

Evaluate the surrogate model on the test dataset and return the updated state.

Computes predictions, metrics on the test set. Optionally saves predictions if configured. Updates the task state with computed metrics.

Parameters:

state (State) – Current task state containing dataset and surrogate.

Return type:

State

Returns:

Updated task state with evaluation metrics.

abstractmethod run(**kwargs)[source]

Run the task.

This method must be implemented by subclasses to define the specific task execution logic.

Parameters:

**kwargs (Any) – Task-specific keyword arguments.

Return type:

None

setup(dataset, surrogate)[source]

Setup the task with dataset and surrogate model.

Parameters:
  • dataset (BaseDataset) – The dataset containing train/validation/test splits.

  • surrogate (Surrogate) – The surrogate model to use for predictions.

Raises:

RuntimeError – If dataset.setup() has not been called before this method.

Return type:

State

Returns:

Initialized task state with the provided dataset and surrogate.