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

N = 1
observations = []
def solve(x):
    nq, nc, ops = x
    ql = [0] * nq
    cl = [0] * nc
    for op in ops:
        name, qs = op[0], op[1]
        if name == 'barrier':
            qs = qs or list(range(nq))
            top = max(ql[q] for q in qs)
            for q in qs:
                ql[q] = top
            continue
        if name == 'id':
            continue
        cbits = []
        if name == 'measure':
            cbits = op[2]
        elif len(op) > 2 and op[2] == 'if':
            cbits = [op[3]]
        level = 1 + max([ql[q] for q in qs] + [cl[c] for c in cbits])
        for q in qs:
            ql[q] = level
        if name == 'measure':
            for c in cbits:
                cl[c] = level
    return [max(ql + cl + [0]), ql]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: late read then early-qubit measure', [2, 1, [['h', [1]], ['h', [1]], ['h', [1]], ['x', [1], 'if', 0], ['measure', [0], [0]]]], [5, [5, 4]]], ['regression: read then measure other clbit writer', [3, 2, [['h', [2]], ['h', [2]], ['z', [2], 'if', 1], ['measure', [0], [1]], ['x', [1], 'if', 1]]], [5, [4, 5, 3]]], ['regression: random schedule 26', [2, 2, [['measure', [0], [0]], ['x', [1], 'if', 0], ['measure', [0], [0]], ['cx', [0, 1]], ['h', [1]], ['rz', [1]]]], [6, [4, 6]]], ['control: barrier aligns everything', [3, 1, [['h', [0]], ['h', [0]], ['barrier', []], ['x', [2]]]], [3, [2, 2, 3]]], ['control: partial barrier', [3, 1, [['h', [0]], ['barrier', [0, 1]], ['x', [1]], ['x', [2]]]], [2, [1, 2, 1]]], ['control: toffoli waits on all', [3, 0, [['h', [2]], ['h', [2]], ['ccx', [0, 1, 2]], ['x', [0]]]], [4, [4, 3, 3]]], ['control: cx waits on target', [2, 0, [['h', [1]], ['h', [1]], ['cx', [0, 1]]]], [3, [3, 3]]]], [['regression: late read then early-qubit measure', [2, 1, [['h', [1]], ['h', [1]], ['h', [1]], ['x', [1], 'if', 0], ['measure', [0], [0]]]], [5, [5, 4]]], ['regression: read then measure other clbit writer', [3, 2, [['h', [2]], ['h', [2]], ['z', [2], 'if', 1], ['measure', [0], [1]], ['x', [1], 'if', 1]]], [5, [4, 5, 3]]], ['regression: random schedule 26', [2, 2, [['measure', [0], [0]], ['x', [1], 'if', 0], ['measure', [0], [0]], ['cx', [0, 1]], ['h', [1]], ['rz', [1]]]], [6, [4, 6]]], ['control: identity is free', [1, 0, [['id', [0]], ['id', [0]], ['x', [0]]]], [1, [1]]], ['control: conditioned gate after measure', [2, 1, [['h', [0]], ['measure', [0], [0]], ['x', [1], 'if', 0]]], [3, [2, 3]]], ['control: measure after conditioned read', [2, 1, [['h', [0]], ['h', [0]], ['h', [0]], ['x', [1], 'if', 0], ['measure', [1], [0]]]], [3, [3, 2]]], ['control: empty circuit', [2, 1, []], [0, [0, 0]]]], [['regression: late read then early-qubit measure', [2, 1, [['h', [1]], ['h', [1]], ['h', [1]], ['x', [1], 'if', 0], ['measure', [0], [0]]]], [5, [5, 4]]], ['regression: read then measure other clbit writer', [3, 2, [['h', [2]], ['h', [2]], ['z', [2], 'if', 1], ['measure', [0], [1]], ['x', [1], 'if', 1]]], [5, [4, 5, 3]]], ['regression: random schedule 26', [2, 2, [['measure', [0], [0]], ['x', [1], 'if', 0], ['measure', [0], [0]], ['cx', [0, 1]], ['h', [1]], ['rz', [1]]]], [6, [4, 6]]], ['control: random schedule 0', [1, 2, [['x', [0]], ['rz', [0]], ['measure', [0], [0]], ['x', [0]], ['barrier', [0]], ['x', [0], 'if', 1], ['x', [0], 'if', 1], ['x', [0]], ['measure', [0], [0]]]], [8, [8]]], ['control: random schedule 1', [4, 2, [['ccx', [1, 0, 3]], ['ccx', [2, 1, 3]], ['barrier', [0, 1, 2, 3]], ['cx', [1, 0]], ['id', [1]], ['cx', [1, 2]], ['cx', [0, 2]]]], [5, [5, 4, 5, 2]]], ['control: random schedule 2', [1, 1, [['h', [0]], ['rz', [0]], ['x', [0]], ['x', [0], 'if', 0], ['x', [0]], ['x', [0]], ['x', [0], 'if', 0], ['id', [0]]]], [7, [7]]], ['control: random schedule 3', [1, 2, [['h', [0]], ['h', [0]]]], [2, [2]]]], [['regression: late read then early-qubit measure', [2, 1, [['h', [1]], ['h', [1]], ['h', [1]], ['x', [1], 'if', 0], ['measure', [0], [0]]]], [5, [5, 4]]], ['regression: read then measure other clbit writer', [3, 2, [['h', [2]], ['h', [2]], ['z', [2], 'if', 1], ['measure', [0], [1]], ['x', [1], 'if', 1]]], [5, [4, 5, 3]]], ['regression: random schedule 26', [2, 2, [['measure', [0], [0]], ['x', [1], 'if', 0], ['measure', [0], [0]], ['cx', [0, 1]], ['h', [1]], ['rz', [1]]]], [6, [4, 6]]], ['control: random schedule 4', [4, 1, [['measure', [3], [0]], ['ccx', [2, 1, 0]], ['ccx', [0, 2, 3]]]], [2, [2, 1, 2, 2]]], ['control: random schedule 5', [3, 2, [['ccx', [0, 1, 2]], ['ccx', [2, 1, 0]], ['barrier', [0, 1, 2]], ['x', [1]]]], [3, [2, 3, 2]]], ['control: random schedule 6', [4, 2, [['barrier', [2]], ['cx', [1, 2]], ['ccx', [2, 3, 0]]]], [2, [2, 1, 2, 2]]], ['control: random schedule 7', [4, 2, [['x', [2], 'if', 1], ['x', [1]], ['barrier', [2]], ['cx', [0, 1]], ['h', [2]]]], [2, [2, 2, 2, 0]]]], [['regression: late read then early-qubit measure', [2, 1, [['h', [1]], ['h', [1]], ['h', [1]], ['x', [1], 'if', 0], ['measure', [0], [0]]]], [5, [5, 4]]], ['regression: read then measure other clbit writer', [3, 2, [['h', [2]], ['h', [2]], ['z', [2], 'if', 1], ['measure', [0], [1]], ['x', [1], 'if', 1]]], [5, [4, 5, 3]]], ['regression: random schedule 26', [2, 2, [['measure', [0], [0]], ['x', [1], 'if', 0], ['measure', [0], [0]], ['cx', [0, 1]], ['h', [1]], ['rz', [1]]]], [6, [4, 6]]], ['control: random schedule 8', [1, 1, [['x', [0], 'if', 0], ['rz', [0]], ['rz', [0]], ['h', [0]], ['rz', [0]], ['h', [0]], ['measure', [0], [0]], ['rz', [0]]]], [8, [8]]], ['control: random schedule 9', [3, 1, [['cx', [2, 1]], ['h', [1]], ['barrier', [1, 2]]]], [2, [0, 2, 2]]], ['control: random schedule 10', [4, 1, [['id', [2]]]], [0, [0, 0, 0, 0]]], ['control: random schedule 11', [2, 2, [['barrier', [0]], ['barrier', [1]], ['h', [1]], ['h', [0]], ['id', [0]], ['cx', [0, 1]], ['x', [1]], ['rz', [0]]]], [3, [3, 3]]]]]
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
    ql = [0] * nq
    cl = [0] * nc
    for op in ops:
        name, qs = op[0], op[1]
        if name == 'barrier':
            qs = qs or list(range(nq))
            top = max(ql[q] for q in qs)
            for q in qs:
                ql[q] = top
            continue
        if name == 'id':
            continue
        cbits = []
        if name == 'measure':
            cbits = op[2]
        elif len(op) > 2 and op[2] == 'if':
            cbits = [op[3]]
        level = 1 + max([ql[q] for q in qs] + [cl[c] for c in cbits])
        for q in qs:
            ql[q] = level
        for c in cbits:
            cl[c] = level if name == 'measure' else level - 1
    return [max(ql + cl + [0]), ql]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: late read then early-qubit measure', [2, 1, [['h', [1]], ['h', [1]], ['h', [1]], ['x', [1], 'if', 0], ['measure', [0], [0]]]], [5, [5, 4]]], ['regression: read then measure other clbit writer', [3, 2, [['h', [2]], ['h', [2]], ['z', [2], 'if', 1], ['measure', [0], [1]], ['x', [1], 'if', 1]]], [5, [4, 5, 3]]], ['regression: random schedule 26', [2, 2, [['measure', [0], [0]], ['x', [1], 'if', 0], ['measure', [0], [0]], ['cx', [0, 1]], ['h', [1]], ['rz', [1]]]], [6, [4, 6]]], ['control: barrier aligns everything', [3, 1, [['h', [0]], ['h', [0]], ['barrier', []], ['x', [2]]]], [3, [2, 2, 3]]], ['control: partial barrier', [3, 1, [['h', [0]], ['barrier', [0, 1]], ['x', [1]], ['x', [2]]]], [2, [1, 2, 1]]], ['control: toffoli waits on all', [3, 0, [['h', [2]], ['h', [2]], ['ccx', [0, 1, 2]], ['x', [0]]]], [4, [4, 3, 3]]], ['control: cx waits on target', [2, 0, [['h', [1]], ['h', [1]], ['cx', [0, 1]]]], [3, [3, 3]]]], [['regression: late read then early-qubit measure', [2, 1, [['h', [1]], ['h', [1]], ['h', [1]], ['x', [1], 'if', 0], ['measure', [0], [0]]]], [5, [5, 4]]], ['regression: read then measure other clbit writer', [3, 2, [['h', [2]], ['h', [2]], ['z', [2], 'if', 1], ['measure', [0], [1]], ['x', [1], 'if', 1]]], [5, [4, 5, 3]]], ['regression: random schedule 26', [2, 2, [['measure', [0], [0]], ['x', [1], 'if', 0], ['measure', [0], [0]], ['cx', [0, 1]], ['h', [1]], ['rz', [1]]]], [6, [4, 6]]], ['control: identity is free', [1, 0, [['id', [0]], ['id', [0]], ['x', [0]]]], [1, [1]]], ['control: conditioned gate after measure', [2, 1, [['h', [0]], ['measure', [0], [0]], ['x', [1], 'if', 0]]], [3, [2, 3]]], ['control: measure after conditioned read', [2, 1, [['h', [0]], ['h', [0]], ['h', [0]], ['x', [1], 'if', 0], ['measure', [1], [0]]]], [3, [3, 2]]], ['control: empty circuit', [2, 1, []], [0, [0, 0]]]], [['regression: late read then early-qubit measure', [2, 1, [['h', [1]], ['h', [1]], ['h', [1]], ['x', [1], 'if', 0], ['measure', [0], [0]]]], [5, [5, 4]]], ['regression: read then measure other clbit writer', [3, 2, [['h', [2]], ['h', [2]], ['z', [2], 'if', 1], ['measure', [0], [1]], ['x', [1], 'if', 1]]], [5, [4, 5, 3]]], ['regression: random schedule 26', [2, 2, [['measure', [0], [0]], ['x', [1], 'if', 0], ['measure', [0], [0]], ['cx', [0, 1]], ['h', [1]], ['rz', [1]]]], [6, [4, 6]]], ['control: random schedule 0', [1, 2, [['x', [0]], ['rz', [0]], ['measure', [0], [0]], ['x', [0]], ['barrier', [0]], ['x', [0], 'if', 1], ['x', [0], 'if', 1], ['x', [0]], ['measure', [0], [0]]]], [8, [8]]], ['control: random schedule 1', [4, 2, [['ccx', [1, 0, 3]], ['ccx', [2, 1, 3]], ['barrier', [0, 1, 2, 3]], ['cx', [1, 0]], ['id', [1]], ['cx', [1, 2]], ['cx', [0, 2]]]], [5, [5, 4, 5, 2]]], ['control: random schedule 2', [1, 1, [['h', [0]], ['rz', [0]], ['x', [0]], ['x', [0], 'if', 0], ['x', [0]], ['x', [0]], ['x', [0], 'if', 0], ['id', [0]]]], [7, [7]]], ['control: random schedule 3', [1, 2, [['h', [0]], ['h', [0]]]], [2, [2]]]], [['regression: late read then early-qubit measure', [2, 1, [['h', [1]], ['h', [1]], ['h', [1]], ['x', [1], 'if', 0], ['measure', [0], [0]]]], [5, [5, 4]]], ['regression: read then measure other clbit writer', [3, 2, [['h', [2]], ['h', [2]], ['z', [2], 'if', 1], ['measure', [0], [1]], ['x', [1], 'if', 1]]], [5, [4, 5, 3]]], ['regression: random schedule 26', [2, 2, [['measure', [0], [0]], ['x', [1], 'if', 0], ['measure', [0], [0]], ['cx', [0, 1]], ['h', [1]], ['rz', [1]]]], [6, [4, 6]]], ['control: random schedule 4', [4, 1, [['measure', [3], [0]], ['ccx', [2, 1, 0]], ['ccx', [0, 2, 3]]]], [2, [2, 1, 2, 2]]], ['control: random schedule 5', [3, 2, [['ccx', [0, 1, 2]], ['ccx', [2, 1, 0]], ['barrier', [0, 1, 2]], ['x', [1]]]], [3, [2, 3, 2]]], ['control: random schedule 6', [4, 2, [['barrier', [2]], ['cx', [1, 2]], ['ccx', [2, 3, 0]]]], [2, [2, 1, 2, 2]]], ['control: random schedule 7', [4, 2, [['x', [2], 'if', 1], ['x', [1]], ['barrier', [2]], ['cx', [0, 1]], ['h', [2]]]], [2, [2, 2, 2, 0]]]], [['regression: late read then early-qubit measure', [2, 1, [['h', [1]], ['h', [1]], ['h', [1]], ['x', [1], 'if', 0], ['measure', [0], [0]]]], [5, [5, 4]]], ['regression: read then measure other clbit writer', [3, 2, [['h', [2]], ['h', [2]], ['z', [2], 'if', 1], ['measure', [0], [1]], ['x', [1], 'if', 1]]], [5, [4, 5, 3]]], ['regression: random schedule 26', [2, 2, [['measure', [0], [0]], ['x', [1], 'if', 0], ['measure', [0], [0]], ['cx', [0, 1]], ['h', [1]], ['rz', [1]]]], [6, [4, 6]]], ['control: random schedule 8', [1, 1, [['x', [0], 'if', 0], ['rz', [0]], ['rz', [0]], ['h', [0]], ['rz', [0]], ['h', [0]], ['measure', [0], [0]], ['rz', [0]]]], [8, [8]]], ['control: random schedule 9', [3, 1, [['cx', [2, 1]], ['h', [1]], ['barrier', [1, 2]]]], [2, [0, 2, 2]]], ['control: random schedule 10', [4, 1, [['id', [2]]]], [0, [0, 0, 0, 0]]], ['control: random schedule 11', [2, 2, [['barrier', [0]], ['barrier', [1]], ['h', [1]], ['h', [0]], ['id', [0]], ['cx', [0, 1]], ['x', [1]], ['rz', [0]]]], [3, [3, 3]]]]]
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 measurement into c0 issued after a gate conditioned on c0 is placed before that read completes.

