Skip to content

Commit f60a1da

Browse files
Copilotfgfuchs
andcommitted
Fix parameter display in notebook (call createParameterizedCircuit before printing n_gamma/n_beta)
Co-authored-by: fgfuchs <2428162+fgfuchs@users.noreply.github.com>
1 parent 52b3ce4 commit f60a1da

File tree

1 file changed

+13
-36
lines changed

1 file changed

+13
-36
lines changed

examples/MaxCut/MixerComparison.ipynb

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
"\n",
99
"This notebook compares three QAOA variants on the **house graph** (5 nodes, 6 edges):\n",
1010
"\n",
11-
"| Variant | Problem | Mixer | γ / layer | β / layer |\n",
11+
"| Variant | Problem | Mixer | \u03b3 / layer | \u03b2 / layer |\n",
1212
"|---------|---------|-------|-----------|----------|\n",
1313
"| **Vanilla** | `MaxCut` | `X` | 1 | 1 |\n",
1414
"| **Free** | `MaxCut` | `XMultiAngle` | 1 | N (one per qubit) |\n",
1515
"| **Orbit** | `MaxCutOrbit` | `X` | K (one per edge orbit) | 1 |\n",
1616
"\n",
17-
"- **Vanilla QAOA** uses the standard X mixer with a single shared γ and β per layer.\n",
18-
"- **Free QAOA** (multi-angle) gives each qubit its own independent β, increasing expressibility.\n",
19-
"- **Orbit QAOA** exploits the graph's automorphism group: edges in the same symmetry orbit share a γ parameter, enabling the optimizer to differentiate structurally distinct edge types without the full multi-angle overhead."
17+
"- **Vanilla QAOA** uses the standard X mixer with a single shared \u03b3 and \u03b2 per layer.\n",
18+
"- **Free QAOA** (multi-angle) gives each qubit its own independent \u03b2, increasing expressibility.\n",
19+
"- **Orbit QAOA** exploits the graph's automorphism group: edges in the same symmetry orbit share a \u03b3 parameter, enabling the optimizer to differentiate structurally distinct edge types without the full multi-angle overhead."
2020
]
2121
},
2222
{
@@ -101,7 +101,7 @@
101101
"source": [
102102
"### Edge Orbits of the House Graph\n",
103103
"\n",
104-
"The orbit QAOA assigns one γ parameter per edge orbit of the graph's automorphism group."
104+
"The orbit QAOA assigns one \u03b3 parameter per edge orbit of the graph's automorphism group."
105105
]
106106
},
107107
{
@@ -129,30 +129,7 @@
129129
"metadata": {},
130130
"outputs": [],
131131
"source": [
132-
"# Vanilla QAOA: X mixer, single γ and β per layer\n",
133-
"qaoa_vanilla = QAOA(\n",
134-
" problem=problems.MaxCut(G),\n",
135-
" mixer=mixers.X(),\n",
136-
" initialstate=initialstates.Plus(),\n",
137-
")\n",
138-
"\n",
139-
"# Free QAOA: XMultiAngle mixer, one β per qubit\n",
140-
"qaoa_free = QAOA(\n",
141-
" problem=problems.MaxCut(G),\n",
142-
" mixer=mixers.XMultiAngle(),\n",
143-
" initialstate=initialstates.Plus(),\n",
144-
")\n",
145-
"\n",
146-
"# Orbit QAOA: X mixer, one γ per edge orbit of the graph\n",
147-
"qaoa_orbit = QAOA(\n",
148-
" problem=problems.MaxCutOrbit(G),\n",
149-
" mixer=mixers.X(),\n",
150-
" initialstate=initialstates.Plus(),\n",
151-
")\n",
152-
"\n",
153-
"print(f\"Vanilla — γ/layer: {qaoa_vanilla.n_gamma}, β/layer: {qaoa_vanilla.n_beta}\")\n",
154-
"print(f\"Free — γ/layer: {qaoa_free.n_gamma}, β/layer: {qaoa_free.n_beta}\")\n",
155-
"print(f\"Orbit — γ/layer: {qaoa_orbit.n_gamma}, β/layer: {qaoa_orbit.n_beta}\")"
132+
"# Vanilla QAOA: X mixer, single \u03b3 and \u03b2 per layer\nqaoa_vanilla = QAOA(\n problem=problems.MaxCut(G),\n mixer=mixers.X(),\n initialstate=initialstates.Plus(),\n)\n\n# Free QAOA: XMultiAngle mixer, one \u03b2 per qubit\nqaoa_free = QAOA(\n problem=problems.MaxCut(G),\n mixer=mixers.XMultiAngle(),\n initialstate=initialstates.Plus(),\n)\n\n# Orbit QAOA: X mixer, one \u03b3 per edge orbit of the graph\nqaoa_orbit = QAOA(\n problem=problems.MaxCutOrbit(G),\n mixer=mixers.X(),\n initialstate=initialstates.Plus(),\n)\n\n# Build circuits at depth 1 to inspect parameter counts\nfor q in (qaoa_vanilla, qaoa_free, qaoa_orbit):\n q.createParameterizedCircuit(depth=1)\n\nprint(f\"Vanilla \u2014 \u03b3/layer: {qaoa_vanilla.n_gamma}, \u03b2/layer: {qaoa_vanilla.n_beta}\")\nprint(f\"Free \u2014 \u03b3/layer: {qaoa_free.n_gamma}, \u03b2/layer: {qaoa_free.n_beta}\")\nprint(f\"Orbit \u2014 \u03b3/layer: {qaoa_orbit.n_gamma}, \u03b2/layer: {qaoa_orbit.n_beta}\")"
156133
]
157134
},
158135
{
@@ -161,7 +138,7 @@
161138
"source": [
162139
"### Energy Landscape at Depth 1 (Vanilla)\n",
163140
"\n",
164-
"Sample the energy landscape over (γ, β) for the vanilla instance."
141+
"Sample the energy landscape over (\u03b3, \u03b2) for the vanilla instance."
165142
]
166143
},
167144
{
@@ -175,7 +152,7 @@
175152
"\n",
176153
"fig = plt.figure(figsize=(6, 5))\n",
177154
"plot_E(qaoa_vanilla, fig=fig)\n",
178-
"plt.title(\"Vanilla QAOA energy landscape (depth 1)\")\n",
155+
"plt.title(\"Vanilla QAOA \u2014 energy landscape (depth 1)\")\n",
179156
"plt.show()"
180157
]
181158
},
@@ -236,7 +213,7 @@
236213
" fig=fig,\n",
237214
")\n",
238215
"\n",
239-
"plt.title(\"Approximation ratio vs. depth House graph\")\n",
216+
"plt.title(\"Approximation ratio vs. depth \u2014 House graph\")\n",
240217
"plt.tight_layout()\n",
241218
"plt.show()"
242219
]
@@ -247,9 +224,9 @@
247224
"source": [
248225
"### Optimal Angles at Maximum Depth (Vanilla)\n",
249226
"\n",
250-
"`plot_angles` expects the standard 1 γ + 1 β per-layer format. \n",
227+
"`plot_angles` expects the standard 1 \u03b3 + 1 \u03b2 per-layer format. \n",
251228
"We display it for the vanilla variant; the free and orbit instances use a\n",
252-
"different layout (multiple γ or β per layer)."
229+
"different layout (multiple \u03b3 or \u03b2 per layer)."
253230
]
254231
},
255232
{
@@ -260,7 +237,7 @@
260237
"source": [
261238
"fig = plt.figure()\n",
262239
"plot_angles(qaoa_vanilla, maxdepth, label=\"Vanilla\", style=\"ob\", fig=fig)\n",
263-
"plt.title(f\"Optimal angles Vanilla QAOA, depth {maxdepth}\")\n",
240+
"plt.title(f\"Optimal angles \u2014 Vanilla QAOA, depth {maxdepth}\")\n",
264241
"plt.tight_layout()\n",
265242
"plt.show()"
266243
]
@@ -279,4 +256,4 @@
279256
},
280257
"nbformat": 4,
281258
"nbformat_minor": 4
282-
}
259+
}

0 commit comments

Comments
 (0)