broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
    n, gates = x
    dim = 1 << n
    st = [0j] * dim
    st[0] = 1 + 0j
    r = 1 / math.sqrt(2)
    for g in gates:
        op = g[0]
        if op in ('h', 'x', 'y', 'z', 's', 'sdg', 't'):
            m = 1 << g[1]
            for i in range(dim):
                if i & m:
                    continue
                a, b = st[i], st[i | m]
                if op == 'h':
                    st[i], st[i | m] = (a + b) * r, (a - b) * r
                elif op == 'x':
                    st[i], st[i | m] = b, a
                elif op == 'y':
                    st[i], st[i | m] = 1j * b, -1j * a
                elif op == 'z':
                    st[i | m] = -b
                elif op == 's':
                    st[i | m] = 1j * b
                elif op == 'sdg':
                    st[i | m] = -1j * b
                else:
                    st[i | m] = b * cmath.exp(1j * math.pi / 4)
        elif op == 'cx':
            c, t = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & c and not i & t:
                    st[i], st[i | t] = st[i | t], st[i]
        elif op == 'cz':
            both = (1 << g[1]) | (1 << g[2])
            for i in range(dim):
                if i & both == both:
                    st[i] = -st[i]
        elif op == 'swap':
            a, b = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & a and not i & b:
                    j = (i ^ a) | b
                    st[i], st[j] = st[j], 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: y on ground state', [1, [['y', 0]]], [[0.0, 0.0], [0.0, 1.0]]], ['regression: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['regression: random circuit 15', [2, [['cx', 1, 0], ['z', 0], ['cz', 1, 0], ['h', 1], ['h', 0], ['y', 1], ['h', 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, -0.707107]]], ['control: empty circuit on two qubits', [2, []], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: bell pair', [2, [['h', 0], ['cx', 0, 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: ghz three qubits', [3, [['h', 0], ['cx', 0, 1], ['cx', 1, 2]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: cx with control on high qubit', [2, [['x', 1], ['cx', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]]], [['regression: random circuit 2', [3, [['z', 0], ['sdg', 1], ['cx', 1, 0], ['cz', 0, 1], ['cx', 2, 0], ['y', 0], ['z', 2]]], [[0.0, 0.0], [0.0, 1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['repair check: random circuit 17', [3, [['swap', 2, 0], ['t', 2], ['y', 1], ['sdg', 0], ['y', 1], ['cz', 0, 1], ['z', 2]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['control: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['control: h on excited qubit', [1, [['x', 0], ['h', 0]]], [[0.707107, 0.0], [-0.707107, 0.0]]]], [['regression: random circuit 19', [1, [['sdg', 0], ['y', 0], ['sdg', 0], ['s', 0], ['x', 0], ['z', 0], ['t', 0]]], [[0.0, 1.0], [0.0, 0.0]]], ['regression: random circuit 21', [3, [['cz', 2, 0], ['s', 0], ['cx', 1, 0], ['y', 2], ['sdg', 0], ['sdg', 2], ['cx', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['control: single x on qubit 0 of three', [3, [['x', 0]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 1', [3, [['cx', 1, 2], ['cz', 2, 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 3', [2, [['x', 1], ['s', 1], ['x', 0], ['h', 0], ['s', 1], ['h', 1]]], [[-0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['control: random circuit 5', [2, [['cx', 1, 0], ['cx', 0, 1], ['t', 1], ['h', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.707107, 0.0], [0.0, 0.0]]]], [['regression: random circuit 31', [3, [['cx', 0, 2], ['x', 2], ['y', 2]]], [[0.0, -1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 32', [1, [['x', 0], ['sdg', 0], ['x', 0], ['sdg', 0], ['s', 0], ['y', 0]]], [[0.0, 0.0], [1.0, 0.0]]], ['repair check: random circuit 17', [3, [['swap', 2, 0], ['t', 2], ['y', 1], ['sdg', 0], ['y', 1], ['cz', 0, 1], ['z', 2]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 6', [2, [['cz', 0, 1], ['cz', 0, 1], ['z', 1], ['sdg', 0], ['x', 0], ['x', 1], ['cx', 0, 1]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['control: random circuit 8', [1, [['s', 0], ['h', 0], ['s', 0]]], [[0.707107, 0.0], [0.0, 0.707107]]], ['control: random circuit 9', [1, [['z', 0], ['t', 0], ['z', 0], ['h', 0]]], [[0.707107, 0.0], [0.707107, 0.0]]]], [['regression: random circuit 39', [3, [['swap', 0, 2], ['cx', 2, 1], ['y', 2], ['z', 2], ['cx', 0, 1], ['sdg', 0], ['cx', 2, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, -1.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: y on ground state', [1, [['y', 0]]], [[0.0, 0.0], [0.0, 1.0]]], ['regression: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['control: random circuit 10', [3, [['cz', 0, 1], ['h', 0], ['z', 0], ['cx', 0, 1], ['s', 0], ['sdg', 0]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [-0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 11', [2, [['s', 0], ['h', 0]]], [[0.707107, 0.0], [0.707107, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 12', [3, [['sdg', 2], ['h', 2], ['h', 1], ['s', 0], ['z', 0], ['cx', 0, 1]]], [[0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0]]], ['control: random circuit 13', [2, [['sdg', 0], ['cz', 0, 1], ['swap', 0, 1], ['cx', 1, 0]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
    n, gates = x
    dim = 1 << n
    st = [0j] * dim
    st[0] = 1 + 0j
    r = 1 / math.sqrt(2)
    for g in gates:
        op = g[0]
        if op in ('h', 'x', 'y', 'z', 's', 'sdg', 't'):
            m = 1 << g[1]
            for i in range(dim):
                if i & m:
                    continue
                a, b = st[i], st[i | m]
                if op == 'h':
                    st[i], st[i | m] = (a + b) * r, (a - b) * r
                elif op == 'x':
                    st[i], st[i | m] = b, a
                elif op == 'y':
                    st[i], st[i | m] = 1j * b, 1j * a
                elif op == 'z':
                    st[i | m] = -b
                elif op == 's':
                    st[i | m] = 1j * b
                elif op == 'sdg':
                    st[i | m] = -1j * b
                else:
                    st[i | m] = b * cmath.exp(1j * math.pi / 4)
        elif op == 'cx':
            c, t = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & c and not i & t:
                    st[i], st[i | t] = st[i | t], st[i]
        elif op == 'cz':
            both = (1 << g[1]) | (1 << g[2])
            for i in range(dim):
                if i & both == both:
                    st[i] = -st[i]
        elif op == 'swap':
            a, b = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & a and not i & b:
                    j = (i ^ a) | b
                    st[i], st[j] = st[j], 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: y on ground state', [1, [['y', 0]]], [[0.0, 0.0], [0.0, 1.0]]], ['regression: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['regression: random circuit 15', [2, [['cx', 1, 0], ['z', 0], ['cz', 1, 0], ['h', 1], ['h', 0], ['y', 1], ['h', 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, -0.707107]]], ['control: empty circuit on two qubits', [2, []], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: bell pair', [2, [['h', 0], ['cx', 0, 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: ghz three qubits', [3, [['h', 0], ['cx', 0, 1], ['cx', 1, 2]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: cx with control on high qubit', [2, [['x', 1], ['cx', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]]], [['regression: random circuit 2', [3, [['z', 0], ['sdg', 1], ['cx', 1, 0], ['cz', 0, 1], ['cx', 2, 0], ['y', 0], ['z', 2]]], [[0.0, 0.0], [0.0, 1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['repair check: random circuit 17', [3, [['swap', 2, 0], ['t', 2], ['y', 1], ['sdg', 0], ['y', 1], ['cz', 0, 1], ['z', 2]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['control: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['control: h on excited qubit', [1, [['x', 0], ['h', 0]]], [[0.707107, 0.0], [-0.707107, 0.0]]]], [['regression: random circuit 19', [1, [['sdg', 0], ['y', 0], ['sdg', 0], ['s', 0], ['x', 0], ['z', 0], ['t', 0]]], [[0.0, 1.0], [0.0, 0.0]]], ['regression: random circuit 21', [3, [['cz', 2, 0], ['s', 0], ['cx', 1, 0], ['y', 2], ['sdg', 0], ['sdg', 2], ['cx', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['control: single x on qubit 0 of three', [3, [['x', 0]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 1', [3, [['cx', 1, 2], ['cz', 2, 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 3', [2, [['x', 1], ['s', 1], ['x', 0], ['h', 0], ['s', 1], ['h', 1]]], [[-0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['control: random circuit 5', [2, [['cx', 1, 0], ['cx', 0, 1], ['t', 1], ['h', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.707107, 0.0], [0.0, 0.0]]]], [['regression: random circuit 31', [3, [['cx', 0, 2], ['x', 2], ['y', 2]]], [[0.0, -1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 32', [1, [['x', 0], ['sdg', 0], ['x', 0], ['sdg', 0], ['s', 0], ['y', 0]]], [[0.0, 0.0], [1.0, 0.0]]], ['repair check: random circuit 17', [3, [['swap', 2, 0], ['t', 2], ['y', 1], ['sdg', 0], ['y', 1], ['cz', 0, 1], ['z', 2]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 6', [2, [['cz', 0, 1], ['cz', 0, 1], ['z', 1], ['sdg', 0], ['x', 0], ['x', 1], ['cx', 0, 1]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['control: random circuit 8', [1, [['s', 0], ['h', 0], ['s', 0]]], [[0.707107, 0.0], [0.0, 0.707107]]], ['control: random circuit 9', [1, [['z', 0], ['t', 0], ['z', 0], ['h', 0]]], [[0.707107, 0.0], [0.707107, 0.0]]]], [['regression: random circuit 39', [3, [['swap', 0, 2], ['cx', 2, 1], ['y', 2], ['z', 2], ['cx', 0, 1], ['sdg', 0], ['cx', 2, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, -1.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: y on ground state', [1, [['y', 0]]], [[0.0, 0.0], [0.0, 1.0]]], ['regression: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['control: random circuit 10', [3, [['cz', 0, 1], ['h', 0], ['z', 0], ['cx', 0, 1], ['s', 0], ['sdg', 0]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [-0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 11', [2, [['s', 0], ['h', 0]]], [[0.707107, 0.0], [0.707107, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 12', [3, [['sdg', 2], ['h', 2], ['h', 1], ['s', 0], ['z', 0], ['cx', 0, 1]]], [[0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0]]], ['control: random circuit 13', [2, [['sdg', 0], ['cz', 0, 1], ['swap', 0, 1], ['cx', 1, 0]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 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)

prompt:
After Y on |0> the simulator reports amplitude -i on |1> instead of +i, and interference with later H gates flips outcome probabilities.

Input [n, gates]; start in |0...0>, apply gates h,x,y,z,s,sdg,t (["g", q]) and cx,cz,swap (["g", a, b]) with qubit 0 as the least significant bit of the basis index; return the statevector as [re, im] pairs rounded to 6 decimals.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
    n, gates = x
    dim = 1 << n
    st = [0j] * dim
    st[0] = 1 + 0j
    r = 1 / math.sqrt(2)
    for g in gates:
        op = g[0]
        if op in ('h', 'x', 'y', 'z', 's', 'sdg', 't'):
            m = 1 << (n - 1 - g[1])
            for i in range(dim):
                if i & m:
                    continue
                a, b = st[i], st[i | m]
                if op == 'h':
                    st[i], st[i | m] = (a + b) * r, (a - b) * r
                elif op == 'x':
                    st[i], st[i | m] = b, a
                elif op == 'y':
                    st[i], st[i | m] = -1j * b, 1j * a
                elif op == 'z':
                    st[i | m] = -b
                elif op == 's':
                    st[i | m] = 1j * b
                elif op == 'sdg':
                    st[i | m] = -1j * b
                else:
                    st[i | m] = b * cmath.exp(1j * math.pi / 4)
        elif op == 'cx':
            c, t = 1 << (n - 1 - g[1]), 1 << (n - 1 - g[2])
            for i in range(dim):
                if i & c and not i & t:
                    st[i], st[i | t] = st[i | t], st[i]
        elif op == 'cz':
            both = (1 << g[1]) | (1 << g[2])
            for i in range(dim):
                if i & both == both:
                    st[i] = -st[i]
        elif op == 'swap':
            a, b = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & a and not i & b:
                    j = (i ^ a) | b
                    st[i], st[j] = st[j], 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: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['repair check: bell pair', [2, [['h', 0], ['cx', 0, 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: empty circuit on two qubits', [2, []], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: y on ground state', [1, [['y', 0]]], [[0.0, 0.0], [0.0, 1.0]]], ['control: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['control: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]]], [['regression: random circuit 2', [3, [['z', 0], ['sdg', 1], ['cx', 1, 0], ['cz', 0, 1], ['cx', 2, 0], ['y', 0], ['z', 2]]], [[0.0, 0.0], [0.0, 1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['repair check: cx with control on high qubit', [2, [['x', 1], ['cx', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['control: h on excited qubit', [1, [['x', 0], ['h', 0]]], [[0.707107, 0.0], [-0.707107, 0.0]]], ['control: random circuit 0', [3, [['swap', 2, 1], ['cx', 2, 0], ['z', 2], ['y', 1], ['cx', 0, 2], ['s', 1], ['swap', 1, 0]]], [[0.0, 0.0], [-1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 1', [3, [['cx', 1, 2], ['cz', 2, 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 3', [2, [['x', 1], ['s', 1], ['x', 0], ['h', 0], ['s', 1], ['h', 1]]], [[-0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]]], [['regression: random circuit 6', [2, [['cz', 0, 1], ['cz', 0, 1], ['z', 1], ['sdg', 0], ['x', 0], ['x', 1], ['cx', 0, 1]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 10', [3, [['cz', 0, 1], ['h', 0], ['z', 0], ['cx', 0, 1], ['s', 0], ['sdg', 0]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [-0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['repair check: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['control: random circuit 8', [1, [['s', 0], ['h', 0], ['s', 0]]], [[0.707107, 0.0], [0.0, 0.707107]]], ['control: random circuit 9', [1, [['z', 0], ['t', 0], ['z', 0], ['h', 0]]], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: random circuit 13', [2, [['sdg', 0], ['cz', 0, 1], ['swap', 0, 1], ['cx', 1, 0]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 16', [1, [['h', 0], ['h', 0], ['x', 0]]], [[0.0, 0.0], [1.0, 0.0]]]], [['regression: random circuit 12', [3, [['sdg', 2], ['h', 2], ['h', 1], ['s', 0], ['z', 0], ['cx', 0, 1]]], [[0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0]]], ['regression: random circuit 14', [2, [['z', 0], ['swap', 0, 1], ['x', 1], ['t', 0]]], [[0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 21', [3, [['cz', 2, 0], ['s', 0], ['cx', 1, 0], ['y', 2], ['sdg', 0], ['sdg', 2], ['cx', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 17', [3, [['swap', 2, 0], ['t', 2], ['y', 1], ['sdg', 0], ['y', 1], ['cz', 0, 1], ['z', 2]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 18', [1, [['s', 0]]], [[1.0, 0.0], [0.0, 0.0]]], ['control: random circuit 19', [1, [['sdg', 0], ['y', 0], ['sdg', 0], ['s', 0], ['x', 0], ['z', 0], ['t', 0]]], [[0.0, 1.0], [0.0, 0.0]]], ['control: random circuit 22', [3, [['z', 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]], [['regression: random circuit 20', [3, [['cx', 0, 1], ['h', 2], ['t', 1], ['x', 0], ['x', 2], ['t', 1]]], [[0.0, 0.0], [0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 21', [3, [['cz', 2, 0], ['s', 0], ['cx', 1, 0], ['y', 2], ['sdg', 0], ['sdg', 2], ['cx', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 29', [2, [['h', 1], ['sdg', 0], ['cx', 1, 0], ['z', 1], ['h', 1], ['t', 0], ['s', 1]]], [[0.5, 0.0], [-0.353553, -0.353553], [0.0, 0.5], [-0.353553, 0.353553]]], ['control: random circuit 24', [2, [['s', 1], ['cz', 0, 1], ['cx', 1, 0], ['t', 1], ['cx', 0, 1], ['s', 1], ['t', 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 27', [3, [['sdg', 0], ['cx', 2, 1], ['cz', 0, 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 28', [3, [['sdg', 2], ['sdg', 0]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 30', [1, [['h', 0]]], [[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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
    n, gates = x
    dim = 1 << n
    st = [0j] * dim
    st[0] = 1 + 0j
    r = 1 / math.sqrt(2)
    for g in gates:
        op = g[0]
        if op in ('h', 'x', 'y', 'z', 's', 'sdg', 't'):
            m = 1 << g[1]
            for i in range(dim):
                if i & m:
                    continue
                a, b = st[i], st[i | m]
                if op == 'h':
                    st[i], st[i | m] = (a + b) * r, (a - b) * r
                elif op == 'x':
                    st[i], st[i | m] = b, a
                elif op == 'y':
                    st[i], st[i | m] = -1j * b, 1j * a
                elif op == 'z':
                    st[i | m] = -b
                elif op == 's':
                    st[i | m] = 1j * b
                elif op == 'sdg':
                    st[i | m] = -1j * b
                else:
                    st[i | m] = b * cmath.exp(1j * math.pi / 4)
        elif op == 'cx':
            c, t = 1 << (n - 1 - g[1]), 1 << (n - 1 - g[2])
            for i in range(dim):
                if i & c and not i & t:
                    st[i], st[i | t] = st[i | t], st[i]
        elif op == 'cz':
            both = (1 << g[1]) | (1 << g[2])
            for i in range(dim):
                if i & both == both:
                    st[i] = -st[i]
        elif op == 'swap':
            a, b = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & a and not i & b:
                    j = (i ^ a) | b
                    st[i], st[j] = st[j], 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: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['repair check: bell pair', [2, [['h', 0], ['cx', 0, 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: empty circuit on two qubits', [2, []], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: y on ground state', [1, [['y', 0]]], [[0.0, 0.0], [0.0, 1.0]]], ['control: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['control: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]]], [['regression: random circuit 2', [3, [['z', 0], ['sdg', 1], ['cx', 1, 0], ['cz', 0, 1], ['cx', 2, 0], ['y', 0], ['z', 2]]], [[0.0, 0.0], [0.0, 1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['repair check: cx with control on high qubit', [2, [['x', 1], ['cx', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['control: h on excited qubit', [1, [['x', 0], ['h', 0]]], [[0.707107, 0.0], [-0.707107, 0.0]]], ['control: random circuit 0', [3, [['swap', 2, 1], ['cx', 2, 0], ['z', 2], ['y', 1], ['cx', 0, 2], ['s', 1], ['swap', 1, 0]]], [[0.0, 0.0], [-1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 1', [3, [['cx', 1, 2], ['cz', 2, 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 3', [2, [['x', 1], ['s', 1], ['x', 0], ['h', 0], ['s', 1], ['h', 1]]], [[-0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]]], [['regression: random circuit 6', [2, [['cz', 0, 1], ['cz', 0, 1], ['z', 1], ['sdg', 0], ['x', 0], ['x', 1], ['cx', 0, 1]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 10', [3, [['cz', 0, 1], ['h', 0], ['z', 0], ['cx', 0, 1], ['s', 0], ['sdg', 0]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [-0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['repair check: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['control: random circuit 8', [1, [['s', 0], ['h', 0], ['s', 0]]], [[0.707107, 0.0], [0.0, 0.707107]]], ['control: random circuit 9', [1, [['z', 0], ['t', 0], ['z', 0], ['h', 0]]], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: random circuit 13', [2, [['sdg', 0], ['cz', 0, 1], ['swap', 0, 1], ['cx', 1, 0]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 16', [1, [['h', 0], ['h', 0], ['x', 0]]], [[0.0, 0.0], [1.0, 0.0]]]], [['regression: random circuit 12', [3, [['sdg', 2], ['h', 2], ['h', 1], ['s', 0], ['z', 0], ['cx', 0, 1]]], [[0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0]]], ['regression: random circuit 14', [2, [['z', 0], ['swap', 0, 1], ['x', 1], ['t', 0]]], [[0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 21', [3, [['cz', 2, 0], ['s', 0], ['cx', 1, 0], ['y', 2], ['sdg', 0], ['sdg', 2], ['cx', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 17', [3, [['swap', 2, 0], ['t', 2], ['y', 1], ['sdg', 0], ['y', 1], ['cz', 0, 1], ['z', 2]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 18', [1, [['s', 0]]], [[1.0, 0.0], [0.0, 0.0]]], ['control: random circuit 19', [1, [['sdg', 0], ['y', 0], ['sdg', 0], ['s', 0], ['x', 0], ['z', 0], ['t', 0]]], [[0.0, 1.0], [0.0, 0.0]]], ['control: random circuit 22', [3, [['z', 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]], [['regression: random circuit 20', [3, [['cx', 0, 1], ['h', 2], ['t', 1], ['x', 0], ['x', 2], ['t', 1]]], [[0.0, 0.0], [0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 21', [3, [['cz', 2, 0], ['s', 0], ['cx', 1, 0], ['y', 2], ['sdg', 0], ['sdg', 2], ['cx', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 29', [2, [['h', 1], ['sdg', 0], ['cx', 1, 0], ['z', 1], ['h', 1], ['t', 0], ['s', 1]]], [[0.5, 0.0], [-0.353553, -0.353553], [0.0, 0.5], [-0.353553, 0.353553]]], ['control: random circuit 24', [2, [['s', 1], ['cz', 0, 1], ['cx', 1, 0], ['t', 1], ['cx', 0, 1], ['s', 1], ['t', 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 27', [3, [['sdg', 0], ['cx', 2, 1], ['cz', 0, 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 28', [3, [['sdg', 2], ['sdg', 0]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 30', [1, [['h', 0]]], [[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)

prompt:
An X on qubit 0 of a three-qubit register excites basis index 4 instead of index 1.

Input [n, gates]; start in |0...0>, apply gates h,x,y,z,s,sdg,t (["g", q]) and cx,cz,swap (["g", a, b]) with qubit 0 as the least significant bit of the basis index; return the statevector as [re, im] pairs rounded to 6 decimals.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
    n, gates = x
    dim = 1 << n
    st = [0j] * dim
    st[0] = 1 + 0j
    r = 1 / math.sqrt(2)
    for g in gates:
        op = g[0]
        if op in ('h', 'x', 'y', 'z', 's', 'sdg', 't'):
            m = 1 << g[1]
            for i in range(dim):
                if i & m:
                    continue
                a, b = st[i], st[i | m]
                if op == 'h':
                    st[i], st[i | m] = (a + b) * r, (a - b) * r
                elif op == 'x':
                    st[i], st[i | m] = b, a
                elif op == 'y':
                    st[i], st[i | m] = -1j * b, 1j * a
                elif op == 'z':
                    st[i | m] = -b
                elif op == 's':
                    st[i | m] = 1j * b
                elif op == 'sdg':
                    st[i | m] = 1j * b
                else:
                    st[i | m] = b * cmath.exp(1j * math.pi / 4)
        elif op == 'cx':
            c, t = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & c and not i & t:
                    st[i], st[i | t] = st[i | t], st[i]
        elif op == 'cz':
            both = (1 << g[1]) | (1 << g[2])
            for i in range(dim):
                if i & both == both:
                    st[i] = -st[i]
        elif op == 'swap':
            a, b = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & a and not i & b:
                    j = (i ^ a) | b
                    st[i], st[j] = st[j], 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: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['regression: random circuit 10', [3, [['cz', 0, 1], ['h', 0], ['z', 0], ['cx', 0, 1], ['s', 0], ['sdg', 0]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [-0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 32', [1, [['x', 0], ['sdg', 0], ['x', 0], ['sdg', 0], ['s', 0], ['y', 0]]], [[0.0, 0.0], [1.0, 0.0]]], ['control: empty circuit on two qubits', [2, []], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: bell pair', [2, [['h', 0], ['cx', 0, 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: ghz three qubits', [3, [['h', 0], ['cx', 0, 1], ['cx', 1, 2]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: cx with control on high qubit', [2, [['x', 1], ['cx', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]]], [['regression: random circuit 21', [3, [['cz', 2, 0], ['s', 0], ['cx', 1, 0], ['y', 2], ['sdg', 0], ['sdg', 2], ['cx', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 32', [1, [['x', 0], ['sdg', 0], ['x', 0], ['sdg', 0], ['s', 0], ['y', 0]]], [[0.0, 0.0], [1.0, 0.0]]], ['regression: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['control: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: y on ground state', [1, [['y', 0]]], [[0.0, 0.0], [0.0, 1.0]]], ['control: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['control: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]]], [['regression: random circuit 10', [3, [['cz', 0, 1], ['h', 0], ['z', 0], ['cx', 0, 1], ['s', 0], ['sdg', 0]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [-0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 19', [1, [['sdg', 0], ['y', 0], ['sdg', 0], ['s', 0], ['x', 0], ['z', 0], ['t', 0]]], [[0.0, 1.0], [0.0, 0.0]]], ['regression: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['control: h on excited qubit', [1, [['x', 0], ['h', 0]]], [[0.707107, 0.0], [-0.707107, 0.0]]], ['control: single x on qubit 0 of three', [3, [['x', 0]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 0', [3, [['swap', 2, 1], ['cx', 2, 0], ['z', 2], ['y', 1], ['cx', 0, 2], ['s', 1], ['swap', 1, 0]]], [[0.0, 0.0], [-1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 1', [3, [['cx', 1, 2], ['cz', 2, 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]], [['regression: random circuit 32', [1, [['x', 0], ['sdg', 0], ['x', 0], ['sdg', 0], ['s', 0], ['y', 0]]], [[0.0, 0.0], [1.0, 0.0]]], ['regression: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['control: random circuit 2', [3, [['z', 0], ['sdg', 1], ['cx', 1, 0], ['cz', 0, 1], ['cx', 2, 0], ['y', 0], ['z', 2]]], [[0.0, 0.0], [0.0, 1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 3', [2, [['x', 1], ['s', 1], ['x', 0], ['h', 0], ['s', 1], ['h', 1]]], [[-0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['control: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['control: random circuit 5', [2, [['cx', 1, 0], ['cx', 0, 1], ['t', 1], ['h', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.707107, 0.0], [0.0, 0.0]]], ['regression: random circuit 10', [3, [['cz', 0, 1], ['h', 0], ['z', 0], ['cx', 0, 1], ['s', 0], ['sdg', 0]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [-0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]], [['regression: random circuit 19', [1, [['sdg', 0], ['y', 0], ['sdg', 0], ['s', 0], ['x', 0], ['z', 0], ['t', 0]]], [[0.0, 1.0], [0.0, 0.0]]], ['regression: random circuit 21', [3, [['cz', 2, 0], ['s', 0], ['cx', 1, 0], ['y', 2], ['sdg', 0], ['sdg', 2], ['cx', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['control: random circuit 6', [2, [['cz', 0, 1], ['cz', 0, 1], ['z', 1], ['sdg', 0], ['x', 0], ['x', 1], ['cx', 0, 1]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['control: random circuit 8', [1, [['s', 0], ['h', 0], ['s', 0]]], [[0.707107, 0.0], [0.0, 0.707107]]], ['control: random circuit 9', [1, [['z', 0], ['t', 0], ['z', 0], ['h', 0]]], [[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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
    n, gates = x
    dim = 1 << n
    st = [0j] * dim
    st[0] = 1 + 0j
    r = 1 / math.sqrt(2)
    for g in gates:
        op = g[0]
        if op in ('h', 'x', 'y', 'z', 's', 'sdg', 't'):
            m = 1 << g[1]
            for i in range(dim):
                if i & m:
                    continue
                a, b = st[i], st[i | m]
                if op == 'h':
                    st[i], st[i | m] = (a + b) * r, (a - b) * r
                elif op == 'x':
                    st[i], st[i | m] = b, a
                elif op == 'y':
                    st[i], st[i | m] = -1j * b, 1j * a
                elif op == 'z':
                    st[i | m] = -b
                elif op == 's':
                    st[i | m] = 1j * b
                elif op == 'sdg':
                    st[i | m] = 1j * b.conjugate()
                else:
                    st[i | m] = b * cmath.exp(1j * math.pi / 4)
        elif op == 'cx':
            c, t = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & c and not i & t:
                    st[i], st[i | t] = st[i | t], st[i]
        elif op == 'cz':
            both = (1 << g[1]) | (1 << g[2])
            for i in range(dim):
                if i & both == both:
                    st[i] = -st[i]
        elif op == 'swap':
            a, b = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & a and not i & b:
                    j = (i ^ a) | b
                    st[i], st[j] = st[j], 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: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['regression: random circuit 10', [3, [['cz', 0, 1], ['h', 0], ['z', 0], ['cx', 0, 1], ['s', 0], ['sdg', 0]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [-0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 32', [1, [['x', 0], ['sdg', 0], ['x', 0], ['sdg', 0], ['s', 0], ['y', 0]]], [[0.0, 0.0], [1.0, 0.0]]], ['control: empty circuit on two qubits', [2, []], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: bell pair', [2, [['h', 0], ['cx', 0, 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: ghz three qubits', [3, [['h', 0], ['cx', 0, 1], ['cx', 1, 2]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: cx with control on high qubit', [2, [['x', 1], ['cx', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]]], [['regression: random circuit 21', [3, [['cz', 2, 0], ['s', 0], ['cx', 1, 0], ['y', 2], ['sdg', 0], ['sdg', 2], ['cx', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 32', [1, [['x', 0], ['sdg', 0], ['x', 0], ['sdg', 0], ['s', 0], ['y', 0]]], [[0.0, 0.0], [1.0, 0.0]]], ['regression: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['control: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: y on ground state', [1, [['y', 0]]], [[0.0, 0.0], [0.0, 1.0]]], ['control: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['control: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]]], [['regression: random circuit 10', [3, [['cz', 0, 1], ['h', 0], ['z', 0], ['cx', 0, 1], ['s', 0], ['sdg', 0]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [-0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 19', [1, [['sdg', 0], ['y', 0], ['sdg', 0], ['s', 0], ['x', 0], ['z', 0], ['t', 0]]], [[0.0, 1.0], [0.0, 0.0]]], ['regression: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['control: h on excited qubit', [1, [['x', 0], ['h', 0]]], [[0.707107, 0.0], [-0.707107, 0.0]]], ['control: single x on qubit 0 of three', [3, [['x', 0]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 0', [3, [['swap', 2, 1], ['cx', 2, 0], ['z', 2], ['y', 1], ['cx', 0, 2], ['s', 1], ['swap', 1, 0]]], [[0.0, 0.0], [-1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 1', [3, [['cx', 1, 2], ['cz', 2, 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]], [['regression: random circuit 32', [1, [['x', 0], ['sdg', 0], ['x', 0], ['sdg', 0], ['s', 0], ['y', 0]]], [[0.0, 0.0], [1.0, 0.0]]], ['regression: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['control: random circuit 2', [3, [['z', 0], ['sdg', 1], ['cx', 1, 0], ['cz', 0, 1], ['cx', 2, 0], ['y', 0], ['z', 2]]], [[0.0, 0.0], [0.0, 1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 3', [2, [['x', 1], ['s', 1], ['x', 0], ['h', 0], ['s', 1], ['h', 1]]], [[-0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['control: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['control: random circuit 5', [2, [['cx', 1, 0], ['cx', 0, 1], ['t', 1], ['h', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.707107, 0.0], [0.0, 0.0]]], ['regression: random circuit 10', [3, [['cz', 0, 1], ['h', 0], ['z', 0], ['cx', 0, 1], ['s', 0], ['sdg', 0]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [-0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]], [['regression: random circuit 19', [1, [['sdg', 0], ['y', 0], ['sdg', 0], ['s', 0], ['x', 0], ['z', 0], ['t', 0]]], [[0.0, 1.0], [0.0, 0.0]]], ['regression: random circuit 21', [3, [['cz', 2, 0], ['s', 0], ['cx', 1, 0], ['y', 2], ['sdg', 0], ['sdg', 2], ['cx', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['control: random circuit 6', [2, [['cz', 0, 1], ['cz', 0, 1], ['z', 1], ['sdg', 0], ['x', 0], ['x', 1], ['cx', 0, 1]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['control: random circuit 8', [1, [['s', 0], ['h', 0], ['s', 0]]], [[0.707107, 0.0], [0.0, 0.707107]]], ['control: random circuit 9', [1, [['z', 0], ['t', 0], ['z', 0], ['h', 0]]], [[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)

prompt:
H followed by Sdg yields the |+i> state instead of |-i>, so a subsequent measurement basis change reports the wrong eigenstate.

Input [n, gates]; start in |0...0>, apply gates h,x,y,z,s,sdg,t (["g", q]) and cx,cz,swap (["g", a, b]) with qubit 0 as the least significant bit of the basis index; return the statevector as [re, im] pairs rounded to 6 decimals.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
    n, gates = x
    dim = 1 << n
    st = [0j] * dim
    st[0] = 1 + 0j
    r = 1 / math.sqrt(2)
    for g in gates:
        op = g[0]
        if op in ('h', 'x', 'y', 'z', 's', 'sdg', 't'):
            m = 1 << g[1]
            for i in range(dim):
                if i & m:
                    continue
                a, b = st[i], st[i | m]
                if op == 'h':
                    st[i], st[i | m] = (a + b) * r, (a - b) * r
                elif op == 'x':
                    st[i], st[i | m] = b, a
                elif op == 'y':
                    st[i], st[i | m] = -1j * b, 1j * a
                elif op == 'z':
                    st[i | m] = -b
                elif op == 's':
                    st[i | m] = 1j * b
                elif op == 'sdg':
                    st[i | m] = -1j * b
                else:
                    st[i | m] = b * cmath.exp(1j * math.pi / 8)
        elif op == 'cx':
            c, t = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & c and not i & t:
                    st[i], st[i | t] = st[i | t], st[i]
        elif op == 'cz':
            both = (1 << g[1]) | (1 << g[2])
            for i in range(dim):
                if i & both == both:
                    st[i] = -st[i]
        elif op == 'swap':
            a, b = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & a and not i & b:
                    j = (i ^ a) | b
                    st[i], st[j] = st[j], 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: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['regression: random circuit 29', [2, [['h', 1], ['sdg', 0], ['cx', 1, 0], ['z', 1], ['h', 1], ['t', 0], ['s', 1]]], [[0.5, 0.0], [-0.353553, -0.353553], [0.0, 0.5], [-0.353553, 0.353553]]], ['control: empty circuit on two qubits', [2, []], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: bell pair', [2, [['h', 0], ['cx', 0, 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: ghz three qubits', [3, [['h', 0], ['cx', 0, 1], ['cx', 1, 2]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: cx with control on high qubit', [2, [['x', 1], ['cx', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]]], [['regression: random circuit 29', [2, [['h', 1], ['sdg', 0], ['cx', 1, 0], ['z', 1], ['h', 1], ['t', 0], ['s', 1]]], [[0.5, 0.0], [-0.353553, -0.353553], [0.0, 0.5], [-0.353553, 0.353553]]], ['regression: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['control: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: y on ground state', [1, [['y', 0]]], [[0.0, 0.0], [0.0, 1.0]]], ['control: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['control: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]]], [['regression: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['regression: random circuit 29', [2, [['h', 1], ['sdg', 0], ['cx', 1, 0], ['z', 1], ['h', 1], ['t', 0], ['s', 1]]], [[0.5, 0.0], [-0.353553, -0.353553], [0.0, 0.5], [-0.353553, 0.353553]]], ['control: h on excited qubit', [1, [['x', 0], ['h', 0]]], [[0.707107, 0.0], [-0.707107, 0.0]]], ['control: single x on qubit 0 of three', [3, [['x', 0]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 0', [3, [['swap', 2, 1], ['cx', 2, 0], ['z', 2], ['y', 1], ['cx', 0, 2], ['s', 1], ['swap', 1, 0]]], [[0.0, 0.0], [-1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 1', [3, [['cx', 1, 2], ['cz', 2, 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]], [['regression: random circuit 29', [2, [['h', 1], ['sdg', 0], ['cx', 1, 0], ['z', 1], ['h', 1], ['t', 0], ['s', 1]]], [[0.5, 0.0], [-0.353553, -0.353553], [0.0, 0.5], [-0.353553, 0.353553]]], ['regression: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['control: random circuit 2', [3, [['z', 0], ['sdg', 1], ['cx', 1, 0], ['cz', 0, 1], ['cx', 2, 0], ['y', 0], ['z', 2]]], [[0.0, 0.0], [0.0, 1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 3', [2, [['x', 1], ['s', 1], ['x', 0], ['h', 0], ['s', 1], ['h', 1]]], [[-0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['control: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['control: random circuit 5', [2, [['cx', 1, 0], ['cx', 0, 1], ['t', 1], ['h', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.707107, 0.0], [0.0, 0.0]]]], [['regression: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['regression: random circuit 29', [2, [['h', 1], ['sdg', 0], ['cx', 1, 0], ['z', 1], ['h', 1], ['t', 0], ['s', 1]]], [[0.5, 0.0], [-0.353553, -0.353553], [0.0, 0.5], [-0.353553, 0.353553]]], ['control: random circuit 6', [2, [['cz', 0, 1], ['cz', 0, 1], ['z', 1], ['sdg', 0], ['x', 0], ['x', 1], ['cx', 0, 1]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['control: random circuit 8', [1, [['s', 0], ['h', 0], ['s', 0]]], [[0.707107, 0.0], [0.0, 0.707107]]], ['control: random circuit 9', [1, [['z', 0], ['t', 0], ['z', 0], ['h', 0]]], [[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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
    n, gates = x
    dim = 1 << n
    st = [0j] * dim
    st[0] = 1 + 0j
    r = 1 / math.sqrt(2)
    for g in gates:
        op = g[0]
        if op in ('h', 'x', 'y', 'z', 's', 'sdg', 't'):
            m = 1 << g[1]
            for i in range(dim):
                if i & m:
                    continue
                a, b = st[i], st[i | m]
                if op == 'h':
                    st[i], st[i | m] = (a + b) * r, (a - b) * r
                elif op == 'x':
                    st[i], st[i | m] = b, a
                elif op == 'y':
                    st[i], st[i | m] = -1j * b, 1j * a
                elif op == 'z':
                    st[i | m] = -b
                elif op == 's':
                    st[i | m] = 1j * b
                elif op == 'sdg':
                    st[i | m] = -1j * b
                else:
                    st[i | m] = b * cmath.exp(-1j * math.pi / 4)
        elif op == 'cx':
            c, t = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & c and not i & t:
                    st[i], st[i | t] = st[i | t], st[i]
        elif op == 'cz':
            both = (1 << g[1]) | (1 << g[2])
            for i in range(dim):
                if i & both == both:
                    st[i] = -st[i]
        elif op == 'swap':
            a, b = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & a and not i & b:
                    j = (i ^ a) | b
                    st[i], st[j] = st[j], 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: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['regression: random circuit 29', [2, [['h', 1], ['sdg', 0], ['cx', 1, 0], ['z', 1], ['h', 1], ['t', 0], ['s', 1]]], [[0.5, 0.0], [-0.353553, -0.353553], [0.0, 0.5], [-0.353553, 0.353553]]], ['control: empty circuit on two qubits', [2, []], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: bell pair', [2, [['h', 0], ['cx', 0, 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: ghz three qubits', [3, [['h', 0], ['cx', 0, 1], ['cx', 1, 2]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: cx with control on high qubit', [2, [['x', 1], ['cx', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]]], [['regression: random circuit 29', [2, [['h', 1], ['sdg', 0], ['cx', 1, 0], ['z', 1], ['h', 1], ['t', 0], ['s', 1]]], [[0.5, 0.0], [-0.353553, -0.353553], [0.0, 0.5], [-0.353553, 0.353553]]], ['regression: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['control: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: y on ground state', [1, [['y', 0]]], [[0.0, 0.0], [0.0, 1.0]]], ['control: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['control: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]]], [['regression: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['regression: random circuit 29', [2, [['h', 1], ['sdg', 0], ['cx', 1, 0], ['z', 1], ['h', 1], ['t', 0], ['s', 1]]], [[0.5, 0.0], [-0.353553, -0.353553], [0.0, 0.5], [-0.353553, 0.353553]]], ['control: h on excited qubit', [1, [['x', 0], ['h', 0]]], [[0.707107, 0.0], [-0.707107, 0.0]]], ['control: single x on qubit 0 of three', [3, [['x', 0]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 0', [3, [['swap', 2, 1], ['cx', 2, 0], ['z', 2], ['y', 1], ['cx', 0, 2], ['s', 1], ['swap', 1, 0]]], [[0.0, 0.0], [-1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 1', [3, [['cx', 1, 2], ['cz', 2, 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]], [['regression: random circuit 29', [2, [['h', 1], ['sdg', 0], ['cx', 1, 0], ['z', 1], ['h', 1], ['t', 0], ['s', 1]]], [[0.5, 0.0], [-0.353553, -0.353553], [0.0, 0.5], [-0.353553, 0.353553]]], ['regression: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['control: random circuit 2', [3, [['z', 0], ['sdg', 1], ['cx', 1, 0], ['cz', 0, 1], ['cx', 2, 0], ['y', 0], ['z', 2]]], [[0.0, 0.0], [0.0, 1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 3', [2, [['x', 1], ['s', 1], ['x', 0], ['h', 0], ['s', 1], ['h', 1]]], [[-0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['control: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['control: random circuit 5', [2, [['cx', 1, 0], ['cx', 0, 1], ['t', 1], ['h', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.707107, 0.0], [0.0, 0.0]]]], [['regression: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['regression: random circuit 29', [2, [['h', 1], ['sdg', 0], ['cx', 1, 0], ['z', 1], ['h', 1], ['t', 0], ['s', 1]]], [[0.5, 0.0], [-0.353553, -0.353553], [0.0, 0.5], [-0.353553, 0.353553]]], ['control: random circuit 6', [2, [['cz', 0, 1], ['cz', 0, 1], ['z', 1], ['sdg', 0], ['x', 0], ['x', 1], ['cx', 0, 1]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['control: random circuit 8', [1, [['s', 0], ['h', 0], ['s', 0]]], [[0.707107, 0.0], [0.0, 0.707107]]], ['control: random circuit 9', [1, [['z', 0], ['t', 0], ['z', 0], ['h', 0]]], [[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)

prompt:
After H then T the |1> amplitude has phase 22.5 degrees instead of 45 degrees.

Input [n, gates]; start in |0...0>, apply gates h,x,y,z,s,sdg,t (["g", q]) and cx,cz,swap (["g", a, b]) with qubit 0 as the least significant bit of the basis index; return the statevector as [re, im] pairs rounded to 6 decimals.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
    n, gates = x
    dim = 1 << n
    st = [0j] * dim
    st[0] = 1 + 0j
    r = 1 / math.sqrt(2)
    for g in gates:
        op = g[0]
        if op in ('h', 'x', 'y', 'z', 's', 'sdg', 't'):
            m = 1 << g[1]
            for i in range(dim):
                if i & m:
                    continue
                a, b = st[i], st[i | m]
                if op == 'h':
                    st[i], st[i | m] = (a + b) * r, (a - b) * r
                elif op == 'x':
                    st[i], st[i | m] = b, a
                elif op == 'y':
                    st[i], st[i | m] = -1j * b, 1j * a
                elif op == 'z':
                    st[i | m] = -b
                elif op == 's':
                    st[i | m] = 1j * b
                elif op == 'sdg':
                    st[i | m] = -1j * b
                else:
                    st[i | m] = b * cmath.exp(1j * math.pi / 4)
        elif op == 'cx':
            c, t = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & c and not i & t:
                    st[i], st[i | t] = st[i | t], st[i]
        elif op == 'cz':
            both = (1 << g[1]) | (1 << g[2])
            for i in range(dim):
                if i & both == both:
                    st[i] = -st[i]
        elif op == 'swap':
            a, b = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if bool(i & a) != bool(i & b):
                    j = (i ^ a) | b
                    st[i], st[j] = st[j], 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: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['repair check: random circuit 0', [3, [['swap', 2, 1], ['cx', 2, 0], ['z', 2], ['y', 1], ['cx', 0, 2], ['s', 1], ['swap', 1, 0]]], [[0.0, 0.0], [-1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: empty circuit on two qubits', [2, []], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: bell pair', [2, [['h', 0], ['cx', 0, 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: ghz three qubits', [3, [['h', 0], ['cx', 0, 1], ['cx', 1, 2]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: cx with control on high qubit', [2, [['x', 1], ['cx', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]]], [['regression: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['regression: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['repair check: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['control: y on ground state', [1, [['y', 0]]], [[0.0, 0.0], [0.0, 1.0]]], ['control: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['control: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['control: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]]], [['regression: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['repair check: random circuit 0', [3, [['swap', 2, 1], ['cx', 2, 0], ['z', 2], ['y', 1], ['cx', 0, 2], ['s', 1], ['swap', 1, 0]]], [[0.0, 0.0], [-1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: h on excited qubit', [1, [['x', 0], ['h', 0]]], [[0.707107, 0.0], [-0.707107, 0.0]]], ['control: single x on qubit 0 of three', [3, [['x', 0]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 1', [3, [['cx', 1, 2], ['cz', 2, 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 2', [3, [['z', 0], ['sdg', 1], ['cx', 1, 0], ['cz', 0, 1], ['cx', 2, 0], ['y', 0], ['z', 2]]], [[0.0, 0.0], [0.0, 1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]], [['regression: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['regression: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['repair check: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['control: random circuit 3', [2, [['x', 1], ['s', 1], ['x', 0], ['h', 0], ['s', 1], ['h', 1]]], [[-0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['control: random circuit 5', [2, [['cx', 1, 0], ['cx', 0, 1], ['t', 1], ['h', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.707107, 0.0], [0.0, 0.0]]], ['control: random circuit 6', [2, [['cz', 0, 1], ['cz', 0, 1], ['z', 1], ['sdg', 0], ['x', 0], ['x', 1], ['cx', 0, 1]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 8', [1, [['s', 0], ['h', 0], ['s', 0]]], [[0.707107, 0.0], [0.0, 0.707107]]]], [['regression: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['repair check: random circuit 0', [3, [['swap', 2, 1], ['cx', 2, 0], ['z', 2], ['y', 1], ['cx', 0, 2], ['s', 1], ['swap', 1, 0]]], [[0.0, 0.0], [-1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 9', [1, [['z', 0], ['t', 0], ['z', 0], ['h', 0]]], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: random circuit 10', [3, [['cz', 0, 1], ['h', 0], ['z', 0], ['cx', 0, 1], ['s', 0], ['sdg', 0]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [-0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 11', [2, [['s', 0], ['h', 0]]], [[0.707107, 0.0], [0.707107, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 12', [3, [['sdg', 2], ['h', 2], ['h', 1], ['s', 0], ['z', 0], ['cx', 0, 1]]], [[0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
    n, gates = x
    dim = 1 << n
    st = [0j] * dim
    st[0] = 1 + 0j
    r = 1 / math.sqrt(2)
    for g in gates:
        op = g[0]
        if op in ('h', 'x', 'y', 'z', 's', 'sdg', 't'):
            m = 1 << g[1]
            for i in range(dim):
                if i & m:
                    continue
                a, b = st[i], st[i | m]
                if op == 'h':
                    st[i], st[i | m] = (a + b) * r, (a - b) * r
                elif op == 'x':
                    st[i], st[i | m] = b, a
                elif op == 'y':
                    st[i], st[i | m] = -1j * b, 1j * a
                elif op == 'z':
                    st[i | m] = -b
                elif op == 's':
                    st[i | m] = 1j * b
                elif op == 'sdg':
                    st[i | m] = -1j * b
                else:
                    st[i | m] = b * cmath.exp(1j * math.pi / 4)
        elif op == 'cx':
            c, t = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & c and not i & t:
                    st[i], st[i | t] = st[i | t], st[i]
        elif op == 'cz':
            both = (1 << g[1]) | (1 << g[2])
            for i in range(dim):
                if i & both == both:
                    st[i] = -st[i]
        elif op == 'swap':
            a, b = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & b and not i & a:
                    j = (i ^ a) | b
                    st[i], st[j] = st[j], 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: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['repair check: random circuit 0', [3, [['swap', 2, 1], ['cx', 2, 0], ['z', 2], ['y', 1], ['cx', 0, 2], ['s', 1], ['swap', 1, 0]]], [[0.0, 0.0], [-1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: empty circuit on two qubits', [2, []], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: bell pair', [2, [['h', 0], ['cx', 0, 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: ghz three qubits', [3, [['h', 0], ['cx', 0, 1], ['cx', 1, 2]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['control: cx with control on high qubit', [2, [['x', 1], ['cx', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]]], [['regression: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['regression: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['repair check: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['control: y on ground state', [1, [['y', 0]]], [[0.0, 0.0], [0.0, 1.0]]], ['control: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['control: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['control: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]]], [['regression: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['repair check: random circuit 0', [3, [['swap', 2, 1], ['cx', 2, 0], ['z', 2], ['y', 1], ['cx', 0, 2], ['s', 1], ['swap', 1, 0]]], [[0.0, 0.0], [-1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: h on excited qubit', [1, [['x', 0], ['h', 0]]], [[0.707107, 0.0], [-0.707107, 0.0]]], ['control: single x on qubit 0 of three', [3, [['x', 0]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 1', [3, [['cx', 1, 2], ['cz', 2, 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 2', [3, [['z', 0], ['sdg', 1], ['cx', 1, 0], ['cz', 0, 1], ['cx', 2, 0], ['y', 0], ['z', 2]]], [[0.0, 0.0], [0.0, 1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]], [['regression: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['regression: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['repair check: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['control: random circuit 3', [2, [['x', 1], ['s', 1], ['x', 0], ['h', 0], ['s', 1], ['h', 1]]], [[-0.5, 0.0], [0.5, 0.0], [0.5, 0.0], [-0.5, 0.0]]], ['control: random circuit 5', [2, [['cx', 1, 0], ['cx', 0, 1], ['t', 1], ['h', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.707107, 0.0], [0.0, 0.0]]], ['control: random circuit 6', [2, [['cz', 0, 1], ['cz', 0, 1], ['z', 1], ['sdg', 0], ['x', 0], ['x', 1], ['cx', 0, 1]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 8', [1, [['s', 0], ['h', 0], ['s', 0]]], [[0.707107, 0.0], [0.0, 0.707107]]]], [['regression: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['repair check: random circuit 0', [3, [['swap', 2, 1], ['cx', 2, 0], ['z', 2], ['y', 1], ['cx', 0, 2], ['s', 1], ['swap', 1, 0]]], [[0.0, 0.0], [-1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 9', [1, [['z', 0], ['t', 0], ['z', 0], ['h', 0]]], [[0.707107, 0.0], [0.707107, 0.0]]], ['control: random circuit 10', [3, [['cz', 0, 1], ['h', 0], ['z', 0], ['cx', 0, 1], ['s', 0], ['sdg', 0]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [-0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 11', [2, [['s', 0], ['h', 0]]], [[0.707107, 0.0], [0.707107, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 12', [3, [['sdg', 2], ['h', 2], ['h', 1], ['s', 0], ['z', 0], ['cx', 0, 1]]], [[0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 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)

prompt:
SWAP(0,2) after X on qubit 0 leaves the excitation on qubit 0; the gate acts as identity.

Input [n, gates]; start in |0...0>, apply gates h,x,y,z,s,sdg,t (["g", q]) and cx,cz,swap (["g", a, b]) with qubit 0 as the least significant bit of the basis index; return the statevector as [re, im] pairs rounded to 6 decimals.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
    n, gates = x
    dim = 1 << n
    st = [0j] * dim
    st[0] = 1 + 0j
    r = 1 / math.sqrt(2)
    for g in gates:
        op = g[0]
        if op in ('h', 'x', 'y', 'z', 's', 'sdg', 't'):
            m = 1 << g[1]
            for i in range(dim):
                if i & m:
                    continue
                a, b = st[i], st[i | m]
                if op == 'h':
                    st[i], st[i | m] = (a + b) * r, (b - a) * r
                elif op == 'x':
                    st[i], st[i | m] = b, a
                elif op == 'y':
                    st[i], st[i | m] = -1j * b, 1j * a
                elif op == 'z':
                    st[i | m] = -b
                elif op == 's':
                    st[i | m] = 1j * b
                elif op == 'sdg':
                    st[i | m] = -1j * b
                else:
                    st[i | m] = b * cmath.exp(1j * math.pi / 4)
        elif op == 'cx':
            c, t = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & c and not i & t:
                    st[i], st[i | t] = st[i | t], st[i]
        elif op == 'cz':
            both = (1 << g[1]) | (1 << g[2])
            for i in range(dim):
                if i & both == both:
                    st[i] = -st[i]
        elif op == 'swap':
            a, b = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & a and not i & b:
                    j = (i ^ a) | b
                    st[i], st[j] = st[j], 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: bell pair', [2, [['h', 0], ['cx', 0, 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['regression: ghz three qubits', [3, [['h', 0], ['cx', 0, 1], ['cx', 1, 2]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['regression: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['control: empty circuit on two qubits', [2, []], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: cx with control on high qubit', [2, [['x', 1], ['cx', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['control: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: y on ground state', [1, [['y', 0]]], [[0.0, 0.0], [0.0, 1.0]]]], [['regression: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['regression: h on excited qubit', [1, [['x', 0], ['h', 0]]], [[0.707107, 0.0], [-0.707107, 0.0]]], ['regression: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['control: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['control: single x on qubit 0 of three', [3, [['x', 0]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 0', [3, [['swap', 2, 1], ['cx', 2, 0], ['z', 2], ['y', 1], ['cx', 0, 2], ['s', 1], ['swap', 1, 0]]], [[0.0, 0.0], [-1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 1', [3, [['cx', 1, 2], ['cz', 2, 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]], [['regression: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['regression: random circuit 5', [2, [['cx', 1, 0], ['cx', 0, 1], ['t', 1], ['h', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.707107, 0.0], [0.0, 0.0]]], ['regression: h on excited qubit', [1, [['x', 0], ['h', 0]]], [[0.707107, 0.0], [-0.707107, 0.0]]], ['control: random circuit 2', [3, [['z', 0], ['sdg', 1], ['cx', 1, 0], ['cz', 0, 1], ['cx', 2, 0], ['y', 0], ['z', 2]]], [[0.0, 0.0], [0.0, 1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 6', [2, [['cz', 0, 1], ['cz', 0, 1], ['z', 1], ['sdg', 0], ['x', 0], ['x', 1], ['cx', 0, 1]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['control: random circuit 13', [2, [['sdg', 0], ['cz', 0, 1], ['swap', 0, 1], ['cx', 1, 0]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]], [['regression: random circuit 9', [1, [['z', 0], ['t', 0], ['z', 0], ['h', 0]]], [[0.707107, 0.0], [0.707107, 0.0]]], ['regression: random circuit 10', [3, [['cz', 0, 1], ['h', 0], ['z', 0], ['cx', 0, 1], ['s', 0], ['sdg', 0]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [-0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['control: random circuit 14', [2, [['z', 0], ['swap', 0, 1], ['x', 1], ['t', 0]]], [[0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0]]], ['control: random circuit 17', [3, [['swap', 2, 0], ['t', 2], ['y', 1], ['sdg', 0], ['y', 1], ['cz', 0, 1], ['z', 2]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 18', [1, [['s', 0]]], [[1.0, 0.0], [0.0, 0.0]]], ['control: random circuit 19', [1, [['sdg', 0], ['y', 0], ['sdg', 0], ['s', 0], ['x', 0], ['z', 0], ['t', 0]]], [[0.0, 1.0], [0.0, 0.0]]]], [['regression: random circuit 12', [3, [['sdg', 2], ['h', 2], ['h', 1], ['s', 0], ['z', 0], ['cx', 0, 1]]], [[0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0]]], ['regression: random circuit 15', [2, [['cx', 1, 0], ['z', 0], ['cz', 1, 0], ['h', 1], ['h', 0], ['y', 1], ['h', 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, -0.707107]]], ['regression: random circuit 8', [1, [['s', 0], ['h', 0], ['s', 0]]], [[0.707107, 0.0], [0.0, 0.707107]]], ['control: random circuit 21', [3, [['cz', 2, 0], ['s', 0], ['cx', 1, 0], ['y', 2], ['sdg', 0], ['sdg', 2], ['cx', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 22', [3, [['z', 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 24', [2, [['s', 1], ['cz', 0, 1], ['cx', 1, 0], ['t', 1], ['cx', 0, 1], ['s', 1], ['t', 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 25', [2, [['y', 1], ['z', 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 1.0], [0.0, 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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import cmath
N = 1
observations = []
def solve(x):
    n, gates = x
    dim = 1 << n
    st = [0j] * dim
    st[0] = 1 + 0j
    r = 1 / math.sqrt(2)
    for g in gates:
        op = g[0]
        if op in ('h', 'x', 'y', 'z', 's', 'sdg', 't'):
            m = 1 << g[1]
            for i in range(dim):
                if i & m:
                    continue
                a, b = st[i], st[i | m]
                if op == 'h':
                    st[i], st[i | m] = (a + b) * 0.5, (a - b) * 0.5
                elif op == 'x':
                    st[i], st[i | m] = b, a
                elif op == 'y':
                    st[i], st[i | m] = -1j * b, 1j * a
                elif op == 'z':
                    st[i | m] = -b
                elif op == 's':
                    st[i | m] = 1j * b
                elif op == 'sdg':
                    st[i | m] = -1j * b
                else:
                    st[i | m] = b * cmath.exp(1j * math.pi / 4)
        elif op == 'cx':
            c, t = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & c and not i & t:
                    st[i], st[i | t] = st[i | t], st[i]
        elif op == 'cz':
            both = (1 << g[1]) | (1 << g[2])
            for i in range(dim):
                if i & both == both:
                    st[i] = -st[i]
        elif op == 'swap':
            a, b = 1 << g[1], 1 << g[2]
            for i in range(dim):
                if i & a and not i & b:
                    j = (i ^ a) | b
                    st[i], st[j] = st[j], 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: bell pair', [2, [['h', 0], ['cx', 0, 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['regression: ghz three qubits', [3, [['h', 0], ['cx', 0, 1], ['cx', 1, 2]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.707107, 0.0]]], ['regression: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['control: empty circuit on two qubits', [2, []], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: cx with control on high qubit', [2, [['x', 1], ['cx', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['control: swap moves excitation', [3, [['x', 0], ['swap', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: y on ground state', [1, [['y', 0]]], [[0.0, 0.0], [0.0, 1.0]]]], [['regression: sdg after h', [2, [['h', 1], ['sdg', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, 0.0]]], ['regression: h on excited qubit', [1, [['x', 0], ['h', 0]]], [[0.707107, 0.0], [-0.707107, 0.0]]], ['regression: t after h', [1, [['h', 0], ['t', 0]]], [[0.707107, 0.0], [0.5, 0.5]]], ['control: y after x', [1, [['x', 0], ['y', 0]]], [[0.0, -1.0], [0.0, 0.0]]], ['control: single x on qubit 0 of three', [3, [['x', 0]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 0', [3, [['swap', 2, 1], ['cx', 2, 0], ['z', 2], ['y', 1], ['cx', 0, 2], ['s', 1], ['swap', 1, 0]]], [[0.0, 0.0], [-1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 1', [3, [['cx', 1, 2], ['cz', 2, 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]], [['regression: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['regression: random circuit 5', [2, [['cx', 1, 0], ['cx', 0, 1], ['t', 1], ['h', 1]]], [[0.707107, 0.0], [0.0, 0.0], [0.707107, 0.0], [0.0, 0.0]]], ['regression: h on excited qubit', [1, [['x', 0], ['h', 0]]], [[0.707107, 0.0], [-0.707107, 0.0]]], ['control: random circuit 2', [3, [['z', 0], ['sdg', 1], ['cx', 1, 0], ['cz', 0, 1], ['cx', 2, 0], ['y', 0], ['z', 2]]], [[0.0, 0.0], [0.0, 1.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 6', [2, [['cz', 0, 1], ['cz', 0, 1], ['z', 1], ['sdg', 0], ['x', 0], ['x', 1], ['cx', 0, 1]]], [[0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 7', [2, [['s', 0], ['cz', 1, 0], ['x', 1], ['cx', 1, 0], ['swap', 1, 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0]]], ['control: random circuit 13', [2, [['sdg', 0], ['cz', 0, 1], ['swap', 0, 1], ['cx', 1, 0]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]], [['regression: random circuit 9', [1, [['z', 0], ['t', 0], ['z', 0], ['h', 0]]], [[0.707107, 0.0], [0.707107, 0.0]]], ['regression: random circuit 10', [3, [['cz', 0, 1], ['h', 0], ['z', 0], ['cx', 0, 1], ['s', 0], ['sdg', 0]]], [[0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [-0.707107, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['regression: random circuit 4', [2, [['cx', 0, 1], ['cz', 0, 1], ['h', 1], ['x', 1], ['y', 0], ['swap', 0, 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.707107], [0.0, 0.707107]]], ['control: random circuit 14', [2, [['z', 0], ['swap', 0, 1], ['x', 1], ['t', 0]]], [[0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0]]], ['control: random circuit 17', [3, [['swap', 2, 0], ['t', 2], ['y', 1], ['sdg', 0], ['y', 1], ['cz', 0, 1], ['z', 2]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 18', [1, [['s', 0]]], [[1.0, 0.0], [0.0, 0.0]]], ['control: random circuit 19', [1, [['sdg', 0], ['y', 0], ['sdg', 0], ['s', 0], ['x', 0], ['z', 0], ['t', 0]]], [[0.0, 1.0], [0.0, 0.0]]]], [['regression: random circuit 12', [3, [['sdg', 2], ['h', 2], ['h', 1], ['s', 0], ['z', 0], ['cx', 0, 1]]], [[0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0], [0.5, 0.0], [0.0, 0.0]]], ['regression: random circuit 15', [2, [['cx', 1, 0], ['z', 0], ['cz', 1, 0], ['h', 1], ['h', 0], ['y', 1], ['h', 1]]], [[0.0, 0.0], [0.0, 0.0], [0.0, -0.707107], [0.0, -0.707107]]], ['regression: random circuit 8', [1, [['s', 0], ['h', 0], ['s', 0]]], [[0.707107, 0.0], [0.0, 0.707107]]], ['control: random circuit 21', [3, [['cz', 2, 0], ['s', 0], ['cx', 1, 0], ['y', 2], ['sdg', 0], ['sdg', 2], ['cx', 0, 2]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 22', [3, [['z', 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 24', [2, [['s', 1], ['cz', 0, 1], ['cx', 1, 0], ['t', 1], ['cx', 0, 1], ['s', 1], ['t', 1]]], [[1.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]], ['control: random circuit 25', [2, [['y', 1], ['z', 0]]], [[0.0, 0.0], [0.0, 0.0], [0.0, 1.0], [0.0, 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)

prompt:
H applied to |1> returns (-|0> + |1>)/sqrt2 rather than (|0> - |1>)/sqrt2, so later interference cancels the wrong outcome.

Input [n, gates]; start in |0...0>, apply gates h,x,y,z,s,sdg,t (["g", q]) and cx,cz,swap (["g", a, b]) with qubit 0 as the least significant bit of the basis index; return the statevector as [re, im] pairs rounded to 6 decimals.

split: open-access


prompt:
Measuring qubits [0, 1] of |01> (qubit 0 excited) is reported as outcome "10" instead of "01".

Input [n, amps, qubits]; amps are 2**n [re, im] pairs (qubit 0 = LSB), possibly unnormalized. Return the marginal outcome distribution over the listed qubits as {bitstring: probability} where the first listed qubit is the rightmost character, probabilities are normalized by the total squared norm, rounded to 6 decimals after summation, and zero entries are omitted. Errors: "bad-length", "duplicate-qubit", "bad-qubit", "zero-state" (total squared norm <= 1e-12).

split: open-access