Input [nq, nc, ops]; ops are [name, qubits], ["measure", [q], [c]], ["g", [q], "if", c] (classically conditioned), ["barrier", qubits] (empty list = all qubits) and ["id", [q]]. ASAP layering: each op lands one layer after the latest of its qubits and any clbit it reads or writes, and sets those levels; barriers align the listed qubits to their maximum without adding a layer; id costs nothing. Return [depth, qubit levels].

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
    ql = [0] * nq
    cl = [0] * nc
    for op in ops:
        name, qs = op[0], op[1]
        if name == 'barrier':
            qs = qs or list(range(nq))
            top = max(ql[q] for q in qs)
            for q in qs:
                ql[q] = top + 1
            continue
        if name == 'id':
            continue
        cbits = []
        if name == 'measure':
            cbits = op[2]
        elif len(op) > 2 and op[2] == 'if':
            cbits = [op[3]]
        level = 1 + max([ql[q] for q in qs] + [cl[c] for c in cbits])
        for q in qs:
            ql[q] = level
        for c in cbits:
            cl[c] = level
    return [max(ql + cl + [0]), ql]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: barrier aligns everything', [3, 1, [['h', [0]], ['h', [0]], ['barrier', []], ['x', [2]]]], [3, [2, 2, 3]]], ['regression: partial barrier', [3, 1, [['h', [0]], ['barrier', [0, 1]], ['x', [1]], ['x', [2]]]], [2, [1, 2, 1]]], ['regression: random schedule 1', [4, 2, [['ccx', [1, 0, 3]], ['ccx', [2, 1, 3]], ['barrier', [0, 1, 2, 3]], ['cx', [1, 0]], ['id', [1]], ['cx', [1, 2]], ['cx', [0, 2]]]], [5, [5, 4, 5, 2]]], ['control: toffoli waits on all', [3, 0, [['h', [2]], ['h', [2]], ['ccx', [0, 1, 2]], ['x', [0]]]], [4, [4, 3, 3]]], ['control: cx waits on target', [2, 0, [['h', [1]], ['h', [1]], ['cx', [0, 1]]]], [3, [3, 3]]], ['control: identity is free', [1, 0, [['id', [0]], ['id', [0]], ['x', [0]]]], [1, [1]]], ['control: conditioned gate after measure', [2, 1, [['h', [0]], ['measure', [0], [0]], ['x', [1], 'if', 0]]], [3, [2, 3]]]], [['regression: random schedule 1', [4, 2, [['ccx', [1, 0, 3]], ['ccx', [2, 1, 3]], ['barrier', [0, 1, 2, 3]], ['cx', [1, 0]], ['id', [1]], ['cx', [1, 2]], ['cx', [0, 2]]]], [5, [5, 4, 5, 2]]], ['regression: random schedule 5', [3, 2, [['ccx', [0, 1, 2]], ['ccx', [2, 1, 0]], ['barrier', [0, 1, 2]], ['x', [1]]]], [3, [2, 3, 2]]], ['regression: random schedule 23', [4, 1, [['barrier', [0, 1, 2, 3]], ['x', [3], 'if', 0], ['rz', [2]], ['rz', [1]], ['cx', [0, 3]], ['x', [3], 'if', 0], ['rz', [2]], ['barrier', [0, 2, 3]]]], [3, [3, 1, 3, 3]]], ['control: measure after conditioned read', [2, 1, [['h', [0]], ['h', [0]], ['h', [0]], ['x', [1], 'if', 0], ['measure', [1], [0]]]], [3, [3, 2]]], ['control: empty circuit', [2, 1, []], [0, [0, 0]]], ['control: late read then early-qubit measure', [2, 1, [['h', [1]], ['h', [1]], ['h', [1]], ['x', [1], 'if', 0], ['measure', [0], [0]]]], [5, [5, 4]]], ['control: read then measure other clbit writer', [3, 2, [['h', [2]], ['h', [2]], ['z', [2], 'if', 1], ['measure', [0], [1]], ['x', [1], 'if', 1]]], [5, [4, 5, 3]]]], [['regression: random schedule 7', [4, 2, [['x', [2], 'if', 1], ['x', [1]], ['barrier', [2]], ['cx', [0, 1]], ['h', [2]]]], [2, [2, 2, 2, 0]]], ['regression: random schedule 9', [3, 1, [['cx', [2, 1]], ['h', [1]], ['barrier', [1, 2]]]], [2, [0, 2, 2]]], ['regression: random schedule 37', [3, 2, [['rz', [2]], ['rz', [0]], ['h', [0]], ['h', [2]], ['rz', [2]], ['barrier', []], ['x', [0], 'if', 0]]], [4, [4, 3, 3]]], ['control: random schedule 2', [1, 1, [['h', [0]], ['rz', [0]], ['x', [0]], ['x', [0], 'if', 0], ['x', [0]], ['x', [0]], ['x', [0], 'if', 0], ['id', [0]]]], [7, [7]]], ['control: random schedule 3', [1, 2, [['h', [0]], ['h', [0]]]], [2, [2]]], ['control: random schedule 4', [4, 1, [['measure', [3], [0]], ['ccx', [2, 1, 0]], ['ccx', [0, 2, 3]]]], [2, [2, 1, 2, 2]]], ['control: random schedule 8', [1, 1, [['x', [0], 'if', 0], ['rz', [0]], ['rz', [0]], ['h', [0]], ['rz', [0]], ['h', [0]], ['measure', [0], [0]], ['rz', [0]]]], [8, [8]]]], [['regression: random schedule 12', [1, 2, [['rz', [0]], ['rz', [0]], ['barrier', []], ['rz', [0]], ['id', [0]], ['barrier', [0]], ['x', [0]], ['h', [0]]]], [5, [5]]], ['regression: random schedule 14', [4, 1, [['cx', [0, 3]], ['x', [0]], ['cx', [0, 2]], ['cx', [2, 3]], ['x', [1], 'if', 0], ['cx', [3, 0]], ['cx', [1, 2]], ['id', [0]], ['barrier', [2]]]], [5, [5, 5, 5, 5]]], ['regression: random schedule 16', [3, 1, [['x', [2], 'if', 0], ['barrier', [0, 1, 2]], ['cx', [1, 2]], ['cx', [0, 1]], ['h', [0]], ['measure', [1], [0]], ['measure', [2], [0]]]], [5, [4, 4, 5]]], ['control: random schedule 10', [4, 1, [['id', [2]]]], [0, [0, 0, 0, 0]]], ['control: random schedule 13', [4, 2, [['cx', [3, 2]], ['x', [3]], ['ccx', [3, 1, 0]], ['ccx', [1, 0, 2]], ['h', [0]]]], [5, [5, 4, 4, 3]]], ['control: random schedule 18', [1, 2, [['x', [0]], ['x', [0]], ['h', [0]], ['rz', [0]], ['rz', [0]], ['x', [0]]]], [6, [6]]], ['control: random schedule 19', [1, 2, [['x', [0]]]], [1, [1]]]], [['regression: random schedule 16', [3, 1, [['x', [2], 'if', 0], ['barrier', [0, 1, 2]], ['cx', [1, 2]], ['cx', [0, 1]], ['h', [0]], ['measure', [1], [0]], ['measure', [2], [0]]]], [5, [4, 4, 5]]], ['regression: random schedule 17', [2, 1, [['barrier', [1]], ['rz', [1]], ['cx', [1, 0]], ['cx', [1, 0]], ['x', [1]], ['cx', [0, 1]], ['measure', [1], [0]], ['h', [0]], ['barrier', [0, 1]]]], [6, [6, 6]]], ['regression: random schedule 30', [4, 2, [['cx', [2, 1]], ['barrier', [0, 1, 2, 3]], ['cx', [1, 0]]]], [2, [2, 2, 1, 1]]], ['control: random schedule 20', [4, 2, [['x', [3], 'if', 1], ['h', [2]], ['cx', [2, 1]], ['rz', [1]]]], [3, [0, 3, 2, 1]]], ['control: random schedule 22', [1, 1, [['measure', [0], [0]], ['measure', [0], [0]], ['x', [0]], ['h', [0]], ['rz', [0]], ['rz', [0]], ['rz', [0]], ['measure', [0], [0]]]], [8, [8]]], ['control: random schedule 26', [2, 2, [['measure', [0], [0]], ['x', [1], 'if', 0], ['measure', [0], [0]], ['cx', [0, 1]], ['h', [1]], ['rz', [1]]]], [6, [4, 6]]], ['control: random schedule 27', [2, 1, [['rz', [0]], ['cx', [1, 0]], ['x', [1]], ['h', [1]], ['x', [0], 'if', 0], ['h', [1]], ['h', [0]]]], [5, [4, 5]]]]]
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
    ql = [0] * nq
    cl = [0] * nc
    for op in ops:
        name, qs = op[0], op[1]
        if name == 'barrier':
            qs = qs or list(range(nq))
            top = ql[qs[0]]
            for q in qs:
                ql[q] = top
            continue
        if name == 'id':
            continue
        cbits = []
        if name == 'measure':
            cbits = op[2]
        elif len(op) > 2 and op[2] == 'if':
            cbits = [op[3]]
        level = 1 + max([ql[q] for q in qs] + [cl[c] for c in cbits])
        for q in qs:
            ql[q] = level
        for c in cbits:
            cl[c] = level
    return [max(ql + cl + [0]), ql]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: barrier aligns everything', [3, 1, [['h', [0]], ['h', [0]], ['barrier', []], ['x', [2]]]], [3, [2, 2, 3]]], ['regression: partial barrier', [3, 1, [['h', [0]], ['barrier', [0, 1]], ['x', [1]], ['x', [2]]]], [2, [1, 2, 1]]], ['regression: random schedule 1', [4, 2, [['ccx', [1, 0, 3]], ['ccx', [2, 1, 3]], ['barrier', [0, 1, 2, 3]], ['cx', [1, 0]], ['id', [1]], ['cx', [1, 2]], ['cx', [0, 2]]]], [5, [5, 4, 5, 2]]], ['control: toffoli waits on all', [3, 0, [['h', [2]], ['h', [2]], ['ccx', [0, 1, 2]], ['x', [0]]]], [4, [4, 3, 3]]], ['control: cx waits on target', [2, 0, [['h', [1]], ['h', [1]], ['cx', [0, 1]]]], [3, [3, 3]]], ['control: identity is free', [1, 0, [['id', [0]], ['id', [0]], ['x', [0]]]], [1, [1]]], ['control: conditioned gate after measure', [2, 1, [['h', [0]], ['measure', [0], [0]], ['x', [1], 'if', 0]]], [3, [2, 3]]]], [['regression: random schedule 1', [4, 2, [['ccx', [1, 0, 3]], ['ccx', [2, 1, 3]], ['barrier', [0, 1, 2, 3]], ['cx', [1, 0]], ['id', [1]], ['cx', [1, 2]], ['cx', [0, 2]]]], [5, [5, 4, 5, 2]]], ['regression: random schedule 5', [3, 2, [['ccx', [0, 1, 2]], ['ccx', [2, 1, 0]], ['barrier', [0, 1, 2]], ['x', [1]]]], [3, [2, 3, 2]]], ['regression: random schedule 23', [4, 1, [['barrier', [0, 1, 2, 3]], ['x', [3], 'if', 0], ['rz', [2]], ['rz', [1]], ['cx', [0, 3]], ['x', [3], 'if', 0], ['rz', [2]], ['barrier', [0, 2, 3]]]], [3, [3, 1, 3, 3]]], ['control: measure after conditioned read', [2, 1, [['h', [0]], ['h', [0]], ['h', [0]], ['x', [1], 'if', 0], ['measure', [1], [0]]]], [3, [3, 2]]], ['control: empty circuit', [2, 1, []], [0, [0, 0]]], ['control: late read then early-qubit measure', [2, 1, [['h', [1]], ['h', [1]], ['h', [1]], ['x', [1], 'if', 0], ['measure', [0], [0]]]], [5, [5, 4]]], ['control: read then measure other clbit writer', [3, 2, [['h', [2]], ['h', [2]], ['z', [2], 'if', 1], ['measure', [0], [1]], ['x', [1], 'if', 1]]], [5, [4, 5, 3]]]], [['regression: random schedule 7', [4, 2, [['x', [2], 'if', 1], ['x', [1]], ['barrier', [2]], ['cx', [0, 1]], ['h', [2]]]], [2, [2, 2, 2, 0]]], ['regression: random schedule 9', [3, 1, [['cx', [2, 1]], ['h', [1]], ['barrier', [1, 2]]]], [2, [0, 2, 2]]], ['regression: random schedule 37', [3, 2, [['rz', [2]], ['rz', [0]], ['h', [0]], ['h', [2]], ['rz', [2]], ['barrier', []], ['x', [0], 'if', 0]]], [4, [4, 3, 3]]], ['control: random schedule 2', [1, 1, [['h', [0]], ['rz', [0]], ['x', [0]], ['x', [0], 'if', 0], ['x', [0]], ['x', [0]], ['x', [0], 'if', 0], ['id', [0]]]], [7, [7]]], ['control: random schedule 3', [1, 2, [['h', [0]], ['h', [0]]]], [2, [2]]], ['control: random schedule 4', [4, 1, [['measure', [3], [0]], ['ccx', [2, 1, 0]], ['ccx', [0, 2, 3]]]], [2, [2, 1, 2, 2]]], ['control: random schedule 8', [1, 1, [['x', [0], 'if', 0], ['rz', [0]], ['rz', [0]], ['h', [0]], ['rz', [0]], ['h', [0]], ['measure', [0], [0]], ['rz', [0]]]], [8, [8]]]], [['regression: random schedule 12', [1, 2, [['rz', [0]], ['rz', [0]], ['barrier', []], ['rz', [0]], ['id', [0]], ['barrier', [0]], ['x', [0]], ['h', [0]]]], [5, [5]]], ['regression: random schedule 14', [4, 1, [['cx', [0, 3]], ['x', [0]], ['cx', [0, 2]], ['cx', [2, 3]], ['x', [1], 'if', 0], ['cx', [3, 0]], ['cx', [1, 2]], ['id', [0]], ['barrier', [2]]]], [5, [5, 5, 5, 5]]], ['regression: random schedule 16', [3, 1, [['x', [2], 'if', 0], ['barrier', [0, 1, 2]], ['cx', [1, 2]], ['cx', [0, 1]], ['h', [0]], ['measure', [1], [0]], ['measure', [2], [0]]]], [5, [4, 4, 5]]], ['control: random schedule 10', [4, 1, [['id', [2]]]], [0, [0, 0, 0, 0]]], ['control: random schedule 13', [4, 2, [['cx', [3, 2]], ['x', [3]], ['ccx', [3, 1, 0]], ['ccx', [1, 0, 2]], ['h', [0]]]], [5, [5, 4, 4, 3]]], ['control: random schedule 18', [1, 2, [['x', [0]], ['x', [0]], ['h', [0]], ['rz', [0]], ['rz', [0]], ['x', [0]]]], [6, [6]]], ['control: random schedule 19', [1, 2, [['x', [0]]]], [1, [1]]]], [['regression: random schedule 16', [3, 1, [['x', [2], 'if', 0], ['barrier', [0, 1, 2]], ['cx', [1, 2]], ['cx', [0, 1]], ['h', [0]], ['measure', [1], [0]], ['measure', [2], [0]]]], [5, [4, 4, 5]]], ['regression: random schedule 17', [2, 1, [['barrier', [1]], ['rz', [1]], ['cx', [1, 0]], ['cx', [1, 0]], ['x', [1]], ['cx', [0, 1]], ['measure', [1], [0]], ['h', [0]], ['barrier', [0, 1]]]], [6, [6, 6]]], ['regression: random schedule 30', [4, 2, [['cx', [2, 1]], ['barrier', [0, 1, 2, 3]], ['cx', [1, 0]]]], [2, [2, 2, 1, 1]]], ['control: random schedule 20', [4, 2, [['x', [3], 'if', 1], ['h', [2]], ['cx', [2, 1]], ['rz', [1]]]], [3, [0, 3, 2, 1]]], ['control: random schedule 22', [1, 1, [['measure', [0], [0]], ['measure', [0], [0]], ['x', [0]], ['h', [0]], ['rz', [0]], ['rz', [0]], ['rz', [0]], ['measure', [0], [0]]]], [8, [8]]], ['control: random schedule 26', [2, 2, [['measure', [0], [0]], ['x', [1], 'if', 0], ['measure', [0], [0]], ['cx', [0, 1]], ['h', [1]], ['rz', [1]]]], [6, [4, 6]]], ['control: random schedule 27', [2, 1, [['rz', [0]], ['cx', [1, 0]], ['x', [1]], ['h', [1]], ['x', [0], 'if', 0], ['h', [1]], ['h', [0]]]], [5, [4, 5]]]]]
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:
Adding a barrier to a circuit increases its reported depth by one.

