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.core.base.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.
-
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.
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_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
(problems=None, methods=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.
- Parameters
problems (
Union
[List
[BenchmarkProblem
],List
[str
],None
]) – Problems to benchmark on, represented as BenchmarkProblem-s or string keys (must be in standard BOProblems). Defaults to all standard BOProblems.methods (
Union
[List
[GenerationStrategy
],List
[str
],None
]) – Methods to benchmark, represented as generation strategies or or string keys (must be in standard BOMethods). Defaults to all standard BOMethods.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