Quantum Nonogram Solver
runs in your browser
Grover search scored against a backtracking solver on an NP-complete puzzle, enumerated to 4x4 and run on IBM hardware. Built at Qualcomm Institute.
- 62,535 boards enumerated to 4x4: backtracking beats Grover on 100% of one-solution boards from 3x3 up
- 5.9x chance on ibm_fez: 36.8% correct on a 2×2 puzzle vs 6.25% (47.3% noiseless), 377 of 1,024 shots
- Qiskit
- Grover
- Flask
- Socket.IO
- IBM Quantum
Nonograms are picture-logic puzzles: fill a grid so every row and column matches its run-length clues. Underneath, that is a Boolean satisfiability problem — which makes it a clean testbed for the real question: where does a quantum computer actually help? Here, it does not.
Begun at Qualcomm Institute as a group project. The enumeration, the clue-pattern oracle, the hardware runs and everything measured below are mine.
How it works
The standard oracle hands the clue formula to Qiskit’s PhaseOracleGate, which reduces it over all 2^n grids and emits one multi-controlled Z per solution. Constructing it means solving the puzzle first. Its cost is then a function of board size and solution count alone: across 30 distinct single-solution 4x4 boards it compiles to the same 227.5 two-qubit gates every time — the median of 8 recorded transpiler seeds against the FakeTorino device model, and the eight-seed multiset is identical board to board. Different puzzle, identical circuit. A benchmark resting on it reports the cost of Grover on an arbitrary n-bit function, not on the problem in its title.
So I built an oracle that does not hold the answer: it raises a flag qubit per line over that line’s legal patterns, which costs about 7x the answer-marking form at 3x3 and grows exponentially in line width.
It is also still an enumeration, only over patterns instead of solutions. The oracle that tests the clues instead — a reversible run-length automaton per line, polynomial in line width — is the one that should eventually win, so I built that as well and measured both on 2xW boards from width 2 to 14.
The two series fit different models, which is the whole point of building the second one. Over widths 2 to 14 the clue oracle is exponential in line width — R^2 0.989 against 0.970 for a polynomial — and the automaton is polynomial at W^1.82, R^2 0.995 against 0.933 for an exponential. Over the last six widths the clue oracle grows x1.50 per width and the automaton x1.19, so the gap closes, and a ratio that keeps falling has to reach 1 somewhere.
It does not reach it anywhere this machine can check. The automaton starts 16x dearer at width 2 and is still 1.8x the oracle it was meant to replace at width 14, the widest board that fits. Carrying the measured growth rates forward puts the two at equal cost between widths 16 and 17, and that is an extrapolation rather than a measurement: surveying width 15 needs about 1,040 GB and the machine has 549 GB. The better asymptotics are real and the sizes at which they pay are out of reach, which is the same answer the rest of the project keeps giving.
Which oracle is cheaper is not the only thing deciding the bill. The same 3x3 circuit compiles to 19,357 two-qubit gates or 3,240 depending on one decision: whether the compiler is lent two spare qubits to borrow during synthesis. That is 5.97x the gates and 7.91x the depth from a choice that changes nothing about the algorithm.
Routing onto the device’s lattice is more than half the dearer total, and it is not a constant overhead that can be quoted once. The gate underneath explains the gap: one many-controlled X over c controls costs exactly 6(c - 1) with a qubit to borrow, and grows about c^2.4 without, so the penalty widens from 1.2x at three controls to 20.8x at twenty-five.
A whole Grover round inherits that. Before routing it costs exactly 12n - 25 at every size measured; routing multiplies it by 2.69 at sixteen qubits, and refusing the spare qubits multiplies it by a further 15.5.
The result
Every solvable board up to 4x4 was enumerated and deduplicated by clue pair — 62,535 puzzles — and scored against Grover’s round count. On 100% of single-solution boards from 3x3 upward, a backtracking solver’s worst board asks fewer questions than Grover needs rounds: 15 against 17 at 3x3, 56 against 201 at 4x4, and 246 against 4,549 over the 299,990 single-solution boards in a 400,000-grid 5x5 sample.
The gap widens with every size. The two units are reported separately rather than merged, since a placement is an upper bound on grid queries and a Grover round is exact. Collapsing them into one ratio would also hide how much the answer depends on the unit: against exhaustive search the same 3x3 circuit wins on two-qubit gates, draws on gate count, and loses once the qubits it holds idle are charged for.
On hardware, a 2x2 puzzle on ibm_fez resolved the correct state at 36.8% against 6.25% for chance — 377 of 1,024 shots, against 47.3% for the same one-iteration circuit run noiselessly. A measured lift on a real device, not a textbook figure. One iteration, transpiled depth 146, job db4m98imb58s7389da60, and the run records its own counts, job id, backend and depth so the figure can be traced back to it. Nothing larger fits: at 3x3 not one of the 17 required rounds survives a 200-layer coherence budget.
A classical solver runs entirely in your browser — draw or randomize a puzzle and it solves instantly, reporting real solve time and search-space size, with no backend awake. Building and running a Grover circuit needs Qiskit, so the quantum side calls a Python service when one is up; when it is not, a gallery of captured simulator runs shows real quantum output instead.
What’s checked
Every oracle is verified against the textbook amplification curve to 1e-9, so the comparison is between circuits that agree on which grids they mark. The automaton oracle is checked exhaustively rather than sampled: across 19 shapes every one of 392,619,856 grids was evaluated, with no phase mismatch and no workspace qubit left entangled, 2^28 grids at the widest board. At 2x2 and 2x3 the bit-level evaluation was reproduced on a full statevector and agreed. The harness records every transpiler seed rather than the best one, which is what let a selection artifact in an early draft be caught. Rebuilding IBM’s own published Grover tutorial reproduces its circuit to within 0.5%. Tests cover the Boolean encoding, solver correctness, oracle amplification, and hardware integration.
Every figure on this page is drawn from the published measurements, and a notebook beside them recomputes each number quoted here from the same files and redraws the figures from them. One number it cannot check is the 227.5 gates the marking oracle compiles to, which was measured in the solver’s own repository and is not among the files published here.