Repository navigation
feat: add QAOA max-cut solver endpoint - #26
Conversation
Redux Build System — CI Report
Overall: ✅ 7 passed · 0 failed · 2 skipped |
Add POST /maxcut-quantum, which solves weighted Max-Cut with QAOA on
the statevector simulator. Input is {"nodes": [...], "edges": [[u, v,
w], ...]}; the answer is the S side in Redux's MAXCUT certificate
format, alongside cut_weight, answer_bitstring, and the circuit qasm.
The cost Hamiltonian is built directly as sum (w/2) Z_i Z_j with
weights normalized to max |w| = 1, and the ansatz is transpiled to
basis gates once before COBYLA so each step avoids a sparse matrix
exponential. The best-cut sample (excluding empty S or T) is returned.
Invalid input yields {"error": ...} with no answer so Redux reports the
solver as unavailable rather than passing on error text. Graphs are
limited to 16 nodes to stay within the router's timeout.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3346a4b to
5091751
Compare
|
Rebased onto |
|
I am taking care of the Dependabot stuff and I will come review this after. |
Trosper3
left a comment
There was a problem hiding this comment.
Looks good, approving. Bad input always comes back as {"error": ...} with no answer, the cost Hamiltonian and the bit order check out, picking the best sampled cut (not the most frequent) is the right call, and the brute-force comparisons in the tests are a nice touch.
One thing to check after deploying: the 16-node cap is sized to this service's 25 second limit, but Redux stops every compute job at 10 seconds today (ComputeLimits:TimeLimitSeconds). Each request also starts a fresh process that has to import Qiskit and SciPy before solving, and that isn't in the 2.7 s figure. Could you time a 16-node solve end to end through Redux on the server? We're also talking about raising Redux's limit to 30 seconds, which would give this plenty of room.
Optional: seeding the sampler would make the same graph give the same answer every time.
The estimator is exact and COBYLA is deterministic, so the sampler is the only random step. Seed it with a fixed default (SEED = 6680) so the same request always gets the same response, accept an optional "seed" in the request to override it, and echo the seed used back in the response. Invalid seeds (negative, non-integer, bool) return an error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
I added a fixed seed. Someone calling it directly can change the seed and it gets reported back in the json. |
MaxCutQAOASolver sends the weighted graph to the quantum service's /maxcut-quantum endpoint, which runs the Quantum Approximate Optimization Algorithm, and returns the S side of the cut it finds. An answer that is not a non-empty proper subset of the nodes is treated as no answer, so the endpoints report 503 solver_unavailable rather than passing it on (#625). The timer is checked before the one blocking call to the service. Requires ReduxISU/quantumsolver#26 for the /maxcut-quantum endpoint. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Adds
POST /maxcut-quantum, which solves weighted Max-Cut with QAOA on the statevector simulator. The code is based on the CS6680 QAOA notebook.Request
{"nodes": ["1", "2", "3"], "edges": [["1", "2", 4], ["2", "3", 2], ["1", "3", 3]]}Each edge is
[u, v, weight], or[u, v]for weight 1. Parallel edges are summed, self-loops are ignored, and graphs are limited to 16 nodes.Response:
answeris the S side in Redux's MAXCUT certificate format (e.g."{1,3}"), pluscut_weight,answer_bitstringandqasm. Invalid input returns{"error": ...}with noanswer, so Redux'sQuantumServerAPI.Askreports the solver as unavailable instead of passing error text along as a certificate.Implementation notes
qiskit_addon_opt_mapperMaxcut +to_isingoutput up to the constant offset, so that package andqiskit_ibm_runtimearen't needed. The only new dependency isscipy(already present through qiskit), now pinned explicitly because it's imported directly.PauliEvolutionGates with a sparse matrix exponential (5 nodes took minutes; it now takes about 0.1 s).qaoa_ansatz, because theQAOAAnsatzclass is deprecated as of Qiskit 2.1.Testing
tests/test_maxcut.pychecks answers against brute force (Redux's default instance and the notebook's graph), weight scaling, parallel edges and self-loops, graphs with no edges, and invalid input.integration/test_api.py.Timing on random graphs (16 nodes is the limit):
QAOA is approximate, so the 16-node shortfall is expected.
Follow-up
Redux still needs a MAXCUT solver class that posts to this endpoint (same pattern as
SATGroverSolver).🤖 Generated with Claude Code