2. Black-box optimization
implementation (integer variables)¶
This section describes the program implementation of FMQA, a black-box optimization method that
utilizes
the Ising machine.
The processing flow of FMQA is described in this tutorial, but it is performed
according to the following cycle.
In black-box optimization, including FMQA, the objective function is treated as a black box, allowing
it
to be generally applied without modifying the program implementation itself. Therefore, it is not
always
necessary to understand the program implementation of black-box optimization explained here.
2.1. Defining the decision variable class¶
Since the Ising machine used during FMQA can directly handle only binary decision variables,
appropriate
encoding is necessary when considering non-binary decision variables such as integers and real
numbers. In
this tutorial, we consider integer decision classes with domain wall encoding and address non-binary
decision variables.
2.1.1. What is domain wall encoding?¶
Domain-Wall Encoding is a method for converting discrete, non-binary variables (e.g., integer
variables
that can take values from 0 to k) into binary variables.
Assume an integer variable $x$ takes $(k+1)$ possible values in $\{0, 1, \dots, k\}$.
In Domain-Wall Encoding, values are represented using $k$ binary variables $q_1,
q_2,
\dots, q_k$ as follows:
- When $x = i$, the first $i$ elements of the variable sequence $\boldsymbol{q}$ are
1,
and
the rest are 0.
- In other words, the position where the switch from
1 to 0 occurs (the
domain
wall) represents the value of $x$.
Example: When $k = 4$¶
| Value of $x$ |
Encoded bit string $\boldsymbol{q}$ |
| 0 |
[0, 0, 0, 0] |
| 1 |
[1, 0, 0, 0] |
| 2 |
[1, 1, 0, 0] |
| 3 |
[1, 1, 1, 0] |
| 4 |
[1, 1, 1, 1] |
Thus, the representation of integer values is uniquely determined by the "wall position (domain
wall)".
The above explanation applies to integer variables with a minimum value of 0. Still, it can also be
extended to integer variables with a non-zero minimum value or real variables by applying a
discretization
technique.
2.1.2. Integer decision variable class
IntegerVariable¶
The IntegerVariable class, to be implemented below, efficiently represents integer
decision
variables by internally using the Amplify SDK's binary variables and applying domain wall encoding.
The core functionality of the IntegerVariable class is the conversion between integer
values
and their binary representations.
-
encode(self, x: int) -> np.ndarray:
This method converts the integer value x passed as an argument into a binary vector
(NumPy array) based on the corresponding domain wall encoding. For example, encoding
x=3
for a variable with bounds=(0, 5) will return an array like
[1., 1., 1., 0., 0.].
-
decode(self, x: np.ndarray) -> int:
This method takes the binary variable results (NumPy array) computed by the Ising machine and
decodes
them back into their original integer values. Following the domain wall encoding, it reconstructs
the
original integer value by counting the number of ones in the array and adding the lower bound.
Additionally, the IntegerVariable class provides the following two properties:
-
constraint:
This property returns the domain wall constraint considered for this integer variable. In
optimization, this constraint needs to be taken into account. This ensures that the Ising machine
handles the associated binary variables (below binary_variables) according to the
domain
wall encoding.
-
binary_variables:
This property returns the vector of Amplify SDK binary variables that constitute this integer
variable. It can be used when you want to reference the integer variable directly as a combination
of
binary variables.
The implementation below also considers Variables, which collectively manages multiple
IntegerVariable objects.