Repository navigation
feat(maxcut): build the QAOA circuit from textbook gates for visualization - #36
Merged
Merged
Conversation
…ation Build the QAOA ansatz directly from h, cx, rz and rx instead of qaoa_ansatz + transpile: a Hadamard layer, then per layer a cx-rz-cx for each edge (the rz angle scaled by the edge's weight) and an rx on each node. The returned qasm now reads as the circuit that ran, about a third shorter than the transpiled rz/sx/cx output, with numeric parameters that the Redux D3 circuit renderer can label. Edges are emitted in rounds that share no node (a greedy edge colouring), so gates on disjoint qubits sit side by side when drawn. The circuit prepares the same state as qaoa_ansatz up to a global phase, with parameters named and ordered the same way, which a new test checks. Also return the optimized angles as "gammas" and "betas". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Redux Build System — CI Report
Overall: ✅ 7 passed · 0 failed · 2 skipped |
Trosper3
approved these changes
Nov 17, 2026
Trosper3
left a comment
There was a problem hiding this comment.
Looks good, thanks Jason. The hand-built circuit matching qaoa_ansatz (same state, same parameter order) is a nice check, and it's faster too. Grouping edges that share no node keeps each layer's edge gates together, then the mixer gates, which is what the Redux picture's layer boxes (ReduxISU/Redux#1026) depend on. I merged #34, #35 and this together locally: no conflicts, and the Max Cut tests pass on 3.13 and 3.14. Merge this before Redux#1026.
Trosper3
pushed a commit
to ReduxISU/Redux
that referenced
this pull request
Nov 17, 2026
MaxCutQAOAVisualization draws the QAOA circuit the quantum service optimized for the graph with the D3 circuit renderer: one wire per node, named after it, the Hadamard layer, a U_C(γk) overlay over each cost layer (a CNOT-RZ-CNOT per edge) and a U_B(βk) overlay over each mixer layer (an RX per qubit), then measurement. Angles are rounded for display and the sampler's barrier is left out. The solved view adds the cut, the measured bits, the cut weight, the angles and the seed. A failure of the quantum service is a 503 solver_unavailable, as for the solver (#625). QasmD3Scheduler now reads parameters in the invariant culture (a decimal-comma culture misread "0.5") and understands the multiples of pi Qiskit writes for exact angles ("pi/2", "-3*pi/4"). Requires ReduxISU/quantumsolver#36 for the circuit's textbook gates and its gammas and betas. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Supports the Max Cut QAOA circuit visualization in Redux (ReduxISU/Redux PR to follow, which depends on this one).
qaoa_circuit()builds QAOA fromh,cx,rzandrx: a Hadamard layer, then per layer acx·rz·cxfor each edge, with therzangleγₖ·w/sscaled by the edge's weight, and anrx(2βₖ)on each node. This replacesqaoa_ansatzplus transpiling torz/sx/cx, which produced long QASM that hid the circuit's structure.edge_rounds()splits the edges into rounds that share no node (a greedy edge colouring). Each round's gates touch disjoint qubits, so they sit side by side when drawn."gammas"and"betas", the optimized angles, one per layer. The README is updated.Redux's D3 circuit renderer can draw this QASM directly. Its parameters are plain numbers, and every gate is one it knows. Redux_GUI's Q.js converter drops all parameterized gates, which is why the Redux side uses D3.
Same circuit, same results
qaoa_ansatzup to a global phase (within 3×10⁻¹⁵ over random weighted graphs and angles), with the parameters named and ordered identically (β[k], thenγ[k]). A new test checks this, so the warm start and the optimizer behave as before.Testing
qaoa_circuitmatchesqaoa_ansatzon three graphs;edge_roundsgives matchings that cover every edge exactly once; the response carries one γ and one β per layer, and the QASM uses onlyh,cx,rz,rx,barrierandmeasure.maxcut_quantum.py. ruff and black are clean.🤖 Generated with Claude Code