ax.benchmark¶
Benchmark Problem¶
-
class
ax.benchmark.benchmark_problem.
BenchmarkProblem
(search_space, optimization_config, name=None, optimal_value=None, evaluate_suggested=True)[source]¶ Bases:
ax.utils.common.equality.Base
Benchmark problem, represented in terms of Ax search space and optimization config. Useful to represent complex problems that involve constaints, non- range parameters, etc.
Note: if this problem is computationally intensive, consider setting evaluate_suggested argument to False.
- Parameters
search_space (
SearchSpace
) – Problem domain.optimization_config (
OptimizationConfig
) – Problem objective and constraints. Note that by default, an Objective in the OptimizationConfig has minimize set to False, so by default an OptimizationConfig is that of maximization.name (
Optional
[str
]) – Optional name of the problem, will default to the name of the objective metric (e.g., “Branin” or “Branin_constrainted” if constraints are present). The name of the problem is reflected in the names of the benchmarking experiments (e.g. “Sobol_on_Branin”).optimal_value (
Optional
[float
]) – Optional target objective value for the optimization.evaluate_suggested (
bool
) – Whether the model-predicted best value should be evaluated when benchmarking on this problem. Note that in practice, this means that for every model-generated trial, an extra point will be evaluated. This extra point is often different from the model- generated trials, since those trials aim to both explore and exploit, so the aim is not usually to suggest the current model-predicted optimum.
-
evaluate_suggested
: bool = None¶
-
name
: str = None¶
-
optimal_value
: Optional[float] = None¶
-
optimization_config
: OptimizationConfig = None¶
-
search_space
: SearchSpace = None¶
-
class
ax.benchmark.benchmark_problem.
SimpleBenchmarkProblem
(f, name=None, domain=None, optimal_value=None, minimize=False, noise_sd=0.0, evaluate_suggested=True)[source]¶ Bases:
ax.benchmark.benchmark_problem.BenchmarkProblem
Benchmark problem, represented in terms of simplified constructions: a callable function, a domain that consists or ranges, etc. This problem does not support parameter or outcome constraints.
Note: if this problem is computationally intensive, consider setting evaluate_suggested argument to False.
- Parameters
f (
Union
[SyntheticFunction
,function
]) – Ax SyntheticFunction or an ad-hoc callable that evaluates points represented as nd-arrays. Input to the callable should be an (n x d) array, where n is the number of points to evaluate, and d is the dimensionality of the points. Returns a float or an (1 x n) array. Used as problem objective.name (
Optional
[str
]) – Optional name of the problem, will default to the name of the objective metric (e.g., “Branin” or “Branin_constrainted” if constraints are present). The name of the problem is reflected in the names of the benchmarking experiments (e.g. “Sobol_on_Branin”).domain (
Optional
[List
[Tuple
[float
,float
]]]) – Problem domain as list of tuples. Parameter names will be derived from the length of this list, as {“x1”, …, “xN”}, where N is the length of this list.optimal_value (
Optional
[float
]) – Optional target objective value for the optimization.minimize (
bool
) – Whether this is a minimization problem, defatuls to False.noise_sd (
float
) – Measure of the noise that will be added to the observations during the optimization. During the evaluation phase, true values will be extracted to measure a method’s performance. Only applicable when using a known SyntetheticFunction as the f argument.evaluate_suggested (
bool
) – Whether the model-predicted best value should be evaluated when benchmarking on this problem. Note that in practice, this means that for every model-generated trial, an extra point will be evaluated. This extra point is often different from the model- generated trials, since those trials aim to both explore and exploit, so the aim is not usually to suggest the current model-predicted optimum.
-
domain
: List[Tuple[float, float]] = None¶
-
evaluate_suggested
: bool = None¶
-
f
: Union[SyntheticFunction, FunctionType] = None¶
-
minimize
: bool = None¶
-
name
: str = None¶
-
noise_sd
: float = None¶
-
optimal_value
: Optional[float] = None¶
Benchmark Result¶
-
class
ax.benchmark.benchmark_result.
BenchmarkResult
(objective_at_true_best, fit_times, gen_times, optimum, model_transitions)[source]¶ Bases:
tuple
-
property
fit_times
¶ Alias for field number 1
-
property
gen_times
¶ Alias for field number 2
-
property
model_transitions
¶ Alias for field number 4
-
property
objective_at_true_best
¶ Alias for field number 0
-
property
optimum
¶ Alias for field number 3
-
property
-
ax.benchmark.benchmark_result.
aggregate_problem_results
(runs, problem, model_transitions=None)[source]¶ - Return type
-
ax.benchmark.benchmark_result.
extract_optimization_trace
(experiment, problem)[source]¶ Extract outcomes of an experiment: best cumulative objective as numpy ND- array, and total model-fitting time and candidate generation time as floats.
- Return type
ndarray
-
ax.benchmark.benchmark_result.
generate_report
(benchmark_results, errors_encountered=None, include_individual_method_plots=False, notebook_env=False)[source]¶ - Return type
Benchmark¶
Module for benchmarking Ax algorithms.
Key terms used:
Trial –– usual Ax Trial or BatchTral, one execution of a given arm or group of arms.
Replication –– one run of an optimization loop; 1 method + problem combination.
Test –– multiple replications, ran for statistical significance.
Full run –– multiple tests: run all methods with all problems.
Method –– (one of) the algorithm(s) being benchmarked.
Problem –– a synthetic function, a surrogate surface, or an ML model, on which to assess the performance of algorithms.
-
exception
ax.benchmark.benchmark.
NonRetryableBenchmarkingError
[source]¶ Bases:
ValueError
Error that indicates an issue with the benchmarking setup (e.g. unexpected problem setup, a benchmarking function called incorrectly, etc.) –– something that prevents the benchmarking suite itself from running, rather than an error that occurs during the runs of the benchmarking trials, replications, or tests.
-
ax.benchmark.benchmark.
benchmark_minimize_callable
(problem, num_trials, method_name, replication_index=None)[source]¶ An interface for evaluating external methods on Ax benchmark problems. The arms run and performance will be tracked by Ax, so the external method can be evaluated alongside Ax methods.
It is designed around methods that implement an interface like scipy.optimize.minimize. This function will return a callable evaluation function that takes in an array of parameter values and returns a float objective value. The evaluation function should always be minimized: if the benchmark problem is a maximization problem, then the value returned by the evaluation function will be negated so it can be used directly by methods that minimize. This callable can be given to an external minimization function, and Ax will track all of the calls made to it and the arms that were evaluated.
This will also return an Experiment object that will track the arms evaluated by the external method in the same way as done for Ax internal benchmarks. This function should thus be used for each benchmark replication.
- Parameters
problem (
BenchmarkProblem
) – The Ax benchmark problem to be used to construct the evalutaion function.num_trials (
int
) – The maximum number of trials for a benchmark run.method_name (
str
) – Name of the method being tested.replication_index (
Optional
[int
]) – Replicate number, if multiple replicates are being run.
- Return type
-
ax.benchmark.benchmark.
benchmark_replication
(problem, method, num_trials, replication_index=None, batch_size=1, raise_all_exceptions=False, benchmark_trial=<function benchmark_trial>, verbose_logging=True, failed_trials_tolerated=5)[source]¶ Runs one benchmarking replication (equivalent to one optimization loop).
- Parameters
problem (
BenchmarkProblem
) – Problem to benchmark on.method (
GenerationStrategy
) – Method to benchmark, represented as generation strategies.num_trials (
int
) – Number of trials in each test experiment.batch_size (
int
) – Batch size for this replication, defaults to 1.raise_all_exceptions (
bool
) – If set to True, any encountered exception will be raised; alternatively, failure tolerance thresholds are used and a few number of trials failed_trials_tolerated can fail before a replication is considered failed.benchmark_trial (
function
) – Function that runs a single trial. Defaults to benchmark_trial in this module and must have the same signature.verbose_logging (
bool
) – Whether logging level should be set to INFO.failed_trials_tolerated (
int
) – How many trials can fail before a replication is considered failed and aborted. Defaults to 5.
- Return type
-
ax.benchmark.benchmark.
benchmark_test
(problem, method, num_trials, num_replications=20, batch_size=1, raise_all_exceptions=False, benchmark_replication=<function benchmark_replication>, benchmark_trial=<function benchmark_trial>, verbose_logging=True, failed_trials_tolerated=5, failed_replications_tolerated=3)[source]¶ Runs one benchmarking test (equivalent to one problem-method combination), translates into num_replication replications, ran for statistical significance of the results.
- Parameters
problem (
BenchmarkProblem
) – Problem to benchmark on.method (
GenerationStrategy
) – Method to benchmark, represented as generation strategies.num_replications (
int
) – Number of times to run each test (each problem-method combination), for an aggregated result.num_trials (
int
) – Number of trials in each test experiment, defaults to 20.batch_size (
int
) – Batch size for this test, defaults to 1.raise_all_exceptions (
bool
) – If set to True, any encountered exception will be raised; alternatively, failure tolerance thresholds are used and a few number of trials failed_trials_tolerated can fail before a replication is considered failed, as well some replications failed_replications_tolerated can fail before a benchmarking test is considered failed.benchmark_replication (
function
) – Function that runs a single benchmarking replication. Defaults to benchmark_replication in this module and must have the same signature.benchmark_trial (
function
) – Function that runs a single trial. Defaults to benchmark_trial in this module and must have the same signature.verbose_logging (
bool
) – Whether logging level should be set to INFO.failed_trials_tolerated (
int
) – How many trials can fail before a replication is considered failed and aborted. Defaults to 5.failed_replications_tolerated (
int
) – How many replications can fail before a test is considered failed and aborted. Defaults to 3.
- Return type
-
ax.benchmark.benchmark.
benchmark_trial
(parameterization=None, evaluation_function=None, experiment=None, trial_index=None)[source]¶ Evaluates one trial from benchmarking replication (an Ax trial or batched trial). Evaluation requires either the parameterization and evalution_ function parameters or the experiment and trial_index parameters.
Note: evaluation function relies on the ordering of items in the parameterization nd-array.
- Parameters
parameterization (
Optional
[ndarray
]) – The parameterization to evaluate.evaluation_function (
Union
[SyntheticFunction
,function
,None
]) – The evaluation function for the benchmark objective.experiment (
Optional
[Experiment
]) – Experiment, for a trial on which to fetch data.trial_index (
Optional
[int
]) – Index of the trial, for which to fetch data.
- Return type
-
ax.benchmark.benchmark.
full_benchmark_run
(problem_groups=None, method_groups=None, num_trials=20, num_replications=20, batch_size=1, raise_all_exceptions=False, benchmark_test=<function benchmark_test>, benchmark_replication=<function benchmark_replication>, benchmark_trial=<function benchmark_trial>, verbose_logging=True, failed_trials_tolerated=5, failed_replications_tolerated=3)[source]¶ Full run of the benchmarking suite. To make benchmarking distrubuted at a level of a test, a replication, or a trial (or any combination of those), by passing in a wrapped (in some scheduling logic) version of a corresponding function from this module.
Here, problem_groups and method_groups are dictionaries that have the same keys such that we can run a specific subset of problems with a corresponding subset of methods.
Example:
problem_groups = { "single_fidelity": [ackley, branin], "multi_fidelity": [augmented_hartmann], } method_groups = { "single_fidelity": [single_task_GP_and_NEI_strategy], "multi_fidelity": [fixed_noise_MFGP_and_MFKG_strategy], }
Here, ackley and branin will be run against single_task_GP_and_NEI_strategy and augmented_hartmann against fixed_noise_MFGP_and_MFKG_strategy.
- Parameters
problem_groups (
Optional
[Dict
[str
,Union
[List
[BenchmarkProblem
],List
[str
]]]]) – Problems to benchmark on, represented as a dictionary from category string to List of BenchmarkProblem-s or string keys (must be in standard BOProblems). More on problem_groups below.method_groups (
Optional
[Dict
[str
,Union
[List
[GenerationStrategy
],List
[str
]]]]) – Methods to benchmark on, represented as a dictionary from category string to List of generation strategies or string keys (must be in standard BOMethods). More on method_groups below.num_replications (
int
) – Number of times to run each test (each problem-method combination), for an aggregated result.num_trials (
Union
[int
,List
[List
[int
]]]) – Number of trials in each test experiment.raise_all_exceptions (
bool
) – If set to True, any encountered exception will be raised; alternatively, failure tolerance thresholds are used and a few number of trials failed_trials_tolerated can fail before a replication is considered failed, as well some replications failed_replications_tolerated can fail before a benchmarking test is considered failed.benchmark_test (
function
) – Function that runs a single benchmarking test. Defaults to benchmark_test in this module and must have the same signature.benchmark_replication (
function
) – Function that runs a single benchmarking replication. Defaults to benchmark_replication in this module and must have the same signature.benchmark_trial (
function
) – Function that runs a single trial. Defaults to benchmark_trial in this module and must have the same signature.verbose_logging (
bool
) – Whether logging level should be set to INFO.failed_trials_tolerated (
int
) – How many trials can fail before a replication is considered failed and aborted. Defaults to 5.failed_replications_tolerated (
int
) – How many replications can fail before a test is considered failed and aborted. Defaults to 3.
- Return type
Benchmark Utilities¶
-
ax.benchmark.utils.
get_corresponding
(value_or_matrix, row, col)[source]¶ If value_or_matrix is a matrix, extract the value in cell specified by row and col. If value_or_matrix is a scalar, just return it.
- Return type
BoTorch Methods¶
-
ax.benchmark.botorch_methods.
fixed_noise_gp_model_constructor
(Xs, Ys, Yvars, task_features, fidelity_features, metric_names, state_dict=None, refit_model=True, **kwargs)[source]¶ - Return type
Model