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.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 11-12 05:03:55] ax.storage.sqa_store.with_db_settings_base: Ax SQL storage initialized with SQLAlchemy 1.4.17
[INFO 11-12 05:03:56] 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 11-12 05:03:56] ax.api.client: Generated new trial 0 with parameters {'x1': 0.0, 'x2': 0.0} using GenerationNode CenterOfSearchSpace.
[INFO 11-12 05:03:56] ax.api.client: Trial 0 marked COMPLETED.
[INFO 11-12 05:03:56] ax.api.client: Generated new trial 1 with parameters {'x1': 6.05323, 'x2': 1.084678} using GenerationNode Sobol.
[INFO 11-12 05:03:56] ax.api.client: Trial 1 marked COMPLETED.
[INFO 11-12 05:03:56] ax.api.client: Generated new trial 2 with parameters {'x1': -7.698796, 'x2': -5.332726} using GenerationNode Sobol.
[INFO 11-12 05:03:56] ax.api.client: Trial 2 marked COMPLETED.
[INFO 11-12 05:03:56] ax.api.client: Generated new trial 3 with parameters {'x1': -2.971408, 'x2': 5.811385} using GenerationNode Sobol.
[INFO 11-12 05:03:56] ax.api.client: Trial 3 marked COMPLETED.
[INFO 11-12 05:03:56] ax.api.client: Generated new trial 4 with parameters {'x1': 0.779084, 'x2': -0.293807} using GenerationNode Sobol.
[INFO 11-12 05:03:56] ax.api.client: Trial 4 marked COMPLETED.
[INFO 11-12 05:03:56] ax.api.client: Generated new trial 5 with parameters {'x1': 0.265305, 'x2': 5.595769} using GenerationNode MBM.
[INFO 11-12 05:03:56] ax.api.client: Trial 5 marked COMPLETED.
[INFO 11-12 05:03:57] ax.api.client: Generated new trial 6 with parameters {'x1': -0.336177, 'x2': 9.979397} using GenerationNode MBM.
[INFO 11-12 05:03:57] ax.api.client: Trial 6 marked COMPLETED.
[INFO 11-12 05:03:57] ax.api.client: Generated new trial 7 with parameters {'x1': -10.0, 'x2': 4.218898} using GenerationNode MBM.
[INFO 11-12 05:03:57] ax.api.client: Trial 7 marked COMPLETED.
[INFO 11-12 05:03:57] ax.api.client: Generated new trial 8 with parameters {'x1': 1.378878, 'x2': 2.623587} using GenerationNode MBM.
[INFO 11-12 05:03:57] ax.api.client: Trial 8 marked COMPLETED.
[INFO 11-12 05:03:58] ax.api.client: Generated new trial 9 with parameters {'x1': -0.471846, 'x2': 3.891076} using GenerationNode MBM.
[INFO 11-12 05:03:58] ax.api.client: Trial 9 marked COMPLETED.
[INFO 11-12 05:03:58] ax.api.client: Generated new trial 10 with parameters {'x1': 7.586231, 'x2': -8.484} using GenerationNode MBM.
[INFO 11-12 05:03:58] ax.api.client: Trial 10 marked COMPLETED.
[INFO 11-12 05:03:58] ax.api.client: Generated new trial 11 with parameters {'x1': 10.0, 'x2': 8.693535} using GenerationNode MBM.
[INFO 11-12 05:03:58] ax.api.client: Trial 11 marked COMPLETED.
[INFO 11-12 05:03:59] ax.api.client: Generated new trial 12 with parameters {'x1': 4.303703, 'x2': -1.003095} using GenerationNode MBM.
[INFO 11-12 05:03:59] ax.api.client: Trial 12 marked COMPLETED.
[INFO 11-12 05:03:59] ax.api.client: Generated new trial 13 with parameters {'x1': -0.24059, 'x2': 4.26933} using GenerationNode MBM.
[INFO 11-12 05:03:59] ax.api.client: Trial 13 marked COMPLETED.
[INFO 11-12 05:04:00] ax.api.client: Generated new trial 14 with parameters {'x1': 10.0, 'x2': -3.091341} using GenerationNode MBM.
[INFO 11-12 05:04:00] ax.api.client: Trial 14 marked COMPLETED.
[INFO 11-12 05:04:00] ax.api.client: Generated new trial 15 with parameters {'x1': 0.480317, 'x2': 3.359358} using GenerationNode MBM.
[INFO 11-12 05:04:00] ax.api.client: Trial 15 marked COMPLETED.
[INFO 11-12 05:04:00] ax.api.client: Generated new trial 16 with parameters {'x1': 0.399541, 'x2': 3.756077} using GenerationNode MBM.
[INFO 11-12 05:04:00] ax.api.client: Trial 16 marked COMPLETED.
[INFO 11-12 05:04:01] ax.api.client: Generated new trial 17 with parameters {'x1': -6.378759, 'x2': 10.0} using GenerationNode MBM.
[INFO 11-12 05:04:01] ax.api.client: Trial 17 marked COMPLETED.
[INFO 11-12 05:04:01] ax.api.client: Generated new trial 18 with parameters {'x1': 1.271155, 'x2': 3.085422} using GenerationNode MBM.
[INFO 11-12 05:04:01] ax.api.client: Trial 18 marked COMPLETED.
[INFO 11-12 05:04:01] ax.api.client: Generated new trial 19 with parameters {'x1': 1.855732, 'x2': 2.169999} using GenerationNode MBM.
[INFO 11-12 05:04:02] ax.api.client: Trial 19 marked COMPLETED.
({'x1': 0.48031694240202927, 'x2': 3.3593580360452373},
{'booth': (np.float64(0.6109715499765542), np.float64(2.8633210541138308))},
15,
'15_0')