Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 92 additions & 24 deletions docs/tutorials/quantum-approximate-optimization-algorithm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 1,
"id": "37b3acfc",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -122,7 +122,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 2,
"id": "6ced6bea",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -415,7 +415,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"<IBMBackend('ibm_pittsburgh')>\n"
"<IBMBackend('test_heron_pok_1')>\n"
]
},
{
Expand Down Expand Up @@ -540,12 +540,12 @@
"name": "stdout",
"output_type": "stream",
"text": [
" message: Optimization terminated successfully.\n",
" message: Return from COBYLA because the trust region radius reaches its lower bound.\n",
" success: True\n",
" status: 1\n",
" fun: -2.6647130127038308\n",
" x: [ 3.611e+00 1.851e+00 2.833e+00 2.674e+00]\n",
" nfev: 35\n",
" status: 0\n",
" fun: -1.6295230263157894\n",
" x: [ 1.530e+00 1.439e+00 4.071e+00 4.434e+00]\n",
" nfev: 26\n",
" maxcv: 0.0\n"
]
}
Expand Down Expand Up @@ -586,7 +586,17 @@
"execution_count": 10,
"id": "e14ecc92",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<Image src=\"/docs/images/tutorials/quantum-approximate-optimization-algorithm/extracted-outputs/e14ecc92-0.avif\" alt=\"Output of the previous code cell\" />"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(12, 6))\n",
"plt.plot(objective_func_vals)\n",
Expand Down Expand Up @@ -637,7 +647,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"{23: 0.0089, 4: 0.0117, 18: 0.0357, 11: 0.1428, 28: 0.0043, 20: 0.1529, 13: 0.0363, 22: 0.1451, 21: 0.0381, 14: 0.0076, 10: 0.042, 15: 0.0059, 12: 0.0093, 26: 0.0498, 9: 0.1422, 7: 0.0116, 5: 0.0444, 17: 0.0073, 29: 0.0052, 27: 0.0106, 30: 0.0087, 2: 0.005, 0: 0.0041, 8: 0.0105, 19: 0.0082, 24: 0.0101, 31: 0.0045, 25: 0.0075, 6: 0.0072, 1: 0.0094, 3: 0.0055, 16: 0.0076}\n"
"{28: 0.0328, 11: 0.0343, 2: 0.0296, 25: 0.0308, 16: 0.0303, 27: 0.0302, 13: 0.0323, 7: 0.0312, 4: 0.0296, 9: 0.0295, 26: 0.0321, 30: 0.031, 23: 0.0324, 31: 0.0303, 21: 0.0335, 15: 0.0317, 12: 0.0309, 29: 0.0297, 3: 0.0313, 5: 0.0312, 6: 0.0274, 10: 0.0329, 22: 0.0353, 0: 0.0315, 20: 0.0326, 8: 0.0322, 14: 0.0306, 17: 0.0295, 18: 0.0279, 1: 0.0325, 24: 0.0334, 19: 0.0295}\n"
]
}
],
Expand Down Expand Up @@ -682,7 +692,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Result bitstring: [0, 0, 1, 0, 1]\n"
"Result bitstring: [0, 1, 1, 0, 1]\n"
]
}
],
Expand Down Expand Up @@ -753,7 +763,17 @@
"execution_count": 15,
"id": "33135970-8bc4-4fb2-ab87-08726a432ce4",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<Image src=\"/docs/images/tutorials/quantum-approximate-optimization-algorithm/extracted-outputs/33135970-8bc4-4fb2-ab87-08726a432ce4-0.avif\" alt=\"Output of the previous code cell\" />"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# auxiliary function to plot graphs\n",
"def plot_result(G, x):\n",
Expand All @@ -780,7 +800,15 @@
"execution_count": 16,
"id": "2f6a73c4-f5ae-4647-a0dd-d77a13f66388",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The value of the cut is: 5\n"
]
}
],
"source": [
"def evaluate_sample(x: Sequence[int], graph: rx.PyGraph) -> float:\n",
" assert len(x) == len(\n",
Expand Down Expand Up @@ -811,7 +839,17 @@
"execution_count": 17,
"id": "590fe2ce",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<Image src=\"/docs/images/tutorials/quantum-approximate-optimization-algorithm/extracted-outputs/590fe2ce-0.avif\" alt=\"Output of the previous code cell\" />"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"n = 100 # Number of nodes in graph\n",
"graph_100 = rx.PyGraph()\n",
Expand Down Expand Up @@ -988,12 +1026,12 @@
"name": "stdout",
"output_type": "stream",
"text": [
" message: Optimization terminated successfully.\n",
" message: Return from COBYLA because the trust region radius reaches its lower bound.\n",
" success: True\n",
" status: 1\n",
" fun: -18.589441985445966\n",
" x: [ 2.754e+00 4.178e+00]\n",
" nfev: 30\n",
" status: 0\n",
" fun: -3.9939191365979383\n",
" x: [ 1.571e+00 3.142e+00]\n",
" nfev: 29\n",
" maxcv: 0.0\n"
]
}
Expand Down Expand Up @@ -1105,7 +1143,17 @@
"execution_count": 24,
"id": "0fda3611",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<Image src=\"/docs/images/tutorials/quantum-approximate-optimization-algorithm/extracted-outputs/0fda3611-0.avif\" alt=\"Output of the previous code cell\" />"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(12, 6))\n",
"plt.plot(objective_func_vals)\n",
Expand Down Expand Up @@ -1140,7 +1188,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Result bitstring: [0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1]\n"
"Result bitstring: [1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1]\n"
]
}
],
Expand Down Expand Up @@ -1196,7 +1244,17 @@
"execution_count": 26,
"id": "b4a25e28",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<Image src=\"/docs/images/tutorials/quantum-approximate-optimization-algorithm/extracted-outputs/b4a25e28-0.avif\" alt=\"Output of the previous code cell\" />"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot_result(graph_100, best_sol_bitstring_100)"
]
Expand All @@ -1219,7 +1277,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"The value of the cut is: 104\n"
"The value of the cut is: 124\n"
]
}
],
Expand Down Expand Up @@ -1302,7 +1360,17 @@
"execution_count": 30,
"id": "4381a2b3",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<Image src=\"/docs/images/tutorials/quantum-approximate-optimization-algorithm/extracted-outputs/4381a2b3-0.avif\" alt=\"Output of the previous code cell\" />"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig, ax = plt.subplots(1, 1, figsize=(8, 6))\n",
"plot_cdf(result_dist, ax, \"Eagle device\")"
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading