FA-91151 / Quantum circuit simulation / Open access
QFT omits the final bit-reversal swaps · case 01
QFT|1> on three qubits returns amplitudes whose frequencies are indexed in bit-reversed order.
ROOT CAUSE
The swap stage after the rotations is missing.
VERIFIED REPAIR
Swap qubit q with n-1-q for q < n//2 after the rotations.
Unsuccessful approach: The attempted repair swaps for every q in range(n), undoing each swap with its mirror.
Case contract
Input [n, j, inverse]. Build the textbook QFT on n qubits (qubit 0 = LSB): for q from n-1 down to 0 apply H(q) then CP(pi / 2**(q-k)) between q and each k < q (k descending), then swap q with n-1-q for q < n//2; the inverse is the reversed sequence with negated phases. Apply it to |j> and return the amplitudes as [re, im] rounded to 6 decimals (QFT|j> = sum_k e^{2 pi i jk/N}|k>/sqrt N).
Why this case matters
QFT circuits are the core of phase estimation and arithmetic; decomposition slips produce bit-reversed or dephased spectra.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
n, j, inverse = x
dim = 1 << n
seq = []
for q in reversed(range(n)):
seq.append(('h', q))
for k in reversed(range(q)):
seq.append(('cp', k, q, math.pi / 2 ** (q - k)))
for q in range(0):
seq.append(('swap', q, n - 1 - q))
if inverse:
seq = [(g[0], g[1], g[2], -g[3]) if g[0] == 'cp' else g for g in reversed(seq)]
st = [0j] * dim
st[j] = 1 + 0j
r = 1 / math.sqrt(2)
for g in seq:
if g[0] == 'h':
m = 1 << g[1]
for i in range(dim):
if not i & m:
a, b = st[i], st[i | m]
st[i], st[i | m] = (a + b) * r, (a - b) * r
elif g[0] == 'cp':
mask = (1 << g[1]) | (1 << g[2])
ph = cmath.exp(1j * g[3])
for i in range(dim):
if i & mask == mask:
st[i] *= ph
else:
a, b = 1 << g[1], 1 << g[2]
for i in range(dim):
if i & a and not i & b:
k2 = (i ^ a) | b
st[i], st[k2] = st[k2], st[i]
return [[round(v.real, 6) + 0.0, round(v.imag, 6) + 0.0] for v in st]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: qft n=2 j=1', [2, 1, False], [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]]], ['regression: qft n=2 j=1 inverse', [2, 1, True], [[0.5, 0.0], [0.0, -0.5], [-0.5, 0.0], [0.0, 0.5]]], ['regression: qft n=2 j=2', [2, 2, False], [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['control: qft n=1 j=0', [1, 0, False], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: qft n=1 j=0 inverse', [1, 0, True], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: qft n=1 j=1', [1, 1, False], [[0.707107, 0.0], [-0.707107, 0.0]]], ['control: qft n=1 j=1 inverse', [1, 1, True], [[0.707107, 0.0], [-0.707107, 0.0]]]], [['regression: qft n=2 j=2 inverse', [2, 2, True], [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['regression: qft n=2 j=3', [2, 3, False], [[0.5, 0.0], [0.0, -0.5], [-0.5, 0.0], [0.0, 0.5]]], ['regression: qft n=2 j=2', [2, 2, False], [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['control: qft n=2 j=0', [2, 0, False], [[0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [0.5, 0.0]]], ['control: qft n=2 j=0 inverse', [2, 0, True], [[0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [0.5, 0.0]]], ['control: qft n=2 j=3 inverse', [2, 3, True], [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]]], ['control: qft n=3 j=0', [3, 0, False], [[0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0]]]], [['regression: qft n=3 j=1 inverse', [3, 1, True], [[0.353553, 0.0], [0.25, -0.25], [0.0, -0.353553], [-0.25, -0.25], [-0.353553, 0.0], [-0.25, 0.25], [0.0, 0.353553], [0.25, 0.25]]], ['regression: qft n=3 j=2', [3, 2, False], [[0.353553, 0.0], [0.0, 0.353553], [-0.353553, 0.0], [0.0, -0.353553], [0.353553, 0.0], [0.0, 0.353553], [-0.353553, 0.0], [0.0, -0.353553]]], ['regression: qft n=2 j=3', [2, 3, False], [[0.5, 0.0], [0.0, -0.5], [-0.5, 0.0], [0.0, 0.5]]], ['control: qft n=3 j=0 inverse', [3, 0, True], [[0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0]]], ['control: qft n=3 j=2 inverse', [3, 2, True], [[0.353553, 0.0], [0.0, -0.353553], [-0.353553, 0.0], [0.0, 0.353553], [0.353553, 0.0], [0.0, -0.353553], [-0.353553, 0.0], [0.0, 0.353553]]], ['control: qft n=3 j=5 inverse', [3, 5, True], [[0.353553, 0.0], [-0.25, 0.25], [0.0, -0.353553], [0.25, 0.25], [-0.353553, 0.0], [0.25, -0.25], [0.0, 0.353553], [-0.25, -0.25]]], ['control: qft n=3 j=7 inverse', [3, 7, True], [[0.353553, 0.0], [0.25, 0.25], [0.0, 0.353553], [-0.25, 0.25], [-0.353553, 0.0], [-0.25, -0.25], [0.0, -0.353553], [0.25, -0.25]]]], [['regression: qft n=3 j=3 inverse', [3, 3, True], [[0.353553, 0.0], [-0.25, -0.25], [0.0, 0.353553], [0.25, -0.25], [-0.353553, 0.0], [0.25, 0.25], [0.0, -0.353553], [-0.25, 0.25]]], ['regression: qft n=3 j=4', [3, 4, False], [[0.353553, 0.0], [-0.353553, 0.0], [0.353553, 0.0], [-0.353553, 0.0], [0.353553, 0.0], [-0.353553, 0.0], [0.353553, 0.0], [-0.353553, 0.0]]], ['regression: qft n=3 j=1 inverse', [3, 1, True], [[0.353553, 0.0], [0.25, -0.25], [0.0, -0.353553], [-0.25, -0.25], [-0.353553, 0.0], [-0.25, 0.25], [0.0, 0.353553], [0.25, 0.25]]], ['control: qft n=4 j=0', [4, 0, False], [[0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0]]], ['control: qft n=4 j=0 inverse', [4, 0, True], [[0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0]]], ['control: qft n=4 j=6 inverse', [4, 6, True], [[0.25, 0.0], [-0.176777, -0.176777], [0.0, 0.25], [0.176777, -0.176777], [-0.25, 0.0], [0.176777, 0.176777], [0.0, -0.25], [-0.176777, 0.176777], [0.25, 0.0], [-0.176777, -0.176777], [0.0, 0.25], [0.176777, -0.176777], [-0.25, 0.0], [0.176777, 0.176777], [0.0, -0.25], [-0.176777, 0.176777]]], ['control: qft n=4 j=9 inverse', [4, 9, True], [[0.25, 0.0], [-0.23097, 0.095671], [0.176777, -0.176777], [-0.095671, 0.23097], [0.0, -0.25], [0.095671, 0.23097], [-0.176777, -0.176777], [0.23097, 0.095671], [-0.25, 0.0], [0.23097, -0.095671], [-0.176777, 0.176777], [0.095671, -0.23097], [0.0, 0.25], [-0.095671, -0.23097], [0.176777, 0.176777], [-0.23097, -0.095671]]]], [['regression: qft n=3 j=5', [3, 5, False], [[0.353553, 0.0], [-0.25, -0.25], [0.0, 0.353553], [0.25, -0.25], [-0.353553, 0.0], [0.25, 0.25], [0.0, -0.353553], [-0.25, 0.25]]], ['regression: qft n=3 j=6', [3, 6, False], [[0.353553, 0.0], [0.0, -0.353553], [-0.353553, 0.0], [0.0, 0.353553], [0.353553, 0.0], [0.0, -0.353553], [-0.353553, 0.0], [0.0, 0.353553]]], ['regression: qft n=3 j=3', [3, 3, False], [[0.353553, 0.0], [-0.25, 0.25], [0.0, -0.353553], [0.25, 0.25], [-0.353553, 0.0], [0.25, -0.25], [0.0, 0.353553], [-0.25, -0.25]]], ['control: qft n=4 j=15 inverse', [4, 15, True], [[0.25, 0.0], [0.23097, 0.095671], [0.176777, 0.176777], [0.095671, 0.23097], [0.0, 0.25], [-0.095671, 0.23097], [-0.176777, 0.176777], [-0.23097, 0.095671], [-0.25, 0.0], [-0.23097, -0.095671], [-0.176777, -0.176777], [-0.095671, -0.23097], [0.0, -0.25], [0.095671, -0.23097], [0.176777, -0.176777], [0.23097, -0.095671]]], ['control: qft n=1 j=0', [1, 0, False], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: qft n=1 j=0 inverse', [1, 0, True], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: qft n=1 j=1', [1, 1, False], [[0.707107, 0.0], [-0.707107, 0.0]]]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: qft n=2 j=1 | [[0.5, 0.0], [-0.5, 0.0], [0.0, 0.5], [0.0, -0.5]] | [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]] | Failed |
| regression: qft n=2 j=1 inverse | [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]] | [[0.5, 0.0], [0.0, -0.5], [-0.5, 0.0], [0.0, 0.5]] | Failed |
| regression: qft n=2 j=2 | [[0.5, 0.0], [0.5, 0.0], [-0.5, 0.0], [-0.5, 0.0]] | [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]] | Failed |
| control: qft n=1 j=0 | [[0.707107, 0.0], [0.707107, 0.0]] | [[0.707107, 0.0], [0.707107, 0.0]] | Passed |
| control: qft n=1 j=0 inverse | [[0.707107, 0.0], [0.707107, 0.0]] | [[0.707107, 0.0], [0.707107, 0.0]] | Passed |
| control: qft n=1 j=1 | [[0.707107, 0.0], [-0.707107, 0.0]] | [[0.707107, 0.0], [-0.707107, 0.0]] | Passed |
| control: qft n=1 j=1 inverse | [[0.707107, 0.0], [-0.707107, 0.0]] | [[0.707107, 0.0], [-0.707107, 0.0]] | Passed |
SHA-256 / 7a62ed2c7b0dfb3884c2557776a1d0a3644fdf596c961f8cf66349844570023e
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
n, j, inverse = x
dim = 1 << n
seq = []
for q in reversed(range(n)):
seq.append(('h', q))
for k in reversed(range(q)):
seq.append(('cp', k, q, math.pi / 2 ** (q - k)))
for q in range(n):
seq.append(('swap', q, n - 1 - q))
if inverse:
seq = [(g[0], g[1], g[2], -g[3]) if g[0] == 'cp' else g for g in reversed(seq)]
st = [0j] * dim
st[j] = 1 + 0j
r = 1 / math.sqrt(2)
for g in seq:
if g[0] == 'h':
m = 1 << g[1]
for i in range(dim):
if not i & m:
a, b = st[i], st[i | m]
st[i], st[i | m] = (a + b) * r, (a - b) * r
elif g[0] == 'cp':
mask = (1 << g[1]) | (1 << g[2])
ph = cmath.exp(1j * g[3])
for i in range(dim):
if i & mask == mask:
st[i] *= ph
else:
a, b = 1 << g[1], 1 << g[2]
for i in range(dim):
if i & a and not i & b:
k2 = (i ^ a) | b
st[i], st[k2] = st[k2], st[i]
return [[round(v.real, 6) + 0.0, round(v.imag, 6) + 0.0] for v in st]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: qft n=2 j=1', [2, 1, False], [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]]], ['regression: qft n=2 j=1 inverse', [2, 1, True], [[0.5, 0.0], [0.0, -0.5], [-0.5, 0.0], [0.0, 0.5]]], ['regression: qft n=2 j=2', [2, 2, False], [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['control: qft n=1 j=0', [1, 0, False], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: qft n=1 j=0 inverse', [1, 0, True], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: qft n=1 j=1', [1, 1, False], [[0.707107, 0.0], [-0.707107, 0.0]]], ['control: qft n=1 j=1 inverse', [1, 1, True], [[0.707107, 0.0], [-0.707107, 0.0]]]], [['regression: qft n=2 j=2 inverse', [2, 2, True], [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['regression: qft n=2 j=3', [2, 3, False], [[0.5, 0.0], [0.0, -0.5], [-0.5, 0.0], [0.0, 0.5]]], ['regression: qft n=2 j=2', [2, 2, False], [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['control: qft n=2 j=0', [2, 0, False], [[0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [0.5, 0.0]]], ['control: qft n=2 j=0 inverse', [2, 0, True], [[0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [0.5, 0.0]]], ['control: qft n=2 j=3 inverse', [2, 3, True], [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]]], ['control: qft n=3 j=0', [3, 0, False], [[0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0]]]], [['regression: qft n=3 j=1 inverse', [3, 1, True], [[0.353553, 0.0], [0.25, -0.25], [0.0, -0.353553], [-0.25, -0.25], [-0.353553, 0.0], [-0.25, 0.25], [0.0, 0.353553], [0.25, 0.25]]], ['regression: qft n=3 j=2', [3, 2, False], [[0.353553, 0.0], [0.0, 0.353553], [-0.353553, 0.0], [0.0, -0.353553], [0.353553, 0.0], [0.0, 0.353553], [-0.353553, 0.0], [0.0, -0.353553]]], ['regression: qft n=2 j=3', [2, 3, False], [[0.5, 0.0], [0.0, -0.5], [-0.5, 0.0], [0.0, 0.5]]], ['control: qft n=3 j=0 inverse', [3, 0, True], [[0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0]]], ['control: qft n=3 j=2 inverse', [3, 2, True], [[0.353553, 0.0], [0.0, -0.353553], [-0.353553, 0.0], [0.0, 0.353553], [0.353553, 0.0], [0.0, -0.353553], [-0.353553, 0.0], [0.0, 0.353553]]], ['control: qft n=3 j=5 inverse', [3, 5, True], [[0.353553, 0.0], [-0.25, 0.25], [0.0, -0.353553], [0.25, 0.25], [-0.353553, 0.0], [0.25, -0.25], [0.0, 0.353553], [-0.25, -0.25]]], ['control: qft n=3 j=7 inverse', [3, 7, True], [[0.353553, 0.0], [0.25, 0.25], [0.0, 0.353553], [-0.25, 0.25], [-0.353553, 0.0], [-0.25, -0.25], [0.0, -0.353553], [0.25, -0.25]]]], [['regression: qft n=3 j=3 inverse', [3, 3, True], [[0.353553, 0.0], [-0.25, -0.25], [0.0, 0.353553], [0.25, -0.25], [-0.353553, 0.0], [0.25, 0.25], [0.0, -0.353553], [-0.25, 0.25]]], ['regression: qft n=3 j=4', [3, 4, False], [[0.353553, 0.0], [-0.353553, 0.0], [0.353553, 0.0], [-0.353553, 0.0], [0.353553, 0.0], [-0.353553, 0.0], [0.353553, 0.0], [-0.353553, 0.0]]], ['regression: qft n=3 j=1 inverse', [3, 1, True], [[0.353553, 0.0], [0.25, -0.25], [0.0, -0.353553], [-0.25, -0.25], [-0.353553, 0.0], [-0.25, 0.25], [0.0, 0.353553], [0.25, 0.25]]], ['control: qft n=4 j=0', [4, 0, False], [[0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0]]], ['control: qft n=4 j=0 inverse', [4, 0, True], [[0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0]]], ['control: qft n=4 j=6 inverse', [4, 6, True], [[0.25, 0.0], [-0.176777, -0.176777], [0.0, 0.25], [0.176777, -0.176777], [-0.25, 0.0], [0.176777, 0.176777], [0.0, -0.25], [-0.176777, 0.176777], [0.25, 0.0], [-0.176777, -0.176777], [0.0, 0.25], [0.176777, -0.176777], [-0.25, 0.0], [0.176777, 0.176777], [0.0, -0.25], [-0.176777, 0.176777]]], ['control: qft n=4 j=9 inverse', [4, 9, True], [[0.25, 0.0], [-0.23097, 0.095671], [0.176777, -0.176777], [-0.095671, 0.23097], [0.0, -0.25], [0.095671, 0.23097], [-0.176777, -0.176777], [0.23097, 0.095671], [-0.25, 0.0], [0.23097, -0.095671], [-0.176777, 0.176777], [0.095671, -0.23097], [0.0, 0.25], [-0.095671, -0.23097], [0.176777, 0.176777], [-0.23097, -0.095671]]]], [['regression: qft n=3 j=5', [3, 5, False], [[0.353553, 0.0], [-0.25, -0.25], [0.0, 0.353553], [0.25, -0.25], [-0.353553, 0.0], [0.25, 0.25], [0.0, -0.353553], [-0.25, 0.25]]], ['regression: qft n=3 j=6', [3, 6, False], [[0.353553, 0.0], [0.0, -0.353553], [-0.353553, 0.0], [0.0, 0.353553], [0.353553, 0.0], [0.0, -0.353553], [-0.353553, 0.0], [0.0, 0.353553]]], ['regression: qft n=3 j=3', [3, 3, False], [[0.353553, 0.0], [-0.25, 0.25], [0.0, -0.353553], [0.25, 0.25], [-0.353553, 0.0], [0.25, -0.25], [0.0, 0.353553], [-0.25, -0.25]]], ['control: qft n=4 j=15 inverse', [4, 15, True], [[0.25, 0.0], [0.23097, 0.095671], [0.176777, 0.176777], [0.095671, 0.23097], [0.0, 0.25], [-0.095671, 0.23097], [-0.176777, 0.176777], [-0.23097, 0.095671], [-0.25, 0.0], [-0.23097, -0.095671], [-0.176777, -0.176777], [-0.095671, -0.23097], [0.0, -0.25], [0.095671, -0.23097], [0.176777, -0.176777], [0.23097, -0.095671]]], ['control: qft n=1 j=0', [1, 0, False], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: qft n=1 j=0 inverse', [1, 0, True], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: qft n=1 j=1', [1, 1, False], [[0.707107, 0.0], [-0.707107, 0.0]]]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: qft n=2 j=1 | [[0.5, 0.0], [-0.5, 0.0], [0.0, 0.5], [0.0, -0.5]] | [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]] | Failed |
| regression: qft n=2 j=1 inverse | [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]] | [[0.5, 0.0], [0.0, -0.5], [-0.5, 0.0], [0.0, 0.5]] | Failed |
| regression: qft n=2 j=2 | [[0.5, 0.0], [0.5, 0.0], [-0.5, 0.0], [-0.5, 0.0]] | [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]] | Failed |
| control: qft n=1 j=0 | [[0.707107, 0.0], [0.707107, 0.0]] | [[0.707107, 0.0], [0.707107, 0.0]] | Passed |
| control: qft n=1 j=0 inverse | [[0.707107, 0.0], [0.707107, 0.0]] | [[0.707107, 0.0], [0.707107, 0.0]] | Passed |
| control: qft n=1 j=1 | [[0.707107, 0.0], [-0.707107, 0.0]] | [[0.707107, 0.0], [-0.707107, 0.0]] | Passed |
| control: qft n=1 j=1 inverse | [[0.707107, 0.0], [-0.707107, 0.0]] | [[0.707107, 0.0], [-0.707107, 0.0]] | Passed |
SHA-256 / b1a5cde783ad0fd6c6a776a3ab660698b7bc5937c4bccde4eccfb39736f33ef4
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
n, j, inverse = x
dim = 1 << n
seq = []
for q in reversed(range(n)):
seq.append(('h', q))
for k in reversed(range(q)):
seq.append(('cp', k, q, math.pi / 2 ** (q - k)))
for q in range(n // 2):
seq.append(('swap', q, n - 1 - q))
if inverse:
seq = [(g[0], g[1], g[2], -g[3]) if g[0] == 'cp' else g for g in reversed(seq)]
st = [0j] * dim
st[j] = 1 + 0j
r = 1 / math.sqrt(2)
for g in seq:
if g[0] == 'h':
m = 1 << g[1]
for i in range(dim):
if not i & m:
a, b = st[i], st[i | m]
st[i], st[i | m] = (a + b) * r, (a - b) * r
elif g[0] == 'cp':
mask = (1 << g[1]) | (1 << g[2])
ph = cmath.exp(1j * g[3])
for i in range(dim):
if i & mask == mask:
st[i] *= ph
else:
a, b = 1 << g[1], 1 << g[2]
for i in range(dim):
if i & a and not i & b:
k2 = (i ^ a) | b
st[i], st[k2] = st[k2], st[i]
return [[round(v.real, 6) + 0.0, round(v.imag, 6) + 0.0] for v in st]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: qft n=2 j=1', [2, 1, False], [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]]], ['regression: qft n=2 j=1 inverse', [2, 1, True], [[0.5, 0.0], [0.0, -0.5], [-0.5, 0.0], [0.0, 0.5]]], ['regression: qft n=2 j=2', [2, 2, False], [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['control: qft n=1 j=0', [1, 0, False], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: qft n=1 j=0 inverse', [1, 0, True], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: qft n=1 j=1', [1, 1, False], [[0.707107, 0.0], [-0.707107, 0.0]]], ['control: qft n=1 j=1 inverse', [1, 1, True], [[0.707107, 0.0], [-0.707107, 0.0]]]], [['regression: qft n=2 j=2 inverse', [2, 2, True], [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['regression: qft n=2 j=3', [2, 3, False], [[0.5, 0.0], [0.0, -0.5], [-0.5, 0.0], [0.0, 0.5]]], ['regression: qft n=2 j=2', [2, 2, False], [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['control: qft n=2 j=0', [2, 0, False], [[0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [0.5, 0.0]]], ['control: qft n=2 j=0 inverse', [2, 0, True], [[0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [0.5, 0.0]]], ['control: qft n=2 j=3 inverse', [2, 3, True], [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]]], ['control: qft n=3 j=0', [3, 0, False], [[0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0]]]], [['regression: qft n=3 j=1 inverse', [3, 1, True], [[0.353553, 0.0], [0.25, -0.25], [0.0, -0.353553], [-0.25, -0.25], [-0.353553, 0.0], [-0.25, 0.25], [0.0, 0.353553], [0.25, 0.25]]], ['regression: qft n=3 j=2', [3, 2, False], [[0.353553, 0.0], [0.0, 0.353553], [-0.353553, 0.0], [0.0, -0.353553], [0.353553, 0.0], [0.0, 0.353553], [-0.353553, 0.0], [0.0, -0.353553]]], ['regression: qft n=2 j=3', [2, 3, False], [[0.5, 0.0], [0.0, -0.5], [-0.5, 0.0], [0.0, 0.5]]], ['control: qft n=3 j=0 inverse', [3, 0, True], [[0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0], [0.353553, 0.0]]], ['control: qft n=3 j=2 inverse', [3, 2, True], [[0.353553, 0.0], [0.0, -0.353553], [-0.353553, 0.0], [0.0, 0.353553], [0.353553, 0.0], [0.0, -0.353553], [-0.353553, 0.0], [0.0, 0.353553]]], ['control: qft n=3 j=5 inverse', [3, 5, True], [[0.353553, 0.0], [-0.25, 0.25], [0.0, -0.353553], [0.25, 0.25], [-0.353553, 0.0], [0.25, -0.25], [0.0, 0.353553], [-0.25, -0.25]]], ['control: qft n=3 j=7 inverse', [3, 7, True], [[0.353553, 0.0], [0.25, 0.25], [0.0, 0.353553], [-0.25, 0.25], [-0.353553, 0.0], [-0.25, -0.25], [0.0, -0.353553], [0.25, -0.25]]]], [['regression: qft n=3 j=3 inverse', [3, 3, True], [[0.353553, 0.0], [-0.25, -0.25], [0.0, 0.353553], [0.25, -0.25], [-0.353553, 0.0], [0.25, 0.25], [0.0, -0.353553], [-0.25, 0.25]]], ['regression: qft n=3 j=4', [3, 4, False], [[0.353553, 0.0], [-0.353553, 0.0], [0.353553, 0.0], [-0.353553, 0.0], [0.353553, 0.0], [-0.353553, 0.0], [0.353553, 0.0], [-0.353553, 0.0]]], ['regression: qft n=3 j=1 inverse', [3, 1, True], [[0.353553, 0.0], [0.25, -0.25], [0.0, -0.353553], [-0.25, -0.25], [-0.353553, 0.0], [-0.25, 0.25], [0.0, 0.353553], [0.25, 0.25]]], ['control: qft n=4 j=0', [4, 0, False], [[0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0]]], ['control: qft n=4 j=0 inverse', [4, 0, True], [[0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.25, 0.0]]], ['control: qft n=4 j=6 inverse', [4, 6, True], [[0.25, 0.0], [-0.176777, -0.176777], [0.0, 0.25], [0.176777, -0.176777], [-0.25, 0.0], [0.176777, 0.176777], [0.0, -0.25], [-0.176777, 0.176777], [0.25, 0.0], [-0.176777, -0.176777], [0.0, 0.25], [0.176777, -0.176777], [-0.25, 0.0], [0.176777, 0.176777], [0.0, -0.25], [-0.176777, 0.176777]]], ['control: qft n=4 j=9 inverse', [4, 9, True], [[0.25, 0.0], [-0.23097, 0.095671], [0.176777, -0.176777], [-0.095671, 0.23097], [0.0, -0.25], [0.095671, 0.23097], [-0.176777, -0.176777], [0.23097, 0.095671], [-0.25, 0.0], [0.23097, -0.095671], [-0.176777, 0.176777], [0.095671, -0.23097], [0.0, 0.25], [-0.095671, -0.23097], [0.176777, 0.176777], [-0.23097, -0.095671]]]], [['regression: qft n=3 j=5', [3, 5, False], [[0.353553, 0.0], [-0.25, -0.25], [0.0, 0.353553], [0.25, -0.25], [-0.353553, 0.0], [0.25, 0.25], [0.0, -0.353553], [-0.25, 0.25]]], ['regression: qft n=3 j=6', [3, 6, False], [[0.353553, 0.0], [0.0, -0.353553], [-0.353553, 0.0], [0.0, 0.353553], [0.353553, 0.0], [0.0, -0.353553], [-0.353553, 0.0], [0.0, 0.353553]]], ['regression: qft n=3 j=3', [3, 3, False], [[0.353553, 0.0], [-0.25, 0.25], [0.0, -0.353553], [0.25, 0.25], [-0.353553, 0.0], [0.25, -0.25], [0.0, 0.353553], [-0.25, -0.25]]], ['control: qft n=4 j=15 inverse', [4, 15, True], [[0.25, 0.0], [0.23097, 0.095671], [0.176777, 0.176777], [0.095671, 0.23097], [0.0, 0.25], [-0.095671, 0.23097], [-0.176777, 0.176777], [-0.23097, 0.095671], [-0.25, 0.0], [-0.23097, -0.095671], [-0.176777, -0.176777], [-0.095671, -0.23097], [0.0, -0.25], [0.095671, -0.23097], [0.176777, -0.176777], [0.23097, -0.095671]]], ['control: qft n=1 j=0', [1, 0, False], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: qft n=1 j=0 inverse', [1, 0, True], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: qft n=1 j=1', [1, 1, False], [[0.707107, 0.0], [-0.707107, 0.0]]]]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: qft n=2 j=1 | [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]] | [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]] | Passed |
| regression: qft n=2 j=1 inverse | [[0.5, 0.0], [0.0, -0.5], [-0.5, 0.0], [0.0, 0.5]] | [[0.5, 0.0], [0.0, -0.5], [-0.5, 0.0], [0.0, 0.5]] | Passed |
| regression: qft n=2 j=2 | [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]] | [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]] | Passed |
| control: qft n=1 j=0 | [[0.707107, 0.0], [0.707107, 0.0]] | [[0.707107, 0.0], [0.707107, 0.0]] | Passed |
| control: qft n=1 j=0 inverse | [[0.707107, 0.0], [0.707107, 0.0]] | [[0.707107, 0.0], [0.707107, 0.0]] | Passed |
| control: qft n=1 j=1 | [[0.707107, 0.0], [-0.707107, 0.0]] | [[0.707107, 0.0], [-0.707107, 0.0]] | Passed |
| control: qft n=1 j=1 inverse | [[0.707107, 0.0], [-0.707107, 0.0]] | [[0.707107, 0.0], [-0.707107, 0.0]] | Passed |
SHA-256 / 5a062dca61a866f021a1cb7b35fb03b0d01f3aee046f8d5dff18fc80a36b0317
Verification & scope
A deterministic bounded teaching model with a stipulated toy contract; amplitudes are rounded to fixed decimals for strict JSON output. It is not a production quantum SDK and claims no standards conformance. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:51:33.369658+00:00.
Case digest / 1d65c6ac9c8c8016405034eae152f0d41112a21a5e932d068e411fc299367f45