Skip to content

Commit eb2ea6e

Browse files
fixed review comments of qaoa
1 parent ca31280 commit eb2ea6e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

algorithms/qaoa/qaoa.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
"id": "1",
1414
"metadata": {},
1515
"source": [
16-
">The **Quantum Approximate Optimization Algorithm (QAOA)**, introduced by Edward Farhi, Jeffrey Goldstone, and Sam Gutmannan [[1](#QAOA)], is a hybrid quantum–classical method for tackling combinatorial optimization problems like Max-Cut, scheduling, and constraint satisfaction. It prepares a parameterized quantum state by alternating two simple operations: one that encodes the problem’s cost function and another that “mixes” amplitudes across candidate solutions. After measuring the circuit, a classical optimizer updates the parameters to increase the expected cost, repeating this loop until good solutions are found. QAOA is especially appealing for near-term quantum devices because it uses shallow circuits, yet its quality can systematically improve as you increase the number of alternating layers. We demonstrate the algorithm by analyzing the Max-Cut and Knapsack problems. The former is an unconstrained optimization problem, while the latter is a constrained task. \n",
16+
">The **Quantum Approximate Optimization Algorithm (QAOA)**, introduced by Edward Farhi, Jeffrey Goldstone, and Sam Gutmann [[1](#QAOA)], is a hybrid quantum–classical method for tackling combinatorial optimization problems like Max-Cut, scheduling, and constraint satisfaction. It prepares a parameterized quantum state by alternating two simple operations: one that encodes the problem’s cost function and another that “mixes” amplitudes across candidate solutions. After measuring the circuit, a classical optimizer updates the parameters to increase the expected cost, repeating this loop until good solutions are found. QAOA is especially appealing for near-term quantum devices because it uses shallow circuits, yet its quality can systematically improve as you increase the number of alternating layers. We demonstrate the algorithm by analyzing the Max-Cut and Knapsack problems. The former is an unconstrained optimization problem, while the latter is a constrained task. \n",
1717
">\n",
18-
"> - **Input:** Classical objective function $C(x)=\\sum_{\\alpha=1}^{m} C_{\\alpha}(x)$ returning the number of satisied clauses by the $n$ bit string $x$, where $C_{\\alpha}(x)$ evaluates to $1$ if $z$ satisfies clause $\\alpha$ and $0$ otherwise. \n",
19-
"> - **Output:** Binary string $x^*$, constituting the best solution from the pool of solution candidates, maximizing the objective function.\n",
18+
"> - **Input:** Classical objective function $C(x)$ on $n$-bit variable $x$. $C(x)$ is commonly constructed to output the number of satisfied clauses by the $x$. \n",
19+
"> - **Output:** A bit array $x^*$, constituting the best solution from the pool of candidates, maximizing the objective function.\n",
2020
">\n",
2121
"> **Complexity:** The algorithm involves iteration over two types of operations. The \"cost\" operations involve $O(m)$ two-qubit gates, scaling linearly with the number of clauses m. While the mixing operation involves $n$ single-qubit gates. Hence, a single shot of a $p$-depth QAOA circuit includes $O(p(n+m))$ single and double qubit gates. \n",
2222
">\n",
@@ -43,18 +43,18 @@
4343
"1. **Cost layer:** \n",
4444
" A phase rotation in the $Z$-direction is applied based on the cost function:\n",
4545
" $$\n",
46-
" |x\\rangle \\xrightarrow{U_{\\text{C}}(\\gamma)} e^{i\\gamma H_C(x)} |x\\rangle ,\n",
46+
" |x\\rangle \\xrightarrow{U_{\\text{C}}(\\gamma)} e^{i\\gamma H_C(x)} |x\\rangle ~~,\n",
4747
" $$\n",
4848
" where $H_C(x)$ is diagonal in the computational basis, encoding the classical cost function $C(x)$. \n",
4949
"\n",
5050
"3. **Mixer layer:** \n",
5151
" An $X$-rotation is applied to all qubits:\n",
5252
" $$\n",
53-
" U_B(\\beta) = e^{-i\\beta H_M}, \\quad \\text{with } H_M = \\sum_i X_i.\n",
53+
" U_B(\\beta) = e^{-i\\beta H_M}, \\quad \\text{with } H_M = \\sum_i X_i~~.\n",
5454
" $$\n",
5555
" This operation induces transitions between computational basis states based on the phases that were assigned by the previous layer\n",
5656
"\n",
57-
"By alternating these operations, the QAOA ansatz explores the combinatorial optimization space. After $p$ iterations, the state is measured in the computational basis. Repeated repetitions of the basic experiment lead to a sample of bit strings $\\{x\\}$ and associated costs $\\{C(x)\\}$. The average cost is given by the expectation value $\\langle \\boldsymbol{\\gamma}\\boldsymbol{\\beta}| H_C(x)|{\\boldsymbol{\\gamma}\\boldsymbol{\\beta}}\\rangle$. Following, the variational parameters are adjusted according to a chosen classical optimization algorithm, and the procedure is repeated until convergence of $C(x)$ to a maximum value.\n",
57+
"By alternating these operations, the QAOA ansatz explores the combinatorial optimization space. After $p$ iterations, the state is measured in the computational basis. Repeated repetitions of the basic experiment lead to a sample of binary arrays (i.e, bit strings) $\\{x\\}$ and associated costs $\\{C(x)\\}$. The average cost is given by the expectation value $\\langle \\boldsymbol{\\gamma}\\boldsymbol{\\beta}| H_C(x)|{\\boldsymbol{\\gamma}\\boldsymbol{\\beta}}\\rangle$. Following, the variational parameters are adjusted according to a chosen classical optimization algorithm, and the procedure is repeated until convergence of $C(x)$ to a maximum value.\n",
5858
"\n",
5959
"**Note:** In the limit of $p\\rightarrow \\infty$, the QAOA ansatz state can approximate adiabatic evolution and converges to the optimum solution (see Technical Notes).\n"
6060
]
@@ -73,13 +73,13 @@
7373
"metadata": {},
7474
"source": [
7575
"The implementation follows a modular design, associating a regular and `@qfunc` functions to the algorithmic components:\n",
76-
"- A **cost function** evaluating the classical cost function associated with a particular bit string.\n",
76+
"- A **cost function** evaluating the classical cost function associated with a particular binary array instance.\n",
7777
" \n",
7878
"- **cost layer** function which employs the cost function to evaluate phase rotations of quantum states in the computational basis, with a parameter $\\gamma$ controlling the extent of phase rotation.\n",
7979
"\n",
8080
"- A **mixer layer**, that applies a uniform $RX$ rotations (with parameter $\\beta$) to all qubits.\n",
8181
"\n",
82-
"- **QAOA ansatz**, the overall circuit is constructed by first preparing a uniform superposition (via a Hadamard transform), consisting the ground state of the mixer Hamiltonian $H_B$, and then alternating the cost and mixer layers for a specified number of layers."
82+
"- **QAOA ansatz**, the overall circuit is constructed by first preparing a uniform superposition (via a Hadamard transform), which constitutes the ground state of the mixer Hamiltonian $H_B$, and then alternating the cost and mixer layers for a specified number of layers."
8383
]
8484
},
8585
{
@@ -103,7 +103,7 @@
103103
"$$\n",
104104
"C_{\\text{MC}}(x)=\\sum_{(i,j) \\in E} \\frac{1-x_i x_j}{2}\n",
105105
"$$\n",
106-
"where $x = x_1x_2\\dots x_{|V|}$ is a bit string encoding the graphs vertices, and $x_i = 1$, $i\\in [1,n]$ if the $i$'th vertex is in subset $S$ or $x_i = -1$ if the $i$'th vertex is in $\\bar{S}$.\n",
106+
"where $x = x_1x_2\\dots x_{|V|}$ is a bit array encoding the graphs vertices, and $x_i = 1$, $i\\in [1,n]$ if the $i$'th vertex is in subset $S$ or $x_i = -1$ if the $i$'th vertex is in $\\bar{S}$.\n",
107107
"\n",
108108
"The Max-Cut problem is known to be $\\mathsf{NP}$-complete.\n",
109109
"\n",

0 commit comments

Comments
 (0)