Input [nq, nc, ops]; ops are [name, qubits], ["measure", [q], [c]], ["g", [q], "if", c] (classically conditioned), ["barrier", qubits] (empty list = all qubits) and ["id", [q]]. ASAP layering: each op lands one layer after the latest of its qubits and any clbit it reads or writes, and sets those levels; barriers align the listed qubits to their maximum without adding a layer; id costs nothing. Return [depth, qubit levels].

split: open-access


prompt:
A CNOT against the native direction is emitted unchanged and would be rejected by the device.

Input [edges, ops]; edges are directed native CNOT pairs [c, t]. Each ["cx", c, t] is kept if [c, t] is native, else rewritten as h c, h t, cx t c, h c, h t if [t, c] is native, else the result is ["unroutable", op index]; c == t gives ["invalid", op index]. Other ops pass through. A final stack pass cancels an ["h", q] against an identical immediately preceding ["h", q].

split: open-access


prompt:
A reversed CNOT is emitted as h c, h t, cx c t, h c, h t, still in the non-native direction.

Input [edges, ops]; edges are directed native CNOT pairs [c, t]. Each ["cx", c, t] is kept if [c, t] is native, else rewritten as h c, h t, cx t c, h c, h t if [t, c] is native, else the result is ["unroutable", op index]; c == t gives ["invalid", op index]. Other ops pass through. A final stack pass cancels an ["h", q] against an identical immediately preceding ["h", q].

