MultiOptimizer

class MultiOptimizer

Bases: _OptimizerBase[_T, _C]

Methods

__init__

Initialize the multi-objective optimizer.

add_random_training_data

Add randomly generated solution vectors to the training data.

add_solution

Add a new solution to the training data.

evaluate_objective

Evaluate the objective function for a given solution.

fallback_solution

Try to find an alternative solution when only duplicate solutions are returned from annealing.

find_unique_solution

Find a unique solution from a list of solutions.

minimize_surrogate

Find solutions that minimize the surrogate model.

optimize

Optimize the black-box function.

train_surrogate

Train the surrogate model(s).

values_from_solution

Convert a FlattenedSolution to a variable-name-keyed dict of values.

Attributes

amplify_model

Returns the amplify model.

best

Returns the best solution found so far.

blackbox

Returns the black-box function.

encoding_info

Returns the encoding information for the black-box function.

history

Returns the history of optimization iterations.

initial_training_data

Returns the initial training data for the black-box function.

rng

Returns the random number generator used in the optimizer.

surrogate_data_transformer

Returns the data transformers for the surrogate model training data.

surrogate_model

Returns the surrogate models.

surrogate_training_data

Returns the training data for the surrogate model (encoded if pre_encoding is True).

training_data

Returns the training data for the black-box function.

classmethod __class_getitem__(params)
__init__(
blackbox: BlackBoxFuncBase,
trainer: list[_T],
client: _C = AmplifyAEClient({'url': 'https://optigan.fixstars.com', 'token': '', 'compression': true, 'solver': 'Constraint', 'parameters': {}}),
*,
training_data: Dataset | None = None,
constraints: Constraint | ConstraintList | None = None,
pre_encoding: bool = True,
seed: int = 0,
surrogate_data_transformer: list[DataTransformer | None] | None = None,
) None

Initialize the multi-objective optimizer.

Parameters:
  • blackbox (BlackBoxFuncBase) – A black-box function defined with the @blackbox decorator.

  • trainer (list[_T]) – A list of Trainer instances, one per objective. Each element must be a distinct instance; passing the same instance for multiple objectives causes the internal model state to be shared, leading to incorrect training.

  • client (_C, optional) – A solver client defined with the Amplify SDK. Defaults to _default_client.

  • training_data (Dataset | None) – A training dataset for the surrogate model. Defaults to None.

  • constraints (amplify.Constraint | amplify.ConstraintList | None, optional) – Constraints. Defaults to None.

  • pre_encoding (bool, optional) – Whether to perform pre-encoding (True) or post-encoding (False). Defaults to True.

  • seed (int, optional) – A random seed. Defaults to 0.

  • surrogate_data_transformer (list[DataTransformer | None] | None, optional) – A list of data transformers (one per objective), or None. Each non-None element must be a distinct instance; passing the same instance for multiple objectives causes the scaling parameters to be shared across objectives. Defaults to None.

Raises:
  • TypeError – If blackbox is not a subclass of BlackBoxFuncBase.

  • TypeError – If trainer is not a list.

  • TypeError – If trainer contains non-Trainer elements.

  • TypeError – If client is not an instance of amplify.BaseClient.

  • TypeError – If training_data is not an instance of Dataset or None.

  • TypeError – If constraints is not an instance of amplify.Constraint, amplify.ConstraintList or None.

  • TypeError – If surrogate_data_transformer contains elements that are not DataTransformer or None.

  • ValueError – If trainer is an empty list.

  • ValueError – If trainer contains only one element (use Optimizer instead).

  • ValueError – If trainer contains duplicate instances.

  • ValueError – If surrogate_data_transformer list length does not match the number of objectives.

  • ValueError – If surrogate_data_transformer contains duplicate instances.

classmethod __init_subclass__(*args, **kwargs)

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

add_random_training_data(num_data: int, max_trials: int | None = None) None

Add randomly generated solution vectors to the training data.

If user-defined constraints are given to the optimizer, the random solutions are generated to satisfy the constraints.

Parameters:
  • num_data (int) – The number of solutions to be added.

  • max_trials (int | None, optional) – The max number of trials. This value must be greater than or equal to

  • None. (num_data. If None is given max_trials is set as 2 * num_data. Defaults to)

Raises:

ValueError – If max_trials is less than num_data.

add_solution(solution: FlattenedSolution, objective: float | list[float]) None

Add a new solution to the training data.

Parameters:
evaluate_objective(solution: FlattenedSolution, use_cache: bool = False) list[float]

Evaluate the objective function for a given solution.

Parameters:
  • solution (FlattenedSolution) – The solution to evaluate.

  • use_cache (bool, optional) – Whether to use cached results. Defaults to False.

Returns:

The objective values.

Return type:

list[float]

fallback_solution(
solutions: list[FlattenedSolution],
max_trials: int,
) FlattenedSolution | None

Try to find an alternative solution when only duplicate solutions are returned from annealing.

If user-defined constraints are given to the optimizer, the generated fallback solution is expected to satisfy the constraints.

