Variable Conversion¶
In general, the Ising machines used in QA-BBO can directly handle only binary decision variables. However, practical black-box optimization problems often involve not only binary variables but also integer, real, or mixed-type decision variables. To support such non-binary variables, Amplify-BBOpt internally performs variable conversion when necessary.
Timing of variable conversion¶
When variable conversion is required (i.e., when the decision variables include integer or real variables), variables are converted at one of two stages: pre-encoding or post-encoding. You can specify when the conversion should take place by setting the pre_encoding argument when instantiating Optimizer. The default setting is pre_encoding = True.
from amplify_bbopt import Optimizer
# Instantiate the optimizer class (using pre-encoding; default setting)
optimizer = Optimizer(
blackbox_func,
trainer,
client,
pre_encoding=True,
)
# Instantiate the optimizer class (using post-encoding)
optimizer = Optimizer(
blackbox_func,
trainer,
client,
pre_encoding=False,
)
Note
In the above code, blackbox_func, trainer, and client refer to the previously defined black-box function, surrogate model function, and the Amplify SDK solver client, respectively. For details on their setup, see “Running the Optimization”.
Pre-encoding (Default)¶
Pre-encoding is a variable conversion method in which encoding is performed before constructing the surrogate model function. Since the surrogate model is trained using the encoded training data, its inputs consist only of binary values. An additional advantage of pre-encoding is that it allows the surrogate model to represent relationships of a degree higher than that of the model’s inherent polynomial order as a result of the encoding process.
Pre-encoding is automatically performed within Amplify-BBOpt. The following diagram illustrates the processing flow for pre-encoding.
Post-encoding¶
Post-encoding is a variable conversion method in which encoding is performed after constructing the surrogate model function. In this approach, the surrogate model is built directly using the original training data provided by the user. Therefore, the type of the inputs to the surrogate model depend on the original data values, not on encoded representations. The function form that the surrogate model can express is limited by the polynomial order considered in the surrogate model (typically second order).
Post-encoding is carried out either within Amplify-BBOpt or as part of the internal process of the Amplify SDK. The following diagram illustrates the processing flow for post-encoding. EncodingMethod is the class related to encoding, which is explained in the next section.
Encoding types and settings¶
Encoding method available for pre-encoding¶
When using pre-encoding, you can choose between two encoding methods: domain-wall (default) and one-hot encoding. These methods can be specified using the EncodingMethod class.
EncodingMethodclassThis class defines the encoding method and provides two selectable attributes:
DomainWall(domain-wall) andOneHot(one-hot). The default is domain-wall. The encoding method can be specified when defining decision variables as follows:
In the case of real decision variables, the range specified by bounds must be discretized into discrete points. This discretization behavior can be controlled using the classes DiscretizationSpec and DiscretizationMethod, as summarized below.
DiscretizationSpecclassThis class defines how discretization is performed, with the following key attributes:
method(discretization method) andnum_bins(number of discrete points). By default,method=DiscretizationMethod.Uniformandnum_bins=11are used, meaning that the real variable range is divided into 11 equally spaced discrete points.The
DiscretizationMethodclass defines available discretization schemes:Uniform(uniform discretization) andLogUniform(log-uniform discretization).Caution
When using log-uniform discretization (
DiscretizationMethod.LogUniform), the range (bounds) of the real variable must be positive.>>> from amplify_bbopt import RealVariable, DiscretizationSpec, DiscretizationMethod >>> x_3 = RealVariable( ... bounds=(0.0, 4.0), ... discretization_spec=DiscretizationSpec( ... method=DiscretizationMethod.LogUniform ... ), ... ) Traceback (most recent call last): ... ValueError: Lower bound must be greater than 0 for `LogUniform` discretization.
Encoding methods available for post-encoding¶
When using post-encoding, the available encoding methods are:
EncodingMethod.DomainWall,
EncodingMethod.OneHot, and
EncodingMethod.Amplify.
If EncodingMethod.Amplify is selected, the variable conversion is performed internally within the Amplify SDK according to its default encoding method.
For details on variable conversion handled by the Amplify SDK, see the official documentation pages: Encoding integer variables into binary variables and Encoding real variables into binary variables.