As a first step, we need to encode the problem described in “The MAX k-CUT Problem and Classical Algorithms” in a way that is suitable for the QAOA. There are three different possibilities (of which the first two are presented in [13], and the last is proposed in this article):
-
Qudit encoding: Expressing the solutions as strings of k-dits [as in Eq. (5)] is a natural extension of the MAX (2-)CUT problem to \(k>2\). The problem can be formulated using |V| qudits. To be practically relevant, it requires, however, the realization of a k-level quantum system.
-
One-hot encoding: A second method is to use k bits for each vertex, where the single bit that is 1 encodes which set/color the vertex belongs to. Using this encoding requires k|V| qubits. However, the formulation requires the introduction of constraints to prevent solutions where a vertex belongs to several sets of a partition or none.
-
Binary encoding: For a given k, we encode the information of a vertex belonging to one of the sets by \(|i\rangle _L\), which requires \(L=\lceil log_2(k)\rceil\) qubits. Here, \(\lceil \cdot \rceil\) means rounding up to the nearest integer. This formulation can be executed on systems using qubits and requires L|V| qubits.
Binary encoding uses exponentially fewer qubits as compared to one-hot encoding. As an example, for \(k=4\), encoding the information of a vertex belonging to one of the four sets using one-hot encoding is done through identifying color 1, 2, 3, 4 with the bit strings 0001, 0010, 0100, 1000, respectively. The binary encoding identifies colors 1, 2, 3, 4 with the bit strings 00, 01, 10, 11, respectively. Observe that, for one-hot encoding, there are \(2^4-4=12\) possible bit strings in the space that encode infeasible solutions consisting of multiple colors or no color at all, whereas all possible bit strings in the binary encoding are valid encodings, see also Eq. (3).
In the following, we describe the problem Hamiltonian and unitary evolution for the one-hot encoding as well as the proposed binary encoding.
One-Hot Encoding
Here, we provide a brief description of the one-hot encoding. For details and further discussion, we refer to [13, 23]. The one-hot encoding uses k qubits per vertex, which are indexed, such that, e.g., \(\sigma ^{x,y,z}_{i,a}\) applies a Pauli-X,-Y, or -Z gate to qubit number \(ik+a\), for \(a\in \{1,k\}\). The definition of the approximation ratio (Eq. (6) needs to be adapted to:
$$\begin{aligned} \alpha = \frac{\langle P_\text {feas} H_P P_\text {feas} \rangle }{C(\mathbf {x}^*)}, \end{aligned}$$
(7)
where \(P_\text {feas}\) is the projection operator onto the feasible subspace. In practice, this means that infeasible solutions are assigned zero cost.
Problem Hamiltonian
Up to a global phase, the problem Hamiltonian is given by:
$$\begin{aligned} H_P = \sum _{(i,j)\in E} w_{i,j}\sum _{a=1}^k \sigma ^z_{i,a} \otimes \sigma ^z_{j,a}. \end{aligned}$$
(8)
One way to incorporate the constraint that the feasible subspace consists of only Hamming-weight 1-bit strings is to introduce a quadratic penalty term that results (up to global phase) in the Hamiltonian:
$$\begin{aligned} H_\text {pen} = \frac{1}{2}\sum _{v=1}^{|V|} \sum _{a=1}^{k}\sum _{b=a+1}^{k} \sigma ^z_{v,a} \otimes \sigma ^z_{v,b}. \end{aligned}$$
(9)
Overall, the phase-separating Hamiltonian becomes a weighted sum \(H_P'=H_P + \beta H_\text {pen}\), where \(\beta\) should satisfy \(\beta \ge \frac{|V|}{k}\) and \(\beta > k|E|\), see [23].
Unitary Evolution
The unitary evolution consists of creating an initial state, followed by phase-separating and mixing operators. The unitary evolution of the phase-separating operator given by the exponentiation of \(H_P'\) [see Eqs. (8) and (9)] consists of terms that can be realized through the following circuit:
where \(R_z(\theta ) = e^{-i\frac{\theta }{2}\sigma ^z}\). The standard X-mixing operator is given by:
$$\begin{aligned} e^{-i H_M}, \text { where } H_M = \sum _{v=1}^{|V|} \sum _{a=1}^k \sigma ^x_{v,a}, \end{aligned}$$
(11)
with each individual term realized through \(R_x(\theta )=e^{-i\frac{\theta }{2}\sigma ^x}\) gates. The initial state when using the standard mixing operator is given by \(|\Phi _0\rangle = H^{\otimes k|V|}|0\rangle\), where H is the Hadamard gate. However, this approach does not incorporate the feasibility constraint.
Incorporating the feasibility constraint into the mixer results in the XY mixer for each vertex \(v\in V\) based on the Hamiltonian:
$$\begin{aligned} H_{XY,v} = \frac{1}{2} \sum _{a,b\in K} \sigma ^x_{v,a} \sigma ^x_{v,b} + \sigma ^y_{v,a} \sigma ^y_{v,b}, \end{aligned}$$
(12)
where K is a set consisting of certain pairs of colors (a, b). In this article, we use the parity-partitioned mixer, which can be represented as two separate Hamiltonians:
$$\begin{aligned} \begin{aligned} H_\text {odd}&= H^{XY}_{(1,2)} + H^{XY}_{(3,4)} + \ldots + H^{XY}_{(k-1,k)}\\ H_\text {even}&= H^{XY}_{(2,3)} + H^{XY}_{(4,5)} + \ldots + H^{XY}_{(k,1)},\\ \end{aligned} \end{aligned}$$
(13)
where \(H^{XY}_{(j,k)} = \sigma ^x_j \sigma ^x_{j+1} + \sigma ^y_j \sigma ^y_{j+1}\). The resulting unitary operator is easily implemented in terms of two CX and one \(R_X\) or \(R_Y\) operation. A feasible initial state for the one-hot encoding consistent with the XY mixer is \(|\Phi _0\rangle = |W_k\rangle ^{\otimes |V|}\), where the \(W_k\) state is given by:
$$\begin{aligned} |W_k\rangle = \frac{1}{\sqrt{k}}\left( |100\ldots 000\rangle + |010\ldots 000\rangle + \ldots |000\ldots 001\rangle \right) . \end{aligned}$$
(14)
An efficient algorithm for this with logarithmic (in k) time complexity is presented in [5].
Binary Encoding
In the following, we describe the problem Hamiltonian for the proposed binary encoding, which is given as the sum of local terms, that is:
$$\begin{aligned} H_P = \sum _{(i,j)\in E} w_{i,j} H_{i,j}, \end{aligned}$$
(15)
where \(w_{i,j}\) is the weight of the edge between vertices i and j as well as the resulting unitary evolution.
Problem Hamiltonian
The matrix \(H_{i,j}\) is a diagonal matrix modeling the interaction between vertices i and j:
$$\begin{aligned} H_{i,j}= \begin{pmatrix} d_{0} &{} &{} \\ &{} \ddots &{} \\ &{} &{} d_{2^{2L}-1} \end{pmatrix}. \end{aligned}$$
(16)
From this point on, we consider the two diagonal matrices \(H_P\) and \(A=aI+bH_P\) to be equivalent for all \(a,b\in \mathbb {R}, b\ne 0\). The reason for this is that when we compare the unitary operators \(e^{-i \theta A}\) and \(e^{-i \theta B}\), a parameter \(a\ne 0\) results in applying a “global phase” which is irrelevant, and \(b\ne 0\) can be combined with the parameter \(\theta\). As mentioned in [13], “an affine transformation of the objective function [...] corresponds simply to a physically irrelevant global phase and a rescaling of the parameter”. The cost function can be easily evaluated classically, independent of the specific form of \(H_P\).
From now on, we will adapt the notation that \(|m\rangle _{2^n}\) is the mth basis vector of an n-qubit system. Note that for a basis vector, the decomposition \(|m\rangle _{2^n}=|l_0\rangle _{2^{n-1}}\otimes |l_1\rangle _{2^{n-1}}\) both exists and is unique. The mth entry of the local Hamiltonian \(H_{i,j}\) is given by:
$$\begin{aligned} d_m = {\left\{ \begin{array}{ll} -1, &{} \text { if } l_0\ne l_1 \wedge \lnot (l_0\ge k-1 \wedge l_1\ge k-1), \text { where } l_0, l_1 \text { are given by } |m\rangle _{2^n}=|l_0\rangle _{2^{n-1}}\otimes |l_1\rangle _{2^{n-1}},\\ +1, &{} \text { otherwise. } \end{array}\right. } \end{aligned}$$
(17)
This means that eigenvectors of the local Hamiltonian \(H_{i,j}\) corresponding to eigenvalues \(d_m=-1\) indicate a cut. When k is not a power of two the condition \(\lnot (l_0\ge k-1 \wedge l_1\ge k-1)\) is introduced, such that the sets with number \(k-1,\ldots , 2^L-1\) are not distinguished and become the same set. Organizing the diagonal entries \(d_m\) in a matrix of size \(2^L \times 2^L\), we get a particularly simple structure:
where \(l = 2^L-(k-1)\), I is the identity matrix, J is a matrix of ones, and \(\Gamma ^{c,d}\) is a matrix that has a one at entry c, d and is zero otherwise. Sub-indices indicate the size of the matrix. Observe that \(D=D^T\) and that the sum involving terms \(\Gamma\) is zero if k is a power of two. We can construct the matrix \(H_{i,j}\) from D through:
$$\begin{aligned} H_{i,j} = \text {diag}\left( \text {vec}(D^T)\right) , \end{aligned}$$
(19)
where \(\text {vec}(\dot{)}\) is a linear transformation which converts a matrix into a column vector by stacking the columns on top of each other, and \(\text {diag}(v)\) is a matrix with the entries of the vector v along its diagonal.
Next, we will provide a few examples.
MAX (2-)CUT. For \(k=2\), we can use \(L=\lceil \log _2(2)\rceil =1\) qubit per vertex, where \(\lceil \cdot \rceil\) means rounding up to the nearest integer. The matrix D and the local Hamiltonian are given by:
MAX 3-CUT. For the case \(k=3\), we need \(L=\lceil \log _2(3)\rceil =2\) qubits per vertex. Since two qubits can encode four different sets, we need to make two sets indistinguishable. Choosing sets 2 and 3 to represent one set, the entries of the matrix D and the local Hamiltonian are given by:
MAX 4-CUT. For the case when \(k=4\), we need \(L=\lceil \log _2(4)\rceil =2\) qubits per vertex. The entries of the matrix D and the local Hamiltonian are given by:
Unitary Evolution
For the binary encoding, there are no constraints on the binary strings to be a valid solution. Therefore, there is no need to design special mixers, and the mixing Hamiltonian is given by:
$$\begin{aligned} H_M = \sum _{j=1}^{|V|L} \beta \sigma ^x_{j}, \quad L=\lceil \log _2(k)\rceil . \end{aligned}$$
(23)
This leads to the unitary operator:
$$\begin{aligned} U_{M} = e^{-i\beta H_M} = \prod _{j=1}^{|V|L} e^{-i\beta \sigma ^x_j}. \end{aligned}$$
(24)
Each term in the above product can be implemented with an \(R_x\)-gate.
The unitary operator for phase separation is defined by:
$$\begin{aligned} U_{P} = e^{-i\gamma H_P} = e^{-i\gamma \sum _{(i,j)\in E} w_{i,j} H_{i,j}} = \prod _{(i,j)\in E} e^{-i\gamma w_{i,j} H_{i,j}}, \end{aligned}$$
(25)
where the last equality holds, because the terms \(H_{i,j}\) trivially commute, as they are diagonal matrices. Furthermore, we can use Eq. (18) to further decompose the terms of the product:
$$\begin{aligned} e^{-i\theta H_{i,j}} = e^{-i\theta \text {diag}\left( \text {vec}(2I - J)\right) } \prod _{c,d=k+1, m\ne n}^{2^L} e^{-i 2\theta \text {diag}\left( \text {vec}(\Gamma _{c,d})\right) }. \end{aligned}$$
(26)
Again, equality holds, since only diagonal matrices are involved. The first term in Eq. (26) can be realized through the following circuit:
The qubits are enumerated, such that qubits \(q_i^0, \cdots , q_i^{L-1}\) correspond to the label that is assigned to vertex enumerated i. The logic behind the circuit shown can be understood from a classical point of view. Applying CX-gates on pairs of qubits acting on basis states between vertex i and j results in the state \(|q_i^0\rangle \cdots |q_i^{L-1}\rangle |q_j^0\oplus q_i^0\rangle \cdots |q_j^L\oplus q_i^L\rangle\), where the \(\oplus\) operation is modulo 2. This means that the state of the qubits belonging to j has zero entries if and only if all qubits have the same basis state. Negating the state and applying a multi-controlled \('U_3(0,\phi ,0)\) gate therefore apply a phase if the original (basis) states \(|q_i^0\rangle \cdots |q_i^{L-1}\rangle\) and \(|q_j^0\rangle \cdots |q_j^L\rangle\) differ. After this, one can uncompute by applying X and CX-gates in reversed order, such that the overall change is that of applying a phase.
The remaining terms in Eq. (26) (which vanish if k is a power of 2) can be implemented, e.g., with the help of two ancillary qubits, \(a_0, a_1\), in the following way:
The gates \(N_1, N_2\) in Eq. (28) are of the form \(U_0\otimes \cdots \otimes U_{L-1}\), where \(U_i\in \{I,X\}\) are chosen, such that \(N_1 |0\rangle _L = |c\rangle _L\), and \(N_2 |0\rangle _L = |d\rangle _L\). The logic behind this circuit is that multi-controlled NOT gates are used to set two ancillary qubits to the state one if \(q_i = |c\rangle _L\), and \(q_j = |d\rangle _L\). Of both ancillary qubits are one, a multi-controlled \(U_3(0,\phi ,0)\)-gate is applied to change the phase, followed by a uncomputation steps. The ancillary qubits can be reused for all other pairs \((i,j)\in E\). An example for MAX \(3\)-CUT is shown in Fig. 2.
Table 1 Number of CX operations per layer and number of qubits of the QAOA circuit for a graph \(G=(V,E)\) depending on k Resource Analysis of One-Hot and Binary Encoding
We will give a short analysis of the number of gates required to decompose the basic building blocks of the phase operator \(U_P\), the mixing operator \(U_M\), and the preparation of the initial state for the two different encoding schemes. To be executable on, e.g., one of IBM’s quantum devices, all terms need to be decomposed using gates from the set of basis gates \(\{U_3,CX\}\), where:
$$\begin{aligned} U_3(\theta ,\phi ,\lambda ) = \begin{pmatrix} \cos (\theta /2) &{} -e^{i\lambda } \sin (\theta /2) \\ e^{i\phi } \sin (\theta /2) &{} e^{i(\phi +\lambda )}\cos (\theta /2) \\ \end{pmatrix}, \quad CX = \begin{pmatrix} 1 &{} 0 &{} 0 &{} 0 \\ 0 &{} 1 &{} 0 &{} 0 \\ 0 &{} 0 &{} 0 &{} 1 \\ 0 &{} 0 &{} 1 &{} 0 \\ \end{pmatrix}. \end{aligned}$$
(29)
Note that \(U_3(0,\phi ,0) = \text {diag}(1, e^{i\phi })\). Throughout, we assume full connectivity of the qubits, i.e., a CX gate can be executed directly on any pair of qubits, without the need for applying SWAP or Bridge-gates [14]. Furthermore, (multi-)controlled \(U_3(0,\phi ,0)\) operations can be implemented in terms of its square root \(V = U_3(0,\phi /2,0)\), and \(V^\dagger\), using polynomially many CX-gates, see, e.g., [19]. To implement the circuit shown in Eq. (27), one needs 2L CX-gates, 2L X-gates, and 1 (multi-)controlled \(U_3\)-gate. When k is not a power of two, we need to additionally execute the circuits of the form, as shown in Eq. (28). This requires 2L \(C^{L}X\)-gates, 2 \(C^{L}U_3\)-gates, and L X-gates. In general, these need to be applied \(2(2^L-k)\) times. In the worst case, when \(k = 2^n+1\), we need to apply these gates \(2(2^n-1)\) times. Overall, Table 1 shows the width (number of qubits) and depth requirements of the complete circuit for MAX \(k\)-CUT. We can see that low depth and width are achieved when k is a power of two.
The analysis shows that one-hot encoding has a strong limitation when it comes to the requirement of number of qubits. In addition, preparation of \(W_k\) and XY mixers is more costly than the standard X mixer sufficient for binary encoding. Furthermore, when the number of qubits is limited to a few hundred or thousand, only one-hot encoding for the cases \(k=2,4\) and possibly \(k=3\) will be of practical interest when quantum advantage is to be achieved.