split: open-access


prompt:
cx 2 2 is reported as ["unroutable", i] instead of ["invalid", i], hiding a malformed circuit behind a hardware message.

Input [edges, ops]; edges are directed native CNOT pairs [c, t]. Each ["cx", c, t] is kept if [c, t] is native, else rewritten as h c, h t, cx t c, h c, h t if [t, c] is native, else the result is ["unroutable", op index]; c == t gives ["invalid", op index]. Other ops pass through. A final stack pass cancels an ["h", q] against an identical immediately preceding ["h", q].

split: open-access


prompt:
h 0 followed by h 1 is deleted entirely.

Input [edges, ops]; edges are directed native CNOT pairs [c, t]. Each ["cx", c, t] is kept if [c, t] is native, else rewritten as h c, h t, cx t c, h c, h t if [t, c] is native, else the result is ["unroutable", op index]; c == t gives ["invalid", op index]. Other ops pass through. A final stack pass cancels an ["h", q] against an identical immediately preceding ["h", q].

split: open-access


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

N = 1
observations = []
def solve(x):
    edges, ops = x
    allowed = {(a, b) for a, b in edges}
    out = []
    for idx, op in enumerate(ops):
        if op[0] != 'cx':
            out.append(list(op))
            continue
        c, t = op[1], op[2]
        if c == t:
            return ['invalid', idx]
        if (c, t) in allowed:
            out.append(['cx', c, t])
        elif (t, c) in allowed:
            out += [['h', c], ['h', t], ['cx', t, c], ['h', c], ['h', t]]
        else:
            return ['unroutable', len(out)]
    res = []
    for op in out:
        if op[0] == 'h' and res and res[-1] == op:
            res.pop()
        else:
            res.append(op)
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: random coupling 20', [[[1, 0], [3, 2], [0, 2]], [['cx', 2, 3], ['cx', 0, 3], ['cx', 2, 3]]], ['unroutable', 1]], ['regression: random coupling 36', [[[0, 2], [2, 1], [1, 0]], [['h', 0], ['cx', 0, 1], ['cx', 0, 3], ['x', 0], ['h', 1]]], ['unroutable', 2]], ['repair check: unroutable pair', [[[0, 1], [1, 2], [2, 3]], [['h', 1], ['cx', 0, 2]]], ['unroutable', 1]], ['control: native direction', [[[0, 1], [1, 2], [2, 3]], [['cx', 0, 1]]], [['cx', 0, 1]]], ['control: reversed direction', [[[0, 1], [1, 2], [2, 3]], [['cx', 1, 0]]], [['h', 1], ['h', 0], ['cx', 0, 1], ['h', 1], ['h', 0]]], ['control: bidirectional edge', [[[0, 1], [1, 0]], [['cx', 1, 0]]], [['cx', 1, 0]]], ['control: self loop', [[[0, 1], [1, 2], [2, 3]], [['h', 0], ['cx', 2, 2]]], ['invalid', 1]]], [['regression: random coupling 50', [[[1, 2], [0, 1], [0, 2], [2, 3]], [['cx', 2, 0], ['cx', 3, 1], ['h', 0], ['h', 1], ['x', 0]]], ['unroutable', 1]], ['regression: random coupling 20', [[[1, 0], [3, 2], [0, 2]], [['cx', 2, 3], ['cx', 0, 3], ['cx', 2, 3]]], ['unroutable', 1]], ['repair check: random coupling 3', [[[1, 0], [2, 3]], [['cx', 1, 2], ['h', 1], ['x', 2]]], ['unroutable', 0]], ['control: hadamards cancel', [[[0, 1], [1, 2], [2, 3]], [['h', 0], ['h', 0], ['x', 1]]], [['x', 1]]], ['control: hadamards on different qubits', [[[0, 1], [1, 2], [2, 3]], [['h', 0], ['h', 1]]], [['h', 0], ['h', 1]]], ['control: flip then h cancels', [[[0, 1], [1, 2], [2, 3]], [['cx', 1, 0], ['h', 0]]], [['h', 1], ['h', 0], ['cx', 0, 1], ['h', 1]]], ['control: flip then h on target cancels', [[[0, 1], [1, 2], [2, 3]], [['cx', 1, 0], ['h', 1], ['cx', 0, 1]]], [['h', 1], ['h', 0], ['cx', 0, 1], ['h', 1], ['h', 0], ['h', 1], ['cx', 0, 1]]]], [['regression: random coupling 46', [[[3, 2], [2, 1], [1, 2]], [['cx', 2, 3], ['cx', 3, 0]]], ['unroutable', 1]], ['regression: random coupling 50', [[[1, 2], [0, 1], [0, 2], [2, 3]], [['cx', 2, 0], ['cx', 3, 1], ['h', 0], ['h', 1], ['x', 0]]], ['unroutable', 1]], ['repair check: random coupling 5', [[[3, 2], [0, 2], [2, 3], [1, 2]], [['cx', 1, 0], ['h', 3], ['h', 0], ['cx', 0, 3]]], ['unroutable', 0]], ['control: random coupling 1', [[[2, 3], [3, 2], [0, 1], [0, 2]], [['h', 1]]], [['h', 1]]], ['control: random coupling 2', [[[0, 2], [2, 3], [2, 1]], [['h', 3]]], [['h', 3]]], ['control: random coupling 8', [[[2, 1], [1, 2], [3, 2]], [['x', 0], ['h', 3]]], [['x', 0], ['h', 3]]], ['control: random coupling 9', [[[0, 2], [0, 1], [1, 2], [3, 2]], [['h', 1], ['cx', 0, 2]]], [['h', 1], ['cx', 0, 2]]]], [['regression: random coupling 36', [[[0, 2], [2, 1], [1, 0]], [['h', 0], ['cx', 0, 1], ['cx', 0, 3], ['x', 0], ['h', 1]]], ['unroutable', 2]], ['regression: random coupling 46', [[[3, 2], [2, 1], [1, 2]], [['cx', 2, 3], ['cx', 3, 0]]], ['unroutable', 1]], ['repair check: random coupling 7', [[[0, 1], [2, 3], [2, 1], [1, 2]], [['cx', 1, 3]]], ['unroutable', 0]], ['control: random coupling 11', [[[2, 3], [1, 2], [3, 2], [0, 2]], [['cx', 2, 3], ['cx', 0, 2], ['h', 2], ['cx', 1, 1], ['h', 0]]], ['invalid', 3]], ['control: random coupling 16', [[[1, 2], [2, 3], [0, 2]], [['x', 0], ['cx', 0, 2], ['x', 1]]], [['x', 0], ['cx', 0, 2], ['x', 1]]], ['control: random coupling 17', [[[0, 1], [2, 1], [1, 2], [2, 3], [3, 2]], [['cx', 2, 3], ['h', 3], ['x', 0], ['h', 2]]], [['cx', 2, 3], ['h', 3], ['x', 0], ['h', 2]]], ['control: random coupling 25', [[[0, 2], [2, 1], [0, 1], [2, 3], [1, 2]], [['cx', 1, 0], ['cx', 0, 2], ['x', 1], ['x', 3], ['h', 3]]], [['h', 1], ['h', 0], ['cx', 0, 1], ['h', 1], ['h', 0], ['cx', 0, 2], ['x', 1], ['x', 3], ['h', 3]]]], [['regression: random coupling 20', [[[1, 0], [3, 2], [0, 2]], [['cx', 2, 3], ['cx', 0, 3], ['cx', 2, 3]]], ['unroutable', 1]], ['regression: random coupling 36', [[[0, 2], [2, 1], [1, 0]], [['h', 0], ['cx', 0, 1], ['cx', 0, 3], ['x', 0], ['h', 1]]], ['unroutable', 2]], ['repair check: random coupling 12', [[[0, 2], [3, 2]], [['x', 2], ['cx', 3, 1], ['h', 2], ['h', 3]]], ['unroutable', 1]], ['control: random coupling 26', [[[1, 0], [0, 1]], [['x', 3]]], [['x', 3]]], ['control: random coupling 27', [[[0, 1], [1, 0], [2, 3], [3, 2]], [['cx', 2, 3], ['h', 2], ['cx', 2, 3]]], [['cx', 2, 3], ['h', 2], ['cx', 2, 3]]], ['control: random coupling 31', [[[1, 2], [1, 0], [0, 1], [0, 2]], [['cx', 1, 1]]], ['invalid', 0]], ['control: random coupling 32', [[[3, 2], [0, 2], [1, 2]], [['h', 0]]], [['h', 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

