Skip to main content
Version: 1.3.1

Quickstart

Ax is an open-source platform for adaptive experimentation, a technique used to efficiently tune parameters in complex systems. This guide will walk through installation, core concepts, and basic usage of Ax.

Installation​

We recommend using pip to install Ax.

pip install ax-platform

Core concepts​

  • Experiment: A process of iteratively suggesting and evaluating parameters to improve some objective.
  • Parameter: A variable that can be adjusted -- a collection of these form the space we are searching over during the optimization.
  • Objective: The value being optimized.
  • Trial: A set of parameters and the associated objective.
  • Client: An object that manages the experiment and provides methods for interacting with it.
from ax.api.client import Client
from ax.api.configs import RangeParameterConfig

# 1. Initialize the Client.
client = Client()

# 2. Configure where Ax will search.
client.configure_experiment(
name="booth_function",
parameters=[
RangeParameterConfig(
name="x1",
bounds=(-10.0, 10.0),
parameter_type="float",
),
RangeParameterConfig(
name="x2",
bounds=(-10.0, 10.0),
parameter_type="float",
),
],
)

# 3. Configure a metric for Ax to target (see other Tutorials for adding constraints,
# multiple objectives, tracking metrics etc.)
client.configure_optimization(objective="-1 * booth")

# 4. Conduct the experiment with 20 trials: get each trial from Ax, evaluate the
# objective function, and log data back to Ax.
for _ in range(20):
# Use higher value of `max_trials` to run trials in parallel.
for trial_index, parameters in client.get_next_trials(max_trials=1).items():
client.complete_trial(
trial_index=trial_index,
raw_data={
"booth": (parameters["x1"] + 2 * parameters["x2"] - 7) ** 2
+ (2 * parameters["x1"] + parameters["x2"] - 5) ** 2
},
)

