FAILURE MAP
← Case archive

FA-91156 / Quantum circuit simulation / Open access

Inverse QFT reverses the gates but keeps phase signs · case 01

The inverse QFT applied to |j> is not the conjugate spectrum; round trips do not return to the input.

Verified by executionVariant 1 · 7 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The inverse sequence reverses gate order but reuses the positive controlled-phase angles.

VERIFIED REPAIR

Reverse the gate order and negate every controlled-phase angle.

Unsuccessful approach: The attempted repair reverses and negates the rotations but leaves the swap stage at the end, so the swaps are applied after instead of before the inverse rotations.

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(n // 2):
        seq.append(('swap', q, n - 1 - q))
    if inverse:
        seq = list(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 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=3 inverse', [2, 3, True], [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]]], ['repair check: 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]]], ['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=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]]], ['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=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=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=1', [2, 1, False], [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]]], ['control: qft n=2 j=2', [2, 2, False], [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]]], [['regression: qft n=3 j=6 inverse', [3, 6, 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]]], ['regression: 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=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=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', [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]]], ['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=1', [3, 1, 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=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]]], ['regression: 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]]], ['repair check: qft n=3 j=4 inverse', [3, 4, 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', [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]]], ['control: 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=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]]], ['control: 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=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]]], ['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=3 j=6 inverse', [3, 6, 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=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]]], ['control: qft n=3 j=7', [3, 7, 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=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]]]]]
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 fixtureActualExpectedOutcome
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]]Failed
regression: qft n=2 j=3 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]]Failed
repair check: qft n=2 j=2 inverse[[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 / d928d142cb9dc5ec9ad3d83f0a7f04cdd7070291b14dc02db9ce136da62facc6

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 // 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) if g[0] != 'swap'] + [g for g in seq if g[0] == 'swap']
    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 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=3 inverse', [2, 3, True], [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]]], ['repair check: 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]]], ['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=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]]], ['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=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=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=1', [2, 1, False], [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]]], ['control: qft n=2 j=2', [2, 2, False], [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]]], [['regression: qft n=3 j=6 inverse', [3, 6, 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]]], ['regression: 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=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=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', [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]]], ['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=1', [3, 1, 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=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]]], ['regression: 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]]], ['repair check: qft n=3 j=4 inverse', [3, 4, 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', [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]]], ['control: 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=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]]], ['control: 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=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]]], ['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=3 j=6 inverse', [3, 6, 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=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]]], ['control: qft n=3 j=7', [3, 7, 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=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]]]]]
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 fixtureActualExpectedOutcome
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=3 inverse[[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
repair check: qft n=2 j=2 inverse[[0.5, 0.0], [-0.5, 0.0], [0.0, -0.5], [0.0, 0.5]][[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 / 136c7c086e53b9dd7993fef1b96466e03b6a7170553822c057c2351609651408

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 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=3 inverse', [2, 3, True], [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]]], ['repair check: 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]]], ['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=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]]], ['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=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=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=1', [2, 1, False], [[0.5, 0.0], [0.0, 0.5], [-0.5, 0.0], [0.0, -0.5]]], ['control: qft n=2 j=2', [2, 2, False], [[0.5, 0.0], [-0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]]], [['regression: qft n=3 j=6 inverse', [3, 6, 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]]], ['regression: 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=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=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', [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]]], ['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=1', [3, 1, 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=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]]], ['regression: 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]]], ['repair check: qft n=3 j=4 inverse', [3, 4, 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', [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]]], ['control: 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=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]]], ['control: 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=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]]], ['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=3 j=6 inverse', [3, 6, 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=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]]], ['control: qft n=3 j=7', [3, 7, 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=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]]]]]
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 fixtureActualExpectedOutcome
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=3 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
repair check: qft n=2 j=2 inverse[[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 / 7b0a8e7c2167110d0829a187b3625338bf795bf1ac543baccd0d525fd396974e

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.462666+00:00.

Case digest / 2af6c6adfae3339a4b1b96daf79f757e037f3d0272fa857176766ba3508104b3