Skip to content

Running a sweep

run_sweep async

run_sweep(config_path: str, *, no_cache: bool = False, verbose: int = 0, state_dir: Path = DEFAULT_STATE_DIR, on_event: Callable[[dict], None] | None = None, on_sample: Callable[[dict], None] | None = None, samples_per_cell: int = 0, batch_size: int | None = None, mlflow_experiment: str | None = None, mlflow_tracking_uri: str | None = None, mlflow_tags: dict | None = None) -> dict

Run the full sweep and return the JSON-serializable result dict.

on_event, when given, receives progress dicts as the sweep advances: sweep_start (models, datasets), dataset_start, dataset_resumed (models already scored / queued for a retry, only when a previous attempt left state behind), dataset_ready (batches), cell_start (model), batch (batch, batches_total, running reward), cell_end (metrics), dataset_end (statuses per model) and sweep_end. Raising SweepCancelled from it aborts the sweep.

on_sample, with samples_per_cell > 0, receives the first rows of each (model, dataset) cell as {dataset, model, index, input, target, output} — what the model was asked and what it answered, which the aggregate matrix throws away. Rows are numbered in dataset order, so the same index is the same row for every model.

mlflow_experiment, when given (and observability is enabled), attaches an MLflow Monitor callback that logs each trial's evaluate metrics as one run of that experiment, tagged with mlflow_tags, the dataset and the model. Without it the framework still adds its default Monitor, which files metrics under an experiment named after the program.

Programmatic entry point (e.g. for an API endpoint that needs the matrix without going through stdout). One GridSearch tuner runs per dataset over Choice("language_model", ...) — model is the only HP axis; the dataset is a fixed search context. Each tuner persists trial state under <state_dir>/<dataset>/ (default .open-arena, override with state_dir), the same cache the CLI reads, and distinct state_dirs never collide.

That cache is also what makes a sweep resumable: point a new call at the state_dir of an interrupted one (with no_cache=False, which is the default) and every cell that completed is skipped — its scores are read back from the trial — while the cells that failed or were in flight are re-run along with the ones never reached. Programs are only built for the cells that still have to run. See _resume_grid.

The cells run in turn, model-major, on this event loop (_run_cell), each with a view of its dataset batched to the run's batch_size (else the dataset's own): the batch is what the framework sends at once. A cell's program, with its own reward and metrics, is built as the cell starts and closed when its trial ends (the tuner's Program.close), so what it opens (an agent judge's sandbox, an A2A agent's client) lives for that one cell, and memory does not grow with the grid. Whatever a cancellation or an error left open is closed before the sweep returns.

A cell that cannot give a score ends FAILED (or INVALID) with why, and the other cells still run: an agent whose MCP servers gave no tools, a cell none of whose rows got an answer (_NoAnswerGuard), any error raised while it ran. A row that alone got no answer scores 0 and the cell goes on. The result's rows carry each cell's status.

no_cache=True drops every per-dataset cache before starting — use it when the model list or any dataset's reward / metric set changed. It is also what makes a run un-resumable, so a resume must never set it. verbose is forwarded to Program.evaluate (0 silent, 1 progress bar, 2 per-batch).