# 5. Obtain the best-performing configuration; the true minimum for the booth
# function is at (1, 3).
client.get_best_parameterization()
Output:
[INFO 06-09 17:01:51] ax.storage.sqa_store.with_db_settings_base: Ax SQL storage initialized with SQLAlchemy 1.4.17
[INFO 06-09 17:01:52] ax.api.client: GenerationStrategy(name='Center+Sobol+MBM:fast', nodes=[CenterGenerationNode(next_node_name='Sobol', use_existing_trials_for_initialization=True), GenerationNode(name='Sobol', generator_specs=[GeneratorSpec(generator_enum=Sobol, generator_key_override=None)], transition_criteria=[MinTrials(transition_to='MBM'), MinTrials(transition_to='MBM')], suggested_experiment_status=ExperimentStatus.INITIALIZATION, pausing_criteria=[MaxTrialsAwaitingData(threshold=5)]), GenerationNode(name='MBM', generator_specs=[GeneratorSpec(generator_enum=BoTorch, generator_key_override=None)], transition_criteria=None, suggested_experiment_status=ExperimentStatus.OPTIMIZATION, pausing_criteria=None)]) chosen based on user input and problem structure.
[INFO 06-09 17:01:52] ax.api.client: Generated new trial 0 with parameters {'x1': 0.0, 'x2': 0.0} using GenerationNode CenterOfSearchSpace.
[INFO 06-09 17:01:52] ax.api.client: Trial 0 marked COMPLETED.
[INFO 06-09 17:01:52] ax.api.client: Generated new trial 1 with parameters {'x1': -5.596903, 'x2': 0.062022} using GenerationNode Sobol.
[INFO 06-09 17:01:52] ax.api.client: Trial 1 marked COMPLETED.
[INFO 06-09 17:01:52] ax.api.client: Generated new trial 2 with parameters {'x1': 5.209355, 'x2': -8.311537} using GenerationNode Sobol.
[INFO 06-09 17:01:52] ax.api.client: Trial 2 marked COMPLETED.
[INFO 06-09 17:01:52] ax.api.client: Generated new trial 3 with parameters {'x1': 2.225228, 'x2': 9.588584} using GenerationNode Sobol.
[INFO 06-09 17:01:52] ax.api.client: Trial 3 marked COMPLETED.
[INFO 06-09 17:01:52] ax.api.client: Generated new trial 4 with parameters {'x1': -1.989228, 'x2': -1.256059} using GenerationNode Sobol.
[INFO 06-09 17:01:52] ax.api.client: Trial 4 marked COMPLETED.
[INFO 06-09 17:01:53] ax.api.client: Generated new trial 5 with parameters {'x1': 1.325318, 'x2': 0.375086} using GenerationNode MBM.
[INFO 06-09 17:01:53] ax.api.client: Trial 5 marked COMPLETED.
[INFO 06-09 17:01:53] ax.api.client: Generated new trial 6 with parameters {'x1': 1.491725, 'x2': 2.422511} using GenerationNode MBM.
[INFO 06-09 17:01:53] ax.api.client: Trial 6 marked COMPLETED.
[INFO 06-09 17:01:53] ax.api.client: Generated new trial 7 with parameters {'x1': 3.066025, 'x2': 1.828885} using GenerationNode MBM.
[INFO 06-09 17:01:53] ax.api.client: Trial 7 marked COMPLETED.
[INFO 06-09 17:01:54] ax.api.client: Generated new trial 8 with parameters {'x1': 2.131122, 'x2': 1.77528} using GenerationNode MBM.
[INFO 06-09 17:01:54] ax.api.client: Trial 8 marked COMPLETED.
[INFO 06-09 17:01:54] ax.api.client: Generated new trial 9 with parameters {'x1': 10.0, 'x2': -0.091705} using GenerationNode MBM.
[INFO 06-09 17:01:54] ax.api.client: Trial 9 marked COMPLETED.
[INFO 06-09 17:01:54] ax.api.client: Generated new trial 10 with parameters {'x1': 10.0, 'x2': 7.690792} using GenerationNode MBM.
[INFO 06-09 17:01:54] ax.api.client: Trial 10 marked COMPLETED.
[INFO 06-09 17:01:55] ax.api.client: Generated new trial 11 with parameters {'x1': -4.348175, 'x2': 9.510878} using GenerationNode MBM.
[INFO 06-09 17:01:55] ax.api.client: Trial 11 marked COMPLETED.
[INFO 06-09 17:01:55] ax.api.client: Generated new trial 12 with parameters {'x1': -1.367938, 'x2': 5.71426} using GenerationNode MBM.
[INFO 06-09 17:01:55] ax.api.client: Trial 12 marked COMPLETED.
[INFO 06-09 17:01:55] ax.api.client: Generated new trial 13 with parameters {'x1': 3.535961, 'x2': -0.088949} using GenerationNode MBM.
[INFO 06-09 17:01:55] ax.api.client: Trial 13 marked COMPLETED.
[INFO 06-09 17:01:56] ax.api.client: Generated new trial 14 with parameters {'x1': -10.0, 'x2': 10.0} using GenerationNode MBM.
[INFO 06-09 17:01:56] ax.api.client: Trial 14 marked COMPLETED.
[INFO 06-09 17:01:56] ax.api.client: Generated new trial 15 with parameters {'x1': 0.633892, 'x2': 3.143235} using GenerationNode MBM.
[INFO 06-09 17:01:56] ax.api.client: Trial 15 marked COMPLETED.
[INFO 06-09 17:01:57] ax.api.client: Generated new trial 16 with parameters {'x1': 0.944918, 'x2': 3.326061} using GenerationNode MBM.
[INFO 06-09 17:01:57] ax.api.client: Trial 16 marked COMPLETED.
[INFO 06-09 17:01:57] ax.api.client: Generated new trial 17 with parameters {'x1': 1.36205, 'x2': 2.255636} using GenerationNode MBM.
[INFO 06-09 17:01:57] ax.api.client: Trial 17 marked COMPLETED.
[INFO 06-09 17:01:58] ax.api.client: Generated new trial 18 with parameters {'x1': 1.110508, 'x2': 2.779555} using GenerationNode MBM.
[INFO 06-09 17:01:58] ax.api.client: Trial 18 marked COMPLETED.
[INFO 06-09 17:01:58] ax.api.client: Generated new trial 19 with parameters {'x1': 1.742964, 'x2': 2.04961} using GenerationNode MBM.
[INFO 06-09 17:01:58] ax.api.client: Trial 19 marked COMPLETED.
({'x1': 1.4917251197578436, 'x2': 2.422511037978902},
{'booth': (np.float64(-0.029788071856472698),
np.float64(2.5057246267307405))},
6,
'6_0')