bayesian_optimization module

Define bayesian optimization algorithms.

class BayesianOptimizationLW(*, compensating_elements, objective_factory, design_space, compute_beam_propagation, cavity_settings_factory, reference_simulation_output, optimisation_algorithm_kwargs=None, history_kwargs=None, **kwargs)[source]

Bases: OptimisationAlgorithm

Bayesian optimization algorithm.

Under the hood, relies on bayes_opt.BayesianOptimization.

The keys defined in TOML key: optimisation_algorithm_kwargs are passed to bayes_opt.BayesianOptimization.maximize().

Special keys:

Parameters:
supports_constraints: bool = False
optimize()[source]

Set up the optimization and solve the problem.

Return type:

OptiSol

Returns:

Gives list of solutions, corresponding objective, convergence violation if applicable, etc.

_to_maximise(**kwargs)[source]

The function to maximize by BO.

This is the classic OptimisationAlgorithm._norm_wrapper_residuals(), with two adaptations:

  • Multiplied by -1.0 to maximize instead of minimize

  • Takes arguments as floats instead of numpy array. - Keys are Variable.__str__()

Return type:

float

property _default_kwargs: dict[str, Any]

Create the kwargs for the optimisation.

_generate_opti_sol(result)[source]

Store the optimization results.

Parameters:

result (dict[str, Any] | None)

Return type:

OptiSol

_format_variables()[source]

Map every variable name with its limits.

Return type:

tuple[dict[str, float], dict[str, tuple[float, float]]]

_to_numpy(**kwargs)[source]

Convert dict of variables to numpy array.

Return type:

ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]

acquisition_function()[source]

Get acquisition function.

Todo

Allow for user-defined acquisition function.

We use kwargs from the "acquisition" key. It can look like:

[wtf.optimisation_algorithm_kwargs]
# arguments passed to `BayesianOptimization.maximize` method

[wtf.optimisation_algorithm_kwargs.acquisition]
# arguments used to define acquisition function
# Name of a func in `bayes_opt.acquisition`:
acquisition_name = "UpperConfidenceBound"
# Kwargs passed to this function:
kwargs = { kappa = 2.576, random_state = 42 }
Return type:

AcquisitionFunction | None

_abc_impl = <_abc._abc_data object at 0x7318f91bc300>