broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    nq, nc, ops = x
    q = [0] * nq
    c = [0] * nc
    for op in ops:
        name = op[0]
        if name == 'x':
            q[op[1]] ^= 1
        elif name == 'cx':
            if q[op[1]]:
                q[op[2]] ^= 1
        elif name == 'ccx':
            if q[op[1]] or q[op[2]]:
                q[op[3]] ^= 1
        elif name == 'swap':
            a, b = op[1], op[2]
            q[a], q[b] = q[b], q[a]
        elif name == 'measure':
            _, qb, cb = op
            c[cb] = q[qb]
        elif name == 'reset':
            q[op[1]] = 0
        elif name == 'x_if':
            creg = sum(bit << i for i, bit in enumerate(c))
            if creg == op[2]:
                q[op[1]] ^= 1
    return {'qubits': ''.join(str(b) for b in reversed(q)), 'clbits': ''.join(str(b) for b in reversed(c))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: toffoli one control', [3, 3, [['x', 0], ['ccx', 0, 1, 2]]], {'qubits': '001', 'clbits': '000'}], ['regression: random dynamic 10', [3, 3, [['x', 2], ['measure', 2, 2], ['ccx', 2, 1, 0], ['swap', 0, 2], ['cx', 2, 0], ['x', 1], ['ccx', 2, 0, 1], ['cx', 2, 0], ['x', 1]]], {'qubits': '001', 'clbits': '100'}], ['repair check: toffoli no controls', [3, 3, [['ccx', 0, 1, 2]]], {'qubits': '000', 'clbits': '000'}], ['control: feed-forward on register value 2', [2, 2, [['x', 1], ['measure', 1, 1], ['x_if', 0, 2]]], {'qubits': '11', 'clbits': '10'}], ['control: reset excited qubit', [1, 1, [['x', 0], ['reset', 0], ['measure', 0, 0]]], {'qubits': '0', 'clbits': '0'}], ['control: measure into other clbit', [2, 2, [['x', 0], ['measure', 0, 1]]], {'qubits': '01', 'clbits': '10'}], ['control: swap excitation', [2, 2, [['x', 0], ['swap', 0, 1]]], {'qubits': '10', 'clbits': '00'}]], [['regression: random dynamic 41', [3, 3, [['x_if', 2, 4], ['x_if', 2, 3], ['measure', 2, 2], ['x', 1], ['swap', 1, 0], ['ccx', 0, 2, 1]]], {'qubits': '001', 'clbits': '000'}], ['regression: random dynamic 52', [3, 3, [['x', 2], ['ccx', 0, 2, 1], ['cx', 1, 2], ['measure', 1, 2], ['x_if', 2, 3], ['measure', 2, 1], ['x', 2], ['x', 1]]], {'qubits': '010', 'clbits': '010'}], ['repair check: random dynamic 7', [4, 4, [['ccx', 1, 0, 2], ['x_if', 1, 6]]], {'qubits': '0000', 'clbits': '0000'}], ['control: asymmetric output', [3, 3, [['x', 0], ['measure', 0, 0]]], {'qubits': '001', 'clbits': '001'}], ['control: random dynamic 0', [4, 4, [['cx', 2, 1], ['reset', 2], ['x_if', 1, 5], ['x_if', 3, 6], ['reset', 2], ['cx', 3, 1], ['swap', 1, 2], ['x', 0]]], {'qubits': '0001', 'clbits': '0000'}], ['control: random dynamic 1', [2, 2, [['cx', 1, 0], ['x_if', 0, 2], ['x', 1], ['swap', 0, 1], ['reset', 1], ['cx', 1, 0], ['x', 1]]], {'qubits': '11', 'clbits': '00'}], ['control: random dynamic 2', [3, 3, [['cx', 2, 1], ['x', 1], ['measure', 1, 1], ['x', 0], ['x_if', 2, 5], ['reset', 1], ['cx', 2, 0], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '011', 'clbits': '010'}]], [['regression: random dynamic 54', [4, 4, [['x', 0], ['cx', 0, 2], ['measure', 1, 1], ['ccx', 2, 3, 0], ['x_if', 1, 0], ['cx', 3, 0], ['swap', 2, 0], ['x', 0]]], {'qubits': '0110', 'clbits': '0000'}], ['regression: toffoli one control', [3, 3, [['x', 0], ['ccx', 0, 1, 2]]], {'qubits': '001', 'clbits': '000'}], ['repair check: random dynamic 22', [4, 4, [['swap', 3, 1], ['x', 2], ['measure', 1, 2], ['ccx', 0, 1, 2]]], {'qubits': '0100', 'clbits': '0000'}], ['control: random dynamic 4', [2, 2, [['x', 0], ['measure', 1, 1]]], {'qubits': '01', 'clbits': '00'}], ['control: random dynamic 5', [4, 4, [['x_if', 1, 4], ['reset', 1], ['x_if', 1, 10], ['x', 0], ['measure', 2, 1], ['measure', 1, 0]]], {'qubits': '0001', 'clbits': '0000'}], ['control: random dynamic 6', [2, 2, [['reset', 0], ['x', 1], ['swap', 1, 0], ['reset', 0], ['measure', 1, 0], ['x_if', 0, 1], ['cx', 0, 1], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 9', [2, 2, [['cx', 0, 1], ['cx', 0, 1], ['measure', 0, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 0, 1], ['measure', 0, 1], ['measure', 0, 0], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}]], [['regression: random dynamic 23', [4, 4, [['reset', 1], ['x', 3], ['x_if', 3, 0], ['swap', 0, 2], ['x', 0], ['x', 1], ['ccx', 1, 2, 0], ['measure', 2, 2], ['cx', 3, 0]]], {'qubits': '0011', 'clbits': '0000'}], ['regression: random dynamic 41', [3, 3, [['x_if', 2, 4], ['x_if', 2, 3], ['measure', 2, 2], ['x', 1], ['swap', 1, 0], ['ccx', 0, 2, 1]]], {'qubits': '001', 'clbits': '000'}], ['repair check: random dynamic 31', [3, 3, [['measure', 2, 2], ['reset', 2], ['cx', 2, 0], ['ccx', 1, 0, 2], ['measure', 2, 1], ['x', 2]]], {'qubits': '100', 'clbits': '000'}], ['control: random dynamic 11', [3, 3, [['reset', 2], ['x', 2]]], {'qubits': '100', 'clbits': '000'}], ['control: random dynamic 12', [3, 3, [['x', 1], ['x', 2]]], {'qubits': '110', 'clbits': '000'}], ['control: random dynamic 13', [2, 2, [['x_if', 1, 0], ['x', 0], ['swap', 1, 0], ['x', 1], ['cx', 1, 0], ['x_if', 1, 3], ['measure', 1, 1], ['swap', 1, 0], ['x', 1]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 14', [2, 2, [['measure', 1, 0], ['reset', 0], ['measure', 0, 1], ['x_if', 1, 3], ['cx', 1, 0], ['cx', 0, 1], ['x_if', 1, 1], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}]], [['regression: random dynamic 53', [3, 3, [['x', 1], ['reset', 2], ['ccx', 1, 2, 0], ['cx', 1, 2], ['ccx', 2, 1, 0], ['cx', 1, 0], ['x', 2], ['measure', 2, 2]]], {'qubits': '010', 'clbits': '000'}], ['regression: random dynamic 54', [4, 4, [['x', 0], ['cx', 0, 2], ['measure', 1, 1], ['ccx', 2, 3, 0], ['x_if', 1, 0], ['cx', 3, 0], ['swap', 2, 0], ['x', 0]]], {'qubits': '0110', 'clbits': '0000'}], ['repair check: random dynamic 37', [4, 4, [['ccx', 0, 2, 1], ['measure', 3, 2], ['x', 2], ['cx', 1, 0], ['cx', 1, 3], ['x_if', 2, 2]]], {'qubits': '0100', 'clbits': '0000'}], ['control: random dynamic 15', [3, 3, [['cx', 2, 1], ['x_if', 0, 0], ['cx', 2, 1], ['ccx', 0, 1, 2], ['reset', 2], ['reset', 1], ['cx', 0, 1]]], {'qubits': '011', 'clbits': '000'}], ['control: random dynamic 16', [2, 2, [['reset', 0], ['x_if', 0, 1], ['x', 0]]], {'qubits': '01', 'clbits': '00'}], ['control: random dynamic 17', [2, 2, [['reset', 0], ['measure', 0, 0], ['cx', 0, 1], ['x', 1], ['measure', 0, 0]]], {'qubits': '10', 'clbits': '00'}], ['control: random dynamic 18', [2, 2, [['swap', 0, 1], ['x', 0], ['cx', 0, 1], ['cx', 0, 1]]], {'qubits': '01', 'clbits': '00'}]]]
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

N = 1
observations = []
def solve(x):
    nq, nc, ops = x
    q = [0] * nq
    c = [0] * nc
    for op in ops:
        name = op[0]
        if name == 'x':
            q[op[1]] ^= 1
        elif name == 'cx':
            if q[op[1]]:
                q[op[2]] ^= 1
        elif name == 'ccx':
            if q[op[1]] == q[op[2]]:
                q[op[3]] ^= 1
        elif name == 'swap':
            a, b = op[1], op[2]
            q[a], q[b] = q[b], q[a]
        elif name == 'measure':
            _, qb, cb = op
            c[cb] = q[qb]
        elif name == 'reset':
            q[op[1]] = 0
        elif name == 'x_if':
            creg = sum(bit << i for i, bit in enumerate(c))
            if creg == op[2]:
                q[op[1]] ^= 1
    return {'qubits': ''.join(str(b) for b in reversed(q)), 'clbits': ''.join(str(b) for b in reversed(c))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: toffoli one control', [3, 3, [['x', 0], ['ccx', 0, 1, 2]]], {'qubits': '001', 'clbits': '000'}], ['regression: random dynamic 10', [3, 3, [['x', 2], ['measure', 2, 2], ['ccx', 2, 1, 0], ['swap', 0, 2], ['cx', 2, 0], ['x', 1], ['ccx', 2, 0, 1], ['cx', 2, 0], ['x', 1]]], {'qubits': '001', 'clbits': '100'}], ['repair check: toffoli no controls', [3, 3, [['ccx', 0, 1, 2]]], {'qubits': '000', 'clbits': '000'}], ['control: feed-forward on register value 2', [2, 2, [['x', 1], ['measure', 1, 1], ['x_if', 0, 2]]], {'qubits': '11', 'clbits': '10'}], ['control: reset excited qubit', [1, 1, [['x', 0], ['reset', 0], ['measure', 0, 0]]], {'qubits': '0', 'clbits': '0'}], ['control: measure into other clbit', [2, 2, [['x', 0], ['measure', 0, 1]]], {'qubits': '01', 'clbits': '10'}], ['control: swap excitation', [2, 2, [['x', 0], ['swap', 0, 1]]], {'qubits': '10', 'clbits': '00'}]], [['regression: random dynamic 41', [3, 3, [['x_if', 2, 4], ['x_if', 2, 3], ['measure', 2, 2], ['x', 1], ['swap', 1, 0], ['ccx', 0, 2, 1]]], {'qubits': '001', 'clbits': '000'}], ['regression: random dynamic 52', [3, 3, [['x', 2], ['ccx', 0, 2, 1], ['cx', 1, 2], ['measure', 1, 2], ['x_if', 2, 3], ['measure', 2, 1], ['x', 2], ['x', 1]]], {'qubits': '010', 'clbits': '010'}], ['repair check: random dynamic 7', [4, 4, [['ccx', 1, 0, 2], ['x_if', 1, 6]]], {'qubits': '0000', 'clbits': '0000'}], ['control: asymmetric output', [3, 3, [['x', 0], ['measure', 0, 0]]], {'qubits': '001', 'clbits': '001'}], ['control: random dynamic 0', [4, 4, [['cx', 2, 1], ['reset', 2], ['x_if', 1, 5], ['x_if', 3, 6], ['reset', 2], ['cx', 3, 1], ['swap', 1, 2], ['x', 0]]], {'qubits': '0001', 'clbits': '0000'}], ['control: random dynamic 1', [2, 2, [['cx', 1, 0], ['x_if', 0, 2], ['x', 1], ['swap', 0, 1], ['reset', 1], ['cx', 1, 0], ['x', 1]]], {'qubits': '11', 'clbits': '00'}], ['control: random dynamic 2', [3, 3, [['cx', 2, 1], ['x', 1], ['measure', 1, 1], ['x', 0], ['x_if', 2, 5], ['reset', 1], ['cx', 2, 0], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '011', 'clbits': '010'}]], [['regression: random dynamic 54', [4, 4, [['x', 0], ['cx', 0, 2], ['measure', 1, 1], ['ccx', 2, 3, 0], ['x_if', 1, 0], ['cx', 3, 0], ['swap', 2, 0], ['x', 0]]], {'qubits': '0110', 'clbits': '0000'}], ['regression: toffoli one control', [3, 3, [['x', 0], ['ccx', 0, 1, 2]]], {'qubits': '001', 'clbits': '000'}], ['repair check: random dynamic 22', [4, 4, [['swap', 3, 1], ['x', 2], ['measure', 1, 2], ['ccx', 0, 1, 2]]], {'qubits': '0100', 'clbits': '0000'}], ['control: random dynamic 4', [2, 2, [['x', 0], ['measure', 1, 1]]], {'qubits': '01', 'clbits': '00'}], ['control: random dynamic 5', [4, 4, [['x_if', 1, 4], ['reset', 1], ['x_if', 1, 10], ['x', 0], ['measure', 2, 1], ['measure', 1, 0]]], {'qubits': '0001', 'clbits': '0000'}], ['control: random dynamic 6', [2, 2, [['reset', 0], ['x', 1], ['swap', 1, 0], ['reset', 0], ['measure', 1, 0], ['x_if', 0, 1], ['cx', 0, 1], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 9', [2, 2, [['cx', 0, 1], ['cx', 0, 1], ['measure', 0, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 0, 1], ['measure', 0, 1], ['measure', 0, 0], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}]], [['regression: random dynamic 23', [4, 4, [['reset', 1], ['x', 3], ['x_if', 3, 0], ['swap', 0, 2], ['x', 0], ['x', 1], ['ccx', 1, 2, 0], ['measure', 2, 2], ['cx', 3, 0]]], {'qubits': '0011', 'clbits': '0000'}], ['regression: random dynamic 41', [3, 3, [['x_if', 2, 4], ['x_if', 2, 3], ['measure', 2, 2], ['x', 1], ['swap', 1, 0], ['ccx', 0, 2, 1]]], {'qubits': '001', 'clbits': '000'}], ['repair check: random dynamic 31', [3, 3, [['measure', 2, 2], ['reset', 2], ['cx', 2, 0], ['ccx', 1, 0, 2], ['measure', 2, 1], ['x', 2]]], {'qubits': '100', 'clbits': '000'}], ['control: random dynamic 11', [3, 3, [['reset', 2], ['x', 2]]], {'qubits': '100', 'clbits': '000'}], ['control: random dynamic 12', [3, 3, [['x', 1], ['x', 2]]], {'qubits': '110', 'clbits': '000'}], ['control: random dynamic 13', [2, 2, [['x_if', 1, 0], ['x', 0], ['swap', 1, 0], ['x', 1], ['cx', 1, 0], ['x_if', 1, 3], ['measure', 1, 1], ['swap', 1, 0], ['x', 1]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 14', [2, 2, [['measure', 1, 0], ['reset', 0], ['measure', 0, 1], ['x_if', 1, 3], ['cx', 1, 0], ['cx', 0, 1], ['x_if', 1, 1], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}]], [['regression: random dynamic 53', [3, 3, [['x', 1], ['reset', 2], ['ccx', 1, 2, 0], ['cx', 1, 2], ['ccx', 2, 1, 0], ['cx', 1, 0], ['x', 2], ['measure', 2, 2]]], {'qubits': '010', 'clbits': '000'}], ['regression: random dynamic 54', [4, 4, [['x', 0], ['cx', 0, 2], ['measure', 1, 1], ['ccx', 2, 3, 0], ['x_if', 1, 0], ['cx', 3, 0], ['swap', 2, 0], ['x', 0]]], {'qubits': '0110', 'clbits': '0000'}], ['repair check: random dynamic 37', [4, 4, [['ccx', 0, 2, 1], ['measure', 3, 2], ['x', 2], ['cx', 1, 0], ['cx', 1, 3], ['x_if', 2, 2]]], {'qubits': '0100', 'clbits': '0000'}], ['control: random dynamic 15', [3, 3, [['cx', 2, 1], ['x_if', 0, 0], ['cx', 2, 1], ['ccx', 0, 1, 2], ['reset', 2], ['reset', 1], ['cx', 0, 1]]], {'qubits': '011', 'clbits': '000'}], ['control: random dynamic 16', [2, 2, [['reset', 0], ['x_if', 0, 1], ['x', 0]]], {'qubits': '01', 'clbits': '00'}], ['control: random dynamic 17', [2, 2, [['reset', 0], ['measure', 0, 0], ['cx', 0, 1], ['x', 1], ['measure', 0, 0]]], {'qubits': '10', 'clbits': '00'}], ['control: random dynamic 18', [2, 2, [['swap', 0, 1], ['x', 0], ['cx', 0, 1], ['cx', 0, 1]]], {'qubits': '01', 'clbits': '00'}]]]
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:
ccx with only its first control set flips the target.

Input [nq, nc, ops] on computational basis states only: ["x", q], ["cx", c, t], ["ccx", a, b, t], ["swap", a, b], ["measure", q, c], ["reset", q], ["x_if", q, value] (flip q when the classical register value, clbit 0 = LSB, equals value). Return {"qubits": bits with qubit nq-1 leftmost, "clbits": bits with clbit nc-1 leftmost}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    nq, nc, ops = x
    q = [0] * nq
    c = [0] * nc
    for op in ops:
        name = op[0]
        if name == 'x':
            q[op[1]] ^= 1
        elif name == 'cx':
            if q[op[1]]:
                q[op[2]] ^= 1
        elif name == 'ccx':
            if q[op[1]] and q[op[2]]:
                q[op[3]] ^= 1
        elif name == 'swap':
            a, b = op[1], op[2]
            q[a], q[b] = q[b], q[a]
        elif name == 'measure':
            _, cb, qb = op
            c[cb] = q[qb]
        elif name == 'reset':
            q[op[1]] = 0
        elif name == 'x_if':
            creg = sum(bit << i for i, bit in enumerate(c))
            if creg == op[2]:
                q[op[1]] ^= 1
    return {'qubits': ''.join(str(b) for b in reversed(q)), 'clbits': ''.join(str(b) for b in reversed(c))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: measure into other clbit', [2, 2, [['x', 0], ['measure', 0, 1]]], {'qubits': '01', 'clbits': '10'}], ['regression: random dynamic 5', [4, 4, [['x_if', 1, 4], ['reset', 1], ['x_if', 1, 10], ['x', 0], ['measure', 2, 1], ['measure', 1, 0]]], {'qubits': '0001', 'clbits': '0000'}], ['regression: random dynamic 38', [2, 2, [['x_if', 0, 1], ['measure', 1, 0], ['x_if', 1, 0], ['cx', 1, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '10'}], ['control: feed-forward on register value 2', [2, 2, [['x', 1], ['measure', 1, 1], ['x_if', 0, 2]]], {'qubits': '11', 'clbits': '10'}], ['control: reset excited qubit', [1, 1, [['x', 0], ['reset', 0], ['measure', 0, 0]]], {'qubits': '0', 'clbits': '0'}], ['control: toffoli one control', [3, 3, [['x', 0], ['ccx', 0, 1, 2]]], {'qubits': '001', 'clbits': '000'}], ['control: toffoli no controls', [3, 3, [['ccx', 0, 1, 2]]], {'qubits': '000', 'clbits': '000'}]], [['regression: random dynamic 24', [2, 2, [['measure', 1, 0], ['swap', 1, 0], ['x', 0], ['cx', 0, 1], ['x_if', 0, 0], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '01', 'clbits': '00'}], ['regression: random dynamic 38', [2, 2, [['x_if', 0, 1], ['measure', 1, 0], ['x_if', 1, 0], ['cx', 1, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '10'}], ['regression: random dynamic 43', [3, 3, [['x', 1], ['swap', 1, 2], ['x_if', 2, 6], ['measure', 2, 0], ['measure', 2, 0], ['x', 2]]], {'qubits': '000', 'clbits': '001'}], ['control: swap excitation', [2, 2, [['x', 0], ['swap', 0, 1]]], {'qubits': '10', 'clbits': '00'}], ['control: asymmetric output', [3, 3, [['x', 0], ['measure', 0, 0]]], {'qubits': '001', 'clbits': '001'}], ['control: random dynamic 0', [4, 4, [['cx', 2, 1], ['reset', 2], ['x_if', 1, 5], ['x_if', 3, 6], ['reset', 2], ['cx', 3, 1], ['swap', 1, 2], ['x', 0]]], {'qubits': '0001', 'clbits': '0000'}], ['control: random dynamic 1', [2, 2, [['cx', 1, 0], ['x_if', 0, 2], ['x', 1], ['swap', 0, 1], ['reset', 1], ['cx', 1, 0], ['x', 1]]], {'qubits': '11', 'clbits': '00'}]], [['regression: random dynamic 59', [3, 3, [['cx', 2, 1], ['x', 1], ['measure', 1, 0], ['x_if', 0, 1], ['reset', 2]]], {'qubits': '011', 'clbits': '001'}], ['regression: measure into other clbit', [2, 2, [['x', 0], ['measure', 0, 1]]], {'qubits': '01', 'clbits': '10'}], ['regression: random dynamic 38', [2, 2, [['x_if', 0, 1], ['measure', 1, 0], ['x_if', 1, 0], ['cx', 1, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '10'}], ['control: random dynamic 2', [3, 3, [['cx', 2, 1], ['x', 1], ['measure', 1, 1], ['x', 0], ['x_if', 2, 5], ['reset', 1], ['cx', 2, 0], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '011', 'clbits': '010'}], ['control: random dynamic 3', [4, 4, [['ccx', 3, 0, 2], ['x_if', 1, 8], ['x_if', 1, 10], ['measure', 0, 3], ['reset', 0], ['measure', 0, 1]]], {'qubits': '0000', 'clbits': '0000'}], ['control: random dynamic 4', [2, 2, [['x', 0], ['measure', 1, 1]]], {'qubits': '01', 'clbits': '00'}], ['control: random dynamic 6', [2, 2, [['reset', 0], ['x', 1], ['swap', 1, 0], ['reset', 0], ['measure', 1, 0], ['x_if', 0, 1], ['cx', 0, 1], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '00', 'clbits': '00'}]], [['regression: random dynamic 22', [4, 4, [['swap', 3, 1], ['x', 2], ['measure', 1, 2], ['ccx', 0, 1, 2]]], {'qubits': '0100', 'clbits': '0000'}], ['regression: random dynamic 24', [2, 2, [['measure', 1, 0], ['swap', 1, 0], ['x', 0], ['cx', 0, 1], ['x_if', 0, 0], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '01', 'clbits': '00'}], ['regression: random dynamic 38', [2, 2, [['x_if', 0, 1], ['measure', 1, 0], ['x_if', 1, 0], ['cx', 1, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '10'}], ['control: random dynamic 7', [4, 4, [['ccx', 1, 0, 2], ['x_if', 1, 6]]], {'qubits': '0000', 'clbits': '0000'}], ['control: random dynamic 8', [3, 3, [['reset', 2], ['x', 1], ['ccx', 0, 2, 1], ['measure', 1, 1], ['reset', 2]]], {'qubits': '010', 'clbits': '010'}], ['control: random dynamic 9', [2, 2, [['cx', 0, 1], ['cx', 0, 1], ['measure', 0, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 0, 1], ['measure', 0, 1], ['measure', 0, 0], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 10', [3, 3, [['x', 2], ['measure', 2, 2], ['ccx', 2, 1, 0], ['swap', 0, 2], ['cx', 2, 0], ['x', 1], ['ccx', 2, 0, 1], ['cx', 2, 0], ['x', 1]]], {'qubits': '001', 'clbits': '100'}]], [['regression: random dynamic 43', [3, 3, [['x', 1], ['swap', 1, 2], ['x_if', 2, 6], ['measure', 2, 0], ['measure', 2, 0], ['x', 2]]], {'qubits': '000', 'clbits': '001'}], ['regression: random dynamic 59', [3, 3, [['cx', 2, 1], ['x', 1], ['measure', 1, 0], ['x_if', 0, 1], ['reset', 2]]], {'qubits': '011', 'clbits': '001'}], ['repair check: random dynamic 52', [3, 3, [['x', 2], ['ccx', 0, 2, 1], ['cx', 1, 2], ['measure', 1, 2], ['x_if', 2, 3], ['measure', 2, 1], ['x', 2], ['x', 1]]], {'qubits': '010', 'clbits': '010'}], ['control: random dynamic 11', [3, 3, [['reset', 2], ['x', 2]]], {'qubits': '100', 'clbits': '000'}], ['control: random dynamic 12', [3, 3, [['x', 1], ['x', 2]]], {'qubits': '110', 'clbits': '000'}], ['control: random dynamic 13', [2, 2, [['x_if', 1, 0], ['x', 0], ['swap', 1, 0], ['x', 1], ['cx', 1, 0], ['x_if', 1, 3], ['measure', 1, 1], ['swap', 1, 0], ['x', 1]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 14', [2, 2, [['measure', 1, 0], ['reset', 0], ['measure', 0, 1], ['x_if', 1, 3], ['cx', 1, 0], ['cx', 0, 1], ['x_if', 1, 1], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}]]]
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

N = 1
observations = []
def solve(x):
    nq, nc, ops = x
    q = [0] * nq
    c = [0] * nc
    for op in ops:
        name = op[0]
        if name == 'x':
            q[op[1]] ^= 1
        elif name == 'cx':
            if q[op[1]]:
                q[op[2]] ^= 1
        elif name == 'ccx':
            if q[op[1]] and q[op[2]]:
                q[op[3]] ^= 1
        elif name == 'swap':
            a, b = op[1], op[2]
            q[a], q[b] = q[b], q[a]
        elif name == 'measure':
            _, qb, cb = op
            c[qb] = q[qb]
        elif name == 'reset':
            q[op[1]] = 0
        elif name == 'x_if':
            creg = sum(bit << i for i, bit in enumerate(c))
            if creg == op[2]:
                q[op[1]] ^= 1
    return {'qubits': ''.join(str(b) for b in reversed(q)), 'clbits': ''.join(str(b) for b in reversed(c))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: measure into other clbit', [2, 2, [['x', 0], ['measure', 0, 1]]], {'qubits': '01', 'clbits': '10'}], ['regression: random dynamic 5', [4, 4, [['x_if', 1, 4], ['reset', 1], ['x_if', 1, 10], ['x', 0], ['measure', 2, 1], ['measure', 1, 0]]], {'qubits': '0001', 'clbits': '0000'}], ['regression: random dynamic 38', [2, 2, [['x_if', 0, 1], ['measure', 1, 0], ['x_if', 1, 0], ['cx', 1, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '10'}], ['control: feed-forward on register value 2', [2, 2, [['x', 1], ['measure', 1, 1], ['x_if', 0, 2]]], {'qubits': '11', 'clbits': '10'}], ['control: reset excited qubit', [1, 1, [['x', 0], ['reset', 0], ['measure', 0, 0]]], {'qubits': '0', 'clbits': '0'}], ['control: toffoli one control', [3, 3, [['x', 0], ['ccx', 0, 1, 2]]], {'qubits': '001', 'clbits': '000'}], ['control: toffoli no controls', [3, 3, [['ccx', 0, 1, 2]]], {'qubits': '000', 'clbits': '000'}]], [['regression: random dynamic 24', [2, 2, [['measure', 1, 0], ['swap', 1, 0], ['x', 0], ['cx', 0, 1], ['x_if', 0, 0], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '01', 'clbits': '00'}], ['regression: random dynamic 38', [2, 2, [['x_if', 0, 1], ['measure', 1, 0], ['x_if', 1, 0], ['cx', 1, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '10'}], ['regression: random dynamic 43', [3, 3, [['x', 1], ['swap', 1, 2], ['x_if', 2, 6], ['measure', 2, 0], ['measure', 2, 0], ['x', 2]]], {'qubits': '000', 'clbits': '001'}], ['control: swap excitation', [2, 2, [['x', 0], ['swap', 0, 1]]], {'qubits': '10', 'clbits': '00'}], ['control: asymmetric output', [3, 3, [['x', 0], ['measure', 0, 0]]], {'qubits': '001', 'clbits': '001'}], ['control: random dynamic 0', [4, 4, [['cx', 2, 1], ['reset', 2], ['x_if', 1, 5], ['x_if', 3, 6], ['reset', 2], ['cx', 3, 1], ['swap', 1, 2], ['x', 0]]], {'qubits': '0001', 'clbits': '0000'}], ['control: random dynamic 1', [2, 2, [['cx', 1, 0], ['x_if', 0, 2], ['x', 1], ['swap', 0, 1], ['reset', 1], ['cx', 1, 0], ['x', 1]]], {'qubits': '11', 'clbits': '00'}]], [['regression: random dynamic 59', [3, 3, [['cx', 2, 1], ['x', 1], ['measure', 1, 0], ['x_if', 0, 1], ['reset', 2]]], {'qubits': '011', 'clbits': '001'}], ['regression: measure into other clbit', [2, 2, [['x', 0], ['measure', 0, 1]]], {'qubits': '01', 'clbits': '10'}], ['regression: random dynamic 38', [2, 2, [['x_if', 0, 1], ['measure', 1, 0], ['x_if', 1, 0], ['cx', 1, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '10'}], ['control: random dynamic 2', [3, 3, [['cx', 2, 1], ['x', 1], ['measure', 1, 1], ['x', 0], ['x_if', 2, 5], ['reset', 1], ['cx', 2, 0], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '011', 'clbits': '010'}], ['control: random dynamic 3', [4, 4, [['ccx', 3, 0, 2], ['x_if', 1, 8], ['x_if', 1, 10], ['measure', 0, 3], ['reset', 0], ['measure', 0, 1]]], {'qubits': '0000', 'clbits': '0000'}], ['control: random dynamic 4', [2, 2, [['x', 0], ['measure', 1, 1]]], {'qubits': '01', 'clbits': '00'}], ['control: random dynamic 6', [2, 2, [['reset', 0], ['x', 1], ['swap', 1, 0], ['reset', 0], ['measure', 1, 0], ['x_if', 0, 1], ['cx', 0, 1], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '00', 'clbits': '00'}]], [['regression: random dynamic 22', [4, 4, [['swap', 3, 1], ['x', 2], ['measure', 1, 2], ['ccx', 0, 1, 2]]], {'qubits': '0100', 'clbits': '0000'}], ['regression: random dynamic 24', [2, 2, [['measure', 1, 0], ['swap', 1, 0], ['x', 0], ['cx', 0, 1], ['x_if', 0, 0], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '01', 'clbits': '00'}], ['regression: random dynamic 38', [2, 2, [['x_if', 0, 1], ['measure', 1, 0], ['x_if', 1, 0], ['cx', 1, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '10'}], ['control: random dynamic 7', [4, 4, [['ccx', 1, 0, 2], ['x_if', 1, 6]]], {'qubits': '0000', 'clbits': '0000'}], ['control: random dynamic 8', [3, 3, [['reset', 2], ['x', 1], ['ccx', 0, 2, 1], ['measure', 1, 1], ['reset', 2]]], {'qubits': '010', 'clbits': '010'}], ['control: random dynamic 9', [2, 2, [['cx', 0, 1], ['cx', 0, 1], ['measure', 0, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 0, 1], ['measure', 0, 1], ['measure', 0, 0], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 10', [3, 3, [['x', 2], ['measure', 2, 2], ['ccx', 2, 1, 0], ['swap', 0, 2], ['cx', 2, 0], ['x', 1], ['ccx', 2, 0, 1], ['cx', 2, 0], ['x', 1]]], {'qubits': '001', 'clbits': '100'}]], [['regression: random dynamic 43', [3, 3, [['x', 1], ['swap', 1, 2], ['x_if', 2, 6], ['measure', 2, 0], ['measure', 2, 0], ['x', 2]]], {'qubits': '000', 'clbits': '001'}], ['regression: random dynamic 59', [3, 3, [['cx', 2, 1], ['x', 1], ['measure', 1, 0], ['x_if', 0, 1], ['reset', 2]]], {'qubits': '011', 'clbits': '001'}], ['repair check: random dynamic 52', [3, 3, [['x', 2], ['ccx', 0, 2, 1], ['cx', 1, 2], ['measure', 1, 2], ['x_if', 2, 3], ['measure', 2, 1], ['x', 2], ['x', 1]]], {'qubits': '010', 'clbits': '010'}], ['control: random dynamic 11', [3, 3, [['reset', 2], ['x', 2]]], {'qubits': '100', 'clbits': '000'}], ['control: random dynamic 12', [3, 3, [['x', 1], ['x', 2]]], {'qubits': '110', 'clbits': '000'}], ['control: random dynamic 13', [2, 2, [['x_if', 1, 0], ['x', 0], ['swap', 1, 0], ['x', 1], ['cx', 1, 0], ['x_if', 1, 3], ['measure', 1, 1], ['swap', 1, 0], ['x', 1]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 14', [2, 2, [['measure', 1, 0], ['reset', 0], ['measure', 0, 1], ['x_if', 1, 3], ['cx', 1, 0], ['cx', 0, 1], ['x_if', 1, 1], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}]]]
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:
measure 0 -> c1 copies qubit 1 into clbit 0.

Input [nq, nc, ops] on computational basis states only: ["x", q], ["cx", c, t], ["ccx", a, b, t], ["swap", a, b], ["measure", q, c], ["reset", q], ["x_if", q, value] (flip q when the classical register value, clbit 0 = LSB, equals value). Return {"qubits": bits with qubit nq-1 leftmost, "clbits": bits with clbit nc-1 leftmost}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    nq, nc, ops = x
    q = [0] * nq
    c = [0] * nc
    for op in ops:
        name = op[0]
        if name == 'x':
            q[op[1]] ^= 1
        elif name == 'cx':
            if q[op[1]]:
                q[op[2]] ^= 1
        elif name == 'ccx':
            if q[op[1]] and q[op[2]]:
                q[op[3]] ^= 1
        elif name == 'swap':
            a, b = op[1], op[2]
            q[a], q[b] = q[b], q[a]
        elif name == 'measure':
            _, qb, cb = op
            c[cb] = q[qb]
        elif name == 'reset':
            q[op[1]] = 0
        elif name == 'x_if':
            creg = sum(bit << i for i, bit in enumerate(c))
            if creg == op[2]:
                q[op[1]] ^= 1
    return {'qubits': ''.join(str(b) for b in q), 'clbits': ''.join(str(b) for b in c)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: feed-forward on register value 2', [2, 2, [['x', 1], ['measure', 1, 1], ['x_if', 0, 2]]], {'qubits': '11', 'clbits': '10'}], ['regression: toffoli one control', [3, 3, [['x', 0], ['ccx', 0, 1, 2]]], {'qubits': '001', 'clbits': '000'}], ['regression: measure into other clbit', [2, 2, [['x', 0], ['measure', 0, 1]]], {'qubits': '01', 'clbits': '10'}], ['control: reset excited qubit', [1, 1, [['x', 0], ['reset', 0], ['measure', 0, 0]]], {'qubits': '0', 'clbits': '0'}], ['control: toffoli no controls', [3, 3, [['ccx', 0, 1, 2]]], {'qubits': '000', 'clbits': '000'}], ['control: random dynamic 1', [2, 2, [['cx', 1, 0], ['x_if', 0, 2], ['x', 1], ['swap', 0, 1], ['reset', 1], ['cx', 1, 0], ['x', 1]]], {'qubits': '11', 'clbits': '00'}], ['control: random dynamic 3', [4, 4, [['ccx', 3, 0, 2], ['x_if', 1, 8], ['x_if', 1, 10], ['measure', 0, 3], ['reset', 0], ['measure', 0, 1]]], {'qubits': '0000', 'clbits': '0000'}]], [['regression: swap excitation', [2, 2, [['x', 0], ['swap', 0, 1]]], {'qubits': '10', 'clbits': '00'}], ['regression: asymmetric output', [3, 3, [['x', 0], ['measure', 0, 0]]], {'qubits': '001', 'clbits': '001'}], ['regression: random dynamic 10', [3, 3, [['x', 2], ['measure', 2, 2], ['ccx', 2, 1, 0], ['swap', 0, 2], ['cx', 2, 0], ['x', 1], ['ccx', 2, 0, 1], ['cx', 2, 0], ['x', 1]]], {'qubits': '001', 'clbits': '100'}], ['control: random dynamic 6', [2, 2, [['reset', 0], ['x', 1], ['swap', 1, 0], ['reset', 0], ['measure', 1, 0], ['x_if', 0, 1], ['cx', 0, 1], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 7', [4, 4, [['ccx', 1, 0, 2], ['x_if', 1, 6]]], {'qubits': '0000', 'clbits': '0000'}], ['control: random dynamic 8', [3, 3, [['reset', 2], ['x', 1], ['ccx', 0, 2, 1], ['measure', 1, 1], ['reset', 2]]], {'qubits': '010', 'clbits': '010'}], ['control: random dynamic 9', [2, 2, [['cx', 0, 1], ['cx', 0, 1], ['measure', 0, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 0, 1], ['measure', 0, 1], ['measure', 0, 0], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}]], [['regression: random dynamic 2', [3, 3, [['cx', 2, 1], ['x', 1], ['measure', 1, 1], ['x', 0], ['x_if', 2, 5], ['reset', 1], ['cx', 2, 0], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '011', 'clbits': '010'}], ['regression: random dynamic 4', [2, 2, [['x', 0], ['measure', 1, 1]]], {'qubits': '01', 'clbits': '00'}], ['regression: random dynamic 38', [2, 2, [['x_if', 0, 1], ['measure', 1, 0], ['x_if', 1, 0], ['cx', 1, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '10'}], ['control: random dynamic 13', [2, 2, [['x_if', 1, 0], ['x', 0], ['swap', 1, 0], ['x', 1], ['cx', 1, 0], ['x_if', 1, 3], ['measure', 1, 1], ['swap', 1, 0], ['x', 1]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 14', [2, 2, [['measure', 1, 0], ['reset', 0], ['measure', 0, 1], ['x_if', 1, 3], ['cx', 1, 0], ['cx', 0, 1], ['x_if', 1, 1], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 20', [2, 2, [['cx', 1, 0], ['x', 0], ['x_if', 0, 0], ['cx', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 21', [4, 4, [['swap', 1, 2], ['measure', 3, 0], ['x_if', 0, 10], ['swap', 0, 2], ['x_if', 2, 9], ['cx', 0, 2], ['x_if', 0, 15], ['cx', 0, 3]]], {'qubits': '0000', 'clbits': '0000'}]], [['regression: random dynamic 10', [3, 3, [['x', 2], ['measure', 2, 2], ['ccx', 2, 1, 0], ['swap', 0, 2], ['cx', 2, 0], ['x', 1], ['ccx', 2, 0, 1], ['cx', 2, 0], ['x', 1]]], {'qubits': '001', 'clbits': '100'}], ['regression: random dynamic 11', [3, 3, [['reset', 2], ['x', 2]]], {'qubits': '100', 'clbits': '000'}], ['regression: random dynamic 46', [2, 2, [['swap', 0, 1], ['swap', 0, 1], ['reset', 0], ['x', 0], ['x_if', 1, 0], ['x', 0], ['measure', 1, 1], ['cx', 1, 0], ['x', 0]]], {'qubits': '10', 'clbits': '10'}], ['control: random dynamic 25', [2, 2, [['cx', 0, 1], ['measure', 0, 1], ['x_if', 0, 1], ['swap', 0, 1], ['x_if', 0, 2], ['swap', 0, 1], ['measure', 0, 1]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 26', [4, 4, [['x_if', 3, 15], ['cx', 1, 0], ['measure', 0, 2]]], {'qubits': '0000', 'clbits': '0000'}], ['control: random dynamic 27', [2, 2, [['swap', 0, 1], ['measure', 0, 1], ['x_if', 0, 0], ['x_if', 1, 1], ['x', 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 0, 1]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 28', [3, 3, [['ccx', 2, 1, 0], ['x', 0], ['cx', 1, 0], ['x', 2]]], {'qubits': '101', 'clbits': '000'}]], [['regression: random dynamic 15', [3, 3, [['cx', 2, 1], ['x_if', 0, 0], ['cx', 2, 1], ['ccx', 0, 1, 2], ['reset', 2], ['reset', 1], ['cx', 0, 1]]], {'qubits': '011', 'clbits': '000'}], ['regression: random dynamic 16', [2, 2, [['reset', 0], ['x_if', 0, 1], ['x', 0]]], {'qubits': '01', 'clbits': '00'}], ['regression: feed-forward on register value 2', [2, 2, [['x', 1], ['measure', 1, 1], ['x_if', 0, 2]]], {'qubits': '11', 'clbits': '10'}], ['control: random dynamic 29', [2, 2, [['measure', 0, 0], ['swap', 1, 0], ['swap', 0, 1], ['reset', 0], ['swap', 1, 0], ['cx', 0, 1]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 30', [4, 4, [['x_if', 3, 8], ['cx', 1, 2]]], {'qubits': '0000', 'clbits': '0000'}], ['control: random dynamic 33', [4, 4, [['x', 0], ['x_if', 1, 8], ['reset', 1], ['x', 2], ['x', 1], ['swap', 3, 2], ['x', 2]]], {'qubits': '1111', 'clbits': '0000'}], ['control: random dynamic 36', [4, 4, [['swap', 2, 3], ['reset', 1], ['cx', 2, 3], ['ccx', 0, 2, 1]]], {'qubits': '0000', 'clbits': '0000'}]]]
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

N = 1
observations = []
def solve(x):
    nq, nc, ops = x
    q = [0] * nq
    c = [0] * nc
    for op in ops:
        name = op[0]
        if name == 'x':
            q[op[1]] ^= 1
        elif name == 'cx':
            if q[op[1]]:
                q[op[2]] ^= 1
        elif name == 'ccx':
            if q[op[1]] and q[op[2]]:
                q[op[3]] ^= 1
        elif name == 'swap':
            a, b = op[1], op[2]
            q[a], q[b] = q[b], q[a]
        elif name == 'measure':
            _, qb, cb = op
            c[cb] = q[qb]
        elif name == 'reset':
            q[op[1]] = 0
        elif name == 'x_if':
            creg = sum(bit << i for i, bit in enumerate(c))
            if creg == op[2]:
                q[op[1]] ^= 1
    return {'qubits': ''.join(str(b) for b in reversed(q)), 'clbits': ''.join(str(b) for b in c)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: feed-forward on register value 2', [2, 2, [['x', 1], ['measure', 1, 1], ['x_if', 0, 2]]], {'qubits': '11', 'clbits': '10'}], ['regression: toffoli one control', [3, 3, [['x', 0], ['ccx', 0, 1, 2]]], {'qubits': '001', 'clbits': '000'}], ['regression: measure into other clbit', [2, 2, [['x', 0], ['measure', 0, 1]]], {'qubits': '01', 'clbits': '10'}], ['control: reset excited qubit', [1, 1, [['x', 0], ['reset', 0], ['measure', 0, 0]]], {'qubits': '0', 'clbits': '0'}], ['control: toffoli no controls', [3, 3, [['ccx', 0, 1, 2]]], {'qubits': '000', 'clbits': '000'}], ['control: random dynamic 1', [2, 2, [['cx', 1, 0], ['x_if', 0, 2], ['x', 1], ['swap', 0, 1], ['reset', 1], ['cx', 1, 0], ['x', 1]]], {'qubits': '11', 'clbits': '00'}], ['control: random dynamic 3', [4, 4, [['ccx', 3, 0, 2], ['x_if', 1, 8], ['x_if', 1, 10], ['measure', 0, 3], ['reset', 0], ['measure', 0, 1]]], {'qubits': '0000', 'clbits': '0000'}]], [['regression: swap excitation', [2, 2, [['x', 0], ['swap', 0, 1]]], {'qubits': '10', 'clbits': '00'}], ['regression: asymmetric output', [3, 3, [['x', 0], ['measure', 0, 0]]], {'qubits': '001', 'clbits': '001'}], ['regression: random dynamic 10', [3, 3, [['x', 2], ['measure', 2, 2], ['ccx', 2, 1, 0], ['swap', 0, 2], ['cx', 2, 0], ['x', 1], ['ccx', 2, 0, 1], ['cx', 2, 0], ['x', 1]]], {'qubits': '001', 'clbits': '100'}], ['control: random dynamic 6', [2, 2, [['reset', 0], ['x', 1], ['swap', 1, 0], ['reset', 0], ['measure', 1, 0], ['x_if', 0, 1], ['cx', 0, 1], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 7', [4, 4, [['ccx', 1, 0, 2], ['x_if', 1, 6]]], {'qubits': '0000', 'clbits': '0000'}], ['control: random dynamic 8', [3, 3, [['reset', 2], ['x', 1], ['ccx', 0, 2, 1], ['measure', 1, 1], ['reset', 2]]], {'qubits': '010', 'clbits': '010'}], ['control: random dynamic 9', [2, 2, [['cx', 0, 1], ['cx', 0, 1], ['measure', 0, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 0, 1], ['measure', 0, 1], ['measure', 0, 0], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}]], [['regression: random dynamic 2', [3, 3, [['cx', 2, 1], ['x', 1], ['measure', 1, 1], ['x', 0], ['x_if', 2, 5], ['reset', 1], ['cx', 2, 0], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '011', 'clbits': '010'}], ['regression: random dynamic 4', [2, 2, [['x', 0], ['measure', 1, 1]]], {'qubits': '01', 'clbits': '00'}], ['regression: random dynamic 38', [2, 2, [['x_if', 0, 1], ['measure', 1, 0], ['x_if', 1, 0], ['cx', 1, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '10'}], ['control: random dynamic 13', [2, 2, [['x_if', 1, 0], ['x', 0], ['swap', 1, 0], ['x', 1], ['cx', 1, 0], ['x_if', 1, 3], ['measure', 1, 1], ['swap', 1, 0], ['x', 1]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 14', [2, 2, [['measure', 1, 0], ['reset', 0], ['measure', 0, 1], ['x_if', 1, 3], ['cx', 1, 0], ['cx', 0, 1], ['x_if', 1, 1], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 20', [2, 2, [['cx', 1, 0], ['x', 0], ['x_if', 0, 0], ['cx', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 21', [4, 4, [['swap', 1, 2], ['measure', 3, 0], ['x_if', 0, 10], ['swap', 0, 2], ['x_if', 2, 9], ['cx', 0, 2], ['x_if', 0, 15], ['cx', 0, 3]]], {'qubits': '0000', 'clbits': '0000'}]], [['regression: random dynamic 10', [3, 3, [['x', 2], ['measure', 2, 2], ['ccx', 2, 1, 0], ['swap', 0, 2], ['cx', 2, 0], ['x', 1], ['ccx', 2, 0, 1], ['cx', 2, 0], ['x', 1]]], {'qubits': '001', 'clbits': '100'}], ['regression: random dynamic 11', [3, 3, [['reset', 2], ['x', 2]]], {'qubits': '100', 'clbits': '000'}], ['regression: random dynamic 46', [2, 2, [['swap', 0, 1], ['swap', 0, 1], ['reset', 0], ['x', 0], ['x_if', 1, 0], ['x', 0], ['measure', 1, 1], ['cx', 1, 0], ['x', 0]]], {'qubits': '10', 'clbits': '10'}], ['control: random dynamic 25', [2, 2, [['cx', 0, 1], ['measure', 0, 1], ['x_if', 0, 1], ['swap', 0, 1], ['x_if', 0, 2], ['swap', 0, 1], ['measure', 0, 1]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 26', [4, 4, [['x_if', 3, 15], ['cx', 1, 0], ['measure', 0, 2]]], {'qubits': '0000', 'clbits': '0000'}], ['control: random dynamic 27', [2, 2, [['swap', 0, 1], ['measure', 0, 1], ['x_if', 0, 0], ['x_if', 1, 1], ['x', 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 0, 1]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 28', [3, 3, [['ccx', 2, 1, 0], ['x', 0], ['cx', 1, 0], ['x', 2]]], {'qubits': '101', 'clbits': '000'}]], [['regression: random dynamic 15', [3, 3, [['cx', 2, 1], ['x_if', 0, 0], ['cx', 2, 1], ['ccx', 0, 1, 2], ['reset', 2], ['reset', 1], ['cx', 0, 1]]], {'qubits': '011', 'clbits': '000'}], ['regression: random dynamic 16', [2, 2, [['reset', 0], ['x_if', 0, 1], ['x', 0]]], {'qubits': '01', 'clbits': '00'}], ['regression: feed-forward on register value 2', [2, 2, [['x', 1], ['measure', 1, 1], ['x_if', 0, 2]]], {'qubits': '11', 'clbits': '10'}], ['control: random dynamic 29', [2, 2, [['measure', 0, 0], ['swap', 1, 0], ['swap', 0, 1], ['reset', 0], ['swap', 1, 0], ['cx', 0, 1]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 30', [4, 4, [['x_if', 3, 8], ['cx', 1, 2]]], {'qubits': '0000', 'clbits': '0000'}], ['control: random dynamic 33', [4, 4, [['x', 0], ['x_if', 1, 8], ['reset', 1], ['x', 2], ['x', 1], ['swap', 3, 2], ['x', 2]]], {'qubits': '1111', 'clbits': '0000'}], ['control: random dynamic 36', [4, 4, [['swap', 2, 3], ['reset', 1], ['cx', 2, 3], ['ccx', 0, 2, 1]]], {'qubits': '0000', 'clbits': '0000'}]]]
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:
A circuit that excites qubit 0 of three reports "100" instead of "001".

Input [nq, nc, ops] on computational basis states only: ["x", q], ["cx", c, t], ["ccx", a, b, t], ["swap", a, b], ["measure", q, c], ["reset", q], ["x_if", q, value] (flip q when the classical register value, clbit 0 = LSB, equals value). Return {"qubits": bits with qubit nq-1 leftmost, "clbits": bits with clbit nc-1 leftmost}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    nq, nc, ops = x
    q = [0] * nq
    c = [0] * nc
    for op in ops:
        name = op[0]
        if name == 'x':
            q[op[1]] ^= 1
        elif name == 'cx':
            if q[op[1]]:
                q[op[2]] ^= 1
        elif name == 'ccx':
            if q[op[1]] and q[op[2]]:
                q[op[3]] ^= 1
        elif name == 'swap':
            a, b = op[1], op[2]
            q[a] = q[b]
            q[b] = q[a]
        elif name == 'measure':
            _, qb, cb = op
            c[cb] = q[qb]
        elif name == 'reset':
            q[op[1]] = 0
        elif name == 'x_if':
            creg = sum(bit << i for i, bit in enumerate(c))
            if creg == op[2]:
                q[op[1]] ^= 1
    return {'qubits': ''.join(str(b) for b in reversed(q)), 'clbits': ''.join(str(b) for b in reversed(c))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: swap excitation', [2, 2, [['x', 0], ['swap', 0, 1]]], {'qubits': '10', 'clbits': '00'}], ['regression: random dynamic 2', [3, 3, [['cx', 2, 1], ['x', 1], ['measure', 1, 1], ['x', 0], ['x_if', 2, 5], ['reset', 1], ['cx', 2, 0], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '011', 'clbits': '010'}], ['repair check: random dynamic 6', [2, 2, [['reset', 0], ['x', 1], ['swap', 1, 0], ['reset', 0], ['measure', 1, 0], ['x_if', 0, 1], ['cx', 0, 1], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: feed-forward on register value 2', [2, 2, [['x', 1], ['measure', 1, 1], ['x_if', 0, 2]]], {'qubits': '11', 'clbits': '10'}], ['control: reset excited qubit', [1, 1, [['x', 0], ['reset', 0], ['measure', 0, 0]]], {'qubits': '0', 'clbits': '0'}], ['control: toffoli one control', [3, 3, [['x', 0], ['ccx', 0, 1, 2]]], {'qubits': '001', 'clbits': '000'}], ['control: toffoli no controls', [3, 3, [['ccx', 0, 1, 2]]], {'qubits': '000', 'clbits': '000'}]], [['regression: random dynamic 13', [2, 2, [['x_if', 1, 0], ['x', 0], ['swap', 1, 0], ['x', 1], ['cx', 1, 0], ['x_if', 1, 3], ['measure', 1, 1], ['swap', 1, 0], ['x', 1]]], {'qubits': '00', 'clbits': '00'}], ['regression: random dynamic 24', [2, 2, [['measure', 1, 0], ['swap', 1, 0], ['x', 0], ['cx', 0, 1], ['x_if', 0, 0], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '01', 'clbits': '00'}], ['repair check: random dynamic 38', [2, 2, [['x_if', 0, 1], ['measure', 1, 0], ['x_if', 1, 0], ['cx', 1, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '10'}], ['control: measure into other clbit', [2, 2, [['x', 0], ['measure', 0, 1]]], {'qubits': '01', 'clbits': '10'}], ['control: asymmetric output', [3, 3, [['x', 0], ['measure', 0, 0]]], {'qubits': '001', 'clbits': '001'}], ['control: random dynamic 0', [4, 4, [['cx', 2, 1], ['reset', 2], ['x_if', 1, 5], ['x_if', 3, 6], ['reset', 2], ['cx', 3, 1], ['swap', 1, 2], ['x', 0]]], {'qubits': '0001', 'clbits': '0000'}], ['control: random dynamic 1', [2, 2, [['cx', 1, 0], ['x_if', 0, 2], ['x', 1], ['swap', 0, 1], ['reset', 1], ['cx', 1, 0], ['x', 1]]], {'qubits': '11', 'clbits': '00'}]], [['regression: random dynamic 40', [2, 2, [['swap', 0, 1], ['reset', 0], ['swap', 1, 0], ['x', 1], ['swap', 1, 0], ['swap', 0, 1], ['x', 0], ['swap', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '00'}], ['regression: random dynamic 41', [3, 3, [['x_if', 2, 4], ['x_if', 2, 3], ['measure', 2, 2], ['x', 1], ['swap', 1, 0], ['ccx', 0, 2, 1]]], {'qubits': '001', 'clbits': '000'}], ['repair check: random dynamic 38', [2, 2, [['x_if', 0, 1], ['measure', 1, 0], ['x_if', 1, 0], ['cx', 1, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '10'}], ['control: random dynamic 3', [4, 4, [['ccx', 3, 0, 2], ['x_if', 1, 8], ['x_if', 1, 10], ['measure', 0, 3], ['reset', 0], ['measure', 0, 1]]], {'qubits': '0000', 'clbits': '0000'}], ['control: random dynamic 4', [2, 2, [['x', 0], ['measure', 1, 1]]], {'qubits': '01', 'clbits': '00'}], ['control: random dynamic 5', [4, 4, [['x_if', 1, 4], ['reset', 1], ['x_if', 1, 10], ['x', 0], ['measure', 2, 1], ['measure', 1, 0]]], {'qubits': '0001', 'clbits': '0000'}], ['control: random dynamic 7', [4, 4, [['ccx', 1, 0, 2], ['x_if', 1, 6]]], {'qubits': '0000', 'clbits': '0000'}]], [['regression: random dynamic 48', [2, 2, [['x', 0], ['swap', 0, 1], ['swap', 1, 0], ['swap', 0, 1], ['cx', 0, 1]]], {'qubits': '10', 'clbits': '00'}], ['regression: swap excitation', [2, 2, [['x', 0], ['swap', 0, 1]]], {'qubits': '10', 'clbits': '00'}], ['regression: random dynamic 43', [3, 3, [['x', 1], ['swap', 1, 2], ['x_if', 2, 6], ['measure', 2, 0], ['measure', 2, 0], ['x', 2]]], {'qubits': '000', 'clbits': '001'}], ['control: random dynamic 8', [3, 3, [['reset', 2], ['x', 1], ['ccx', 0, 2, 1], ['measure', 1, 1], ['reset', 2]]], {'qubits': '010', 'clbits': '010'}], ['control: random dynamic 9', [2, 2, [['cx', 0, 1], ['cx', 0, 1], ['measure', 0, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 0, 1], ['measure', 0, 1], ['measure', 0, 0], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 11', [3, 3, [['reset', 2], ['x', 2]]], {'qubits': '100', 'clbits': '000'}], ['control: random dynamic 12', [3, 3, [['x', 1], ['x', 2]]], {'qubits': '110', 'clbits': '000'}]], [['regression: random dynamic 10', [3, 3, [['x', 2], ['measure', 2, 2], ['ccx', 2, 1, 0], ['swap', 0, 2], ['cx', 2, 0], ['x', 1], ['ccx', 2, 0, 1], ['cx', 2, 0], ['x', 1]]], {'qubits': '001', 'clbits': '100'}], ['regression: random dynamic 13', [2, 2, [['x_if', 1, 0], ['x', 0], ['swap', 1, 0], ['x', 1], ['cx', 1, 0], ['x_if', 1, 3], ['measure', 1, 1], ['swap', 1, 0], ['x', 1]]], {'qubits': '00', 'clbits': '00'}], ['repair check: random dynamic 54', [4, 4, [['x', 0], ['cx', 0, 2], ['measure', 1, 1], ['ccx', 2, 3, 0], ['x_if', 1, 0], ['cx', 3, 0], ['swap', 2, 0], ['x', 0]]], {'qubits': '0110', 'clbits': '0000'}], ['control: random dynamic 14', [2, 2, [['measure', 1, 0], ['reset', 0], ['measure', 0, 1], ['x_if', 1, 3], ['cx', 1, 0], ['cx', 0, 1], ['x_if', 1, 1], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 15', [3, 3, [['cx', 2, 1], ['x_if', 0, 0], ['cx', 2, 1], ['ccx', 0, 1, 2], ['reset', 2], ['reset', 1], ['cx', 0, 1]]], {'qubits': '011', 'clbits': '000'}], ['control: random dynamic 16', [2, 2, [['reset', 0], ['x_if', 0, 1], ['x', 0]]], {'qubits': '01', 'clbits': '00'}], ['control: random dynamic 17', [2, 2, [['reset', 0], ['measure', 0, 0], ['cx', 0, 1], ['x', 1], ['measure', 0, 0]]], {'qubits': '10', 'clbits': '00'}]]]
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

N = 1
observations = []
def solve(x):
    nq, nc, ops = x
    q = [0] * nq
    c = [0] * nc
    for op in ops:
        name = op[0]
        if name == 'x':
            q[op[1]] ^= 1
        elif name == 'cx':
            if q[op[1]]:
                q[op[2]] ^= 1
        elif name == 'ccx':
            if q[op[1]] and q[op[2]]:
                q[op[3]] ^= 1
        elif name == 'swap':
            a, b = op[1], op[2]
            q[a] ^= q[b]
            q[b] ^= q[a]
        elif name == 'measure':
            _, qb, cb = op
            c[cb] = q[qb]
        elif name == 'reset':
            q[op[1]] = 0
        elif name == 'x_if':
            creg = sum(bit << i for i, bit in enumerate(c))
            if creg == op[2]:
                q[op[1]] ^= 1
    return {'qubits': ''.join(str(b) for b in reversed(q)), 'clbits': ''.join(str(b) for b in reversed(c))}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: swap excitation', [2, 2, [['x', 0], ['swap', 0, 1]]], {'qubits': '10', 'clbits': '00'}], ['regression: random dynamic 2', [3, 3, [['cx', 2, 1], ['x', 1], ['measure', 1, 1], ['x', 0], ['x_if', 2, 5], ['reset', 1], ['cx', 2, 0], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '011', 'clbits': '010'}], ['repair check: random dynamic 6', [2, 2, [['reset', 0], ['x', 1], ['swap', 1, 0], ['reset', 0], ['measure', 1, 0], ['x_if', 0, 1], ['cx', 0, 1], ['swap', 1, 0], ['cx', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: feed-forward on register value 2', [2, 2, [['x', 1], ['measure', 1, 1], ['x_if', 0, 2]]], {'qubits': '11', 'clbits': '10'}], ['control: reset excited qubit', [1, 1, [['x', 0], ['reset', 0], ['measure', 0, 0]]], {'qubits': '0', 'clbits': '0'}], ['control: toffoli one control', [3, 3, [['x', 0], ['ccx', 0, 1, 2]]], {'qubits': '001', 'clbits': '000'}], ['control: toffoli no controls', [3, 3, [['ccx', 0, 1, 2]]], {'qubits': '000', 'clbits': '000'}]], [['regression: random dynamic 13', [2, 2, [['x_if', 1, 0], ['x', 0], ['swap', 1, 0], ['x', 1], ['cx', 1, 0], ['x_if', 1, 3], ['measure', 1, 1], ['swap', 1, 0], ['x', 1]]], {'qubits': '00', 'clbits': '00'}], ['regression: random dynamic 24', [2, 2, [['measure', 1, 0], ['swap', 1, 0], ['x', 0], ['cx', 0, 1], ['x_if', 0, 0], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '01', 'clbits': '00'}], ['repair check: random dynamic 38', [2, 2, [['x_if', 0, 1], ['measure', 1, 0], ['x_if', 1, 0], ['cx', 1, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '10'}], ['control: measure into other clbit', [2, 2, [['x', 0], ['measure', 0, 1]]], {'qubits': '01', 'clbits': '10'}], ['control: asymmetric output', [3, 3, [['x', 0], ['measure', 0, 0]]], {'qubits': '001', 'clbits': '001'}], ['control: random dynamic 0', [4, 4, [['cx', 2, 1], ['reset', 2], ['x_if', 1, 5], ['x_if', 3, 6], ['reset', 2], ['cx', 3, 1], ['swap', 1, 2], ['x', 0]]], {'qubits': '0001', 'clbits': '0000'}], ['control: random dynamic 1', [2, 2, [['cx', 1, 0], ['x_if', 0, 2], ['x', 1], ['swap', 0, 1], ['reset', 1], ['cx', 1, 0], ['x', 1]]], {'qubits': '11', 'clbits': '00'}]], [['regression: random dynamic 40', [2, 2, [['swap', 0, 1], ['reset', 0], ['swap', 1, 0], ['x', 1], ['swap', 1, 0], ['swap', 0, 1], ['x', 0], ['swap', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '00'}], ['regression: random dynamic 41', [3, 3, [['x_if', 2, 4], ['x_if', 2, 3], ['measure', 2, 2], ['x', 1], ['swap', 1, 0], ['ccx', 0, 2, 1]]], {'qubits': '001', 'clbits': '000'}], ['repair check: random dynamic 38', [2, 2, [['x_if', 0, 1], ['measure', 1, 0], ['x_if', 1, 0], ['cx', 1, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 1, 0]]], {'qubits': '11', 'clbits': '10'}], ['control: random dynamic 3', [4, 4, [['ccx', 3, 0, 2], ['x_if', 1, 8], ['x_if', 1, 10], ['measure', 0, 3], ['reset', 0], ['measure', 0, 1]]], {'qubits': '0000', 'clbits': '0000'}], ['control: random dynamic 4', [2, 2, [['x', 0], ['measure', 1, 1]]], {'qubits': '01', 'clbits': '00'}], ['control: random dynamic 5', [4, 4, [['x_if', 1, 4], ['reset', 1], ['x_if', 1, 10], ['x', 0], ['measure', 2, 1], ['measure', 1, 0]]], {'qubits': '0001', 'clbits': '0000'}], ['control: random dynamic 7', [4, 4, [['ccx', 1, 0, 2], ['x_if', 1, 6]]], {'qubits': '0000', 'clbits': '0000'}]], [['regression: random dynamic 48', [2, 2, [['x', 0], ['swap', 0, 1], ['swap', 1, 0], ['swap', 0, 1], ['cx', 0, 1]]], {'qubits': '10', 'clbits': '00'}], ['regression: swap excitation', [2, 2, [['x', 0], ['swap', 0, 1]]], {'qubits': '10', 'clbits': '00'}], ['regression: random dynamic 43', [3, 3, [['x', 1], ['swap', 1, 2], ['x_if', 2, 6], ['measure', 2, 0], ['measure', 2, 0], ['x', 2]]], {'qubits': '000', 'clbits': '001'}], ['control: random dynamic 8', [3, 3, [['reset', 2], ['x', 1], ['ccx', 0, 2, 1], ['measure', 1, 1], ['reset', 2]]], {'qubits': '010', 'clbits': '010'}], ['control: random dynamic 9', [2, 2, [['cx', 0, 1], ['cx', 0, 1], ['measure', 0, 0], ['swap', 0, 1], ['measure', 0, 1], ['swap', 0, 1], ['measure', 0, 1], ['measure', 0, 0], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 11', [3, 3, [['reset', 2], ['x', 2]]], {'qubits': '100', 'clbits': '000'}], ['control: random dynamic 12', [3, 3, [['x', 1], ['x', 2]]], {'qubits': '110', 'clbits': '000'}]], [['regression: random dynamic 10', [3, 3, [['x', 2], ['measure', 2, 2], ['ccx', 2, 1, 0], ['swap', 0, 2], ['cx', 2, 0], ['x', 1], ['ccx', 2, 0, 1], ['cx', 2, 0], ['x', 1]]], {'qubits': '001', 'clbits': '100'}], ['regression: random dynamic 13', [2, 2, [['x_if', 1, 0], ['x', 0], ['swap', 1, 0], ['x', 1], ['cx', 1, 0], ['x_if', 1, 3], ['measure', 1, 1], ['swap', 1, 0], ['x', 1]]], {'qubits': '00', 'clbits': '00'}], ['repair check: random dynamic 54', [4, 4, [['x', 0], ['cx', 0, 2], ['measure', 1, 1], ['ccx', 2, 3, 0], ['x_if', 1, 0], ['cx', 3, 0], ['swap', 2, 0], ['x', 0]]], {'qubits': '0110', 'clbits': '0000'}], ['control: random dynamic 14', [2, 2, [['measure', 1, 0], ['reset', 0], ['measure', 0, 1], ['x_if', 1, 3], ['cx', 1, 0], ['cx', 0, 1], ['x_if', 1, 1], ['swap', 1, 0]]], {'qubits': '00', 'clbits': '00'}], ['control: random dynamic 15', [3, 3, [['cx', 2, 1], ['x_if', 0, 0], ['cx', 2, 1], ['ccx', 0, 1, 2], ['reset', 2], ['reset', 1], ['cx', 0, 1]]], {'qubits': '011', 'clbits': '000'}], ['control: random dynamic 16', [2, 2, [['reset', 0], ['x_if', 0, 1], ['x', 0]]], {'qubits': '01', 'clbits': '00'}], ['control: random dynamic 17', [2, 2, [['reset', 0], ['measure', 0, 0], ['cx', 0, 1], ['x', 1], ['measure', 0, 0]]], {'qubits': '10', 'clbits': '00'}]]]
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 after exciting qubit 0 leaves both qubits excited.

Input [nq, nc, ops] on computational basis states only: ["x", q], ["cx", c, t], ["ccx", a, b, t], ["swap", a, b], ["measure", q, c], ["reset", q], ["x_if", q, value] (flip q when the classical register value, clbit 0 = LSB, equals value). Return {"qubits": bits with qubit nq-1 leftmost, "clbits": bits with clbit nc-1 leftmost}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    N, M = x
    if N < 1 or M < 0 or M > N:
        return 'invalid'
    if M == 0:
        return 'no-solution'
    if 2 * M >= N:
        return {'iterations': 0, 'success': round(M / N, 6)}
    theta = math.asin(M / N)
    k = math.floor(math.pi / (4 * theta))
    return {'iterations': k, 'success': round(math.sin((2 * k + 1) * theta) ** 2, 6)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: odd N just under half', [5, 2], {'iterations': 1, 'success': 0.784}], ['regression: single marked N=4', [4, 1], {'iterations': 1, 'success': 1.0}], ['regression: N=7 M=3', [7, 3], {'iterations': 1, 'success': 0.708455}], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: no marked items', [8, 0], 'no-solution'], ['control: M greater than N', [4, 5], 'invalid'], ['control: negative M', [4, -1], 'invalid']], [['regression: N=9 M=4', [9, 4], {'iterations': 1, 'success': 0.663923}], ['regression: N=8 M=1', [8, 1], {'iterations': 2, 'success': 0.945312}], ['regression: N=7 M=3', [7, 3], {'iterations': 1, 'success': 0.708455}], ['control: empty space', [0, 0], 'invalid'], ['control: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['control: one over the space', [4, 5], 'invalid'], ['control: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}]], [['regression: N=8 M=3', [8, 3], {'iterations': 1, 'success': 0.84375}], ['regression: N=16 M=1', [16, 1], {'iterations': 3, 'success': 0.961319}], ['regression: N=8 M=1', [8, 1], {'iterations': 2, 'success': 0.945312}], ['control: all marked N=3', [3, 3], {'iterations': 0, 'success': 1.0}], ['control: N=8 M=5', [8, 5], {'iterations': 0, 'success': 0.625}], ['control: N=8 M=7', [8, 7], {'iterations': 0, 'success': 0.875}], ['control: N=16 M=13', [16, 13], {'iterations': 0, 'success': 0.8125}]], [['regression: N=16 M=3', [16, 3], {'iterations': 1, 'success': 0.949219}], ['regression: N=16 M=5', [16, 5], {'iterations': 1, 'success': 0.957031}], ['regression: N=8 M=3', [8, 3], {'iterations': 1, 'success': 0.84375}], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: no marked items', [8, 0], 'no-solution'], ['control: M greater than N', [4, 5], 'invalid'], ['control: negative M', [4, -1], 'invalid']], [['regression: N=32 M=1', [32, 1], {'iterations': 4, 'success': 0.999182}], ['regression: N=32 M=2', [32, 2], {'iterations': 3, 'success': 0.961319}], ['regression: N=16 M=2', [16, 2], {'iterations': 2, 'success': 0.945312}], ['control: empty space', [0, 0], 'invalid'], ['control: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['control: one over the space', [4, 5], 'invalid'], ['control: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.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
N = 1
observations = []
def solve(x):
    N, M = x
    if N < 1 or M < 0 or M > N:
        return 'invalid'
    if M == 0:
        return 'no-solution'
    if 2 * M >= N:
        return {'iterations': 0, 'success': round(M / N, 6)}
    theta = math.acos(math.sqrt(M / N))
    k = math.floor(math.pi / (4 * theta))
    return {'iterations': k, 'success': round(math.sin((2 * k + 1) * theta) ** 2, 6)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: odd N just under half', [5, 2], {'iterations': 1, 'success': 0.784}], ['regression: single marked N=4', [4, 1], {'iterations': 1, 'success': 1.0}], ['regression: N=7 M=3', [7, 3], {'iterations': 1, 'success': 0.708455}], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: no marked items', [8, 0], 'no-solution'], ['control: M greater than N', [4, 5], 'invalid'], ['control: negative M', [4, -1], 'invalid']], [['regression: N=9 M=4', [9, 4], {'iterations': 1, 'success': 0.663923}], ['regression: N=8 M=1', [8, 1], {'iterations': 2, 'success': 0.945312}], ['regression: N=7 M=3', [7, 3], {'iterations': 1, 'success': 0.708455}], ['control: empty space', [0, 0], 'invalid'], ['control: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['control: one over the space', [4, 5], 'invalid'], ['control: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}]], [['regression: N=8 M=3', [8, 3], {'iterations': 1, 'success': 0.84375}], ['regression: N=16 M=1', [16, 1], {'iterations': 3, 'success': 0.961319}], ['regression: N=8 M=1', [8, 1], {'iterations': 2, 'success': 0.945312}], ['control: all marked N=3', [3, 3], {'iterations': 0, 'success': 1.0}], ['control: N=8 M=5', [8, 5], {'iterations': 0, 'success': 0.625}], ['control: N=8 M=7', [8, 7], {'iterations': 0, 'success': 0.875}], ['control: N=16 M=13', [16, 13], {'iterations': 0, 'success': 0.8125}]], [['regression: N=16 M=3', [16, 3], {'iterations': 1, 'success': 0.949219}], ['regression: N=16 M=5', [16, 5], {'iterations': 1, 'success': 0.957031}], ['regression: N=8 M=3', [8, 3], {'iterations': 1, 'success': 0.84375}], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: no marked items', [8, 0], 'no-solution'], ['control: M greater than N', [4, 5], 'invalid'], ['control: negative M', [4, -1], 'invalid']], [['regression: N=32 M=1', [32, 1], {'iterations': 4, 'success': 0.999182}], ['regression: N=32 M=2', [32, 2], {'iterations': 3, 'success': 0.961319}], ['regression: N=16 M=2', [16, 2], {'iterations': 2, 'success': 0.945312}], ['control: empty space', [0, 0], 'invalid'], ['control: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['control: one over the space', [4, 5], 'invalid'], ['control: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.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:
For N=1024, M=1 the planner asks for about 804 iterations instead of 25.

Input [N, M]. "invalid" if N < 1, M < 0 or M > N; "no-solution" if M == 0; if 2M >= N return {"iterations": 0, "success": M/N}; else theta = asin(sqrt(M/N)), k = floor(pi/(4 theta)) and success = sin^2((2k+1) theta). Probabilities rounded to 6 decimals.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    N, M = x
    if N < 1 or M < 0 or M > N:
        return 'invalid'
    if M == 0:
        return 'no-solution'
    if 2 * M >= N:
        return {'iterations': 0, 'success': round(M / N, 6)}
    theta = math.asin(math.sqrt(M / N))
    k = math.floor(math.pi / (4 * theta))
    return {'iterations': k, 'success': round(math.sin((2 * k) * theta) ** 2, 6)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: odd N just under half', [5, 2], {'iterations': 1, 'success': 0.784}], ['regression: single marked N=4', [4, 1], {'iterations': 1, 'success': 1.0}], ['regression: N=7 M=3', [7, 3], {'iterations': 1, 'success': 0.708455}], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: no marked items', [8, 0], 'no-solution'], ['control: M greater than N', [4, 5], 'invalid'], ['control: negative M', [4, -1], 'invalid']], [['regression: N=9 M=4', [9, 4], {'iterations': 1, 'success': 0.663923}], ['regression: N=8 M=1', [8, 1], {'iterations': 2, 'success': 0.945312}], ['regression: N=8 M=3', [8, 3], {'iterations': 1, 'success': 0.84375}], ['control: empty space', [0, 0], 'invalid'], ['control: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['control: one over the space', [4, 5], 'invalid'], ['control: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}]], [['regression: N=8 M=3', [8, 3], {'iterations': 1, 'success': 0.84375}], ['regression: N=16 M=1', [16, 1], {'iterations': 3, 'success': 0.961319}], ['regression: N=16 M=2', [16, 2], {'iterations': 2, 'success': 0.945312}], ['control: all marked N=3', [3, 3], {'iterations': 0, 'success': 1.0}], ['control: N=8 M=5', [8, 5], {'iterations': 0, 'success': 0.625}], ['control: N=8 M=7', [8, 7], {'iterations': 0, 'success': 0.875}], ['control: N=16 M=13', [16, 13], {'iterations': 0, 'success': 0.8125}]], [['regression: N=16 M=3', [16, 3], {'iterations': 1, 'success': 0.949219}], ['regression: N=16 M=5', [16, 5], {'iterations': 1, 'success': 0.957031}], ['regression: N=16 M=2', [16, 2], {'iterations': 2, 'success': 0.945312}], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: no marked items', [8, 0], 'no-solution'], ['control: M greater than N', [4, 5], 'invalid'], ['control: negative M', [4, -1], 'invalid']], [['regression: N=32 M=1', [32, 1], {'iterations': 4, 'success': 0.999182}], ['regression: N=32 M=2', [32, 2], {'iterations': 3, 'success': 0.961319}], ['regression: N=16 M=5', [16, 5], {'iterations': 1, 'success': 0.957031}], ['control: empty space', [0, 0], 'invalid'], ['control: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['control: one over the space', [4, 5], 'invalid'], ['control: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.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
N = 1
observations = []
def solve(x):
    N, M = x
    if N < 1 or M < 0 or M > N:
        return 'invalid'
    if M == 0:
        return 'no-solution'
    if 2 * M >= N:
        return {'iterations': 0, 'success': round(M / N, 6)}
    theta = math.asin(math.sqrt(M / N))
    k = math.floor(math.pi / (4 * theta))
    return {'iterations': k, 'success': round(math.sin((2 * k + 1) * theta), 6)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: odd N just under half', [5, 2], {'iterations': 1, 'success': 0.784}], ['regression: single marked N=4', [4, 1], {'iterations': 1, 'success': 1.0}], ['regression: N=7 M=3', [7, 3], {'iterations': 1, 'success': 0.708455}], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: no marked items', [8, 0], 'no-solution'], ['control: M greater than N', [4, 5], 'invalid'], ['control: negative M', [4, -1], 'invalid']], [['regression: N=9 M=4', [9, 4], {'iterations': 1, 'success': 0.663923}], ['regression: N=8 M=1', [8, 1], {'iterations': 2, 'success': 0.945312}], ['regression: N=8 M=3', [8, 3], {'iterations': 1, 'success': 0.84375}], ['control: empty space', [0, 0], 'invalid'], ['control: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['control: one over the space', [4, 5], 'invalid'], ['control: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}]], [['regression: N=8 M=3', [8, 3], {'iterations': 1, 'success': 0.84375}], ['regression: N=16 M=1', [16, 1], {'iterations': 3, 'success': 0.961319}], ['regression: N=16 M=2', [16, 2], {'iterations': 2, 'success': 0.945312}], ['control: all marked N=3', [3, 3], {'iterations': 0, 'success': 1.0}], ['control: N=8 M=5', [8, 5], {'iterations': 0, 'success': 0.625}], ['control: N=8 M=7', [8, 7], {'iterations': 0, 'success': 0.875}], ['control: N=16 M=13', [16, 13], {'iterations': 0, 'success': 0.8125}]], [['regression: N=16 M=3', [16, 3], {'iterations': 1, 'success': 0.949219}], ['regression: N=16 M=5', [16, 5], {'iterations': 1, 'success': 0.957031}], ['regression: N=16 M=2', [16, 2], {'iterations': 2, 'success': 0.945312}], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: no marked items', [8, 0], 'no-solution'], ['control: M greater than N', [4, 5], 'invalid'], ['control: negative M', [4, -1], 'invalid']], [['regression: N=32 M=1', [32, 1], {'iterations': 4, 'success': 0.999182}], ['regression: N=32 M=2', [32, 2], {'iterations': 3, 'success': 0.961319}], ['regression: N=16 M=5', [16, 5], {'iterations': 1, 'success': 0.957031}], ['control: empty space', [0, 0], 'invalid'], ['control: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['control: one over the space', [4, 5], 'invalid'], ['control: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.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:
Success probabilities are reported for angle 2k theta, underestimating the achievable probability.

Input [N, M]. "invalid" if N < 1, M < 0 or M > N; "no-solution" if M == 0; if 2M >= N return {"iterations": 0, "success": M/N}; else theta = asin(sqrt(M/N)), k = floor(pi/(4 theta)) and success = sin^2((2k+1) theta). Probabilities rounded to 6 decimals.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    N, M = x
    if N < 1 or M < 0 or M >= N:
        return 'invalid'
    if M == 0:
        return 'no-solution'
    if 2 * M >= N:
        return {'iterations': 0, 'success': round(M / N, 6)}
    theta = math.asin(math.sqrt(M / N))
    k = math.floor(math.pi / (4 * theta))
    return {'iterations': k, 'success': round(math.sin((2 * k + 1) * theta) ** 2, 6)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['regression: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}], ['repair check: M greater than N', [4, 5], 'invalid'], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: odd N just under half', [5, 2], {'iterations': 1, 'success': 0.784}], ['control: single marked N=4', [4, 1], {'iterations': 1, 'success': 1.0}], ['control: no marked items', [8, 0], 'no-solution']], [['regression: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['regression: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}], ['repair check: M greater than N', [4, 5], 'invalid'], ['control: negative M', [4, -1], 'invalid'], ['control: empty space', [0, 0], 'invalid'], ['control: N=7 M=3', [7, 3], {'iterations': 1, 'success': 0.708455}], ['control: N=9 M=4', [9, 4], {'iterations': 1, 'success': 0.663923}]], [['regression: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['regression: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}], ['repair check: M greater than N', [4, 5], 'invalid'], ['control: N=8 M=1', [8, 1], {'iterations': 2, 'success': 0.945312}], ['control: N=8 M=2', [8, 2], {'iterations': 1, 'success': 1.0}], ['control: N=8 M=3', [8, 3], {'iterations': 1, 'success': 0.84375}], ['control: N=8 M=5', [8, 5], {'iterations': 0, 'success': 0.625}]], [['regression: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['regression: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}], ['repair check: M greater than N', [4, 5], 'invalid'], ['control: N=8 M=7', [8, 7], {'iterations': 0, 'success': 0.875}], ['control: N=16 M=1', [16, 1], {'iterations': 3, 'success': 0.961319}], ['control: N=16 M=2', [16, 2], {'iterations': 2, 'success': 0.945312}], ['control: N=16 M=3', [16, 3], {'iterations': 1, 'success': 0.949219}]], [['regression: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['regression: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}], ['repair check: M greater than N', [4, 5], 'invalid'], ['control: N=16 M=5', [16, 5], {'iterations': 1, 'success': 0.957031}], ['control: N=16 M=7', [16, 7], {'iterations': 1, 'success': 0.683594}], ['control: N=16 M=13', [16, 13], {'iterations': 0, 'success': 0.8125}], ['control: N=32 M=1', [32, 1], {'iterations': 4, 'success': 0.999182}]]]
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
N = 1
observations = []
def solve(x):
    N, M = x
    if N < 1 or M < 0 or M > N + 1:
        return 'invalid'
    if M == 0:
        return 'no-solution'
    if 2 * M >= N:
        return {'iterations': 0, 'success': round(M / N, 6)}
    theta = math.asin(math.sqrt(M / N))
    k = math.floor(math.pi / (4 * theta))
    return {'iterations': k, 'success': round(math.sin((2 * k + 1) * theta) ** 2, 6)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['regression: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}], ['repair check: M greater than N', [4, 5], 'invalid'], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: odd N just under half', [5, 2], {'iterations': 1, 'success': 0.784}], ['control: single marked N=4', [4, 1], {'iterations': 1, 'success': 1.0}], ['control: no marked items', [8, 0], 'no-solution']], [['regression: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['regression: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}], ['repair check: M greater than N', [4, 5], 'invalid'], ['control: negative M', [4, -1], 'invalid'], ['control: empty space', [0, 0], 'invalid'], ['control: N=7 M=3', [7, 3], {'iterations': 1, 'success': 0.708455}], ['control: N=9 M=4', [9, 4], {'iterations': 1, 'success': 0.663923}]], [['regression: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['regression: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}], ['repair check: M greater than N', [4, 5], 'invalid'], ['control: N=8 M=1', [8, 1], {'iterations': 2, 'success': 0.945312}], ['control: N=8 M=2', [8, 2], {'iterations': 1, 'success': 1.0}], ['control: N=8 M=3', [8, 3], {'iterations': 1, 'success': 0.84375}], ['control: N=8 M=5', [8, 5], {'iterations': 0, 'success': 0.625}]], [['regression: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['regression: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}], ['repair check: M greater than N', [4, 5], 'invalid'], ['control: N=8 M=7', [8, 7], {'iterations': 0, 'success': 0.875}], ['control: N=16 M=1', [16, 1], {'iterations': 3, 'success': 0.961319}], ['control: N=16 M=2', [16, 2], {'iterations': 2, 'success': 0.945312}], ['control: N=16 M=3', [16, 3], {'iterations': 1, 'success': 0.949219}]], [['regression: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['regression: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}], ['repair check: M greater than N', [4, 5], 'invalid'], ['control: N=16 M=5', [16, 5], {'iterations': 1, 'success': 0.957031}], ['control: N=16 M=7', [16, 7], {'iterations': 1, 'success': 0.683594}], ['control: N=16 M=13', [16, 13], {'iterations': 0, 'success': 0.8125}], ['control: N=32 M=1', [32, 1], {'iterations': 4, 'success': 0.999182}]]]
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:
N=8, M=8 is reported as "invalid" instead of the trivial zero-iteration plan with success 1.

Input [N, M]. "invalid" if N < 1, M < 0 or M > N; "no-solution" if M == 0; if 2M >= N return {"iterations": 0, "success": M/N}; else theta = asin(sqrt(M/N)), k = floor(pi/(4 theta)) and success = sin^2((2k+1) theta). Probabilities rounded to 6 decimals.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    N, M = x
    if N < 1 or M <= 0 or M > N:
        return 'invalid'
    if M == 0:
        return 'no-solution'
    if 2 * M >= N:
        return {'iterations': 0, 'success': round(M / N, 6)}
    theta = math.asin(math.sqrt(M / N))
    k = math.floor(math.pi / (4 * theta))
    return {'iterations': k, 'success': round(math.sin((2 * k + 1) * theta) ** 2, 6)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: no marked items', [8, 0], 'no-solution'], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: odd N just under half', [5, 2], {'iterations': 1, 'success': 0.784}], ['control: single marked N=4', [4, 1], {'iterations': 1, 'success': 1.0}], ['control: M greater than N', [4, 5], 'invalid'], ['control: empty space', [0, 0], 'invalid']], [['regression: no marked items', [8, 0], 'no-solution'], ['control: negative M', [4, -1], 'invalid'], ['control: empty space', [0, 0], 'invalid'], ['control: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['control: one over the space', [4, 5], 'invalid'], ['control: single marked N=4', [4, 1], {'iterations': 1, 'success': 1.0}]], [['regression: no marked items', [8, 0], 'no-solution'], ['control: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}], ['control: all marked N=3', [3, 3], {'iterations': 0, 'success': 1.0}], ['control: N=7 M=3', [7, 3], {'iterations': 1, 'success': 0.708455}], ['control: N=9 M=4', [9, 4], {'iterations': 1, 'success': 0.663923}], ['control: M greater than N', [4, 5], 'invalid']], [['regression: no marked items', [8, 0], 'no-solution'], ['control: N=8 M=1', [8, 1], {'iterations': 2, 'success': 0.945312}], ['control: N=8 M=2', [8, 2], {'iterations': 1, 'success': 1.0}], ['control: N=8 M=3', [8, 3], {'iterations': 1, 'success': 0.84375}], ['control: N=8 M=5', [8, 5], {'iterations': 0, 'success': 0.625}], ['control: negative M', [4, -1], 'invalid']], [['regression: no marked items', [8, 0], 'no-solution'], ['control: N=8 M=7', [8, 7], {'iterations': 0, 'success': 0.875}], ['control: N=16 M=1', [16, 1], {'iterations': 3, 'success': 0.961319}], ['control: N=16 M=2', [16, 2], {'iterations': 2, 'success': 0.945312}], ['control: N=16 M=3', [16, 3], {'iterations': 1, 'success': 0.949219}], ['control: empty space', [0, 0], 'invalid']]]
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
N = 1
observations = []
def solve(x):
    N, M = x
    if N < 1 or M < 0 or M > N:
        return 'invalid'
    if M == 0:
        return {'iterations': 0, 'success': 0.0}
    if 2 * M >= N:
        return {'iterations': 0, 'success': round(M / N, 6)}
    theta = math.asin(math.sqrt(M / N))
    k = math.floor(math.pi / (4 * theta))
    return {'iterations': k, 'success': round(math.sin((2 * k + 1) * theta) ** 2, 6)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: no marked items', [8, 0], 'no-solution'], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: odd N just under half', [5, 2], {'iterations': 1, 'success': 0.784}], ['control: single marked N=4', [4, 1], {'iterations': 1, 'success': 1.0}], ['control: M greater than N', [4, 5], 'invalid'], ['control: empty space', [0, 0], 'invalid']], [['regression: no marked items', [8, 0], 'no-solution'], ['control: negative M', [4, -1], 'invalid'], ['control: empty space', [0, 0], 'invalid'], ['control: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['control: one over the space', [4, 5], 'invalid'], ['control: single marked N=4', [4, 1], {'iterations': 1, 'success': 1.0}]], [['regression: no marked items', [8, 0], 'no-solution'], ['control: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}], ['control: all marked N=3', [3, 3], {'iterations': 0, 'success': 1.0}], ['control: N=7 M=3', [7, 3], {'iterations': 1, 'success': 0.708455}], ['control: N=9 M=4', [9, 4], {'iterations': 1, 'success': 0.663923}], ['control: M greater than N', [4, 5], 'invalid']], [['regression: no marked items', [8, 0], 'no-solution'], ['control: N=8 M=1', [8, 1], {'iterations': 2, 'success': 0.945312}], ['control: N=8 M=2', [8, 2], {'iterations': 1, 'success': 1.0}], ['control: N=8 M=3', [8, 3], {'iterations': 1, 'success': 0.84375}], ['control: N=8 M=5', [8, 5], {'iterations': 0, 'success': 0.625}], ['control: negative M', [4, -1], 'invalid']], [['regression: no marked items', [8, 0], 'no-solution'], ['control: N=8 M=7', [8, 7], {'iterations': 0, 'success': 0.875}], ['control: N=16 M=1', [16, 1], {'iterations': 3, 'success': 0.961319}], ['control: N=16 M=2', [16, 2], {'iterations': 2, 'success': 0.945312}], ['control: N=16 M=3', [16, 3], {'iterations': 1, 'success': 0.949219}], ['control: empty space', [0, 0], 'invalid']]]
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:
M = 0 yields "invalid" instead of "no-solution".

Input [N, M]. "invalid" if N < 1, M < 0 or M > N; "no-solution" if M == 0; if 2M >= N return {"iterations": 0, "success": M/N}; else theta = asin(sqrt(M/N)), k = floor(pi/(4 theta)) and success = sin^2((2k+1) theta). Probabilities rounded to 6 decimals.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    N, M = x
    if N < 1 or M < 0 or M > N:
        return 'invalid'
    if M == 0:
        return 'no-solution'
    if 2 * M >= N:
        return {'iterations': 0, 'success': round(M / N, 6)}
    theta = math.asin(math.sqrt(M / N))
    k = round(math.pi / (4 * theta))
    return {'iterations': k, 'success': round(math.sin((2 * k + 1) * theta) ** 2, 6)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: single marked N=4', [4, 1], {'iterations': 1, 'success': 1.0}], ['regression: N=8 M=2', [8, 2], {'iterations': 1, 'success': 1.0}], ['repair check: odd N just under half', [5, 2], {'iterations': 1, 'success': 0.784}], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: no marked items', [8, 0], 'no-solution'], ['control: M greater than N', [4, 5], 'invalid'], ['control: negative M', [4, -1], 'invalid']], [['regression: N=32 M=3', [32, 3], {'iterations': 2, 'success': 0.999779}], ['regression: N=32 M=5', [32, 5], {'iterations': 1, 'success': 0.881348}], ['repair check: N=7 M=3', [7, 3], {'iterations': 1, 'success': 0.708455}], ['control: empty space', [0, 0], 'invalid'], ['control: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['control: one over the space', [4, 5], 'invalid'], ['control: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}]], [['regression: N=64 M=3', [64, 3], {'iterations': 3, 'success': 0.998139}], ['regression: N=64 M=5', [64, 5], {'iterations': 2, 'success': 0.976354}], ['repair check: N=8 M=1', [8, 1], {'iterations': 2, 'success': 0.945312}], ['control: all marked N=3', [3, 3], {'iterations': 0, 'success': 1.0}], ['control: N=8 M=5', [8, 5], {'iterations': 0, 'success': 0.625}], ['control: N=8 M=7', [8, 7], {'iterations': 0, 'success': 0.875}], ['control: N=16 M=13', [16, 13], {'iterations': 0, 'success': 0.8125}]], [['regression: N=100 M=1', [100, 1], {'iterations': 7, 'success': 0.995344}], ['regression: N=100 M=2', [100, 2], {'iterations': 5, 'success': 0.999901}], ['repair check: N=8 M=3', [8, 3], {'iterations': 1, 'success': 0.84375}], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: no marked items', [8, 0], 'no-solution'], ['control: M greater than N', [4, 5], 'invalid'], ['control: negative M', [4, -1], 'invalid']], [['regression: N=100 M=7', [100, 7], {'iterations': 2, 'success': 0.947144}], ['regression: N=128 M=1', [128, 1], {'iterations': 8, 'success': 0.99562}], ['repair check: N=16 M=2', [16, 2], {'iterations': 2, 'success': 0.945312}], ['control: empty space', [0, 0], 'invalid'], ['control: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['control: one over the space', [4, 5], 'invalid'], ['control: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.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
N = 1
observations = []
def solve(x):
    N, M = x
    if N < 1 or M < 0 or M > N:
        return 'invalid'
    if M == 0:
        return 'no-solution'
    if 2 * M >= N:
        return {'iterations': 0, 'success': round(M / N, 6)}
    theta = math.asin(math.sqrt(M / N))
    k = math.ceil(math.pi / (4 * theta))
    return {'iterations': k, 'success': round(math.sin((2 * k + 1) * theta) ** 2, 6)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: single marked N=4', [4, 1], {'iterations': 1, 'success': 1.0}], ['regression: N=8 M=2', [8, 2], {'iterations': 1, 'success': 1.0}], ['repair check: odd N just under half', [5, 2], {'iterations': 1, 'success': 0.784}], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: no marked items', [8, 0], 'no-solution'], ['control: M greater than N', [4, 5], 'invalid'], ['control: negative M', [4, -1], 'invalid']], [['regression: N=32 M=3', [32, 3], {'iterations': 2, 'success': 0.999779}], ['regression: N=32 M=5', [32, 5], {'iterations': 1, 'success': 0.881348}], ['repair check: N=7 M=3', [7, 3], {'iterations': 1, 'success': 0.708455}], ['control: empty space', [0, 0], 'invalid'], ['control: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['control: one over the space', [4, 5], 'invalid'], ['control: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.0}]], [['regression: N=64 M=3', [64, 3], {'iterations': 3, 'success': 0.998139}], ['regression: N=64 M=5', [64, 5], {'iterations': 2, 'success': 0.976354}], ['repair check: N=8 M=1', [8, 1], {'iterations': 2, 'success': 0.945312}], ['control: all marked N=3', [3, 3], {'iterations': 0, 'success': 1.0}], ['control: N=8 M=5', [8, 5], {'iterations': 0, 'success': 0.625}], ['control: N=8 M=7', [8, 7], {'iterations': 0, 'success': 0.875}], ['control: N=16 M=13', [16, 13], {'iterations': 0, 'success': 0.8125}]], [['regression: N=100 M=1', [100, 1], {'iterations': 7, 'success': 0.995344}], ['regression: N=100 M=2', [100, 2], {'iterations': 5, 'success': 0.999901}], ['repair check: N=8 M=3', [8, 3], {'iterations': 1, 'success': 0.84375}], ['control: half marked N=4 M=2', [4, 2], {'iterations': 0, 'success': 0.5}], ['control: no marked items', [8, 0], 'no-solution'], ['control: M greater than N', [4, 5], 'invalid'], ['control: negative M', [4, -1], 'invalid']], [['regression: N=100 M=7', [100, 7], {'iterations': 2, 'success': 0.947144}], ['regression: N=128 M=1', [128, 1], {'iterations': 8, 'success': 0.99562}], ['repair check: N=16 M=2', [16, 2], {'iterations': 2, 'success': 0.945312}], ['control: empty space', [0, 0], 'invalid'], ['control: all marked', [8, 8], {'iterations': 0, 'success': 1.0}], ['control: one over the space', [4, 5], 'invalid'], ['control: all marked N=1', [1, 1], {'iterations': 0, 'success': 1.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:
Some sizes plan one extra iteration, overshooting the peak and lowering success.

Input [N, M]. "invalid" if N < 1, M < 0 or M > N; "no-solution" if M == 0; if 2M >= N return {"iterations": 0, "success": M/N}; else theta = asin(sqrt(M/N)), k = floor(pi/(4 theta)) and success = sin^2((2k+1) theta). Probabilities rounded to 6 decimals.

split: open-access


prompt:
A circuit of only RZ gates reports success below 1.

Input [ops, e1, e2, er] with decimal error rates. Success probability is the product of (1-e1) per single-qubit physical gate, (1-e2) per two-qubit gate, (1-e2)^6 (1-e1)^9 per three-qubit gate (Toffoli decomposition), and (1-er) per measured qubit; rz is virtual and barrier/id are free. Return the probability rounded to 9 decimals.

split: open-access


prompt:
Each CNOT multiplies the success by (1-e2)^2.

Input [ops, e1, e2, er] with decimal error rates. Success probability is the product of (1-e1) per single-qubit physical gate, (1-e2) per two-qubit gate, (1-e2)^6 (1-e1)^9 per three-qubit gate (Toffoli decomposition), and (1-er) per measured qubit; rz is virtual and barrier/id are free. Return the probability rounded to 9 decimals.

split: open-access


prompt:
Measuring three qubits in one op costs (1-er) instead of (1-er)^3.

Input [ops, e1, e2, er] with decimal error rates. Success probability is the product of (1-e1) per single-qubit physical gate, (1-e2) per two-qubit gate, (1-e2)^6 (1-e1)^9 per three-qubit gate (Toffoli decomposition), and (1-er) per measured qubit; rz is virtual and barrier/id are free. Return the probability rounded to 9 decimals.

split: open-access


prompt:
A Toffoli costs (1-e2) instead of its six-CNOT, nine-single-qubit decomposition.

Input [ops, e1, e2, er] with decimal error rates. Success probability is the product of (1-e1) per single-qubit physical gate, (1-e2) per two-qubit gate, (1-e2)^6 (1-e1)^9 per three-qubit gate (Toffoli decomposition), and (1-er) per measured qubit; rz is virtual and barrier/id are free. Return the probability rounded to 9 decimals.

split: open-access


prompt:
Damping |1> with g = 0.5 gives z = -1 instead of 0; the channel pushes population the wrong way.

Input [[x, y, z], channels] (decimal strings). Apply in order: depol p (r -> (1-p) r), dephase p (x, y scaled by 1-2p), bitflip p (y, z scaled by 1-2p), ampdamp g (x, y scaled by sqrt(1-g), z -> g + (1-g) z toward |0> at z=+1), h ((x,y,z) -> (z,-y,x)), s ((x,y) -> (-y,x)), x ((y,z) -> (-y,-z)). Return the final vector rounded to 6 decimals.

split: open-access