N = 1
observations = []
def solve(x):
    edges, ops = x
    allowed = {(a, b) for a, b in edges}
    out = []
    for idx, op in enumerate(ops):
        if op[0] != 'cx':
            out.append(list(op))
            continue
        c, t = op[1], op[2]
        if c == t:
            return ['invalid', idx]
        if (c, t) in allowed:
            out.append(['cx', c, t])
        elif (t, c) in allowed:
            out += [['h', c], ['h', t], ['cx', t, c], ['h', c], ['h', t]]
        else:
            return ['unroutable', idx + 1]
    res = []
    for op in out:
        if op[0] == 'h' and res and res[-1] == op:
            res.pop()
        else:
            res.append(op)
    return res
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: random coupling 20', [[[1, 0], [3, 2], [0, 2]], [['cx', 2, 3], ['cx', 0, 3], ['cx', 2, 3]]], ['unroutable', 1]], ['regression: random coupling 36', [[[0, 2], [2, 1], [1, 0]], [['h', 0], ['cx', 0, 1], ['cx', 0, 3], ['x', 0], ['h', 1]]], ['unroutable', 2]], ['repair check: unroutable pair', [[[0, 1], [1, 2], [2, 3]], [['h', 1], ['cx', 0, 2]]], ['unroutable', 1]], ['control: native direction', [[[0, 1], [1, 2], [2, 3]], [['cx', 0, 1]]], [['cx', 0, 1]]], ['control: reversed direction', [[[0, 1], [1, 2], [2, 3]], [['cx', 1, 0]]], [['h', 1], ['h', 0], ['cx', 0, 1], ['h', 1], ['h', 0]]], ['control: bidirectional edge', [[[0, 1], [1, 0]], [['cx', 1, 0]]], [['cx', 1, 0]]], ['control: self loop', [[[0, 1], [1, 2], [2, 3]], [['h', 0], ['cx', 2, 2]]], ['invalid', 1]]], [['regression: random coupling 50', [[[1, 2], [0, 1], [0, 2], [2, 3]], [['cx', 2, 0], ['cx', 3, 1], ['h', 0], ['h', 1], ['x', 0]]], ['unroutable', 1]], ['regression: random coupling 20', [[[1, 0], [3, 2], [0, 2]], [['cx', 2, 3], ['cx', 0, 3], ['cx', 2, 3]]], ['unroutable', 1]], ['repair check: random coupling 3', [[[1, 0], [2, 3]], [['cx', 1, 2], ['h', 1], ['x', 2]]], ['unroutable', 0]], ['control: hadamards cancel', [[[0, 1], [1, 2], [2, 3]], [['h', 0], ['h', 0], ['x', 1]]], [['x', 1]]], ['control: hadamards on different qubits', [[[0, 1], [1, 2], [2, 3]], [['h', 0], ['h', 1]]], [['h', 0], ['h', 1]]], ['control: flip then h cancels', [[[0, 1], [1, 2], [2, 3]], [['cx', 1, 0], ['h', 0]]], [['h', 1], ['h', 0], ['cx', 0, 1], ['h', 1]]], ['control: flip then h on target cancels', [[[0, 1], [1, 2], [2, 3]], [['cx', 1, 0], ['h', 1], ['cx', 0, 1]]], [['h', 1], ['h', 0], ['cx', 0, 1], ['h', 1], ['h', 0], ['h', 1], ['cx', 0, 1]]]], [['regression: random coupling 46', [[[3, 2], [2, 1], [1, 2]], [['cx', 2, 3], ['cx', 3, 0]]], ['unroutable', 1]], ['regression: random coupling 50', [[[1, 2], [0, 1], [0, 2], [2, 3]], [['cx', 2, 0], ['cx', 3, 1], ['h', 0], ['h', 1], ['x', 0]]], ['unroutable', 1]], ['repair check: random coupling 5', [[[3, 2], [0, 2], [2, 3], [1, 2]], [['cx', 1, 0], ['h', 3], ['h', 0], ['cx', 0, 3]]], ['unroutable', 0]], ['control: random coupling 1', [[[2, 3], [3, 2], [0, 1], [0, 2]], [['h', 1]]], [['h', 1]]], ['control: random coupling 2', [[[0, 2], [2, 3], [2, 1]], [['h', 3]]], [['h', 3]]], ['control: random coupling 8', [[[2, 1], [1, 2], [3, 2]], [['x', 0], ['h', 3]]], [['x', 0], ['h', 3]]], ['control: random coupling 9', [[[0, 2], [0, 1], [1, 2], [3, 2]], [['h', 1], ['cx', 0, 2]]], [['h', 1], ['cx', 0, 2]]]], [['regression: random coupling 36', [[[0, 2], [2, 1], [1, 0]], [['h', 0], ['cx', 0, 1], ['cx', 0, 3], ['x', 0], ['h', 1]]], ['unroutable', 2]], ['regression: random coupling 46', [[[3, 2], [2, 1], [1, 2]], [['cx', 2, 3], ['cx', 3, 0]]], ['unroutable', 1]], ['repair check: random coupling 7', [[[0, 1], [2, 3], [2, 1], [1, 2]], [['cx', 1, 3]]], ['unroutable', 0]], ['control: random coupling 11', [[[2, 3], [1, 2], [3, 2], [0, 2]], [['cx', 2, 3], ['cx', 0, 2], ['h', 2], ['cx', 1, 1], ['h', 0]]], ['invalid', 3]], ['control: random coupling 16', [[[1, 2], [2, 3], [0, 2]], [['x', 0], ['cx', 0, 2], ['x', 1]]], [['x', 0], ['cx', 0, 2], ['x', 1]]], ['control: random coupling 17', [[[0, 1], [2, 1], [1, 2], [2, 3], [3, 2]], [['cx', 2, 3], ['h', 3], ['x', 0], ['h', 2]]], [['cx', 2, 3], ['h', 3], ['x', 0], ['h', 2]]], ['control: random coupling 25', [[[0, 2], [2, 1], [0, 1], [2, 3], [1, 2]], [['cx', 1, 0], ['cx', 0, 2], ['x', 1], ['x', 3], ['h', 3]]], [['h', 1], ['h', 0], ['cx', 0, 1], ['h', 1], ['h', 0], ['cx', 0, 2], ['x', 1], ['x', 3], ['h', 3]]]], [['regression: random coupling 20', [[[1, 0], [3, 2], [0, 2]], [['cx', 2, 3], ['cx', 0, 3], ['cx', 2, 3]]], ['unroutable', 1]], ['regression: random coupling 36', [[[0, 2], [2, 1], [1, 0]], [['h', 0], ['cx', 0, 1], ['cx', 0, 3], ['x', 0], ['h', 1]]], ['unroutable', 2]], ['repair check: random coupling 12', [[[0, 2], [3, 2]], [['x', 2], ['cx', 3, 1], ['h', 2], ['h', 3]]], ['unroutable', 1]], ['control: random coupling 26', [[[1, 0], [0, 1]], [['x', 3]]], [['x', 3]]], ['control: random coupling 27', [[[0, 1], [1, 0], [2, 3], [3, 2]], [['cx', 2, 3], ['h', 2], ['cx', 2, 3]]], [['cx', 2, 3], ['h', 2], ['cx', 2, 3]]], ['control: random coupling 31', [[[1, 2], [1, 0], [0, 1], [0, 2]], [['cx', 1, 1]]], ['invalid', 0]], ['control: random coupling 32', [[[3, 2], [0, 2], [1, 2]], [['h', 0]]], [['h', 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 an unroutable gate at input position 1 the error names position 5 after an earlier flip expanded the output.

Input [edges, ops]; edges are directed native CNOT pairs [c, t]. Each ["cx", c, t] is kept if [c, t] is native, else rewritten as h c, h t, cx t c, h c, h t if [t, c] is native, else the result is ["unroutable", op index]; c == t gives ["invalid", op index]. Other ops pass through. A final stack pass cancels an ["h", q] against an identical immediately preceding ["h", q].

split: open-access


prompt:
The |+i> state is drawn at y = -1.

Input [[ar, ai], [br, bi]] for a|0> + b|1> (possibly unnormalized). Return the Bloch vector [2Re(conj(a) b), 2Im(conj(a) b), |a|^2 - |b|^2] divided by |a|^2 + |b|^2, rounded to 6 decimals, or "zero-state" when the squared norm is below 1e-12.

split: open-access


prompt:
|0> is reported with z = -1.

Input [[ar, ai], [br, bi]] for a|0> + b|1> (possibly unnormalized). Return the Bloch vector [2Re(conj(a) b), 2Im(conj(a) b), |a|^2 - |b|^2] divided by |a|^2 + |b|^2, rounded to 6 decimals, or "zero-state" when the squared norm is below 1e-12.

split: open-access


prompt:
|+> is reported at x = 0.5, inside the sphere, although it is a pure state.

Input [[ar, ai], [br, bi]] for a|0> + b|1> (possibly unnormalized). Return the Bloch vector [2Re(conj(a) b), 2Im(conj(a) b), |a|^2 - |b|^2] divided by |a|^2 + |b|^2, rounded to 6 decimals, or "zero-state" when the squared norm is below 1e-12.

split: open-access


prompt:
The unnormalized input 3|0> + 4|1> yields a vector of length 5 instead of 1.

Input [[ar, ai], [br, bi]] for a|0> + b|1> (possibly unnormalized). Return the Bloch vector [2Re(conj(a) b), 2Im(conj(a) b), |a|^2 - |b|^2] divided by |a|^2 + |b|^2, rounded to 6 decimals, or "zero-state" when the squared norm is below 1e-12.

split: open-access


prompt:
Amplitudes of order 1e-7 (numerical noise) are blown up into a unit Bloch vector instead of "zero-state".

Input [[ar, ai], [br, bi]] for a|0> + b|1> (possibly unnormalized). Return the Bloch vector [2Re(conj(a) b), 2Im(conj(a) b), |a|^2 - |b|^2] divided by |a|^2 + |b|^2, rounded to 6 decimals, or "zero-state" when the squared norm is below 1e-12.

split: open-access


prompt:
A Bell state reduces to a matrix with coherences instead of the maximally mixed I/2.

Input [n, amps, keep]; trace out every qubit except keep (0 = LSB) from the pure state and return {"rho": 2x2 matrix of [re, im] entries with rho[r][c] = sum psi_r psi_c^*, trace-normalized, "purity": sum |rho_rc|^2}, all rounded to 6 decimals.

split: open-access


prompt:
For 0.6|0> + 0.8i|1> the off-diagonal entry rho[0][1] is +0.48i instead of -0.48i (the transpose).

Input [n, amps, keep]; trace out every qubit except keep (0 = LSB) from the pure state and return {"rho": 2x2 matrix of [re, im] entries with rho[r][c] = sum psi_r psi_c^*, trace-normalized, "purity": sum |rho_rc|^2}, all rounded to 6 decimals.

split: open-access


prompt:
Keeping qubit 0 of a product state returns the other qubit reduced state.

Input [n, amps, keep]; trace out every qubit except keep (0 = LSB) from the pure state and return {"rho": 2x2 matrix of [re, im] entries with rho[r][c] = sum psi_r psi_c^*, trace-normalized, "purity": sum |rho_rc|^2}, all rounded to 6 decimals.

split: open-access


prompt:
An unnormalized GHZ input yields a reduced matrix with trace 8.

Input [n, amps, keep]; trace out every qubit except keep (0 = LSB) from the pure state and return {"rho": 2x2 matrix of [re, im] entries with rho[r][c] = sum psi_r psi_c^*, trace-normalized, "purity": sum |rho_rc|^2}, all rounded to 6 decimals.

split: open-access


prompt:
A pure product qubit such as |+> reports purity 0.5 instead of 1.

Input [n, amps, keep]; trace out every qubit except keep (0 = LSB) from the pure state and return {"rho": 2x2 matrix of [re, im] entries with rho[r][c] = sum psi_r psi_c^*, trace-normalized, "purity": sum |rho_rc|^2}, all rounded to 6 decimals.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    n, weights, us = x
    if len(weights) != 1 << n:
        return 'bad-length'
    if any(w < 0 for w in weights):
        return 'negative-weight'
    total = sum(weights)
    if total == 0:
        return 'no-support'
    counts = {}
    for idx, s in enumerate(us):
        u = Fraction(s)
        if u < 0 or u >= 1:
            return ['bad-uniform', idx]
        target = u * total
        cum = 0
        for i, w in enumerate(weights):
            cum += w
            if target <= cum:
                break
        key = format(i, '0%db' % n)
        counts[key] = counts.get(key, 0) + 1
    return counts
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['regression: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['regression: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support']], [['regression: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}], ['regression: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['regression: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}], ['control: bad length', [2, [1, 1], ['0.1']], 'bad-length'], ['control: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}], ['control: random shots 4', [2, [0, 2, 2, 2], ['0.248', '3/6', '0.126', '0.765', '0.379']], {'01': 2, '10': 2, '11': 1}]], [['regression: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['regression: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['regression: random shots 14', [3, [0, 1, 2, 0, 0, 3, 1, 0], ['0.559', '6/7', '2/7', '0.29', '0.711', '5/7']], {'101': 3, '110': 1, '010': 2}], ['control: random shots 5', [3, [0, 0, 0, 0, 5, 5, 0, 3], ['8/13', '0.522', '0.318', '0.507', '0.577', '2/13']], {'101': 4, '100': 2}], ['control: random shots 9', [3, [0, 3, 1, 1, 5, 2, 0, 1], ['0.993', '8/13']], {'111': 1, '100': 1}], ['control: random shots 10', [3, [3, 0, 1, 2, 0, 3, 0, 5], ['10/14', '0.687', '0.608']], {'111': 2, '101': 1}], ['control: random shots 11', [2, [1, 2, 0, 2], ['0.643', '0.519', '0.64', '0.875']], {'11': 3, '01': 1}]], [['regression: random shots 15', [1, [0, 1], ['0/1', '0.769', '0.573', '0.347', '0.401', '0/1']], {'1': 6}], ['regression: random shots 16', [1, [0, 1], ['0.929', '0.975', '0.277', '0/1', '0.216']], {'1': 5}], ['regression: random shots 21', [1, [1, 3], ['1/4', '0.282', '0.17']], {'1': 2, '0': 1}], ['control: random shots 12', [3, [5, 5, 5, 5, 1, 3, 0, 0], ['14/24', '0/24', '0.202']], {'010': 1, '000': 2}], ['control: random shots 13', [1, [3, 0], ['0.586', '1/3']], {'0': 2}], ['control: random shots 17', [1, [2, 1], ['0.153', '0.906', '0/3', '0.007', '1/3']], {'0': 4, '1': 1}], ['control: random shots 18', [1, [5, 3], ['4/8', '4/8', '0.129', '0.153', '1/8', '0.326']], {'0': 6}]], [['regression: random shots 30', [3, [0, 1, 3, 3, 0, 2, 0, 0], ['0/9', '0.411', '7/9', '0.796', '0.678', '0/9']], {'001': 2, '010': 1, '101': 2, '011': 1}], ['regression: random shots 35', [2, [2, 1, 0, 0], ['1/3', '0.652', '0.988', '2/3', '0.769', '1/3']], {'00': 3, '01': 3}], ['regression: random shots 39', [1, [3, 5], ['0.57', '5/8', '0.242', '0.174', '3/8']], {'1': 3, '0': 2}], ['control: random shots 19', [1, [3, 2], ['0.826', '0.88']], {'1': 2}], ['control: random shots 20', [1, [5, 1], ['0.272', '0/6', '0.203', '0/6']], {'0': 4}], ['control: random shots 22', [1, [0, 5], ['0.608', '1/5', '2/5']], {'1': 3}], ['control: random shots 23', [1, [2, 0], ['1/2', '0.071', '0/2', '0/2', '0.086', '0.733']], {'0': 6}]]]
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
from fractions import Fraction
N = 1
observations = []
def solve(x):
    n, weights, us = x
    if len(weights) != 1 << n:
        return 'bad-length'
    if any(w < 0 for w in weights):
        return 'negative-weight'
    total = sum(weights)
    if total == 0:
        return 'no-support'
    counts = {}
    for idx, s in enumerate(us):
        u = Fraction(s)
        if u < 0 or u >= 1:
            return ['bad-uniform', idx]
        target = u * total
        cum = 0
        for i, w in enumerate(weights):
            cum += w
            if target <= cum and w > 0:
                break
        key = format(i, '0%db' % n)
        counts[key] = counts.get(key, 0) + 1
    return counts
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['regression: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['regression: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support']], [['regression: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}], ['regression: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['regression: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}], ['control: bad length', [2, [1, 1], ['0.1']], 'bad-length'], ['control: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}], ['control: random shots 4', [2, [0, 2, 2, 2], ['0.248', '3/6', '0.126', '0.765', '0.379']], {'01': 2, '10': 2, '11': 1}]], [['regression: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['regression: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['regression: random shots 14', [3, [0, 1, 2, 0, 0, 3, 1, 0], ['0.559', '6/7', '2/7', '0.29', '0.711', '5/7']], {'101': 3, '110': 1, '010': 2}], ['control: random shots 5', [3, [0, 0, 0, 0, 5, 5, 0, 3], ['8/13', '0.522', '0.318', '0.507', '0.577', '2/13']], {'101': 4, '100': 2}], ['control: random shots 9', [3, [0, 3, 1, 1, 5, 2, 0, 1], ['0.993', '8/13']], {'111': 1, '100': 1}], ['control: random shots 10', [3, [3, 0, 1, 2, 0, 3, 0, 5], ['10/14', '0.687', '0.608']], {'111': 2, '101': 1}], ['control: random shots 11', [2, [1, 2, 0, 2], ['0.643', '0.519', '0.64', '0.875']], {'11': 3, '01': 1}]], [['regression: random shots 15', [1, [0, 1], ['0/1', '0.769', '0.573', '0.347', '0.401', '0/1']], {'1': 6}], ['regression: random shots 16', [1, [0, 1], ['0.929', '0.975', '0.277', '0/1', '0.216']], {'1': 5}], ['regression: random shots 21', [1, [1, 3], ['1/4', '0.282', '0.17']], {'1': 2, '0': 1}], ['control: random shots 12', [3, [5, 5, 5, 5, 1, 3, 0, 0], ['14/24', '0/24', '0.202']], {'010': 1, '000': 2}], ['control: random shots 13', [1, [3, 0], ['0.586', '1/3']], {'0': 2}], ['control: random shots 17', [1, [2, 1], ['0.153', '0.906', '0/3', '0.007', '1/3']], {'0': 4, '1': 1}], ['control: random shots 18', [1, [5, 3], ['4/8', '4/8', '0.129', '0.153', '1/8', '0.326']], {'0': 6}]], [['regression: random shots 30', [3, [0, 1, 3, 3, 0, 2, 0, 0], ['0/9', '0.411', '7/9', '0.796', '0.678', '0/9']], {'001': 2, '010': 1, '101': 2, '011': 1}], ['regression: random shots 35', [2, [2, 1, 0, 0], ['1/3', '0.652', '0.988', '2/3', '0.769', '1/3']], {'00': 3, '01': 3}], ['regression: random shots 39', [1, [3, 5], ['0.57', '5/8', '0.242', '0.174', '3/8']], {'1': 3, '0': 2}], ['control: random shots 19', [1, [3, 2], ['0.826', '0.88']], {'1': 2}], ['control: random shots 20', [1, [5, 1], ['0.272', '0/6', '0.203', '0/6']], {'0': 4}], ['control: random shots 22', [1, [0, 5], ['0.608', '1/5', '2/5']], {'1': 3}], ['control: random shots 23', [1, [2, 0], ['1/2', '0.071', '0/2', '0/2', '0.086', '0.733']], {'0': 6}]]]
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:
u = 0 selects an outcome with zero weight, and u exactly on a cumulative edge lands in the lower bucket.

Input [n, weights, uniforms]; weights are nonnegative integers for basis indices 0..2**n-1 and uniforms are exact decimal or fraction strings in [0, 1). Each uniform u selects the first index i with u * total < cumulative weight through i. Return counts {bitstring: count} with qubit n-1 leftmost. Errors: "bad-length", "negative-weight", "no-support", ["bad-uniform", position].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    n, weights, us = x
    if len(weights) != 1 << n:
        return 'bad-length'
    if any(w < 0 for w in weights):
        return 'negative-weight'
    total = sum(weights)
    if total == 0:
        return 'no-support'
    counts = {}
    for idx, s in enumerate(us):
        u = Fraction(s)
        if u < 0 or u >= 1:
            return ['bad-uniform', idx]
        target = u * total
        cum = 0
        for i, w in enumerate(weights):
            cum += w
            if target < cum:
                break
        key = format(i, '0%db' % n)[::-1]
        counts[key] = counts.get(key, 0) + 1
    return counts
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}], ['regression: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}], ['repair check: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['control: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight']], [['regression: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['regression: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['repair check: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support'], ['control: bad length', [2, [1, 1], ['0.1']], 'bad-length'], ['control: random shots 0', [1, [0, 1], ['0/1', '0.952', '0/1']], {'1': 3}], ['control: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}]], [['regression: random shots 11', [2, [1, 2, 0, 2], ['0.643', '0.519', '0.64', '0.875']], {'11': 3, '01': 1}], ['regression: random shots 14', [3, [0, 1, 2, 0, 0, 3, 1, 0], ['0.559', '6/7', '2/7', '0.29', '0.711', '5/7']], {'101': 3, '110': 1, '010': 2}], ['repair check: random shots 12', [3, [5, 5, 5, 5, 1, 3, 0, 0], ['14/24', '0/24', '0.202']], {'010': 1, '000': 2}], ['control: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['control: random shots 10', [3, [3, 0, 1, 2, 0, 3, 0, 5], ['10/14', '0.687', '0.608']], {'111': 2, '101': 1}], ['control: random shots 13', [1, [3, 0], ['0.586', '1/3']], {'0': 2}], ['control: random shots 15', [1, [0, 1], ['0/1', '0.769', '0.573', '0.347', '0.401', '0/1']], {'1': 6}]], [['regression: random shots 25', [3, [0, 0, 3, 3, 0, 0, 0, 3], ['5/9', '0.444', '0.463']], {'011': 3}], ['regression: random shots 26', [3, [2, 1, 1, 2, 0, 0, 5, 5], ['14/16', '0.295']], {'111': 1, '011': 1}], ['regression: random shots 14', [3, [0, 1, 2, 0, 0, 3, 1, 0], ['0.559', '6/7', '2/7', '0.29', '0.711', '5/7']], {'101': 3, '110': 1, '010': 2}], ['control: random shots 16', [1, [0, 1], ['0.929', '0.975', '0.277', '0/1', '0.216']], {'1': 5}], ['control: random shots 17', [1, [2, 1], ['0.153', '0.906', '0/3', '0.007', '1/3']], {'0': 4, '1': 1}], ['control: random shots 18', [1, [5, 3], ['4/8', '4/8', '0.129', '0.153', '1/8', '0.326']], {'0': 6}], ['control: random shots 19', [1, [3, 2], ['0.826', '0.88']], {'1': 2}]], [['regression: random shots 30', [3, [0, 1, 3, 3, 0, 2, 0, 0], ['0/9', '0.411', '7/9', '0.796', '0.678', '0/9']], {'001': 2, '010': 1, '101': 2, '011': 1}], ['regression: random shots 31', [2, [3, 2, 0, 1], ['2/6', '0.726', '2/6', '0/6', '0.328', '0.558']], {'00': 4, '01': 2}], ['regression: random shots 25', [3, [0, 0, 3, 3, 0, 0, 0, 3], ['5/9', '0.444', '0.463']], {'011': 3}], ['control: random shots 20', [1, [5, 1], ['0.272', '0/6', '0.203', '0/6']], {'0': 4}], ['control: random shots 21', [1, [1, 3], ['1/4', '0.282', '0.17']], {'1': 2, '0': 1}], ['control: random shots 22', [1, [0, 5], ['0.608', '1/5', '2/5']], {'1': 3}], ['control: random shots 23', [1, [2, 0], ['1/2', '0.071', '0/2', '0/2', '0.086', '0.733']], {'0': 6}]]]
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
from fractions import Fraction
N = 1
observations = []
def solve(x):
    n, weights, us = x
    if len(weights) != 1 << n:
        return 'bad-length'
    if any(w < 0 for w in weights):
        return 'negative-weight'
    total = sum(weights)
    if total == 0:
        return 'no-support'
    counts = {}
    for idx, s in enumerate(us):
        u = Fraction(s)
        if u < 0 or u >= 1:
            return ['bad-uniform', idx]
        target = u * total
        cum = 0
        for i, w in enumerate(weights):
            cum += w
            if target < cum:
                break
        key = format(i, 'b')
        counts[key] = counts.get(key, 0) + 1
    return counts
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}], ['regression: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}], ['repair check: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['control: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight']], [['regression: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['regression: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['repair check: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support'], ['control: bad length', [2, [1, 1], ['0.1']], 'bad-length'], ['control: random shots 0', [1, [0, 1], ['0/1', '0.952', '0/1']], {'1': 3}], ['control: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}]], [['regression: random shots 11', [2, [1, 2, 0, 2], ['0.643', '0.519', '0.64', '0.875']], {'11': 3, '01': 1}], ['regression: random shots 14', [3, [0, 1, 2, 0, 0, 3, 1, 0], ['0.559', '6/7', '2/7', '0.29', '0.711', '5/7']], {'101': 3, '110': 1, '010': 2}], ['repair check: random shots 12', [3, [5, 5, 5, 5, 1, 3, 0, 0], ['14/24', '0/24', '0.202']], {'010': 1, '000': 2}], ['control: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['control: random shots 10', [3, [3, 0, 1, 2, 0, 3, 0, 5], ['10/14', '0.687', '0.608']], {'111': 2, '101': 1}], ['control: random shots 13', [1, [3, 0], ['0.586', '1/3']], {'0': 2}], ['control: random shots 15', [1, [0, 1], ['0/1', '0.769', '0.573', '0.347', '0.401', '0/1']], {'1': 6}]], [['regression: random shots 25', [3, [0, 0, 3, 3, 0, 0, 0, 3], ['5/9', '0.444', '0.463']], {'011': 3}], ['regression: random shots 26', [3, [2, 1, 1, 2, 0, 0, 5, 5], ['14/16', '0.295']], {'111': 1, '011': 1}], ['regression: random shots 14', [3, [0, 1, 2, 0, 0, 3, 1, 0], ['0.559', '6/7', '2/7', '0.29', '0.711', '5/7']], {'101': 3, '110': 1, '010': 2}], ['control: random shots 16', [1, [0, 1], ['0.929', '0.975', '0.277', '0/1', '0.216']], {'1': 5}], ['control: random shots 17', [1, [2, 1], ['0.153', '0.906', '0/3', '0.007', '1/3']], {'0': 4, '1': 1}], ['control: random shots 18', [1, [5, 3], ['4/8', '4/8', '0.129', '0.153', '1/8', '0.326']], {'0': 6}], ['control: random shots 19', [1, [3, 2], ['0.826', '0.88']], {'1': 2}]], [['regression: random shots 30', [3, [0, 1, 3, 3, 0, 2, 0, 0], ['0/9', '0.411', '7/9', '0.796', '0.678', '0/9']], {'001': 2, '010': 1, '101': 2, '011': 1}], ['regression: random shots 31', [2, [3, 2, 0, 1], ['2/6', '0.726', '2/6', '0/6', '0.328', '0.558']], {'00': 4, '01': 2}], ['regression: random shots 25', [3, [0, 0, 3, 3, 0, 0, 0, 3], ['5/9', '0.444', '0.463']], {'011': 3}], ['control: random shots 20', [1, [5, 1], ['0.272', '0/6', '0.203', '0/6']], {'0': 4}], ['control: random shots 21', [1, [1, 3], ['1/4', '0.282', '0.17']], {'1': 2, '0': 1}], ['control: random shots 22', [1, [0, 5], ['0.608', '1/5', '2/5']], {'1': 3}], ['control: random shots 23', [1, [2, 0], ['1/2', '0.071', '0/2', '0/2', '0.086', '0.733']], {'0': 6}]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
An outcome on basis index 1 of two qubits is counted as "10" instead of "01".

Input [n, weights, uniforms]; weights are nonnegative integers for basis indices 0..2**n-1 and uniforms are exact decimal or fraction strings in [0, 1). Each uniform u selects the first index i with u * total < cumulative weight through i. Return counts {bitstring: count} with qubit n-1 leftmost. Errors: "bad-length", "negative-weight", "no-support", ["bad-uniform", position].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    n, weights, us = x
    if len(weights) != 1 << n:
        return 'bad-length'
    if any(w < 0 for w in weights):
        return 'negative-weight'
    total = sum(weights)
    if total == 0:
        return 'no-support'
    counts = {}
    for idx, s in enumerate(us):
        u = Fraction(s)
        if u < 0 or u > 1:
            return ['bad-uniform', idx]
        target = u * total
        cum = 0
        for i, w in enumerate(weights):
            cum += w
            if target < cum:
                break
        key = format(i, '0%db' % n)
        counts[key] = counts.get(key, 0) + 1
    return counts
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['control: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support']], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}], ['control: bad length', [2, [1, 1], ['0.1']], 'bad-length'], ['control: random shots 0', [1, [0, 1], ['0/1', '0.952', '0/1']], {'1': 3}], ['control: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}], ['control: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['control: random shots 4', [2, [0, 2, 2, 2], ['0.248', '3/6', '0.126', '0.765', '0.379']], {'01': 2, '10': 2, '11': 1}], ['control: random shots 5', [3, [0, 0, 0, 0, 5, 5, 0, 3], ['8/13', '0.522', '0.318', '0.507', '0.577', '2/13']], {'101': 4, '100': 2}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['control: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['control: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['control: random shots 9', [3, [0, 3, 1, 1, 5, 2, 0, 1], ['0.993', '8/13']], {'111': 1, '100': 1}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: random shots 10', [3, [3, 0, 1, 2, 0, 3, 0, 5], ['10/14', '0.687', '0.608']], {'111': 2, '101': 1}], ['control: random shots 11', [2, [1, 2, 0, 2], ['0.643', '0.519', '0.64', '0.875']], {'11': 3, '01': 1}], ['control: random shots 12', [3, [5, 5, 5, 5, 1, 3, 0, 0], ['14/24', '0/24', '0.202']], {'010': 1, '000': 2}], ['control: random shots 13', [1, [3, 0], ['0.586', '1/3']], {'0': 2}]]]
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
from fractions import Fraction
N = 1
observations = []
def solve(x):
    n, weights, us = x
    if len(weights) != 1 << n:
        return 'bad-length'
    if any(w < 0 for w in weights):
        return 'negative-weight'
    total = sum(weights)
    if total == 0:
        return 'no-support'
    counts = {}
    for idx, s in enumerate(us):
        u = Fraction(s)
        u = u % 1
        target = u * total
        cum = 0
        for i, w in enumerate(weights):
            cum += w
            if target < cum:
                break
        key = format(i, '0%db' % n)
        counts[key] = counts.get(key, 0) + 1
    return counts
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['control: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support']], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}], ['control: bad length', [2, [1, 1], ['0.1']], 'bad-length'], ['control: random shots 0', [1, [0, 1], ['0/1', '0.952', '0/1']], {'1': 3}], ['control: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}], ['control: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['control: random shots 4', [2, [0, 2, 2, 2], ['0.248', '3/6', '0.126', '0.765', '0.379']], {'01': 2, '10': 2, '11': 1}], ['control: random shots 5', [3, [0, 0, 0, 0, 5, 5, 0, 3], ['8/13', '0.522', '0.318', '0.507', '0.577', '2/13']], {'101': 4, '100': 2}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['control: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['control: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['control: random shots 9', [3, [0, 3, 1, 1, 5, 2, 0, 1], ['0.993', '8/13']], {'111': 1, '100': 1}]], [['regression: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['repair check: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: random shots 10', [3, [3, 0, 1, 2, 0, 3, 0, 5], ['10/14', '0.687', '0.608']], {'111': 2, '101': 1}], ['control: random shots 11', [2, [1, 2, 0, 2], ['0.643', '0.519', '0.64', '0.875']], {'11': 3, '01': 1}], ['control: random shots 12', [3, [5, 5, 5, 5, 1, 3, 0, 0], ['14/24', '0/24', '0.202']], {'010': 1, '000': 2}], ['control: random shots 13', [1, [3, 0], ['0.586', '1/3']], {'0': 2}]]]
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 uniform of exactly 1 is silently mapped to the last index, even when its weight is zero, instead of being rejected.

Input [n, weights, uniforms]; weights are nonnegative integers for basis indices 0..2**n-1 and uniforms are exact decimal or fraction strings in [0, 1). Each uniform u selects the first index i with u * total < cumulative weight through i. Return counts {bitstring: count} with qubit n-1 leftmost. Errors: "bad-length", "negative-weight", "no-support", ["bad-uniform", position].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    n, weights, us = x
    if len(weights) != 1 << n:
        return 'bad-length'
    total = sum(weights)
    if total == 0:
        return 'no-support'
    counts = {}
    for idx, s in enumerate(us):
        u = Fraction(s)
        if u < 0 or u >= 1:
            return ['bad-uniform', idx]
        target = u * total
        cum = 0
        for i, w in enumerate(weights):
            cum += w
            if target < cum:
                break
        key = format(i, '0%db' % n)
        counts[key] = counts.get(key, 0) + 1
    return counts
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['control: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}]], [['regression: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support'], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}], ['control: bad length', [2, [1, 1], ['0.1']], 'bad-length'], ['control: random shots 0', [1, [0, 1], ['0/1', '0.952', '0/1']], {'1': 3}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]]], [['regression: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}], ['control: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}], ['control: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['control: random shots 4', [2, [0, 2, 2, 2], ['0.248', '3/6', '0.126', '0.765', '0.379']], {'01': 2, '10': 2, '11': 1}], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]]], [['regression: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: random shots 5', [3, [0, 0, 0, 0, 5, 5, 0, 3], ['8/13', '0.522', '0.318', '0.507', '0.577', '2/13']], {'101': 4, '100': 2}], ['control: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['control: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['control: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support']], [['regression: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: random shots 9', [3, [0, 3, 1, 1, 5, 2, 0, 1], ['0.993', '8/13']], {'111': 1, '100': 1}], ['control: random shots 10', [3, [3, 0, 1, 2, 0, 3, 0, 5], ['10/14', '0.687', '0.608']], {'111': 2, '101': 1}], ['control: random shots 11', [2, [1, 2, 0, 2], ['0.643', '0.519', '0.64', '0.875']], {'11': 3, '01': 1}], ['control: random shots 12', [3, [5, 5, 5, 5, 1, 3, 0, 0], ['14/24', '0/24', '0.202']], {'010': 1, '000': 2}], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}]]]
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
from fractions import Fraction
N = 1
observations = []
def solve(x):
    n, weights, us = x
    if len(weights) != 1 << n:
        return 'bad-length'
    weights = [abs(w) for w in weights]
    total = sum(weights)
    if total == 0:
        return 'no-support'
    counts = {}
    for idx, s in enumerate(us):
        u = Fraction(s)
        if u < 0 or u >= 1:
            return ['bad-uniform', idx]
        target = u * total
        cum = 0
        for i, w in enumerate(weights):
            cum += w
            if target < cum:
                break
        key = format(i, '0%db' % n)
        counts[key] = counts.get(key, 0) + 1
    return counts
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['control: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}]], [['regression: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support'], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}], ['control: bad length', [2, [1, 1], ['0.1']], 'bad-length'], ['control: random shots 0', [1, [0, 1], ['0/1', '0.952', '0/1']], {'1': 3}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]]], [['regression: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}], ['control: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}], ['control: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['control: random shots 4', [2, [0, 2, 2, 2], ['0.248', '3/6', '0.126', '0.765', '0.379']], {'01': 2, '10': 2, '11': 1}], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]]], [['regression: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: random shots 5', [3, [0, 0, 0, 0, 5, 5, 0, 3], ['8/13', '0.522', '0.318', '0.507', '0.577', '2/13']], {'101': 4, '100': 2}], ['control: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['control: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['control: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['control: all zero weights', [1, [0, 0], ['0.5']], 'no-support']], [['regression: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: random shots 9', [3, [0, 3, 1, 1, 5, 2, 0, 1], ['0.993', '8/13']], {'111': 1, '100': 1}], ['control: random shots 10', [3, [3, 0, 1, 2, 0, 3, 0, 5], ['10/14', '0.687', '0.608']], {'111': 2, '101': 1}], ['control: random shots 11', [2, [1, 2, 0, 2], ['0.643', '0.519', '0.64', '0.875']], {'11': 3, '01': 1}], ['control: random shots 12', [3, [5, 5, 5, 5, 1, 3, 0, 0], ['14/24', '0/24', '0.202']], {'010': 1, '000': 2}], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}]]]
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:
Weights [2, -1] produce counts instead of the "negative-weight" error.

Input [n, weights, uniforms]; weights are nonnegative integers for basis indices 0..2**n-1 and uniforms are exact decimal or fraction strings in [0, 1). Each uniform u selects the first index i with u * total < cumulative weight through i. Return counts {bitstring: count} with qubit n-1 leftmost. Errors: "bad-length", "negative-weight", "no-support", ["bad-uniform", position].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
N = 1
observations = []
def solve(x):
    n, weights, us = x
    if len(weights) != 1 << n:
        return 'bad-length'
    if any(w < 0 for w in weights):
        return 'negative-weight'
    total = sum(weights)
    if not weights:
        return 'no-support'
    counts = {}
    for idx, s in enumerate(us):
        u = Fraction(s)
        if u < 0 or u >= 1:
            return ['bad-uniform', idx]
        target = u * total
        cum = 0
        for i, w in enumerate(weights):
            cum += w
            if target < cum:
                break
        key = format(i, '0%db' % n)
        counts[key] = counts.get(key, 0) + 1
    return counts
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: all zero weights', [1, [0, 0], ['0.5']], 'no-support'], ['control: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['control: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}]], [['regression: all zero weights', [1, [0, 0], ['0.5']], 'no-support'], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}], ['control: bad length', [2, [1, 1], ['0.1']], 'bad-length'], ['control: random shots 0', [1, [0, 1], ['0/1', '0.952', '0/1']], {'1': 3}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]]], [['regression: all zero weights', [1, [0, 0], ['0.5']], 'no-support'], ['control: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}], ['control: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}], ['control: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['control: random shots 4', [2, [0, 2, 2, 2], ['0.248', '3/6', '0.126', '0.765', '0.379']], {'01': 2, '10': 2, '11': 1}], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]]], [['regression: all zero weights', [1, [0, 0], ['0.5']], 'no-support'], ['control: random shots 5', [3, [0, 0, 0, 0, 5, 5, 0, 3], ['8/13', '0.522', '0.318', '0.507', '0.577', '2/13']], {'101': 4, '100': 2}], ['control: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['control: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['control: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight']], [['regression: all zero weights', [1, [0, 0], ['0.5']], 'no-support'], ['control: random shots 9', [3, [0, 3, 1, 1, 5, 2, 0, 1], ['0.993', '8/13']], {'111': 1, '100': 1}], ['control: random shots 10', [3, [3, 0, 1, 2, 0, 3, 0, 5], ['10/14', '0.687', '0.608']], {'111': 2, '101': 1}], ['control: random shots 11', [2, [1, 2, 0, 2], ['0.643', '0.519', '0.64', '0.875']], {'11': 3, '01': 1}], ['control: random shots 12', [3, [5, 5, 5, 5, 1, 3, 0, 0], ['14/24', '0/24', '0.202']], {'010': 1, '000': 2}], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}]]]
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
from fractions import Fraction
N = 1
observations = []
def solve(x):
    n, weights, us = x
    if len(weights) != 1 << n:
        return 'bad-length'
    if any(w < 0 for w in weights):
        return 'negative-weight'
    total = sum(weights)
    if total < 0:
        return 'no-support'
    counts = {}
    for idx, s in enumerate(us):
        u = Fraction(s)
        if u < 0 or u >= 1:
            return ['bad-uniform', idx]
        target = u * total
        cum = 0
        for i, w in enumerate(weights):
            cum += w
            if target < cum:
                break
        key = format(i, '0%db' % n)
        counts[key] = counts.get(key, 0) + 1
    return counts
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: all zero weights', [1, [0, 0], ['0.5']], 'no-support'], ['control: boundary uniform on cumulative edge', [1, [1, 1], ['0.5']], {'1': 1}], ['control: zero weight first outcome', [2, [0, 1, 1, 2], ['0', '0.25']], {'01': 1, '10': 1}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}]], [['regression: all zero weights', [1, [0, 0], ['0.5']], 'no-support'], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight'], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}], ['control: bad length', [2, [1, 1], ['0.1']], 'bad-length'], ['control: random shots 0', [1, [0, 1], ['0/1', '0.952', '0/1']], {'1': 3}], ['control: uniform exactly one', [1, [1, 1], ['1']], ['bad-uniform', 0]]], [['regression: all zero weights', [1, [0, 0], ['0.5']], 'no-support'], ['control: random shots 1', [3, [5, 0, 2, 0, 5, 3, 0, 1], ['9/16', '9/16']], {'100': 2}], ['control: random shots 2', [1, [0, 5], ['0.967', '0.119', '0.012', '1/5', '0.243', '0/5']], {'1': 6}], ['control: random shots 3', [1, [3, 5], ['0.916', '3/8', '0.642']], {'1': 3}], ['control: random shots 4', [2, [0, 2, 2, 2], ['0.248', '3/6', '0.126', '0.765', '0.379']], {'01': 2, '10': 2, '11': 1}], ['control: negative uniform', [1, [1, 1], ['-0.25']], ['bad-uniform', 0]]], [['regression: all zero weights', [1, [0, 0], ['0.5']], 'no-support'], ['control: random shots 5', [3, [0, 0, 0, 0, 5, 5, 0, 3], ['8/13', '0.522', '0.318', '0.507', '0.577', '2/13']], {'101': 4, '100': 2}], ['control: random shots 6', [3, [1, 1, 0, 0, 0, 3, 3, 0], ['0.597', '5/8', '0.601']], {'101': 2, '110': 1}], ['control: random shots 7', [2, [0, 1, 0, 0], ['0/1', '0.123']], {'01': 2}], ['control: random shots 8', [2, [1, 0, 1, 3], ['0.813', '2/5', '4/5', '0.149', '0.53']], {'11': 4, '00': 1}], ['control: negative weight', [1, [2, -1], ['0.5']], 'negative-weight']], [['regression: all zero weights', [1, [0, 0], ['0.5']], 'no-support'], ['control: random shots 9', [3, [0, 3, 1, 1, 5, 2, 0, 1], ['0.993', '8/13']], {'111': 1, '100': 1}], ['control: random shots 10', [3, [3, 0, 1, 2, 0, 3, 0, 5], ['10/14', '0.687', '0.608']], {'111': 2, '101': 1}], ['control: random shots 11', [2, [1, 2, 0, 2], ['0.643', '0.519', '0.64', '0.875']], {'11': 3, '01': 1}], ['control: random shots 12', [3, [5, 5, 5, 5, 1, 3, 0, 0], ['14/24', '0/24', '0.202']], {'010': 1, '000': 2}], ['control: high qubit outcome', [2, [0, 0, 1, 0], ['0.3', '0.9']], {'10': 2}]]]
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:
All-zero weights produce counts on the last outcome instead of "no-support".

Input [n, weights, uniforms]; weights are nonnegative integers for basis indices 0..2**n-1 and uniforms are exact decimal or fraction strings in [0, 1). Each uniform u selects the first index i with u * total < cumulative weight through i. Return counts {bitstring: count} with qubit n-1 leftmost. Errors: "bad-length", "negative-weight", "no-support", ["bad-uniform", position].

split: open-access