Skip to main content
Version: Next

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 import Client, 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:
/opt/hostedtoolcache/Python/3.12.11/x64/lib/python3.12/site-packages/pyro/ops/stats.py:527: SyntaxWarning: invalid escape sequence 'g'
we have :math:ES^{*}(P,Q) ge ES^{*}(Q,Q) with equality holding if and only if :math:P=Q, i.e.
[INFO 08-12 05:04:08] ax.api.client: GenerationStrategy(name='Center+Sobol+MBM:fast', nodes=[CenterGenerationNode(next_node_name='Sobol'), GenerationNode(node_name='Sobol', generator_specs=[GeneratorSpec(generator_enum=Sobol, model_key_override=None)], transition_criteria=[MinTrials(transition_to='MBM'), MinTrials(transition_to='MBM')]), GenerationNode(node_name='MBM', generator_specs=[GeneratorSpec(generator_enum=BoTorch, model_key_override=None)], transition_criteria=[])]) chosen based on user input and problem structure.
[INFO 08-12 05:04:08] ax.api.client: Generated new trial 0 with parameters {'x1': 0.0, 'x2': 0.0}using GenerationNode CenterOfSearchSpace.
[INFO 08-12 05:04:08] ax.api.client: Trial 0 marked COMPLETED.
[INFO 08-12 05:04:08] ax.api.client: Generated new trial 1 with parameters {'x1': -3.363032, 'x2': -8.424915}using GenerationNode Sobol.
[INFO 08-12 05:04:08] ax.api.client: Trial 1 marked COMPLETED.
[INFO 08-12 05:04:08] ax.api.client: Generated new trial 2 with parameters {'x1': 3.152691, 'x2': 2.196067}using GenerationNode Sobol.
[INFO 08-12 05:04:08] ax.api.client: Trial 2 marked COMPLETED.
[INFO 08-12 05:04:08] ax.api.client: Generated new trial 3 with parameters {'x1': 6.704291, 'x2': -3.913911}using GenerationNode Sobol.
[INFO 08-12 05:04:08] ax.api.client: Trial 3 marked COMPLETED.
[INFO 08-12 05:04:08] ax.api.client: Generated new trial 4 with parameters {'x1': -6.758383, 'x2': 5.455259}using GenerationNode Sobol.
[INFO 08-12 05:04:08] ax.api.client: Trial 4 marked COMPLETED.
[INFO 08-12 05:04:08] ax.api.client: Generated new trial 5 with parameters {'x1': 10.0, 'x2': -0.752815}using GenerationNode MBM.
[INFO 08-12 05:04:08] ax.api.client: Trial 5 marked COMPLETED.
[INFO 08-12 05:04:09] ax.api.client: Generated new trial 6 with parameters {'x1': -0.631657, 'x2': 4.596011}using GenerationNode MBM.
[INFO 08-12 05:04:09] ax.api.client: Trial 6 marked COMPLETED.
[INFO 08-12 05:04:09] ax.api.client: Generated new trial 7 with parameters {'x1': -0.61039, 'x2': 10.0}using GenerationNode MBM.
[INFO 08-12 05:04:09] ax.api.client: Trial 7 marked COMPLETED.
[INFO 08-12 05:04:10] ax.api.client: Generated new trial 8 with parameters {'x1': 10.0, 'x2': -10.0}using GenerationNode MBM.
[INFO 08-12 05:04:10] ax.api.client: Trial 8 marked COMPLETED.
[INFO 08-12 05:04:10] ax.api.client: Generated new trial 9 with parameters {'x1': 1.368202, 'x2': 2.158534}using GenerationNode MBM.
[INFO 08-12 05:04:10] ax.api.client: Trial 9 marked COMPLETED.
[INFO 08-12 05:04:11] ax.api.client: Generated new trial 10 with parameters {'x1': 10.0, 'x2': 10.0}using GenerationNode MBM.
[INFO 08-12 05:04:11] ax.api.client: Trial 10 marked COMPLETED.
[INFO 08-12 05:04:11] ax.api.client: Generated new trial 11 with parameters {'x1': -5.821468, 'x2': 10.0}using GenerationNode MBM.
[INFO 08-12 05:04:11] ax.api.client: Trial 11 marked COMPLETED.
[INFO 08-12 05:04:12] ax.api.client: Generated new trial 12 with parameters {'x1': 3.284043, 'x2': 0.436535}using GenerationNode MBM.
[INFO 08-12 05:04:12] ax.api.client: Trial 12 marked COMPLETED.
[INFO 08-12 05:04:13] ax.api.client: Generated new trial 13 with parameters {'x1': -0.404835, 'x2': 3.537998}using GenerationNode MBM.
[INFO 08-12 05:04:13] ax.api.client: Trial 13 marked COMPLETED.
[INFO 08-12 05:04:13] ax.api.client: Generated new trial 14 with parameters {'x1': -2.13357, 'x2': 5.694055}using GenerationNode MBM.
[INFO 08-12 05:04:13] ax.api.client: Trial 14 marked COMPLETED.
[INFO 08-12 05:04:14] ax.api.client: Generated new trial 15 with parameters {'x1': 0.681913, 'x2': 2.924424}using GenerationNode MBM.
[INFO 08-12 05:04:14] ax.api.client: Trial 15 marked COMPLETED.
[INFO 08-12 05:04:15] ax.api.client: Generated new trial 16 with parameters {'x1': 2.216731, 'x2': 1.295662}using GenerationNode MBM.
[INFO 08-12 05:04:15] ax.api.client: Trial 16 marked COMPLETED.
[INFO 08-12 05:04:16] ax.api.client: Generated new trial 17 with parameters {'x1': 0.62378, 'x2': 2.567651}using GenerationNode MBM.
[INFO 08-12 05:04:16] ax.api.client: Trial 17 marked COMPLETED.
[INFO 08-12 05:04:17] ax.api.client: Generated new trial 18 with parameters {'x1': 1.578698, 'x2': 2.250053}using GenerationNode MBM.
[INFO 08-12 05:04:17] ax.api.client: Trial 18 marked COMPLETED.
[INFO 08-12 05:04:17] ax.api.client: Generated new trial 19 with parameters {'x1': 1.48358, 'x2': 1.837278}using GenerationNode MBM.
[INFO 08-12 05:04:17] ax.api.client: Trial 19 marked COMPLETED.
({'x1': 1.3682024472275482, 'x2': 2.158533753591661},
{'booth': (np.float64(-0.651748354946676), np.float64(10.387034153053964))},
9,
'9_0')