Variable Conversion¶
For some black-box optimization methods such as FMQA and kernel-QA, the decision variables may need to be converted to more primitive types. This conversion is performed internally so that you do not need to be bothered. Below shows two typical types—a priori and a posteriori—of such conversion.
A priori:
All decision variables and corresponding values in the training data are converted to binary values before constructing the surrogate model/acquisition function (thus, only encoded binary values are passed to the model/function). Thus, the resulting model/function is naturally in a QUBO form, which can be directly passed to most optimization solvers. Amplify-BBOpt implements encoding methods based on domain-wall and one-hot.Note
The original FMQA[1], which is available from
FMQAOptimizer
assumes this a priori variable convesion manner. In Amplify-BBOpt you can consider the following a posteriori conversion as well.A posteriori:
Depending on the optimization method, Amplify-BBOpt considers non-binary decision variables as they are without encoding mentioned above. The surrogate model/acquisition function can be trained based on the non-binary input values directly. The resulting quadratic polynomial of non-binary variables is then passed to the Fixstars Amplify SDK used internally in Amplify-BBOpt. The SDK may further perform variable/model conversion to another form with the default setting before sending the formulation to a optimization solver.
The difference in the above two conversion types is when the conversion happens (i.e. before or after the formulation). In Amplify-BBOpt, you can specify a conversion method from domain_wall
(a priori), one_hot
(a priori) and amplify
(a posteriori) in the instantiation of variables as follows. The default conversion method is domain_wall
. For binary variables, BinaryVariable
and BinaryVariableList
, no conversion is necessary.
Note
As of now, the encoding method amplify
is only available for IntegerVariable
and IntegerVariableList
. The encoding method amplify
is planned to be implemented for RealVariable
and RealVariableList
.
Typical examples of specifying an encoding method and obtaining information of resulting variables are shown below.
from amplify_bbopt import IntegerVariable
# The default encoding method is domain-wall.
int_var_1 = IntegerVariable(bounds=(0, 4))
print(int_var_1)
type nbins len method nvars i=0 i=1 i=2 i=3 i=4
None int 5 1 domain_wall 4 0 1 2 3 4
int_var_2 = IntegerVariable(bounds=(0, 4), method="one_hot")
print(int_var_2)
type nbins len method nvars i=0 i=1 i=2 i=3 i=4
None int 5 1 one_hot 5 0 1 2 3 4
To let Amplify SDK handles the conversion (FM model considers non-binary variables directly in case of FMQA), you can specify as:
int_var_3 = IntegerVariable(bounds=(0, 4), method="amplify")
print(int_var_3)
type nbins len method nvars i=0
None int 1 1 amplify 1 (0, 4)
If a chosen black-box optimization method requires variable encoding, different encoding methods can be used for different variables in single black-box function defined as described in “2. Black-Box Function”, unless otherwise noted. For example, the following usage is valid. See that different encoding methods are specified for the variables in objective_lift_drag
.
from amplify_bbopt import RealVariable, blackbox
from utils.pseudo_simulators import (
pseudo_wing_simulator as wing_simulator,
)
@blackbox
def objective_lift_drag(
width: float = RealVariable(bounds=(1, 20), nbins=100, method="one_hot"),
height: float = RealVariable(bounds=(1, 5), nbins=20),
angle: float = RealVariable(bounds=(0, 45), nbins=20, method="one_hot"),
) -> float:
"""This black-box function executes wing_simulator(), and returns
the negative lift-drag ratio for a given wing's width, height, and angle.
"""
lift, drag = wing_simulator(width, height, angle)
return -lift / drag # value to minimize
print(objective_lift_drag.variables)
type nbins len method nvars i=0 i=1 i=2 i=3 i=4 i=5 i=6 i=7 i=8 i=9 i=10 i=11 i=12 i=13 i=14 i=15 i=16 i=17 i=18 i=19 i=20 i=21 i=22 i=23 i=24 i=25 i=26 i=27 i=28 i=29 i=30 i=31 i=32 i=33 i=34 i=35 i=36 i=37 i=38 i=39 i=40 i=41 i=42 i=43 i=44 i=45 i=46 i=47 i=48 i=49 \
width float 100 1 one_hot 100 1.0 1.1919191919191918 1.3838383838383839 1.5757575757575757 1.7676767676767677 1.9595959595959596 2.1515151515151514 2.3434343434343434 2.5353535353535355 2.727272727272727 2.919191919191919 3.111111111111111 3.3030303030303028 3.494949494949495 3.686868686868687 3.8787878787878785 4.070707070707071 4.262626262626263 4.454545454545454 4.646464646464646 4.838383838383838 5.03030303030303 5.222222222222222 5.4141414141414135 5.6060606060606055 5.797979797979798 5.98989898989899 6.181818181818182 6.373737373737374 6.565656565656565 6.757575757575757 6.949494949494949 7.141414141414141 7.333333333333333 7.525252525252525 7.717171717171717 7.909090909090908 8.1010101010101 8.292929292929292 8.484848484848484 8.676767676767676 8.868686868686869 9.06060606060606 9.252525252525253 9.444444444444445 9.636363636363635 9.828282828282827 10.020202020202019 10.212121212121211 10.404040404040403
height float 20 1 domain_wall 19 1.0 1.2105263157894737 1.4210526315789473 1.631578947368421 1.8421052631578947 2.052631578947368 2.263157894736842 2.473684210526316 2.6842105263157894 2.894736842105263 3.1052631578947367 3.3157894736842106 3.526315789473684 3.7368421052631575 3.9473684210526314 4.157894736842105 4.368421052631579 4.578947368421052 4.789473684210526 5.0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
angle float 20 1 one_hot 20 0.0 2.3684210526315788 4.7368421052631575 7.105263157894736 9.473684210526315 11.842105263157894 14.210526315789473 16.57894736842105 18.94736842105263 21.31578947368421 23.684210526315788 26.052631578947366 28.421052631578945 30.789473684210524 33.1578947368421 35.526315789473685 37.89473684210526 40.263157894736835 42.63157894736842 45.0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
i=50 i=51 i=52 i=53 i=54 i=55 i=56 i=57 i=58 i=59 i=60 i=61 i=62 i=63 i=64 i=65 i=66 i=67 i=68 i=69 i=70 i=71 i=72 i=73 i=74 i=75 i=76 i=77 i=78 i=79 i=80 i=81 i=82 i=83 i=84 i=85 i=86 i=87 i=88 i=89 i=90 i=91 i=92 i=93 i=94 i=95 i=96 i=97 i=98 i=99
width 10.595959595959595 10.787878787878787 10.97979797979798 11.171717171717171 11.363636363636363 11.555555555555555 11.747474747474747 11.93939393939394 12.13131313131313 12.323232323232322 12.515151515151514 12.707070707070706 12.898989898989898 13.09090909090909 13.282828282828282 13.474747474747474 13.666666666666666 13.858585858585858 14.05050505050505 14.242424242424242 14.434343434343434 14.626262626262625 14.818181818181817 15.010101010101009 15.2020202020202 15.393939393939393 15.585858585858585 15.777777777777777 15.969696969696969 16.16161616161616 16.353535353535353 16.545454545454547 16.737373737373737 16.929292929292927 17.12121212121212 17.31313131313131 17.505050505050505 17.696969696969695 17.88888888888889 18.08080808080808 18.27272727272727 18.464646464646464 18.656565656565654 18.848484848484848 19.040404040404038 19.232323232323232 19.424242424242422 19.616161616161616 19.808080808080806 20.0
height - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
angle - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -