FMQAOptimizer¶

class FMQAOptimizer¶

Bases: QAOptimizerBase

Class for FMQA.

Methods

__init__

Initialize kernel-QA optimizer.

fetch_history

Return the optimization history.

optimize

A function to execute black-box optmization with FMQA.

set_best

Set the current best solution and corresponding objective function value.

update_objective_weight

Update the weight for the objective function.

Attributes

amplify_model

The current Amplify-SDK model.

best_objective

Objective function value corresponding to the current best solution (optimaized input).

best_solution

Current best solution (optimized input).

custom_amplify_objective

Custom objective function that may be ceated directly from amplify.PolyArray.

data

Current training dataset (both input and output of an individual objective function).

i_cycle

The number of current optimization cycle.

num_initial_data

A number of the samples in initial data.

objective

Objective function class instance.

objective_weight

The latest weight for the objective function.

surrogate_model

The current surrogate model (e.g. an instance of TorchFM by default).

trainer

The instance of the trainer class (e.g. an instance of TorchFMTrainer by default).

class SolutionFrequency¶

Bases: object

Class to determine whether a given solution appears frequently or not.

__init__(counter_threshold: int) None¶
how_frequent(solution: FlatSolutionDict) int¶
is_frequent(solution: FlatSolutionDict) bool¶
__dict__ = mappingproxy({'__module__': 'amplify_bbopt.optimizer', '__doc__': 'Class to determine whether a given solution appears frequently or not.', '__init__': <function QAOptimizerBase.SolutionFrequency.__init__>, '_update_item': <function QAOptimizerBase.SolutionFrequency._update_item>, '_update_counter': <function QAOptimizerBase.SolutionFrequency._update_counter>, 'is_frequent': <function QAOptimizerBase.SolutionFrequency.is_frequent>, 'how_frequent': <function QAOptimizerBase.SolutionFrequency.how_frequent>, '__dict__': <attribute '__dict__' of 'SolutionFrequency' objects>, '__weakref__': <attribute '__weakref__' of 'SolutionFrequency' objects>, '__annotations__': {'_solution_counter': 'dict[tuple, int]'}})¶
__weakref__¶

list of weak references to the object (if defined)

classmethod __class_getitem__(params)¶
__init__(data: ~amplify_bbopt.data_list.DataList, objective: ~amplify_bbopt.bb_func.BlackBoxFuncBase, client: ~amplify.FixstarsClient | ~amplify.DWaveSamplerClient | ~amplify.LeapHybridSamplerClient | ~amplify.LeapHybridCQMSamplerClient | ~amplify.FujitsuDA4Client | ~amplify.ToshibaSQBM2Client | ~amplify.GurobiClient | ~amplify.NECVA2Client | None = None, trainer_class: type[~amplify_bbopt.trainer.TorchFMTrainer] = <class 'amplify_bbopt.trainer.TorchFMTrainer'>, seed: int = 0, objective_weight: float | ~typing.Callable[[~typing.Any], float] = 1.0) None¶

Initialize kernel-QA optimizer.

By default, the class uses ModelKernelTrainer as a training class, and this training class uses ModelKernel as a default surrogate/acquisition model class.

Parameters:
  • data (DataList) – Initial training dataset.

  • objective (BlackBoxFuncBase) – A black-box function class instance created with blackbox decorator.

  • client (amplify.FixstarsClient | amplify.DWaveSamplerClient | amplify.LeapHybridSamplerClient | amplify.LeapHybridCQMSamplerClient | amplify.FujitsuDA4Client | amplify.ToshibaSQBM2Client | amplify.GurobiClient | amplify.NECVA2Client, optional) – A solver client. Defaults to None.

  • trainer_class (type[TorchFMTrainer], optional) – A solver client available in the Amplify SDK. Defaults to TorchFMTrainer.

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

  • objective_weight (float | Callable[[Any], float], optional) – A weight imposed on the objective function in amplify.Model. If a Callable object is passed, a weight is the return value of the object with the used optimizer instance as an argument at each optimization cycle. Generally, weight is only useful in case of multi-objective optimization using MultiObjectiveOptimizer. Defaults to 1.0.

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.

__str__() str¶

Some human-readable information relevant to the optimizer.

Returns:

Description.

Return type:

str

fetch_history() History¶

Return the optimization history.

Returns:

The optimization history.

Return type:

History

optimize(
num_cycles: int = 10,
constraint_weight: float | None = None,
num_solves: int = 1,
search_max: int = 1000,
show_annealing_history: bool = False,
target_num_iterations: int | None = None,
) None¶

A function to execute black-box optmization with FMQA.

