Adaptive Experimentation
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
-
ModuleNotFoundError: No module named 'ax-platform'
cause The `ax-platform` package is not installed or not available in the current Python environment.fixInstall the package using pip: `pip install ax-platform`. Ensure your virtual environment is activated. -
ERROR: Could not find a version that satisfies the requirement ax-platform
cause This usually indicates an incompatible Python version. Ax 1.2.3+ requires Python 3.11 or newer.fixUpgrade your Python version to 3.11+ or ensure your environment satisfies the `requires_python` metadata. You might also need to upgrade pip: `python -m pip install --upgrade pip`. -
AttributeError: 'RangeParameter' object has no attribute 'lower' (or similar attribute errors related to Pandas/BoTorch)
cause Version mismatch with core dependencies like Pandas or BoTorch. Ax 1.2.3+ expects specific versions (Pandas 3.0+, BoTorch 0.17.0+).fixUpdate Pandas and BoTorch: `pip install --upgrade pandas botorch`. -
OptimizationWarning: Failed to initialize using continuous relaxation. Using `sample_feasible_points` for initialization.
cause This warning from BoTorch (used by Ax) often indicates numerical issues or a challenging optimization landscape where the initial continuous optimization fails, and a fallback is used. It's often a warning, not a fatal error, but can indicate suboptimal performance.fixWhile often ignorable, check your search space definition for extreme bounds or constraints. Consider normalizing parameters. If performance is an issue, consult BoTorch documentation or Ax tutorials on advanced model configuration. -
SyntaxWarning: invalid escape sequence 'g' (or similar 'SyntaxWarning' related to escape sequences)
cause This Python warning is often triggered by raw strings (`r'...'`) or unescaped backslashes in older code that might not be fully compliant with newer Python versions' string literal rules (e.g., Python 3.12+). It can appear in internal library code or examples.fixThis is typically a warning from internal dependencies and might not directly impact your code's functionality, but it can be noisy. Ensure your Python version is compatible with the Ax version. If it's in your code, use raw strings (`r""`) or correctly escape backslashes (`\`).
Warnings
- breaking Ax 1.2.3 and later requires Python 3.11+. Older Python versions will cause installation or runtime failures.
- breaking Ax 1.2.3 and later requires Pandas 3.0+ and BoTorch 0.17.0+ due to breaking changes in their APIs. Older versions may lead to `AttributeError` or unexpected behavior.
- breaking The `transition_to` argument is now explicitly required on `TransitionCriterion` classes in Ax 1.2.3+. Code relying on implicit transitions will fail.
- deprecated The `AxClient` and the 'optimize' loop API (e.g., `ax.service.managed_loop.optimize`) are deprecated as of Ax 1.2.2. While still functional, they may be removed or changed incompatibly in future major/minor releases.
- gotcha SQLAlchemy is not a direct dependency in current Ax versions but is recommended for SQL storage. If installed, `SQLAlchemy>=2.0` can cause compatibility issues with Ax's internal storage components.
Install
-
pip install ax-platform -
pip install "ax-platform[notebook]" -
pip install "ax-platform[mysql]"
Imports
- Client
from ax import Client
- AxClient
from ax.service.ax_client import AxClient
from ax.api.client import Client
- RangeParameterConfig
from ax import RangeParameterConfig
Quickstart
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)