Adaptive Experimentation

1.2.4 · active · verified Thu Apr 16

Ax is an open-source Python library for adaptive experimentation, a technique that uses machine learning to efficiently tune parameters in complex systems. It supports Bayesian optimization and bandit optimization strategies, powered by BoTorch and PyTorch. The library is actively maintained, with a typical release cadence of minor versions every few months, and the current version is 1.2.4.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes an Ax client, configures an experiment to minimize the Booth function, runs 20 trials, and then retrieves the best-found parameters. It demonstrates the core loop of defining a search space, getting new trials, evaluating them, and logging results back to Ax.

from ax import Client, RangeParameterConfig

def booth_function(x1, x2):
    return (x1 + 2 * x2 - 7)**2 + (2 * x1 + x2 - 5)**2

client = Client()
client.configure_experiment(
    name="booth_function_experiment",
    parameters=[
        RangeParameterConfig(name="x1", bounds=(-10.0, 10.0), parameter_type="float"),
        RangeParameterConfig(name="x2", bounds=(-10.0, 10.0), parameter_type="float"),
    ],
    objectives={
        "booth": RangeParameterConfig(name="booth", bounds=(-100.0, 100.0), parameter_type="float", minimize=True)
    }
)

for _ in range(20):
    for trial_index, parameters in client.get_next_trials(max_trials=1).items():
        result = booth_function(parameters["x1"], parameters["x2"])
        client.complete_trial(
            trial_index=trial_index,
            raw_data={"booth": (result, 0.0)} # Tuple (mean, SEM)
        )

best_parameters, metrics = client.get_best_parameterization()
print("Best parameters found:", best_parameters)
print("Corresponding metrics:", metrics)

view raw JSON →