Parameters:
  • num_cycles (int, optional) – A number of optimization iterations. Defaults to 10.

  • constraint_weight (float | None, optional) – A weight for constraints. If set None, the weight is determined based on the latest training data as in 2 times of DataList.abs_y_max. If constraint weights are seperately set for Constraint.weight, this constraint_weight is multiplied on top of Constraint.weight. Defaults to None.

  • num_solves (int, optional) – A number of serial solver execution in the Amplify SDK’s serial solver execution (https://amplify.fixstars.com/en/docs/amplify/v1/serial.html). Defaults to 1.

  • search_max (int, optional) – If the found solution is found the training data, alternative solution close to the original solution is searched for at most search_max times. Defaults to 1000.

  • show_annealing_history (bool, optional) – True to show a annealing history with time stamp. Available when Amplify Annealing Engine (amplify.FixstarsClient) is specified as the client in the constructor. Defaults to False.

  • target_num_iterations (int | None, optional) – Annealing timeout is controlled based on the [previous timeout] * target_num_iterations / [previous num_iterations]. Available when Amplify Annealng Engine is used for optimization solver. Set None to use the given timeout constantly. Defaults to None.

set_best(best_solution_dict: FlatSolutionDict | None = None) None¶

Set the current best solution and corresponding objective function value.

If QAOptimizerBase.custom_amplify_objective is set, the QAOptimizerBase.best_objective include the value of the custom objective as well. This inclusion of the custom objective is the difference from OptimizerBase.set_best.

Parameters:

best_solution_dict (FlatSolutionDict | None, optional) – A solution dictionary. This may contains solution values from other objective functions in case of multiple-objective optimization. In this case, ‘best’ means the variable value vector relevant to an individual objective function, that is a subset of the entire solution which achieve the best of multiple objectives combined. Therefore, the set best here may not be the same as the best in QAOptimizerBase.data. If None is specified, search the best from OptimizerBase.data. Defaults to None.

update_objective_weight(optimizer: Any) None¶

Update the weight for the objective function.

The weight is determined according to the weight function passed to OptimizerBase.__init__ (OptimizerBase.objective_weight is callable). In case of OptimizerBase.objective_weight being float, the weight is constant over optimization cycles. Expected to be executed at the beginning of each optmization cycle.

Parameters:

optimizer (Any) – An optimizer to be passed to the callable OptimizerBase.objective_weight.

__abstractmethods__ = frozenset({})¶
__dict__ = mappingproxy({'__module__': 'amplify_bbopt.optimizer', '__doc__': 'Class for FMQA.', '__init__': <function FMQAOptimizer.__init__>, 'surrogate_model': <property object>, 'trainer': <property object>, '__parameters__': (), '__abstractmethods__': frozenset(), '_abc_impl': <_abc._abc_data object>, '__annotations__': {'_surrogate_model': 'M | None', '_amplify_model': 'amplify.Model | None', '_custom_amplify_objective': 'amplify.Poly | None', '_duplicate_solution_counter': 'dict[tuple, int]', '_target_num_iterations': 'int | None', '_elapsed_time': 'list[float]', '_is_de_duplication': 'list[bool]', '_objective_weight': 'float | None', '_best_objective': 'int | float | None'}})¶
__orig_bases__ = (<class 'amplify_bbopt.optimizer.OptimizerBase'>, typing.Generic[~T, ~M])¶
__parameters__ = ()¶
__slots__ = ()¶
__weakref__¶

list of weak references to the object (if defined)

property amplify_model: Model | None¶

The current Amplify-SDK model. If the model is not constructed yet, return None.

Return type:

amplify.Model | None

property best_objective: int | float¶

Objective function value corresponding to the current best solution (optimaized input).

property best_solution: StructuredSolutionDict¶

Current best solution (optimized input).

property custom_amplify_objective: Poly | None¶

Custom objective function that may be ceated directly from amplify.PolyArray.

Custom objective does NOT have to be converted from the surrogate model of the black-box function. Retieve amplify.PolyArray via Variables.poly_array or Variables.amplify_variables, and construct an Amplify SDK’s objective function directly, which will be added to the objective constructed from a surrogate model while creating amplify.Model. Such a custom objective function must be created after the instantiation of an QA-based optimizer class, as this is when amplify.PolyArray’s are issued for each of the variables.

Returns:

Custom objective function.

Return type:

amplify.Poly | None

property data: DataList¶

Current training dataset (both input and output of an individual objective function).

property i_cycle: int¶

The number of current optimization cycle.

property num_initial_data: int¶

A number of the samples in initial data.

property objective: BlackBoxFuncBase¶

Objective function class instance.

property objective_weight: float | None¶

The latest weight for the objective function.

property surrogate_model: TorchFM | None¶

The current surrogate model (e.g. an instance of TorchFM by default). If not set return None.

property trainer: TorchFMTrainer¶

The instance of the trainer class (e.g. an instance of TorchFMTrainer by default).