Parameters:
  • solutions (list[FlattenedSolution]) – The duplicate input vectors (solutions of the optimization; the element closer to the beginning is a better solution).

  • max_trials (int) – The max number of trials to find an alternative solution that satisfies the given constraints if any. If max_trials is 0 or max_trials runs out, the first solution (annealing best) is returned regardless of the uniqueness of the solution.

Returns:

The alternative solution if found, otherwise None.

Return type:

FlattenedSolution | None

Raises:

ValueError – If max_trials is less than 0.

find_unique_solution(
solutions: list[FlattenedSolution],
) FlattenedSolution | None

Find a unique solution from a list of solutions.

Parameters:

solutions (list[FlattenedSolution]) – The list of solutions to search.

Returns:

The unique solution if found, otherwise None.

Return type:

FlattenedSolution | None

minimize_surrogate(max_retries: int = 10) tuple[list[FlattenedSolution], Result]

Find solutions that minimize the surrogate model.

Parameters:

max_retries (int, optional) – Maximum number of retries for annealing. Defaults to 10.

Returns:

List of optimized solutions and the Amplify SDK’s raw result. Solutions are in order of the objective value (from lowest to highest).

Return type:

tuple[list[FlattenedSolution], amplify.Result]

optimize(num_iterations: int, max_deduplication_trials: int | None = None) None

Optimize the black-box function.

Parameters:
  • num_iterations (int) – The number of iterations to perform.

  • max_deduplication_trials (int | None, optional) – The maximum number of trials to find an alternative solution when duplicate solutions are returned from annealing. If 0 is set, the first solution (annealing best) is returned regardless of the uniqueness of the solution. If None is given, it is set as the number of variables in the black-box function. Defaults to None.

Raises:
  • ValueError – If num_iterations is less than or equal to 0.

  • ValueError – If max_deduplication_trials is less than 0.

  • RuntimeError – If no feasible solution was found in the iteration.

train_surrogate() None

Train the surrogate model(s).

values_from_solution(solution: FlattenedSolution) dict[str, list[float | int] | float | int]

Convert a FlattenedSolution to a variable-name-keyed dict of values.

Parameters:

solution (FlattenedSolution) – A flattened solution, e.g. an element of the list returned by minimize_surrogate().

Returns:

The solution values keyed by variable name,

suitable for Solution.values.

Return type:

dict[str, list[float | int] | float | int]

__abstractmethods__ = frozenset({})
__dict__ = mappingproxy({'__module__': 'amplify_bbopt.optimizer', '__init__': <function MultiOptimizer.__init__>, 'surrogate_model': <property object>, 'surrogate_data_transformer': <property object>, 'best': <property object>, '_transform_surrogate_training_data': <function MultiOptimizer._transform_surrogate_training_data>, '_train_surrogate_models': <function MultiOptimizer._train_surrogate_models>, '_calc_constraint_weight': <function MultiOptimizer._calc_constraint_weight>, '_check_objective_count': <function MultiOptimizer._check_objective_count>, '_build_corrcoef_value': <function MultiOptimizer._build_corrcoef_value>, '_log_objective': <function MultiOptimizer._log_objective>, 'evaluate_objective': <function MultiOptimizer.evaluate_objective>, '__orig_bases__': (amplify_bbopt.optimizer._OptimizerBase[~_T, ~_C],), '__doc__': None, '__parameters__': (~_T, ~_C), '__abstractmethods__': frozenset(), '_abc_impl': <_abc._abc_data object>, '__annotations__': {'_surrogate_models': 'list[SurrogateModel]', '_surrogate_data_transformers': 'list[DataTransformer | None]', '_history': 'list[IterationResult]', '_pre_encoding': 'Final[bool]', '_num_initial_data': 'Final[int]'}})
__orig_bases__ = (amplify_bbopt.optimizer._OptimizerBase[~_T, ~_C],)
__parameters__ = (~_T, ~_C)
__slots__ = ()
__weakref__

list of weak references to the object (if defined)

property amplify_model: AmplifyModel

Returns the amplify model.

property best: Solution

Returns the best solution found so far.

Returns the solution with the minimum weighted sum of objective values, where each objective is appropriately weighted by the user-specified weight. This matches the combined objective value used internally during optimization when constant weights are used. When dynamic weights are considered, the best value is just for reference purpose only.

property blackbox: BlackBoxFuncBase

Returns the black-box function.

property encoding_info: EncodingInfo

Returns the encoding information for the black-box function.

property history: list[IterationResult]

Returns the history of optimization iterations.

property initial_training_data: Dataset

Returns the initial training data for the black-box function.

property rng: Generator

Returns the random number generator used in the optimizer.

property surrogate_data_transformer: list[DataTransformer | None]

Returns the data transformers for the surrogate model training data.

property surrogate_model: list[SurrogateModel]

Returns the surrogate models.

property surrogate_training_data: Dataset

Returns the training data for the surrogate model (encoded if pre_encoding is True).

property training_data: Dataset

Returns the training data for the black-box function.