Quantum circuits, from a Bell pair to next-byte prediction
Learning how quantum computers work by building small circuits, a noisy-chip decay sweep, a plain-Python simulator, and an 8-qubit circuit trained to predict the next byte of text.
Question
What does a quantum computer actually do, in terms an ML person already knows? And can a small circuit be trained like a model to predict text?
Approach
Four pieces, built in order.
| Piece | What it is |
|---|---|
| Bell pair | Two qubits, one H gate and one CNOT, measured 4,000 times. First written in April 2026 against Qiskit’s local simulator, with a switch to send the same circuit to IBM’s least-busy real chip. Rebuilt in November 2026 to target IBM Heron r2 chips (ibm_fez, ibm_kingston, ibm_marrakesh, 156 qubits each). |
| Decay sweep | The Bell pair with a wait inserted between the two gates, swept over waiting times. Run on a noisy local simulator built from a calibration snapshot of ibm_marrakesh (FakeMarrakesh). Nothing touches real hardware. |
| tinyq | The Bell circuit as a 30-line simulator in plain Python. No Qiskit, no complex numbers, no noise. |
| QLOOP | An 8-qubit circuit that maps the current byte of text to a probability for every possible next byte (256 outcomes). The input byte is loaded as a basis state, then layers of learned rotations and entangling gates shape the output. Trained in PyTorch with exact amplitudes and ordinary backprop on FineWeb text. A check mode rebuilds the trained circuit in Qiskit and compares the two. |
A few terms. A qubit’s state can be pictured as an arrow on a sphere: how far it tilts sets the odds of reading 0 or 1, and its rotation around the axis (phase) is invisible to measurement but steers the next gate. T1 is how long a tilted qubit takes to fall back to 0. Bits per byte measures how surprised a model is by each next byte; lower is better.
Results
Hardware on the IBM Heron r2 chips (calibration figures, 2026-11-01)
| Property | Value |
|---|---|
| T1 (time to decay back to 0) | ~135–255 µs |
| T2 (time for phase to scramble) | ~93–164 µs |
| Readout error | ~1% |
| Two-qubit gate (CZ) error | ~0.2% |
ibm_kingston had the best numbers and the longest queue.
Decay sweep (noisy simulator)
| Measure | Result |
|---|---|
| P(first qubit reads 1) | Falls along 50% × e^(−t/T1), as T1 predicts |
| Where it flattens | ~1.5% by ~1.3 ms, the readout error floor |
| Leakage into 01/10 (outcomes a perfect Bell pair never gives) | Flat at ~2% across all waits |
QLOOP gate sets (validation bits per byte, 1,000 steps, 2 scratch qubits)
| Gate set | Bits/byte |
|---|---|
| Fixed CNOT ring between neighbouring qubits | 5.91 |
| Learned rules: “if input bit i is 1, tilt output bit j” (controlled-RY) | 5.38 |
| Learned rules, then a fixed CNOT ring | 5.67 |
| Floor: 256 × 256 count table of next byte given current byte | 3.82 |
The best circuit is still 1.56 bits per byte above the count table, which is the best any model can do when it only sees the current byte.
Findings
- In ML terms, a state is a complex vector (2 qubits gives length 4), a gate is a rotation matrix, and a circuit is a chain of matrix multiplies. Measurement is the only step that can’t be undone.
- The decay sweep measures T1 but is blind to T2. The CNOT only reads the qubit’s tilt, so scrambled phase never shows up. Seeing T2 needs an extra H gate on each qubit before measuring.
- Every measurement has a floor. Once the signal drops below the detector’s own error rate, around 1.5% here, waiting longer teaches nothing.
- Adding a fixed CNOT ring after the learned rules made QLOOP worse (5.38 to 5.67). A gate with no adjustable angle forces correlations the rules then had to undo.
- Without scratch qubits, QLOOP’s output table can’t favour any byte overall. Every row and column of the 256 × 256 table must sum to one. Scratch qubits, ignored at readout, lift that limit.
- The rotation gates used so far keep amplitudes real, so QLOOP never used interference (two routes to the same byte cancelling out). That is the one thing a circuit has that a probability table doesn’t.
Next
- Score a “phase” gate set that does use interference: spread with H on every qubit, mark with learned phase gates (free on IBM hardware), interfere with H again, then tilt. Built and checked against Qiskit to 1e-8.
- Score byte-driven angles, where every angle in the circuit becomes a learned function of the input byte’s bits.
- Send a trained QLOOP circuit to a real Heron chip and compare its output to the exact simulation.