Skip to content

Commit d725ec9

Browse files
committed
CR fix3
1 parent 9e72b31 commit d725ec9

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

algorithms/qaoa/maxcut/qaoa_maxcut.ipynb

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"id": "c8374048-2ead-45c4-ada1-724c73532cf7",
1414
"metadata": {},
1515
"source": [
16-
"This notebook demonstrates the QAOA algorithm using Classiq. It covers the Max-Cut problem as an example of a combinatorial optimization problem, showcasing how QAOA can be applied to graph-based optimization tasks [[1](#QAOA)]."
16+
"This notebook demonstrates the QAOA algorithm using Classiq. It covers the Max-Cut problem as an example of a combinatorial optimization problem, showcasing how QAOA can be applied to unconstrained combinatorial optimization tasks [[1](#QAOA)]."
1717
]
1818
},
1919
{
@@ -106,19 +106,19 @@
106106
"\n",
107107
"The QAOA algorithm comprises two key layers:\n",
108108
"\n",
109-
"1. **Objective Phase (Analog):** \n",
109+
"1. **Cost Layer:** \n",
110110
" A phase rotation in the $Z$-direction is applied based on the cost function:\n",
111111
" $$\n",
112112
" |x\\rangle \\xrightarrow{U_{\\text{o}}(\\gamma)} e^{i\\gamma f_{\\text{obj}}(x)} |x\\rangle,\n",
113113
" $$\n",
114-
" where the objective function $f_{\\text{obj}}(x)$ is defined in [Cell 2](#cell-2) below.\n",
114+
" which encodes the cost associated with a given partition.\n",
115115
"\n",
116-
"2. **Mixing Operator (Digital):** \n",
116+
"2. **Mixer Layer:** \n",
117117
" An $X$-rotation is applied to all qubits:\n",
118118
" $$\n",
119119
" U_B(\\beta) = e^{-i\\beta H_B}, \\quad \\text{with } H_B = \\sum_i X_i.\n",
120120
" $$\n",
121-
" This operator drives transitions between computational basis states, enabling exploration of different candidate partitions.\n",
121+
" This layer drives transitions between computational basis states based on the phases that were assigned by the previous layer.\n",
122122
"\n",
123123
"By alternating these layers, the QAOA ansatz iteratively refines the quantum state toward a partition that minimizes the Hamiltonian (and thus maximizes the number of cut edges).\n"
124124
]
@@ -188,7 +188,6 @@
188188
"metadata": {},
189189
"outputs": [],
190190
"source": [
191-
"graph_nodes = [0, 1, 2, 3, 4]\n",
192191
"graph_edges = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 4), (3, 4)]"
193192
]
194193
},
@@ -223,7 +222,6 @@
223222
"\n",
224223
"# Create a graph instance\n",
225224
"G = nx.Graph()\n",
226-
"G.add_nodes_from(graph_nodes)\n",
227225
"G.add_edges_from(graph_edges)\n",
228226
"\n",
229227
"# Use a layout for better visualization\n",
@@ -371,21 +369,20 @@
371369
},
372370
{
373371
"cell_type": "code",
374-
"execution_count": 6,
372+
"execution_count": 14,
375373
"id": "4fc29cc0-46ce-4a05-ae3b-1e6d0ae8b886",
376374
"metadata": {},
377375
"outputs": [],
378376
"source": [
379377
"@qfunc\n",
380378
"def qaoa_ansatz(\n",
381379
" cost_layer: QCallable[CReal, QArray[QBit]],\n",
382-
" num_layers: CInt,\n",
383380
" gammas: CArray[CReal],\n",
384381
" betas: CArray[CReal],\n",
385382
" qba: QArray[QBit],\n",
386383
"):\n",
387384
" repeat(\n",
388-
" num_layers,\n",
385+
" betas.len,\n",
389386
" lambda i: [\n",
390387
" cost_layer(gammas[i], qba),\n",
391388
" mixer_layer(betas[i], qba),\n",
@@ -406,12 +403,12 @@
406403
"id": "32903984-f50b-4580-909a-413823932c90",
407404
"metadata": {},
408405
"source": [
409-
"As in vanilla QAOA, the quantum program first applies a `hadamard_transform()` to prepare the qubits in a uniform superposition. After this initial state preparation, the circuit sequentially applies the cost and mixer layers, each with their own parameters that are updated by the classical optimization loop as we will show in the next section."
406+
"The quantum program first applies a `hadamard_transform` to prepare the qubits in a uniform superposition. After this initial state preparation, the circuit sequentially applies the cost and mixer layers, each with their own parameters that are updated by the classical optimization loop as we will show in the next section."
410407
]
411408
},
412409
{
413410
"cell_type": "code",
414-
"execution_count": 7,
411+
"execution_count": 15,
415412
"id": "e6518b27-5e9e-4d8a-b880-60c76612d5db",
416413
"metadata": {},
417414
"outputs": [],
@@ -430,7 +427,6 @@
430427
" hadamard_transform(v) # Prepare a uniform superposition\n",
431428
" qaoa_ansatz(\n",
432429
" maxcut_cost_layer,\n",
433-
" NUM_LAYERS,\n",
434430
" params[0:NUM_LAYERS],\n",
435431
" params[NUM_LAYERS : 2 * NUM_LAYERS],\n",
436432
" v,\n",
@@ -447,15 +443,15 @@
447443
},
448444
{
449445
"cell_type": "code",
450-
"execution_count": 8,
446+
"execution_count": 16,
451447
"id": "fb2ad242-4ac2-4fc1-befd-65f8c8aca582",
452448
"metadata": {},
453449
"outputs": [
454450
{
455451
"name": "stdout",
456452
"output_type": "stream",
457453
"text": [
458-
"Opening: https://platform.classiq.io/circuit/2u7p64Ns4kjBako0sk6ONbGvXZD?version=0.70.0\n"
454+
"Opening: https://platform.classiq.io/circuit/2uGTpY3U86Dj3PPQN0Zzpxx2Oeh?version=0.70.0\n"
459455
]
460456
}
461457
],

0 commit comments

Comments
 (0)