broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    n, amps, pauli = x
    if len(pauli) != n:
        return 'length-mismatch'
    if any(c not in 'IXYZ' for c in pauli):
        return 'bad-pauli'
    psi = [complex(a, b) for a, b in amps]
    acc = 0j
    for i, v in enumerate(psi):
        j = i
        phase = 1 + 0j
        for k, c in enumerate(pauli):
            q = n - 1 - k
            bit = (i >> q) & 1
            if c in 'XY':
                j ^= 1 << q
            if c == 'Z' and bit:
                phase = -phase
            elif c == 'Y':
                phase *= 1j if bit == 0 else -1j
        acc += psi[j].conjugate() * phase * v
    norm = sum(abs(v) ** 2 for v in psi)
    return round(acc.real, 6) + 0.0
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: Y on |+i>', [1, [[0.707107, 0], [0, 0.707107]], 'Y'], 1.0], ['regression: X on |+>', [1, [[0.707107, 0], [0.707107, 0]], 'X'], 1.0], ['regression: unnormalized Z', [1, [[3, 0], [0, 4]], 'Z'], -0.28], ['control: ZI on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'ZI'], 1.0], ['control: IZ on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'IZ'], -1.0], ['control: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch']], [['regression: random expectation 0', [1, [[0.071, 0.727], [-1.619, -1.464]], 'I'], 1.0], ['regression: random expectation 2', [1, [[0.489, 0.112], [-0.446, 0.868]], 'X'], -0.200793], ['regression: random expectation 3', [1, [[-0.119, -0.141], [0.0, 0.0]], 'Z'], 1.0], ['control: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch'], ['control: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch']], [['regression: random expectation 4', [1, [[-0.408, 0.461], [-0.359, 0.326]], 'Y'], 0.105809], ['regression: random expectation 5', [3, [[0.616, -0.07], [-0.126, -0.492], [-0.385, 0.046], [-0.714, -0.852], [0.968, -0.035], [-0.129, -0.794], [-0.299, 0.172], [0.772, -0.916]], 'YYZ'], -0.229604], ['regression: random expectation 6', [2, [[0.423, -0.627], [-0.829, 0.103], [0.962, -0.142], [-0.494, -0.183]], 'XX'], -0.7271], ['control: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: random expectation 1', [1, [[0.0, 0.0], [1.97, 0.65]], 'X'], 0.0], ['control: random expectation 45', [1, [[0.0, 0.0], [-0.122, 1.228]], 'Y'], 0.0], ['control: ZI on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'ZI'], 1.0]], [['regression: random expectation 7', [1, [[-1.206, 1.877], [0.69, -0.341]], 'I'], 1.0], ['regression: random expectation 8', [1, [[0.52, 0.586], [-0.138, -0.781]], 'I'], 1.0], ['regression: random expectation 6', [2, [[0.423, -0.627], [-0.829, 0.103], [0.962, -0.142], [-0.494, -0.183]], 'XX'], -0.7271], ['control: IZ on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'IZ'], -1.0], ['control: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch'], ['control: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch']], [['regression: random expectation 10', [3, [[0.0, 0.0], [1.545, 0.342], [0.0, 0.0], [-1.862, -1.433], [0.0, 0.0], [-0.66, -1.507], [0.913, -1.017], [-1.982, -0.009]], 'IZX'], 0.21787], ['regression: random expectation 11', [1, [[-0.422, -1.932], [-1.435, 1.833]], 'Z'], -0.161676], ['regression: random expectation 8', [1, [[0.52, 0.586], [-0.138, -0.781]], 'I'], 1.0], ['control: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['control: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli']]]
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, amps, pauli = x
    if len(pauli) != n:
        return 'length-mismatch'
    if any(c not in 'IXYZ' for c in pauli):
        return 'bad-pauli'
    psi = [complex(a, b) for a, b in amps]
    acc = 0j
    for i, v in enumerate(psi):
        j = i
        phase = 1 + 0j
        for k, c in enumerate(pauli):
            q = n - 1 - k
            bit = (i >> q) & 1
            if c in 'XY':
                j ^= 1 << q
            if c == 'Z' and bit:
                phase = -phase
            elif c == 'Y':
                phase *= 1j if bit == 0 else -1j
        acc += psi[j].conjugate() * phase * v
    norm = sum(abs(v) ** 2 for v in psi)
    return round((acc / math.sqrt(norm)).real, 6) + 0.0
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: Y on |+i>', [1, [[0.707107, 0], [0, 0.707107]], 'Y'], 1.0], ['regression: X on |+>', [1, [[0.707107, 0], [0.707107, 0]], 'X'], 1.0], ['regression: unnormalized Z', [1, [[3, 0], [0, 4]], 'Z'], -0.28], ['control: ZI on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'ZI'], 1.0], ['control: IZ on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'IZ'], -1.0], ['control: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch']], [['regression: random expectation 0', [1, [[0.071, 0.727], [-1.619, -1.464]], 'I'], 1.0], ['regression: random expectation 2', [1, [[0.489, 0.112], [-0.446, 0.868]], 'X'], -0.200793], ['regression: random expectation 3', [1, [[-0.119, -0.141], [0.0, 0.0]], 'Z'], 1.0], ['control: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch'], ['control: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch']], [['regression: random expectation 4', [1, [[-0.408, 0.461], [-0.359, 0.326]], 'Y'], 0.105809], ['regression: random expectation 5', [3, [[0.616, -0.07], [-0.126, -0.492], [-0.385, 0.046], [-0.714, -0.852], [0.968, -0.035], [-0.129, -0.794], [-0.299, 0.172], [0.772, -0.916]], 'YYZ'], -0.229604], ['regression: random expectation 6', [2, [[0.423, -0.627], [-0.829, 0.103], [0.962, -0.142], [-0.494, -0.183]], 'XX'], -0.7271], ['control: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: random expectation 1', [1, [[0.0, 0.0], [1.97, 0.65]], 'X'], 0.0], ['control: random expectation 45', [1, [[0.0, 0.0], [-0.122, 1.228]], 'Y'], 0.0], ['control: ZI on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'ZI'], 1.0]], [['regression: random expectation 7', [1, [[-1.206, 1.877], [0.69, -0.341]], 'I'], 1.0], ['regression: random expectation 8', [1, [[0.52, 0.586], [-0.138, -0.781]], 'I'], 1.0], ['regression: random expectation 6', [2, [[0.423, -0.627], [-0.829, 0.103], [0.962, -0.142], [-0.494, -0.183]], 'XX'], -0.7271], ['control: IZ on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'IZ'], -1.0], ['control: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch'], ['control: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch']], [['regression: random expectation 10', [3, [[0.0, 0.0], [1.545, 0.342], [0.0, 0.0], [-1.862, -1.433], [0.0, 0.0], [-0.66, -1.507], [0.913, -1.017], [-1.982, -0.009]], 'IZX'], 0.21787], ['regression: random expectation 11', [1, [[-0.422, -1.932], [-1.435, 1.833]], 'Z'], -0.161676], ['regression: random expectation 8', [1, [[0.52, 0.586], [-0.138, -0.781]], 'I'], 1.0], ['control: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['control: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli']]]
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 3|0> + 4|1>, <Z> is reported as -7 instead of -0.28.

Input [n, amps, pauli]; pauli is an n-character string over I,X,Y,Z whose rightmost character acts on qubit 0 (LSB). Return the real expectation <psi|P|psi>/<psi|psi> rounded to 6 decimals. Errors: "length-mismatch", "bad-pauli" (any character outside uppercase IXYZ).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    n, amps, pauli = x
    if len(pauli) > n:
        return 'length-mismatch'
    if any(c not in 'IXYZ' for c in pauli):
        return 'bad-pauli'
    psi = [complex(a, b) for a, b in amps]
    acc = 0j
    for i, v in enumerate(psi):
        j = i
        phase = 1 + 0j
        for k, c in enumerate(pauli):
            q = n - 1 - k
            bit = (i >> q) & 1
            if c in 'XY':
                j ^= 1 << q
            if c == 'Z' and bit:
                phase = -phase
            elif c == 'Y':
                phase *= 1j if bit == 0 else -1j
        acc += psi[j].conjugate() * phase * v
    norm = sum(abs(v) ** 2 for v in psi)
    return round((acc / norm).real, 6) + 0.0
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['regression: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch'], ['regression: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: ZI on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'ZI'], 1.0], ['control: IZ on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'IZ'], -1.0], ['control: Y on |+i>', [1, [[0.707107, 0], [0, 0.707107]], 'Y'], 1.0], ['control: X on |+>', [1, [[0.707107, 0], [0.707107, 0]], 'X'], 1.0]], [['regression: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['regression: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['regression: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch'], ['control: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: unnormalized Z', [1, [[3, 0], [0, 4]], 'Z'], -0.28], ['control: random expectation 0', [1, [[0.071, 0.727], [-1.619, -1.464]], 'I'], 1.0]], [['regression: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch'], ['regression: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['regression: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['control: random expectation 1', [1, [[0.0, 0.0], [1.97, 0.65]], 'X'], 0.0], ['control: random expectation 2', [1, [[0.489, 0.112], [-0.446, 0.868]], 'X'], -0.200793], ['control: random expectation 3', [1, [[-0.119, -0.141], [0.0, 0.0]], 'Z'], 1.0], ['control: random expectation 4', [1, [[-0.408, 0.461], [-0.359, 0.326]], 'Y'], 0.105809]], [['regression: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['regression: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['regression: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch'], ['control: random expectation 5', [3, [[0.616, -0.07], [-0.126, -0.492], [-0.385, 0.046], [-0.714, -0.852], [0.968, -0.035], [-0.129, -0.794], [-0.299, 0.172], [0.772, -0.916]], 'YYZ'], -0.229604], ['control: random expectation 6', [2, [[0.423, -0.627], [-0.829, 0.103], [0.962, -0.142], [-0.494, -0.183]], 'XX'], -0.7271], ['control: random expectation 7', [1, [[-1.206, 1.877], [0.69, -0.341]], 'I'], 1.0], ['control: random expectation 8', [1, [[0.52, 0.586], [-0.138, -0.781]], 'I'], 1.0]], [['regression: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['regression: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['regression: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['control: random expectation 9', [3, [[0.685, -0.091], [1.56, 1.459], [-1.17, 0.687], [-0.305, 1.609], [-0.876, -1.673], [-0.535, 0.008], [-1.818, 1.331], [1.693, 1.162]], 'IXI'], -0.046053], ['control: random expectation 10', [3, [[0.0, 0.0], [1.545, 0.342], [0.0, 0.0], [-1.862, -1.433], [0.0, 0.0], [-0.66, -1.507], [0.913, -1.017], [-1.982, -0.009]], 'IZX'], 0.21787], ['control: random expectation 11', [1, [[-0.422, -1.932], [-1.435, 1.833]], 'Z'], -0.161676], ['control: random expectation 12', [3, [[1.741, 0.945], [0.0, 0.0], [0.705, -0.271], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [-1.277, -0.575], [-0.732, 0.787]], 'ZZX'], 0.12672]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    n, amps, pauli = x
    if len(pauli) > n or not pauli:
        return 'length-mismatch'
    if any(c not in 'IXYZ' for c in pauli):
        return 'bad-pauli'
    psi = [complex(a, b) for a, b in amps]
    acc = 0j
    for i, v in enumerate(psi):
        j = i
        phase = 1 + 0j
        for k, c in enumerate(pauli):
            q = n - 1 - k
            bit = (i >> q) & 1
            if c in 'XY':
                j ^= 1 << q
            if c == 'Z' and bit:
                phase = -phase
            elif c == 'Y':
                phase *= 1j if bit == 0 else -1j
        acc += psi[j].conjugate() * phase * v
    norm = sum(abs(v) ** 2 for v in psi)
    return round((acc / norm).real, 6) + 0.0
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['regression: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch'], ['regression: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: ZI on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'ZI'], 1.0], ['control: IZ on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'IZ'], -1.0], ['control: Y on |+i>', [1, [[0.707107, 0], [0, 0.707107]], 'Y'], 1.0], ['control: X on |+>', [1, [[0.707107, 0], [0.707107, 0]], 'X'], 1.0]], [['regression: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['regression: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['regression: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch'], ['control: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: unnormalized Z', [1, [[3, 0], [0, 4]], 'Z'], -0.28], ['control: random expectation 0', [1, [[0.071, 0.727], [-1.619, -1.464]], 'I'], 1.0]], [['regression: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch'], ['regression: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['regression: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['control: random expectation 1', [1, [[0.0, 0.0], [1.97, 0.65]], 'X'], 0.0], ['control: random expectation 2', [1, [[0.489, 0.112], [-0.446, 0.868]], 'X'], -0.200793], ['control: random expectation 3', [1, [[-0.119, -0.141], [0.0, 0.0]], 'Z'], 1.0], ['control: random expectation 4', [1, [[-0.408, 0.461], [-0.359, 0.326]], 'Y'], 0.105809]], [['regression: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['regression: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['regression: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch'], ['control: random expectation 5', [3, [[0.616, -0.07], [-0.126, -0.492], [-0.385, 0.046], [-0.714, -0.852], [0.968, -0.035], [-0.129, -0.794], [-0.299, 0.172], [0.772, -0.916]], 'YYZ'], -0.229604], ['control: random expectation 6', [2, [[0.423, -0.627], [-0.829, 0.103], [0.962, -0.142], [-0.494, -0.183]], 'XX'], -0.7271], ['control: random expectation 7', [1, [[-1.206, 1.877], [0.69, -0.341]], 'I'], 1.0], ['control: random expectation 8', [1, [[0.52, 0.586], [-0.138, -0.781]], 'I'], 1.0]], [['regression: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['regression: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['regression: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['control: random expectation 9', [3, [[0.685, -0.091], [1.56, 1.459], [-1.17, 0.687], [-0.305, 1.609], [-0.876, -1.673], [-0.535, 0.008], [-1.818, 1.331], [1.693, 1.162]], 'IXI'], -0.046053], ['control: random expectation 10', [3, [[0.0, 0.0], [1.545, 0.342], [0.0, 0.0], [-1.862, -1.433], [0.0, 0.0], [-0.66, -1.507], [0.913, -1.017], [-1.982, -0.009]], 'IZX'], 0.21787], ['control: random expectation 11', [1, [[-0.422, -1.932], [-1.435, 1.833]], 'Z'], -0.161676], ['control: random expectation 12', [3, [[1.741, 0.945], [0.0, 0.0], [0.705, -0.271], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [-1.277, -0.575], [-0.732, 0.787]], 'ZZX'], 0.12672]]]
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 one-character string on a two-qubit state returns a number instead of "length-mismatch".

Input [n, amps, pauli]; pauli is an n-character string over I,X,Y,Z whose rightmost character acts on qubit 0 (LSB). Return the real expectation <psi|P|psi>/<psi|psi> rounded to 6 decimals. Errors: "length-mismatch", "bad-pauli" (any character outside uppercase IXYZ).

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    n, amps, pauli = x
    if len(pauli) != n:
        return 'length-mismatch'
    if any(c not in 'IXYZixyz' for c in pauli):
        return 'bad-pauli'
    psi = [complex(a, b) for a, b in amps]
    acc = 0j
    for i, v in enumerate(psi):
        j = i
        phase = 1 + 0j
        for k, c in enumerate(pauli):
            q = n - 1 - k
            bit = (i >> q) & 1
            if c in 'XY':
                j ^= 1 << q
            if c == 'Z' and bit:
                phase = -phase
            elif c == 'Y':
                phase *= 1j if bit == 0 else -1j
        acc += psi[j].conjugate() * phase * v
    norm = sum(abs(v) ** 2 for v in psi)
    return round((acc / norm).real, 6) + 0.0
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: ZI on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'ZI'], 1.0], ['control: IZ on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'IZ'], -1.0], ['control: Y on |+i>', [1, [[0.707107, 0], [0, 0.707107]], 'Y'], 1.0], ['control: X on |+>', [1, [[0.707107, 0], [0.707107, 0]], 'X'], 1.0], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch']], [['regression: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch'], ['control: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch'], ['control: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: Y on |+i>', [1, [[0.707107, 0], [0, 0.707107]], 'Y'], 1.0]], [['regression: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['control: unnormalized Z', [1, [[3, 0], [0, 4]], 'Z'], -0.28], ['control: random expectation 0', [1, [[0.071, 0.727], [-1.619, -1.464]], 'I'], 1.0], ['control: X on |+>', [1, [[0.707107, 0], [0.707107, 0]], 'X'], 1.0]], [['regression: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: random expectation 1', [1, [[0.0, 0.0], [1.97, 0.65]], 'X'], 0.0], ['control: random expectation 2', [1, [[0.489, 0.112], [-0.446, 0.868]], 'X'], -0.200793], ['control: random expectation 3', [1, [[-0.119, -0.141], [0.0, 0.0]], 'Z'], 1.0], ['control: random expectation 4', [1, [[-0.408, 0.461], [-0.359, 0.326]], 'Y'], 0.105809], ['control: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch']], [['regression: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: random expectation 5', [3, [[0.616, -0.07], [-0.126, -0.492], [-0.385, 0.046], [-0.714, -0.852], [0.968, -0.035], [-0.129, -0.794], [-0.299, 0.172], [0.772, -0.916]], 'YYZ'], -0.229604], ['control: random expectation 6', [2, [[0.423, -0.627], [-0.829, 0.103], [0.962, -0.142], [-0.494, -0.183]], 'XX'], -0.7271], ['control: random expectation 7', [1, [[-1.206, 1.877], [0.69, -0.341]], 'I'], 1.0], ['control: random expectation 8', [1, [[0.52, 0.586], [-0.138, -0.781]], 'I'], 1.0], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch']]]
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, amps, pauli = x
    if len(pauli) != n:
        return 'length-mismatch'
    if any(c.upper() not in 'IXYZ' for c in pauli):
        return 'bad-pauli'
    psi = [complex(a, b) for a, b in amps]
    acc = 0j
    for i, v in enumerate(psi):
        j = i
        phase = 1 + 0j
        for k, c in enumerate(pauli):
            q = n - 1 - k
            bit = (i >> q) & 1
            if c in 'XY':
                j ^= 1 << q
            if c == 'Z' and bit:
                phase = -phase
            elif c == 'Y':
                phase *= 1j if bit == 0 else -1j
        acc += psi[j].conjugate() * phase * v
    norm = sum(abs(v) ** 2 for v in psi)
    return round((acc / norm).real, 6) + 0.0
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: ZI on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'ZI'], 1.0], ['control: IZ on |01>', [2, [[0, 0], [1, 0], [0, 0], [0, 0]], 'IZ'], -1.0], ['control: Y on |+i>', [1, [[0.707107, 0], [0, 0.707107]], 'Y'], 1.0], ['control: X on |+>', [1, [[0.707107, 0], [0.707107, 0]], 'X'], 1.0], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch']], [['regression: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch'], ['control: short X on bell', [2, [[0.707107, 0], [0, 0], [0, 0], [0.707107, 0]], 'X'], 'length-mismatch'], ['control: short Y on three qubits', [3, [[0.5, 0], [0, 0.5], [0, 0], [0.5, 0], [0, 0], [0, 0], [0, 0], [0.5, 0]], 'YZ'], 'length-mismatch'], ['control: Y on |+i>', [1, [[0.707107, 0], [0, 0.707107]], 'Y'], 1.0]], [['regression: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: short Z on excited high qubit', [2, [[0, 0], [0, 0], [1, 0], [0, 0]], 'Z'], 'length-mismatch'], ['control: short ZX', [3, [[0.6, 0], [0.8, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]], 'ZX'], 'length-mismatch'], ['control: unnormalized Z', [1, [[3, 0], [0, 4]], 'Z'], -0.28], ['control: random expectation 0', [1, [[0.071, 0.727], [-1.619, -1.464]], 'I'], 1.0], ['control: X on |+>', [1, [[0.707107, 0], [0.707107, 0]], 'X'], 1.0]], [['regression: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: random expectation 1', [1, [[0.0, 0.0], [1.97, 0.65]], 'X'], 0.0], ['control: random expectation 2', [1, [[0.489, 0.112], [-0.446, 0.868]], 'X'], -0.200793], ['control: random expectation 3', [1, [[-0.119, -0.141], [0.0, 0.0]], 'Z'], 1.0], ['control: random expectation 4', [1, [[-0.408, 0.461], [-0.359, 0.326]], 'Y'], 0.105809], ['control: short string', [2, [[1, 0], [0, 0], [0, 0], [0, 0]], 'Z'], 'length-mismatch']], [['regression: lowercase pauli', [1, [[1, 0], [0, 0]], 'z'], 'bad-pauli'], ['control: random expectation 5', [3, [[0.616, -0.07], [-0.126, -0.492], [-0.385, 0.046], [-0.714, -0.852], [0.968, -0.035], [-0.129, -0.794], [-0.299, 0.172], [0.772, -0.916]], 'YYZ'], -0.229604], ['control: random expectation 6', [2, [[0.423, -0.627], [-0.829, 0.103], [0.962, -0.142], [-0.494, -0.183]], 'XX'], -0.7271], ['control: random expectation 7', [1, [[-1.206, 1.877], [0.69, -0.341]], 'I'], 1.0], ['control: random expectation 8', [1, [[0.52, 0.586], [-0.138, -0.781]], 'I'], 1.0], ['control: long string', [1, [[1, 0], [0, 0]], 'ZZ'], 'length-mismatch']]]
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:
The string "z" is evaluated as identity (+1) instead of being rejected as "bad-pauli".

Input [n, amps, pauli]; pauli is an n-character string over I,X,Y,Z whose rightmost character acts on qubit 0 (LSB). Return the real expectation <psi|P|psi>/<psi|psi> rounded to 6 decimals. Errors: "length-mismatch", "bad-pauli" (any character outside uppercase IXYZ).

split: open-access


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

N = 1
observations = []
def solve(x):
    (k1, s1), (k2, s2) = x
    if len(s1) != len(s2):
        return 'length-mismatch'
    table = {('X', 'Y'): (1, 'Z'), ('Y', 'Z'): (1, 'X'), ('Z', 'X'): (1, 'Y'),
             ('Y', 'X'): (3, 'Z'), ('Z', 'Y'): (3, 'X'), ('X', 'Z'): (1, 'Y')}
    k = k1 + k2
    out = []
    for a, b in zip(s1, s2):
        if a == 'I':
            out.append(b)
        elif b == 'I':
            out.append(a)
        elif a == b:
            out.append('I')
        else:
            dk, c = table[(a, b)]
            k += dk
            out.append(c)
    return [k % 4, ''.join(out)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['regression: random product 4', [[0, 'YXY'], [1, 'IZZ']], [1, 'YYX']], ['repair check: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']], ['control: X times Y', [[0, 'X'], [0, 'Y']], [1, 'Z']], ['control: Y times X', [[0, 'Y'], [0, 'X']], [3, 'Z']], ['control: square of Y', [[0, 'Y'], [0, 'Y']], [0, 'I']], ['control: identity factors', [[1, 'II'], [2, 'IZ']], [3, 'IZ']]], [['regression: random product 11', [[-2, 'ZXI'], [3, 'IZX']], [0, 'ZYX']], ['regression: random product 22', [[0, 'XYYI'], [1, 'ZZZX']], [2, 'YXXX']], ['repair check: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']], ['control: anticommuting pair twice', [[0, 'XY'], [0, 'YX']], [0, 'ZZ']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['control: phases wrap', [[3, 'XX'], [3, 'ZZ']], [0, 'YY']], ['control: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']]], [['regression: random product 48', [[-2, 'ZIXI'], [1, 'ZIZX']], [2, 'IIYX']], ['regression: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['repair check: random product 13', [[-1, 'Z'], [3, 'X']], [3, 'Y']], ['control: random product 2', [[0, 'Y'], [1, 'X']], [0, 'Z']], ['control: random product 3', [[1, 'Y'], [0, 'Z']], [2, 'X']], ['control: random product 5', [[0, 'YIXX'], [2, 'ZIYY']], [1, 'XIZZ']], ['control: random product 6', [[0, 'Z'], [0, 'Z']], [0, 'I']]], [['regression: random product 10', [[1, 'XIZX'], [0, 'IYIZ']], [0, 'XYZY']], ['regression: random product 11', [[-2, 'ZXI'], [3, 'IZX']], [0, 'ZYX']], ['repair check: random product 15', [[0, 'YYZI'], [0, 'XYXZ']], [0, 'ZIYZ']], ['control: random product 7', [[3, 'Z'], [2, 'Y']], [0, 'X']], ['control: random product 9', [[0, 'I'], [3, 'I']], [3, 'I']], ['control: random product 12', [[-2, 'ZXIX'], [1, 'ZYXX']], [0, 'IZXI']], ['control: random product 16', [[-1, 'YZI'], [2, 'ZIX']], [2, 'XZX']]], [['regression: random product 38', [[0, 'IIIX'], [1, 'YXYZ']], [0, 'YXYY']], ['regression: random product 48', [[-2, 'ZIXI'], [1, 'ZIZX']], [2, 'IIYX']], ['repair check: random product 37', [[-2, 'IIZ'], [2, 'XZX']], [1, 'XZY']], ['control: random product 17', [[3, 'X'], [0, 'X']], [3, 'I']], ['control: random product 18', [[1, 'XX'], [1, 'YY']], [0, 'ZZ']], ['control: random product 19', [[2, 'I'], [2, 'Y']], [0, 'Y']], ['control: random product 20', [[2, 'III'], [1, 'ZZZ']], [3, 'ZZZ']]]]
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):
    (k1, s1), (k2, s2) = x
    if len(s1) != len(s2):
        return 'length-mismatch'
    table = {('X', 'Y'): (1, 'Z'), ('Y', 'Z'): (1, 'X'), ('Z', 'X'): (3, 'Y'),
             ('Y', 'X'): (3, 'Z'), ('Z', 'Y'): (3, 'X'), ('X', 'Z'): (3, 'Y')}
    k = k1 + k2
    out = []
    for a, b in zip(s1, s2):
        if a == 'I':
            out.append(b)
        elif b == 'I':
            out.append(a)
        elif a == b:
            out.append('I')
        else:
            dk, c = table[(a, b)]
            k += dk
            out.append(c)
    return [k % 4, ''.join(out)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['regression: random product 4', [[0, 'YXY'], [1, 'IZZ']], [1, 'YYX']], ['repair check: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']], ['control: X times Y', [[0, 'X'], [0, 'Y']], [1, 'Z']], ['control: Y times X', [[0, 'Y'], [0, 'X']], [3, 'Z']], ['control: square of Y', [[0, 'Y'], [0, 'Y']], [0, 'I']], ['control: identity factors', [[1, 'II'], [2, 'IZ']], [3, 'IZ']]], [['regression: random product 11', [[-2, 'ZXI'], [3, 'IZX']], [0, 'ZYX']], ['regression: random product 22', [[0, 'XYYI'], [1, 'ZZZX']], [2, 'YXXX']], ['repair check: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']], ['control: anticommuting pair twice', [[0, 'XY'], [0, 'YX']], [0, 'ZZ']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['control: phases wrap', [[3, 'XX'], [3, 'ZZ']], [0, 'YY']], ['control: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']]], [['regression: random product 48', [[-2, 'ZIXI'], [1, 'ZIZX']], [2, 'IIYX']], ['regression: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['repair check: random product 13', [[-1, 'Z'], [3, 'X']], [3, 'Y']], ['control: random product 2', [[0, 'Y'], [1, 'X']], [0, 'Z']], ['control: random product 3', [[1, 'Y'], [0, 'Z']], [2, 'X']], ['control: random product 5', [[0, 'YIXX'], [2, 'ZIYY']], [1, 'XIZZ']], ['control: random product 6', [[0, 'Z'], [0, 'Z']], [0, 'I']]], [['regression: random product 10', [[1, 'XIZX'], [0, 'IYIZ']], [0, 'XYZY']], ['regression: random product 11', [[-2, 'ZXI'], [3, 'IZX']], [0, 'ZYX']], ['repair check: random product 15', [[0, 'YYZI'], [0, 'XYXZ']], [0, 'ZIYZ']], ['control: random product 7', [[3, 'Z'], [2, 'Y']], [0, 'X']], ['control: random product 9', [[0, 'I'], [3, 'I']], [3, 'I']], ['control: random product 12', [[-2, 'ZXIX'], [1, 'ZYXX']], [0, 'IZXI']], ['control: random product 16', [[-1, 'YZI'], [2, 'ZIX']], [2, 'XZX']]], [['regression: random product 38', [[0, 'IIIX'], [1, 'YXYZ']], [0, 'YXYY']], ['regression: random product 48', [[-2, 'ZIXI'], [1, 'ZIZX']], [2, 'IIYX']], ['repair check: random product 37', [[-2, 'IIZ'], [2, 'XZX']], [1, 'XZY']], ['control: random product 17', [[3, 'X'], [0, 'X']], [3, 'I']], ['control: random product 18', [[1, 'XX'], [1, 'YY']], [0, 'ZZ']], ['control: random product 19', [[2, 'I'], [2, 'Y']], [0, 'Y']], ['control: random product 20', [[2, 'III'], [1, 'ZZZ']], [3, 'ZZZ']]]]
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:
X*Z is reported as +iY instead of -iY, so commutation-derived signs are wrong.

Input [[k1, s1], [k2, s2]] representing i**k1 * s1 and i**k2 * s2 (Pauli strings over IXYZ, equal length). Return [k mod 4, s] with i**k * s = (i**k1 s1)(i**k2 s2), using XY=iZ, YZ=iX, ZX=iY and the reversed products with -i. Error "length-mismatch".

split: open-access


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

N = 1
observations = []
def solve(x):
    (k1, s1), (k2, s2) = x
    if len(s1) != len(s2):
        return 'length-mismatch'
    table = {('X', 'Y'): (1, 'Z'), ('Y', 'Z'): (1, 'X'), ('Z', 'X'): (1, 'Y'),
             ('Y', 'X'): (3, 'Z'), ('Z', 'Y'): (3, 'X'), ('X', 'Z'): (3, 'Y')}
    k = k1 * k2
    out = []
    for a, b in zip(s1, s2):
        if a == 'I':
            out.append(b)
        elif b == 'I':
            out.append(a)
        elif a == b:
            out.append('I')
        else:
            dk, c = table[(a, b)]
            k += dk
            out.append(c)
    return [k % 4, ''.join(out)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: identity factors', [[1, 'II'], [2, 'IZ']], [3, 'IZ']], ['regression: negative phase input', [[-1, 'Z'], [0, 'X']], [0, 'Y']], ['regression: phases wrap', [[3, 'XX'], [3, 'ZZ']], [0, 'YY']], ['control: X times Y', [[0, 'X'], [0, 'Y']], [1, 'Z']], ['control: Y times X', [[0, 'Y'], [0, 'X']], [3, 'Z']], ['control: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['control: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']]], [['regression: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']], ['regression: random product 2', [[0, 'Y'], [1, 'X']], [0, 'Z']], ['regression: phases wrap', [[3, 'XX'], [3, 'ZZ']], [0, 'YY']], ['control: square of Y', [[0, 'Y'], [0, 'Y']], [0, 'I']], ['control: anticommuting pair twice', [[0, 'XY'], [0, 'YX']], [0, 'ZZ']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['control: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']]], [['regression: random product 4', [[0, 'YXY'], [1, 'IZZ']], [1, 'YYX']], ['regression: random product 5', [[0, 'YIXX'], [2, 'ZIYY']], [1, 'XIZZ']], ['regression: random product 8', [[-1, 'XZIY'], [3, 'IXYY']], [3, 'XYYI']], ['control: random product 6', [[0, 'Z'], [0, 'Z']], [0, 'I']], ['control: random product 15', [[0, 'YYZI'], [0, 'XYXZ']], [0, 'ZIYZ']], ['control: random product 19', [[2, 'I'], [2, 'Y']], [0, 'Y']], ['control: random product 21', [[2, 'YY'], [2, 'II']], [0, 'YY']]], [['regression: random product 8', [[-1, 'XZIY'], [3, 'IXYY']], [3, 'XYYI']], ['regression: random product 9', [[0, 'I'], [3, 'I']], [3, 'I']], ['regression: random product 12', [[-2, 'ZXIX'], [1, 'ZYXX']], [0, 'IZXI']], ['control: random product 23', [[0, 'YYI'], [0, 'YYX']], [0, 'IIX']], ['control: random product 34', [[-2, 'XXZ'], [2, 'IYZ']], [1, 'XZI']], ['control: random product 35', [[-2, 'IY'], [2, 'IX']], [3, 'IZ']], ['control: random product 37', [[-2, 'IIZ'], [2, 'XZX']], [1, 'XZY']]], [['regression: random product 11', [[-2, 'ZXI'], [3, 'IZX']], [0, 'ZYX']], ['regression: random product 12', [[-2, 'ZXIX'], [1, 'ZYXX']], [0, 'IZXI']], ['regression: random product 13', [[-1, 'Z'], [3, 'X']], [3, 'Y']], ['control: X times Y', [[0, 'X'], [0, 'Y']], [1, 'Z']], ['control: Y times X', [[0, 'Y'], [0, 'X']], [3, 'Z']], ['control: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['control: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']]]]
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):
    (k1, s1), (k2, s2) = x
    if len(s1) != len(s2):
        return 'length-mismatch'
    table = {('X', 'Y'): (1, 'Z'), ('Y', 'Z'): (1, 'X'), ('Z', 'X'): (1, 'Y'),
             ('Y', 'X'): (3, 'Z'), ('Z', 'Y'): (3, 'X'), ('X', 'Z'): (3, 'Y')}
    k = (k1 + k2) % 2
    out = []
    for a, b in zip(s1, s2):
        if a == 'I':
            out.append(b)
        elif b == 'I':
            out.append(a)
        elif a == b:
            out.append('I')
        else:
            dk, c = table[(a, b)]
            k += dk
            out.append(c)
    return [k % 4, ''.join(out)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: identity factors', [[1, 'II'], [2, 'IZ']], [3, 'IZ']], ['regression: negative phase input', [[-1, 'Z'], [0, 'X']], [0, 'Y']], ['regression: phases wrap', [[3, 'XX'], [3, 'ZZ']], [0, 'YY']], ['control: X times Y', [[0, 'X'], [0, 'Y']], [1, 'Z']], ['control: Y times X', [[0, 'Y'], [0, 'X']], [3, 'Z']], ['control: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['control: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']]], [['regression: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']], ['regression: random product 2', [[0, 'Y'], [1, 'X']], [0, 'Z']], ['regression: phases wrap', [[3, 'XX'], [3, 'ZZ']], [0, 'YY']], ['control: square of Y', [[0, 'Y'], [0, 'Y']], [0, 'I']], ['control: anticommuting pair twice', [[0, 'XY'], [0, 'YX']], [0, 'ZZ']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['control: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']]], [['regression: random product 4', [[0, 'YXY'], [1, 'IZZ']], [1, 'YYX']], ['regression: random product 5', [[0, 'YIXX'], [2, 'ZIYY']], [1, 'XIZZ']], ['regression: random product 8', [[-1, 'XZIY'], [3, 'IXYY']], [3, 'XYYI']], ['control: random product 6', [[0, 'Z'], [0, 'Z']], [0, 'I']], ['control: random product 15', [[0, 'YYZI'], [0, 'XYXZ']], [0, 'ZIYZ']], ['control: random product 19', [[2, 'I'], [2, 'Y']], [0, 'Y']], ['control: random product 21', [[2, 'YY'], [2, 'II']], [0, 'YY']]], [['regression: random product 8', [[-1, 'XZIY'], [3, 'IXYY']], [3, 'XYYI']], ['regression: random product 9', [[0, 'I'], [3, 'I']], [3, 'I']], ['regression: random product 12', [[-2, 'ZXIX'], [1, 'ZYXX']], [0, 'IZXI']], ['control: random product 23', [[0, 'YYI'], [0, 'YYX']], [0, 'IIX']], ['control: random product 34', [[-2, 'XXZ'], [2, 'IYZ']], [1, 'XZI']], ['control: random product 35', [[-2, 'IY'], [2, 'IX']], [3, 'IZ']], ['control: random product 37', [[-2, 'IIZ'], [2, 'XZX']], [1, 'XZY']]], [['regression: random product 11', [[-2, 'ZXI'], [3, 'IZX']], [0, 'ZYX']], ['regression: random product 12', [[-2, 'ZXIX'], [1, 'ZYXX']], [0, 'IZXI']], ['regression: random product 13', [[-1, 'Z'], [3, 'X']], [3, 'Y']], ['control: X times Y', [[0, 'X'], [0, 'Y']], [1, 'Z']], ['control: Y times X', [[0, 'Y'], [0, 'X']], [3, 'Z']], ['control: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['control: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']]]]
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:
The product of iX and iZ is reported with phase exponent 1 instead of 2 plus the XZ contribution.

Input [[k1, s1], [k2, s2]] representing i**k1 * s1 and i**k2 * s2 (Pauli strings over IXYZ, equal length). Return [k mod 4, s] with i**k * s = (i**k1 s1)(i**k2 s2), using XY=iZ, YZ=iX, ZX=iY and the reversed products with -i. Error "length-mismatch".

split: open-access


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

N = 1
observations = []
def solve(x):
    (k1, s1), (k2, s2) = x
    if len(s1) != len(s2):
        return 'length-mismatch'
    table = {('X', 'Y'): (1, 'Z'), ('Y', 'Z'): (1, 'X'), ('Z', 'X'): (1, 'Y'),
             ('Y', 'X'): (3, 'Z'), ('Z', 'Y'): (3, 'X'), ('X', 'Z'): (3, 'Y')}
    k = k1 + k2
    out = []
    for a, b in zip(s1, s2):
        if a == 'I':
            out.append(b)
        elif b == 'I':
            out.append(a)
        elif a == b:
            out.append(a)
        else:
            dk, c = table[(a, b)]
            k += dk
            out.append(c)
    return [k % 4, ''.join(out)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: square of Y', [[0, 'Y'], [0, 'Y']], [0, 'I']], ['regression: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']], ['regression: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']], ['control: X times Y', [[0, 'X'], [0, 'Y']], [1, 'Z']], ['control: Y times X', [[0, 'Y'], [0, 'X']], [3, 'Z']], ['control: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['control: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']]], [['regression: random product 6', [[0, 'Z'], [0, 'Z']], [0, 'I']], ['regression: random product 8', [[-1, 'XZIY'], [3, 'IXYY']], [3, 'XYYI']], ['regression: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']], ['control: identity factors', [[1, 'II'], [2, 'IZ']], [3, 'IZ']], ['control: anticommuting pair twice', [[0, 'XY'], [0, 'YX']], [0, 'ZZ']], ['control: negative phase input', [[-1, 'Z'], [0, 'X']], [0, 'Y']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch']], [['regression: random product 15', [[0, 'YYZI'], [0, 'XYXZ']], [0, 'ZIYZ']], ['regression: random product 17', [[3, 'X'], [0, 'X']], [3, 'I']], ['regression: random product 8', [[-1, 'XZIY'], [3, 'IXYY']], [3, 'XYYI']], ['control: phases wrap', [[3, 'XX'], [3, 'ZZ']], [0, 'YY']], ['control: random product 2', [[0, 'Y'], [1, 'X']], [0, 'Z']], ['control: random product 3', [[1, 'Y'], [0, 'Z']], [2, 'X']], ['control: random product 4', [[0, 'YXY'], [1, 'IZZ']], [1, 'YYX']]], [['regression: random product 25', [[-2, 'ZX'], [3, 'YX']], [0, 'XI']], ['regression: random product 27', [[-1, 'YY'], [3, 'IY']], [2, 'YI']], ['regression: random product 17', [[3, 'X'], [0, 'X']], [3, 'I']], ['control: random product 5', [[0, 'YIXX'], [2, 'ZIYY']], [1, 'XIZZ']], ['control: random product 7', [[3, 'Z'], [2, 'Y']], [0, 'X']], ['control: random product 9', [[0, 'I'], [3, 'I']], [3, 'I']], ['control: random product 10', [[1, 'XIZX'], [0, 'IYIZ']], [0, 'XYZY']]], [['regression: random product 33', [[2, 'IZYY'], [3, 'ZYXY']], [3, 'ZXZI']], ['regression: random product 34', [[-2, 'XXZ'], [2, 'IYZ']], [1, 'XZI']], ['regression: random product 27', [[-1, 'YY'], [3, 'IY']], [2, 'YI']], ['control: random product 11', [[-2, 'ZXI'], [3, 'IZX']], [0, 'ZYX']], ['control: random product 13', [[-1, 'Z'], [3, 'X']], [3, 'Y']], ['control: random product 14', [[-2, 'Z'], [0, 'X']], [3, 'Y']], ['control: random product 16', [[-1, 'YZI'], [2, 'ZIX']], [2, 'XZX']]]]
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):
    (k1, s1), (k2, s2) = x
    if len(s1) != len(s2):
        return 'length-mismatch'
    table = {('X', 'Y'): (1, 'Z'), ('Y', 'Z'): (1, 'X'), ('Z', 'X'): (1, 'Y'),
             ('Y', 'X'): (3, 'Z'), ('Z', 'Y'): (3, 'X'), ('X', 'Z'): (3, 'Y')}
    k = k1 + k2
    out = []
    for a, b in zip(s1, s2):
        if a == 'I':
            out.append(b)
        elif b == 'I':
            out.append(a)
        elif a == b:
            k += 2
            out.append('I')
        else:
            dk, c = table[(a, b)]
            k += dk
            out.append(c)
    return [k % 4, ''.join(out)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: square of Y', [[0, 'Y'], [0, 'Y']], [0, 'I']], ['regression: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']], ['regression: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']], ['control: X times Y', [[0, 'X'], [0, 'Y']], [1, 'Z']], ['control: Y times X', [[0, 'Y'], [0, 'X']], [3, 'Z']], ['control: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['control: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']]], [['regression: random product 6', [[0, 'Z'], [0, 'Z']], [0, 'I']], ['regression: random product 8', [[-1, 'XZIY'], [3, 'IXYY']], [3, 'XYYI']], ['regression: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']], ['control: identity factors', [[1, 'II'], [2, 'IZ']], [3, 'IZ']], ['control: anticommuting pair twice', [[0, 'XY'], [0, 'YX']], [0, 'ZZ']], ['control: negative phase input', [[-1, 'Z'], [0, 'X']], [0, 'Y']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch']], [['regression: random product 15', [[0, 'YYZI'], [0, 'XYXZ']], [0, 'ZIYZ']], ['regression: random product 17', [[3, 'X'], [0, 'X']], [3, 'I']], ['regression: random product 8', [[-1, 'XZIY'], [3, 'IXYY']], [3, 'XYYI']], ['control: phases wrap', [[3, 'XX'], [3, 'ZZ']], [0, 'YY']], ['control: random product 2', [[0, 'Y'], [1, 'X']], [0, 'Z']], ['control: random product 3', [[1, 'Y'], [0, 'Z']], [2, 'X']], ['control: random product 4', [[0, 'YXY'], [1, 'IZZ']], [1, 'YYX']]], [['regression: random product 25', [[-2, 'ZX'], [3, 'YX']], [0, 'XI']], ['regression: random product 27', [[-1, 'YY'], [3, 'IY']], [2, 'YI']], ['regression: random product 17', [[3, 'X'], [0, 'X']], [3, 'I']], ['control: random product 5', [[0, 'YIXX'], [2, 'ZIYY']], [1, 'XIZZ']], ['control: random product 7', [[3, 'Z'], [2, 'Y']], [0, 'X']], ['control: random product 9', [[0, 'I'], [3, 'I']], [3, 'I']], ['control: random product 10', [[1, 'XIZX'], [0, 'IYIZ']], [0, 'XYZY']]], [['regression: random product 33', [[2, 'IZYY'], [3, 'ZYXY']], [3, 'ZXZI']], ['regression: random product 34', [[-2, 'XXZ'], [2, 'IYZ']], [1, 'XZI']], ['regression: random product 27', [[-1, 'YY'], [3, 'IY']], [2, 'YI']], ['control: random product 11', [[-2, 'ZXI'], [3, 'IZX']], [0, 'ZYX']], ['control: random product 13', [[-1, 'Z'], [3, 'X']], [3, 'Y']], ['control: random product 14', [[-2, 'Z'], [0, 'X']], [3, 'Y']], ['control: random product 16', [[-1, 'YZI'], [2, 'ZIX']], [2, 'XZX']]]]
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:
Y*Y is reported as Y instead of the identity.

Input [[k1, s1], [k2, s2]] representing i**k1 * s1 and i**k2 * s2 (Pauli strings over IXYZ, equal length). Return [k mod 4, s] with i**k * s = (i**k1 s1)(i**k2 s2), using XY=iZ, YZ=iX, ZX=iY and the reversed products with -i. Error "length-mismatch".

split: open-access


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

N = 1
observations = []
def solve(x):
    (k1, s1), (k2, s2) = x
    if len(s1) != len(s2):
        return 'length-mismatch'
    table = {('X', 'Y'): (1, 'Z'), ('Y', 'Z'): (1, 'X'), ('Z', 'X'): (1, 'Y'),
             ('Y', 'X'): (3, 'Z'), ('Z', 'Y'): (3, 'X'), ('X', 'Z'): (3, 'Y')}
    k = k1 + k2
    out = []
    for a, b in zip(s2, s1):
        if a == 'I':
            out.append(b)
        elif b == 'I':
            out.append(a)
        elif a == b:
            out.append('I')
        else:
            dk, c = table[(a, b)]
            k += dk
            out.append(c)
    return [k % 4, ''.join(out)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: X times Y', [[0, 'X'], [0, 'Y']], [1, 'Z']], ['regression: Y times X', [[0, 'Y'], [0, 'X']], [3, 'Z']], ['repair check: square of Y', [[0, 'Y'], [0, 'Y']], [0, 'I']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['regression: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['regression: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']], ['regression: negative phase input', [[-1, 'Z'], [0, 'X']], [0, 'Y']]], [['regression: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']], ['regression: negative phase input', [[-1, 'Z'], [0, 'X']], [0, 'Y']], ['repair check: anticommuting pair twice', [[0, 'XY'], [0, 'YX']], [0, 'ZZ']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['regression: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['regression: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']], ['regression: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']]], [['regression: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']], ['regression: random product 2', [[0, 'Y'], [1, 'X']], [0, 'Z']], ['repair check: random product 4', [[0, 'YXY'], [1, 'IZZ']], [1, 'YYX']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['regression: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']], ['regression: negative phase input', [[-1, 'Z'], [0, 'X']], [0, 'Y']], ['regression: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']]], [['regression: random product 5', [[0, 'YIXX'], [2, 'ZIYY']], [1, 'XIZZ']], ['regression: random product 7', [[3, 'Z'], [2, 'Y']], [0, 'X']], ['repair check: random product 9', [[0, 'I'], [3, 'I']], [3, 'I']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['regression: negative phase input', [[-1, 'Z'], [0, 'X']], [0, 'Y']], ['regression: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']], ['regression: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']]], [['regression: random product 10', [[1, 'XIZX'], [0, 'IYIZ']], [0, 'XYZY']], ['regression: random product 11', [[-2, 'ZXI'], [3, 'IZX']], [0, 'ZYX']], ['repair check: random product 17', [[3, 'X'], [0, 'X']], [3, 'I']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['regression: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']], ['regression: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']], ['regression: random product 2', [[0, 'Y'], [1, 'X']], [0, 'Z']]]]
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):
    (k1, s1), (k2, s2) = x
    if len(s1) != len(s2):
        return 'length-mismatch'
    table = {('X', 'Y'): (1, 'Z'), ('Y', 'Z'): (1, 'X'), ('Z', 'X'): (1, 'Y'),
             ('Y', 'X'): (3, 'Z'), ('Z', 'Y'): (3, 'X'), ('X', 'Z'): (3, 'Y')}
    k = k1 + k2 + 2
    out = []
    for a, b in zip(s2, s1):
        if a == 'I':
            out.append(b)
        elif b == 'I':
            out.append(a)
        elif a == b:
            out.append('I')
        else:
            dk, c = table[(a, b)]
            k += dk
            out.append(c)
    return [k % 4, ''.join(out)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: X times Y', [[0, 'X'], [0, 'Y']], [1, 'Z']], ['regression: Y times X', [[0, 'Y'], [0, 'X']], [3, 'Z']], ['repair check: square of Y', [[0, 'Y'], [0, 'Y']], [0, 'I']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['regression: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['regression: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']], ['regression: negative phase input', [[-1, 'Z'], [0, 'X']], [0, 'Y']]], [['regression: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']], ['regression: negative phase input', [[-1, 'Z'], [0, 'X']], [0, 'Y']], ['repair check: anticommuting pair twice', [[0, 'XY'], [0, 'YX']], [0, 'ZZ']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['regression: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['regression: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']], ['regression: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']]], [['regression: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']], ['regression: random product 2', [[0, 'Y'], [1, 'X']], [0, 'Z']], ['repair check: random product 4', [[0, 'YXY'], [1, 'IZZ']], [1, 'YYX']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['regression: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']], ['regression: negative phase input', [[-1, 'Z'], [0, 'X']], [0, 'Y']], ['regression: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']]], [['regression: random product 5', [[0, 'YIXX'], [2, 'ZIYY']], [1, 'XIZZ']], ['regression: random product 7', [[3, 'Z'], [2, 'Y']], [0, 'X']], ['repair check: random product 9', [[0, 'I'], [3, 'I']], [3, 'I']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['regression: negative phase input', [[-1, 'Z'], [0, 'X']], [0, 'Y']], ['regression: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']], ['regression: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']]], [['regression: random product 10', [[1, 'XIZX'], [0, 'IYIZ']], [0, 'XYZY']], ['regression: random product 11', [[-2, 'ZXI'], [3, 'IZX']], [0, 'ZYX']], ['repair check: random product 17', [[3, 'X'], [0, 'X']], [3, 'I']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['regression: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']], ['regression: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']], ['regression: random product 2', [[0, 'Y'], [1, 'X']], [0, 'Z']]]]
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:
X*Y is reported as -iZ, the value of Y*X.

Input [[k1, s1], [k2, s2]] representing i**k1 * s1 and i**k2 * s2 (Pauli strings over IXYZ, equal length). Return [k mod 4, s] with i**k * s = (i**k1 s1)(i**k2 s2), using XY=iZ, YZ=iX, ZX=iY and the reversed products with -i. Error "length-mismatch".

split: open-access


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

N = 1
observations = []
def solve(x):
    (k1, s1), (k2, s2) = x
    if len(s1) != len(s2):
        return 'length-mismatch'
    table = {('X', 'Y'): (1, 'Z'), ('Y', 'Z'): (1, 'X'), ('Z', 'X'): (1, 'Y'),
             ('Y', 'X'): (3, 'Z'), ('Z', 'Y'): (3, 'X'), ('X', 'Z'): (3, 'Y')}
    k = k1 + k2
    out = []
    for a, b in zip(s1, s2):
        if a == 'I':
            out.append(b)
        elif b == 'I':
            out.append(a)
        elif a == b:
            out.append('I')
        else:
            dk, c = table[(a, b)]
            k += dk
            out.append(c)
    return [k if k < 4 else k - 4, ''.join(out)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: phases wrap', [[3, 'XX'], [3, 'ZZ']], [0, 'YY']], ['regression: random product 7', [[3, 'Z'], [2, 'Y']], [0, 'X']], ['regression: random product 14', [[-2, 'Z'], [0, 'X']], [3, 'Y']], ['control: X times Y', [[0, 'X'], [0, 'Y']], [1, 'Z']], ['control: Y times X', [[0, 'Y'], [0, 'X']], [3, 'Z']], ['control: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['control: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']]], [['regression: random product 31', [[1, 'YYZ'], [3, 'XXI']], [2, 'ZZZ']], ['regression: random product 33', [[2, 'IZYY'], [3, 'ZYXY']], [3, 'ZXZI']], ['regression: random product 14', [[-2, 'Z'], [0, 'X']], [3, 'Y']], ['control: square of Y', [[0, 'Y'], [0, 'Y']], [0, 'I']], ['control: identity factors', [[1, 'II'], [2, 'IZ']], [3, 'IZ']], ['control: anticommuting pair twice', [[0, 'XY'], [0, 'YX']], [0, 'ZZ']], ['control: negative phase input', [[-1, 'Z'], [0, 'X']], [0, 'Y']]], [['regression: random product 47', [[-2, 'II'], [0, 'YY']], [2, 'YY']], ['regression: phases wrap', [[3, 'XX'], [3, 'ZZ']], [0, 'YY']], ['regression: random product 14', [[-2, 'Z'], [0, 'X']], [3, 'Y']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['control: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']], ['control: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']], ['control: random product 2', [[0, 'Y'], [1, 'X']], [0, 'Z']]], [['regression: random product 14', [[-2, 'Z'], [0, 'X']], [3, 'Y']], ['regression: random product 31', [[1, 'YYZ'], [3, 'XXI']], [2, 'ZZZ']], ['control: random product 3', [[1, 'Y'], [0, 'Z']], [2, 'X']], ['control: random product 4', [[0, 'YXY'], [1, 'IZZ']], [1, 'YYX']], ['control: random product 5', [[0, 'YIXX'], [2, 'ZIYY']], [1, 'XIZZ']], ['control: random product 6', [[0, 'Z'], [0, 'Z']], [0, 'I']], ['regression: random product 33', [[2, 'IZYY'], [3, 'ZYXY']], [3, 'ZXZI']]], [['regression: random product 43', [[2, 'ZY'], [0, 'YX']], [0, 'XZ']], ['regression: random product 47', [[-2, 'II'], [0, 'YY']], [2, 'YY']], ['regression: random product 14', [[-2, 'Z'], [0, 'X']], [3, 'Y']], ['control: random product 8', [[-1, 'XZIY'], [3, 'IXYY']], [3, 'XYYI']], ['control: random product 9', [[0, 'I'], [3, 'I']], [3, 'I']], ['control: random product 10', [[1, 'XIZX'], [0, 'IYIZ']], [0, 'XYZY']], ['control: random product 11', [[-2, 'ZXI'], [3, 'IZX']], [0, 'ZYX']]]]
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):
    (k1, s1), (k2, s2) = x
    if len(s1) != len(s2):
        return 'length-mismatch'
    table = {('X', 'Y'): (1, 'Z'), ('Y', 'Z'): (1, 'X'), ('Z', 'X'): (1, 'Y'),
             ('Y', 'X'): (3, 'Z'), ('Z', 'Y'): (3, 'X'), ('X', 'Z'): (3, 'Y')}
    k = k1 + k2
    out = []
    for a, b in zip(s1, s2):
        if a == 'I':
            out.append(b)
        elif b == 'I':
            out.append(a)
        elif a == b:
            out.append('I')
        else:
            dk, c = table[(a, b)]
            k += dk
            out.append(c)
    return [abs(k) % 4, ''.join(out)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: phases wrap', [[3, 'XX'], [3, 'ZZ']], [0, 'YY']], ['regression: random product 7', [[3, 'Z'], [2, 'Y']], [0, 'X']], ['regression: random product 14', [[-2, 'Z'], [0, 'X']], [3, 'Y']], ['control: X times Y', [[0, 'X'], [0, 'Y']], [1, 'Z']], ['control: Y times X', [[0, 'Y'], [0, 'X']], [3, 'Z']], ['control: X times Z', [[0, 'X'], [0, 'Z']], [3, 'Y']], ['control: Z times X', [[0, 'Z'], [0, 'X']], [1, 'Y']]], [['regression: random product 31', [[1, 'YYZ'], [3, 'XXI']], [2, 'ZZZ']], ['regression: random product 33', [[2, 'IZYY'], [3, 'ZYXY']], [3, 'ZXZI']], ['regression: random product 14', [[-2, 'Z'], [0, 'X']], [3, 'Y']], ['control: square of Y', [[0, 'Y'], [0, 'Y']], [0, 'I']], ['control: identity factors', [[1, 'II'], [2, 'IZ']], [3, 'IZ']], ['control: anticommuting pair twice', [[0, 'XY'], [0, 'YX']], [0, 'ZZ']], ['control: negative phase input', [[-1, 'Z'], [0, 'X']], [0, 'Y']]], [['regression: random product 47', [[-2, 'II'], [0, 'YY']], [2, 'YY']], ['regression: phases wrap', [[3, 'XX'], [3, 'ZZ']], [0, 'YY']], ['regression: random product 14', [[-2, 'Z'], [0, 'X']], [3, 'Y']], ['control: length mismatch', [[0, 'X'], [0, 'XY']], 'length-mismatch'], ['control: random product 0', [[0, 'YY'], [2, 'ZY']], [3, 'XI']], ['control: random product 1', [[-2, 'ZZI'], [2, 'ZXI']], [1, 'IYI']], ['control: random product 2', [[0, 'Y'], [1, 'X']], [0, 'Z']]], [['regression: random product 14', [[-2, 'Z'], [0, 'X']], [3, 'Y']], ['regression: random product 31', [[1, 'YYZ'], [3, 'XXI']], [2, 'ZZZ']], ['control: random product 3', [[1, 'Y'], [0, 'Z']], [2, 'X']], ['control: random product 4', [[0, 'YXY'], [1, 'IZZ']], [1, 'YYX']], ['control: random product 5', [[0, 'YIXX'], [2, 'ZIYY']], [1, 'XIZZ']], ['control: random product 6', [[0, 'Z'], [0, 'Z']], [0, 'I']], ['regression: random product 33', [[2, 'IZYY'], [3, 'ZYXY']], [3, 'ZXZI']]], [['regression: random product 43', [[2, 'ZY'], [0, 'YX']], [0, 'XZ']], ['regression: random product 47', [[-2, 'II'], [0, 'YY']], [2, 'YY']], ['regression: random product 14', [[-2, 'Z'], [0, 'X']], [3, 'Y']], ['control: random product 8', [[-1, 'XZIY'], [3, 'IXYY']], [3, 'XYYI']], ['control: random product 9', [[0, 'I'], [3, 'I']], [3, 'I']], ['control: random product 10', [[1, 'XIZX'], [0, 'IYIZ']], [0, 'XYZY']], ['control: random product 11', [[-2, 'ZXI'], [3, 'IZX']], [0, 'ZYX']]]]
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:
Inputs with negative phase powers or several anticommuting positions return phase exponents outside 0..3.

Input [[k1, s1], [k2, s2]] representing i**k1 * s1 and i**k2 * s2 (Pauli strings over IXYZ, equal length). Return [k mod 4, s] with i**k * s = (i**k1 s1)(i**k2 s2), using XY=iZ, YZ=iX, ZX=iY and the reversed products with -i. Error "length-mismatch".

split: open-access


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

N = 1
observations = []
def solve(x):
    n, gates = x
    xs = [[0] * n for _ in range(n)]
    zs = [[1 if i == j else 0 for j in range(n)] for i in range(n)]
    rs = [0] * n
    for g in gates:
        op = g[0]
        for row in range(n):
            X, Z = xs[row], zs[row]
            if op == 'h':
                a = g[1]
                X[a], Z[a] = Z[a], X[a]
            elif op == 's':
                a = g[1]
                rs[row] ^= X[a] & Z[a]
                Z[a] ^= X[a]
            elif op == 'x':
                rs[row] ^= Z[g[1]]
            elif op == 'z':
                rs[row] ^= X[g[1]]
            elif op == 'cx':
                a, b = g[1], g[2]
                rs[row] ^= X[a] & Z[b] & (X[b] ^ Z[a] ^ 1)
                X[b] ^= X[a]
                Z[a] ^= Z[b]
    letters = {(0, 0): 'I', (1, 0): 'X', (0, 1): 'Z', (1, 1): 'Y'}
    return [('-' if rs[r] else '+') + ''.join(letters[(xs[r][q], zs[r][q])] for q in range(n)) for r in range(n)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: h on y eigenstate', [1, [['h', 0], ['s', 0], ['h', 0]]], ['-Y']], ['regression: random clifford 4', [3, [['cx', 1, 2], ['h', 1], ['cx', 1, 0], ['s', 1], ['x', 2], ['cx', 1, 2], ['cx', 1, 2], ['h', 0], ['cx', 0, 2], ['z', 0], ['s', 2], ['h', 2], ['z', 0]]], ['-XZY', '+ZYI', '-IYX']], ['repair check: bell preparation', [2, [['h', 0], ['cx', 0, 1]]], ['+XX', '+ZZ']], ['control: x flips z sign', [1, [['x', 0]]], ['-Z']], ['control: cx on excited control', [2, [['x', 0], ['cx', 0, 1]]], ['-ZI', '+ZZ']], ['control: random clifford 0', [3, [['cx', 1, 2]]], ['+ZII', '+IZI', '+IZZ']], ['control: random clifford 1', [1, [['z', 0], ['s', 0], ['x', 0], ['x', 0], ['x', 0], ['z', 0], ['z', 0], ['z', 0]]], ['-Z']]], [['regression: random clifford 26', [1, [['x', 0], ['h', 0], ['x', 0], ['h', 0], ['s', 0], ['h', 0], ['s', 0], ['h', 0], ['s', 0], ['s', 0], ['x', 0]]], ['+Y']], ['regression: random clifford 28', [3, [['h', 1], ['cx', 0, 1], ['h', 0], ['cx', 2, 1], ['z', 0], ['x', 0], ['cx', 2, 1], ['h', 1], ['h', 2], ['s', 0], ['h', 0], ['cx', 1, 2]]], ['+YII', '+IZI', '+IIX']], ['repair check: s twice after h', [1, [['h', 0], ['s', 0], ['s', 0]]], ['-X']], ['control: random clifford 3', [1, [['s', 0], ['h', 0], ['h', 0], ['x', 0], ['h', 0], ['h', 0], ['s', 0], ['s', 0]]], ['-Z']], ['control: random clifford 5', [1, [['h', 0], ['h', 0], ['h', 0], ['h', 0], ['z', 0], ['s', 0], ['s', 0], ['s', 0], ['x', 0], ['h', 0], ['x', 0], ['h', 0]]], ['-Z']], ['control: random clifford 6', [1, [['h', 0], ['z', 0], ['h', 0], ['z', 0], ['x', 0], ['h', 0], ['h', 0], ['h', 0], ['h', 0], ['h', 0], ['h', 0], ['s', 0], ['x', 0]]], ['-Z']], ['control: random clifford 10', [1, [['z', 0], ['z', 0], ['s', 0], ['z', 0], ['h', 0], ['h', 0], ['s', 0]]], ['+Z']]], [['regression: random clifford 41', [3, [['s', 2], ['s', 0], ['s', 1], ['cx', 1, 2], ['h', 1], ['cx', 2, 1], ['cx', 1, 2], ['h', 1], ['s', 2], ['cx', 1, 0]]], ['+ZZI', '+IZY', '-XYX']], ['regression: random clifford 42', [3, [['h', 2], ['cx', 1, 0], ['h', 2], ['s', 1], ['h', 0], ['cx', 2, 1], ['x', 2], ['x', 2], ['cx', 0, 2], ['h', 0], ['cx', 0, 2]]], ['-XZZ', '-YZY', '-YIY']], ['repair check: ghz', [3, [['h', 0], ['cx', 0, 1], ['cx', 0, 2]]], ['+XXX', '+ZZI', '+ZIZ']], ['control: random clifford 16', [1, [['x', 0], ['h', 0], ['h', 0], ['h', 0], ['h', 0], ['z', 0], ['z', 0], ['h', 0], ['x', 0], ['h', 0]]], ['-Z']], ['control: random clifford 21', [3, [['h', 0], ['s', 2], ['s', 1], ['h', 0], ['cx', 0, 2], ['cx', 0, 2], ['cx', 1, 2], ['h', 1], ['h', 1], ['cx', 2, 1]]], ['+ZII', '+IZZ', '+IZI']], ['control: random clifford 24', [1, [['x', 0]]], ['-Z']], ['control: random clifford 25', [2, [['cx', 1, 0], ['cx', 1, 0]]], ['+ZI', '+IZ']]], [['regression: random clifford 4', [3, [['cx', 1, 2], ['h', 1], ['cx', 1, 0], ['s', 1], ['x', 2], ['cx', 1, 2], ['cx', 1, 2], ['h', 0], ['cx', 0, 2], ['z', 0], ['s', 2], ['h', 2], ['z', 0]]], ['-XZY', '+ZYI', '-IYX']], ['regression: random clifford 12', [1, [['h', 0], ['s', 0], ['h', 0], ['x', 0], ['s', 0], ['x', 0], ['x', 0], ['z', 0], ['h', 0], ['s', 0], ['s', 0]]], ['+Z']], ['repair check: random clifford 2', [3, [['cx', 0, 2], ['z', 2], ['s', 2], ['h', 0], ['cx', 2, 1], ['x', 1], ['cx', 1, 0], ['x', 1], ['x', 1], ['z', 0], ['cx', 2, 1], ['h', 1], ['h', 0]]], ['-ZII', '-IXI', '-ZIZ']], ['control: random clifford 32', [3, [['z', 1], ['x', 1], ['cx', 1, 0], ['cx', 1, 2], ['cx', 2, 1], ['x', 0], ['cx', 1, 2], ['z', 1], ['z', 1], ['cx', 2, 1], ['z', 2], ['x', 0], ['cx', 0, 2]]], ['+IIZ', '-ZIZ', '+ZZZ']], ['control: random clifford 34', [1, [['z', 0], ['h', 0], ['z', 0], ['h', 0]]], ['-Z']], ['control: random clifford 40', [1, [['h', 0], ['x', 0], ['z', 0], ['s', 0], ['s', 0], ['x', 0], ['x', 0], ['x', 0], ['h', 0]]], ['+Z']], ['control: random clifford 43', [1, [['h', 0], ['x', 0], ['h', 0], ['z', 0], ['x', 0], ['x', 0], ['s', 0]]], ['+Z']]], [['regression: random clifford 28', [3, [['h', 1], ['cx', 0, 1], ['h', 0], ['cx', 2, 1], ['z', 0], ['x', 0], ['cx', 2, 1], ['h', 1], ['h', 2], ['s', 0], ['h', 0], ['cx', 1, 2]]], ['+YII', '+IZI', '+IIX']], ['regression: random clifford 37', [3, [['z', 0], ['cx', 0, 2], ['s', 1], ['z', 1], ['h', 2], ['cx', 0, 1], ['s', 2], ['cx', 1, 0], ['h', 2], ['cx', 1, 0]]], ['+ZII', '+ZZI', '-ZIY']], ['repair check: random clifford 7', [3, [['cx', 0, 2], ['cx', 2, 1], ['s', 0], ['cx', 0, 2], ['cx', 2, 1], ['z', 1], ['z', 0], ['h', 1], ['x', 1]]], ['+ZII', '+ZXI', '+IIZ']], ['control: random clifford 45', [2, [['z', 1], ['h', 0], ['cx', 0, 1], ['cx', 1, 0], ['cx', 0, 1], ['s', 1], ['z', 0], ['h', 0], ['s', 1], ['z', 1], ['cx', 0, 1], ['h', 1], ['cx', 0, 1], ['z', 1]]], ['+ZZ', '+YY']], ['control: random clifford 46', [3, [['s', 0], ['z', 0]]], ['+ZII', '+IZI', '+IIZ']], ['control: random clifford 47', [2, [['cx', 1, 0], ['x', 1], ['z', 1], ['h', 0], ['x', 1], ['cx', 1, 0], ['cx', 0, 1], ['cx', 1, 0], ['z', 0], ['z', 1], ['h', 1], ['s', 1], ['z', 0], ['cx', 0, 1]]], ['-IZ', '+ZI']], ['control: random clifford 48', [2, [['x', 0], ['z', 0], ['x', 1], ['h', 0], ['h', 1], ['h', 1], ['z', 1], ['cx', 1, 0], ['h', 0], ['s', 0]]], ['-ZI', '-IZ']]]]
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):
    n, gates = x
    xs = [[0] * n for _ in range(n)]
    zs = [[1 if i == j else 0 for j in range(n)] for i in range(n)]
    rs = [0] * n
    for g in gates:
        op = g[0]
        for row in range(n):
            X, Z = xs[row], zs[row]
            if op == 'h':
                a = g[1]
                rs[row] ^= X[a] | Z[a]
                X[a], Z[a] = Z[a], X[a]
            elif op == 's':
                a = g[1]
                rs[row] ^= X[a] & Z[a]
                Z[a] ^= X[a]
            elif op == 'x':
                rs[row] ^= Z[g[1]]
            elif op == 'z':
                rs[row] ^= X[g[1]]
            elif op == 'cx':
                a, b = g[1], g[2]
                rs[row] ^= X[a] & Z[b] & (X[b] ^ Z[a] ^ 1)
                X[b] ^= X[a]
                Z[a] ^= Z[b]
    letters = {(0, 0): 'I', (1, 0): 'X', (0, 1): 'Z', (1, 1): 'Y'}
    return [('-' if rs[r] else '+') + ''.join(letters[(xs[r][q], zs[r][q])] for q in range(n)) for r in range(n)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: h on y eigenstate', [1, [['h', 0], ['s', 0], ['h', 0]]], ['-Y']], ['regression: random clifford 4', [3, [['cx', 1, 2], ['h', 1], ['cx', 1, 0], ['s', 1], ['x', 2], ['cx', 1, 2], ['cx', 1, 2], ['h', 0], ['cx', 0, 2], ['z', 0], ['s', 2], ['h', 2], ['z', 0]]], ['-XZY', '+ZYI', '-IYX']], ['repair check: bell preparation', [2, [['h', 0], ['cx', 0, 1]]], ['+XX', '+ZZ']], ['control: x flips z sign', [1, [['x', 0]]], ['-Z']], ['control: cx on excited control', [2, [['x', 0], ['cx', 0, 1]]], ['-ZI', '+ZZ']], ['control: random clifford 0', [3, [['cx', 1, 2]]], ['+ZII', '+IZI', '+IZZ']], ['control: random clifford 1', [1, [['z', 0], ['s', 0], ['x', 0], ['x', 0], ['x', 0], ['z', 0], ['z', 0], ['z', 0]]], ['-Z']]], [['regression: random clifford 26', [1, [['x', 0], ['h', 0], ['x', 0], ['h', 0], ['s', 0], ['h', 0], ['s', 0], ['h', 0], ['s', 0], ['s', 0], ['x', 0]]], ['+Y']], ['regression: random clifford 28', [3, [['h', 1], ['cx', 0, 1], ['h', 0], ['cx', 2, 1], ['z', 0], ['x', 0], ['cx', 2, 1], ['h', 1], ['h', 2], ['s', 0], ['h', 0], ['cx', 1, 2]]], ['+YII', '+IZI', '+IIX']], ['repair check: s twice after h', [1, [['h', 0], ['s', 0], ['s', 0]]], ['-X']], ['control: random clifford 3', [1, [['s', 0], ['h', 0], ['h', 0], ['x', 0], ['h', 0], ['h', 0], ['s', 0], ['s', 0]]], ['-Z']], ['control: random clifford 5', [1, [['h', 0], ['h', 0], ['h', 0], ['h', 0], ['z', 0], ['s', 0], ['s', 0], ['s', 0], ['x', 0], ['h', 0], ['x', 0], ['h', 0]]], ['-Z']], ['control: random clifford 6', [1, [['h', 0], ['z', 0], ['h', 0], ['z', 0], ['x', 0], ['h', 0], ['h', 0], ['h', 0], ['h', 0], ['h', 0], ['h', 0], ['s', 0], ['x', 0]]], ['-Z']], ['control: random clifford 10', [1, [['z', 0], ['z', 0], ['s', 0], ['z', 0], ['h', 0], ['h', 0], ['s', 0]]], ['+Z']]], [['regression: random clifford 41', [3, [['s', 2], ['s', 0], ['s', 1], ['cx', 1, 2], ['h', 1], ['cx', 2, 1], ['cx', 1, 2], ['h', 1], ['s', 2], ['cx', 1, 0]]], ['+ZZI', '+IZY', '-XYX']], ['regression: random clifford 42', [3, [['h', 2], ['cx', 1, 0], ['h', 2], ['s', 1], ['h', 0], ['cx', 2, 1], ['x', 2], ['x', 2], ['cx', 0, 2], ['h', 0], ['cx', 0, 2]]], ['-XZZ', '-YZY', '-YIY']], ['repair check: ghz', [3, [['h', 0], ['cx', 0, 1], ['cx', 0, 2]]], ['+XXX', '+ZZI', '+ZIZ']], ['control: random clifford 16', [1, [['x', 0], ['h', 0], ['h', 0], ['h', 0], ['h', 0], ['z', 0], ['z', 0], ['h', 0], ['x', 0], ['h', 0]]], ['-Z']], ['control: random clifford 21', [3, [['h', 0], ['s', 2], ['s', 1], ['h', 0], ['cx', 0, 2], ['cx', 0, 2], ['cx', 1, 2], ['h', 1], ['h', 1], ['cx', 2, 1]]], ['+ZII', '+IZZ', '+IZI']], ['control: random clifford 24', [1, [['x', 0]]], ['-Z']], ['control: random clifford 25', [2, [['cx', 1, 0], ['cx', 1, 0]]], ['+ZI', '+IZ']]], [['regression: random clifford 4', [3, [['cx', 1, 2], ['h', 1], ['cx', 1, 0], ['s', 1], ['x', 2], ['cx', 1, 2], ['cx', 1, 2], ['h', 0], ['cx', 0, 2], ['z', 0], ['s', 2], ['h', 2], ['z', 0]]], ['-XZY', '+ZYI', '-IYX']], ['regression: random clifford 12', [1, [['h', 0], ['s', 0], ['h', 0], ['x', 0], ['s', 0], ['x', 0], ['x', 0], ['z', 0], ['h', 0], ['s', 0], ['s', 0]]], ['+Z']], ['repair check: random clifford 2', [3, [['cx', 0, 2], ['z', 2], ['s', 2], ['h', 0], ['cx', 2, 1], ['x', 1], ['cx', 1, 0], ['x', 1], ['x', 1], ['z', 0], ['cx', 2, 1], ['h', 1], ['h', 0]]], ['-ZII', '-IXI', '-ZIZ']], ['control: random clifford 32', [3, [['z', 1], ['x', 1], ['cx', 1, 0], ['cx', 1, 2], ['cx', 2, 1], ['x', 0], ['cx', 1, 2], ['z', 1], ['z', 1], ['cx', 2, 1], ['z', 2], ['x', 0], ['cx', 0, 2]]], ['+IIZ', '-ZIZ', '+ZZZ']], ['control: random clifford 34', [1, [['z', 0], ['h', 0], ['z', 0], ['h', 0]]], ['-Z']], ['control: random clifford 40', [1, [['h', 0], ['x', 0], ['z', 0], ['s', 0], ['s', 0], ['x', 0], ['x', 0], ['x', 0], ['h', 0]]], ['+Z']], ['control: random clifford 43', [1, [['h', 0], ['x', 0], ['h', 0], ['z', 0], ['x', 0], ['x', 0], ['s', 0]]], ['+Z']]], [['regression: random clifford 28', [3, [['h', 1], ['cx', 0, 1], ['h', 0], ['cx', 2, 1], ['z', 0], ['x', 0], ['cx', 2, 1], ['h', 1], ['h', 2], ['s', 0], ['h', 0], ['cx', 1, 2]]], ['+YII', '+IZI', '+IIX']], ['regression: random clifford 37', [3, [['z', 0], ['cx', 0, 2], ['s', 1], ['z', 1], ['h', 2], ['cx', 0, 1], ['s', 2], ['cx', 1, 0], ['h', 2], ['cx', 1, 0]]], ['+ZII', '+ZZI', '-ZIY']], ['repair check: random clifford 7', [3, [['cx', 0, 2], ['cx', 2, 1], ['s', 0], ['cx', 0, 2], ['cx', 2, 1], ['z', 1], ['z', 0], ['h', 1], ['x', 1]]], ['+ZII', '+ZXI', '+IIZ']], ['control: random clifford 45', [2, [['z', 1], ['h', 0], ['cx', 0, 1], ['cx', 1, 0], ['cx', 0, 1], ['s', 1], ['z', 0], ['h', 0], ['s', 1], ['z', 1], ['cx', 0, 1], ['h', 1], ['cx', 0, 1], ['z', 1]]], ['+ZZ', '+YY']], ['control: random clifford 46', [3, [['s', 0], ['z', 0]]], ['+ZII', '+IZI', '+IIZ']], ['control: random clifford 47', [2, [['cx', 1, 0], ['x', 1], ['z', 1], ['h', 0], ['x', 1], ['cx', 1, 0], ['cx', 0, 1], ['cx', 1, 0], ['z', 0], ['z', 1], ['h', 1], ['s', 1], ['z', 0], ['cx', 0, 1]]], ['-IZ', '+ZI']], ['control: random clifford 48', [2, [['x', 0], ['z', 0], ['x', 1], ['h', 0], ['h', 1], ['h', 1], ['z', 1], ['cx', 1, 0], ['h', 0], ['s', 0]]], ['-ZI', '-IZ']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
H S H on |0> reports stabilizer +Y instead of -Y.

Input [n, gates] with gates h, s, x, z (["g", q]) and cx (["cx", c, t]). Track the n stabilizer generators of |0...0> (initially Z on each qubit) under the Aaronson-Gottesman update rules and return them as signed strings such as "+XX", character q describing qubit q.

split: open-access


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

N = 1
observations = []
def solve(x):
    n, gates = x
    xs = [[0] * n for _ in range(n)]
    zs = [[1 if i == j else 0 for j in range(n)] for i in range(n)]
    rs = [0] * n
    for g in gates:
        op = g[0]
        for row in range(n):
            X, Z = xs[row], zs[row]
            if op == 'h':
                a = g[1]
                rs[row] ^= X[a] & Z[a]
                X[a], Z[a] = Z[a], X[a]
            elif op == 's':
                a = g[1]
                Z[a] ^= X[a]
                rs[row] ^= X[a] & Z[a]
            elif op == 'x':
                rs[row] ^= Z[g[1]]
            elif op == 'z':
                rs[row] ^= X[g[1]]
            elif op == 'cx':
                a, b = g[1], g[2]
                rs[row] ^= X[a] & Z[b] & (X[b] ^ Z[a] ^ 1)
                X[b] ^= X[a]
                Z[a] ^= Z[b]
    letters = {(0, 0): 'I', (1, 0): 'X', (0, 1): 'Z', (1, 1): 'Y'}
    return [('-' if rs[r] else '+') + ''.join(letters[(xs[r][q], zs[r][q])] for q in range(n)) for r in range(n)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: h then s', [1, [['h', 0], ['s', 0]]], ['+Y']], ['regression: h on y eigenstate', [1, [['h', 0], ['s', 0], ['h', 0]]], ['-Y']], ['repair check: random clifford 1', [1, [['z', 0], ['s', 0], ['x', 0], ['x', 0], ['x', 0], ['z', 0], ['z', 0], ['z', 0]]], ['-Z']], ['control: bell preparation', [2, [['h', 0], ['cx', 0, 1]]], ['+XX', '+ZZ']], ['control: s twice after h', [1, [['h', 0], ['s', 0], ['s', 0]]], ['-X']], ['control: x flips z sign', [1, [['x', 0]]], ['-Z']], ['control: z on plus', [1, [['h', 0], ['z', 0]]], ['-X']]], [['regression: random clifford 11', [2, [['s', 1], ['h', 0], ['cx', 0, 1], ['s', 0], ['x', 0]]], ['-YX', '-ZZ']], ['regression: random clifford 17', [1, [['h', 0], ['s', 0], ['h', 0], ['h', 0], ['x', 0], ['s', 0], ['s', 0]]], ['+Y']], ['repair check: random clifford 3', [1, [['s', 0], ['h', 0], ['h', 0], ['x', 0], ['h', 0], ['h', 0], ['s', 0], ['s', 0]]], ['-Z']], ['control: cx on excited control', [2, [['x', 0], ['cx', 0, 1]]], ['-ZI', '+ZZ']], ['control: ghz', [3, [['h', 0], ['cx', 0, 1], ['cx', 0, 2]]], ['+XXX', '+ZZI', '+ZIZ']], ['control: random clifford 0', [3, [['cx', 1, 2]]], ['+ZII', '+IZI', '+IZZ']], ['control: random clifford 8', [3, [['cx', 0, 1], ['h', 2], ['h', 2], ['h', 0], ['cx', 2, 1], ['h', 2], ['z', 0], ['cx', 1, 2]]], ['-XII', '-XZX', '+IIX']]], [['regression: random clifford 28', [3, [['h', 1], ['cx', 0, 1], ['h', 0], ['cx', 2, 1], ['z', 0], ['x', 0], ['cx', 2, 1], ['h', 1], ['h', 2], ['s', 0], ['h', 0], ['cx', 1, 2]]], ['+YII', '+IZI', '+IIX']], ['regression: random clifford 29', [3, [['h', 2], ['s', 0], ['z', 1], ['h', 0], ['s', 0], ['z', 2], ['x', 1], ['z', 0], ['h', 2]]], ['-YII', '-IZI', '-IIZ']], ['repair check: random clifford 5', [1, [['h', 0], ['h', 0], ['h', 0], ['h', 0], ['z', 0], ['s', 0], ['s', 0], ['s', 0], ['x', 0], ['h', 0], ['x', 0], ['h', 0]]], ['-Z']], ['control: random clifford 10', [1, [['z', 0], ['z', 0], ['s', 0], ['z', 0], ['h', 0], ['h', 0], ['s', 0]]], ['+Z']], ['control: random clifford 12', [1, [['h', 0], ['s', 0], ['h', 0], ['x', 0], ['s', 0], ['x', 0], ['x', 0], ['z', 0], ['h', 0], ['s', 0], ['s', 0]]], ['+Z']], ['control: random clifford 15', [2, [['z', 1], ['cx', 0, 1], ['x', 1], ['h', 1]]], ['+ZI', '-ZX']], ['control: random clifford 16', [1, [['x', 0], ['h', 0], ['h', 0], ['h', 0], ['h', 0], ['z', 0], ['z', 0], ['h', 0], ['x', 0], ['h', 0]]], ['-Z']]], [['regression: random clifford 37', [3, [['z', 0], ['cx', 0, 2], ['s', 1], ['z', 1], ['h', 2], ['cx', 0, 1], ['s', 2], ['cx', 1, 0], ['h', 2], ['cx', 1, 0]]], ['+ZII', '+ZZI', '-ZIY']], ['regression: random clifford 38', [3, [['z', 1], ['h', 0], ['h', 2], ['h', 2], ['cx', 1, 2], ['cx', 2, 1], ['h', 1], ['h', 1], ['cx', 0, 1], ['h', 2], ['cx', 2, 1], ['s', 1], ['x', 0], ['s', 2]]], ['+XYI', '+ZXX', '-ZZZ']], ['repair check: random clifford 7', [3, [['cx', 0, 2], ['cx', 2, 1], ['s', 0], ['cx', 0, 2], ['cx', 2, 1], ['z', 1], ['z', 0], ['h', 1], ['x', 1]]], ['+ZII', '+ZXI', '+IIZ']], ['control: random clifford 19', [2, [['h', 0], ['cx', 1, 0], ['cx', 1, 0], ['cx', 0, 1], ['h', 0], ['cx', 1, 0], ['cx', 1, 0], ['cx', 0, 1], ['cx', 0, 1], ['cx', 1, 0], ['cx', 0, 1]]], ['+XZ', '-YY']], ['control: random clifford 20', [3, [['cx', 2, 0], ['h', 2], ['z', 0], ['cx', 2, 1], ['cx', 0, 2], ['cx', 2, 1]]], ['+ZIX', '+ZZI', '+IIX']], ['control: random clifford 22', [3, [['h', 2], ['h', 0], ['cx', 1, 0], ['s', 1], ['cx', 0, 1], ['cx', 1, 0], ['s', 0], ['cx', 2, 1]]], ['+IXI', '+ZII', '+IXX']], ['control: random clifford 24', [1, [['x', 0]]], ['-Z']]], [['regression: random clifford 52', [1, [['h', 0], ['h', 0], ['s', 0], ['x', 0], ['x', 0], ['x', 0], ['z', 0], ['s', 0], ['h', 0], ['s', 0]]], ['-Y']], ['regression: random clifford 54', [1, [['h', 0], ['h', 0], ['x', 0], ['s', 0], ['h', 0], ['s', 0], ['h', 0], ['h', 0], ['h', 0], ['h', 0]]], ['-Y']], ['repair check: random clifford 13', [1, [['z', 0], ['x', 0], ['z', 0], ['z', 0], ['s', 0], ['x', 0], ['h', 0], ['h', 0], ['z', 0], ['h', 0]]], ['+X']], ['control: random clifford 25', [2, [['cx', 1, 0], ['cx', 1, 0]]], ['+ZI', '+IZ']], ['control: random clifford 27', [2, [['cx', 1, 0], ['x', 0], ['h', 0], ['cx', 1, 0], ['cx', 1, 0], ['cx', 1, 0], ['h', 0], ['cx', 0, 1], ['cx', 0, 1], ['h', 0], ['z', 1], ['h', 1]]], ['-XX', '+IX']], ['control: random clifford 32', [3, [['z', 1], ['x', 1], ['cx', 1, 0], ['cx', 1, 2], ['cx', 2, 1], ['x', 0], ['cx', 1, 2], ['z', 1], ['z', 1], ['cx', 2, 1], ['z', 2], ['x', 0], ['cx', 0, 2]]], ['+IIZ', '-ZIZ', '+ZZZ']], ['control: random clifford 34', [1, [['z', 0], ['h', 0], ['z', 0], ['h', 0]]], ['-Z']]]]
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):
    n, gates = x
    xs = [[0] * n for _ in range(n)]
    zs = [[1 if i == j else 0 for j in range(n)] for i in range(n)]
    rs = [0] * n
    for g in gates:
        op = g[0]
        for row in range(n):
            X, Z = xs[row], zs[row]
            if op == 'h':
                a = g[1]
                rs[row] ^= X[a] & Z[a]
                X[a], Z[a] = Z[a], X[a]
            elif op == 's':
                a = g[1]
                rs[row] ^= Z[a]
                Z[a] ^= X[a]
            elif op == 'x':
                rs[row] ^= Z[g[1]]
            elif op == 'z':
                rs[row] ^= X[g[1]]
            elif op == 'cx':
                a, b = g[1], g[2]
                rs[row] ^= X[a] & Z[b] & (X[b] ^ Z[a] ^ 1)
                X[b] ^= X[a]
                Z[a] ^= Z[b]
    letters = {(0, 0): 'I', (1, 0): 'X', (0, 1): 'Z', (1, 1): 'Y'}
    return [('-' if rs[r] else '+') + ''.join(letters[(xs[r][q], zs[r][q])] for q in range(n)) for r in range(n)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['regression: h then s', [1, [['h', 0], ['s', 0]]], ['+Y']], ['regression: h on y eigenstate', [1, [['h', 0], ['s', 0], ['h', 0]]], ['-Y']], ['repair check: random clifford 1', [1, [['z', 0], ['s', 0], ['x', 0], ['x', 0], ['x', 0], ['z', 0], ['z', 0], ['z', 0]]], ['-Z']], ['control: bell preparation', [2, [['h', 0], ['cx', 0, 1]]], ['+XX', '+ZZ']], ['control: s twice after h', [1, [['h', 0], ['s', 0], ['s', 0]]], ['-X']], ['control: x flips z sign', [1, [['x', 0]]], ['-Z']], ['control: z on plus', [1, [['h', 0], ['z', 0]]], ['-X']]], [['regression: random clifford 11', [2, [['s', 1], ['h', 0], ['cx', 0, 1], ['s', 0], ['x', 0]]], ['-YX', '-ZZ']], ['regression: random clifford 17', [1, [['h', 0], ['s', 0], ['h', 0], ['h', 0], ['x', 0], ['s', 0], ['s', 0]]], ['+Y']], ['repair check: random clifford 3', [1, [['s', 0], ['h', 0], ['h', 0], ['x', 0], ['h', 0], ['h', 0], ['s', 0], ['s', 0]]], ['-Z']], ['control: cx on excited control', [2, [['x', 0], ['cx', 0, 1]]], ['-ZI', '+ZZ']], ['control: ghz', [3, [['h', 0], ['cx', 0, 1], ['cx', 0, 2]]], ['+XXX', '+ZZI', '+ZIZ']], ['control: random clifford 0', [3, [['cx', 1, 2]]], ['+ZII', '+IZI', '+IZZ']], ['control: random clifford 8', [3, [['cx', 0, 1], ['h', 2], ['h', 2], ['h', 0], ['cx', 2, 1], ['h', 2], ['z', 0], ['cx', 1, 2]]], ['-XII', '-XZX', '+IIX']]], [['regression: random clifford 28', [3, [['h', 1], ['cx', 0, 1], ['h', 0], ['cx', 2, 1], ['z', 0], ['x', 0], ['cx', 2, 1], ['h', 1], ['h', 2], ['s', 0], ['h', 0], ['cx', 1, 2]]], ['+YII', '+IZI', '+IIX']], ['regression: random clifford 29', [3, [['h', 2], ['s', 0], ['z', 1], ['h', 0], ['s', 0], ['z', 2], ['x', 1], ['z', 0], ['h', 2]]], ['-YII', '-IZI', '-IIZ']], ['repair check: random clifford 5', [1, [['h', 0], ['h', 0], ['h', 0], ['h', 0], ['z', 0], ['s', 0], ['s', 0], ['s', 0], ['x', 0], ['h', 0], ['x', 0], ['h', 0]]], ['-Z']], ['control: random clifford 10', [1, [['z', 0], ['z', 0], ['s', 0], ['z', 0], ['h', 0], ['h', 0], ['s', 0]]], ['+Z']], ['control: random clifford 12', [1, [['h', 0], ['s', 0], ['h', 0], ['x', 0], ['s', 0], ['x', 0], ['x', 0], ['z', 0], ['h', 0], ['s', 0], ['s', 0]]], ['+Z']], ['control: random clifford 15', [2, [['z', 1], ['cx', 0, 1], ['x', 1], ['h', 1]]], ['+ZI', '-ZX']], ['control: random clifford 16', [1, [['x', 0], ['h', 0], ['h', 0], ['h', 0], ['h', 0], ['z', 0], ['z', 0], ['h', 0], ['x', 0], ['h', 0]]], ['-Z']]], [['regression: random clifford 37', [3, [['z', 0], ['cx', 0, 2], ['s', 1], ['z', 1], ['h', 2], ['cx', 0, 1], ['s', 2], ['cx', 1, 0], ['h', 2], ['cx', 1, 0]]], ['+ZII', '+ZZI', '-ZIY']], ['regression: random clifford 38', [3, [['z', 1], ['h', 0], ['h', 2], ['h', 2], ['cx', 1, 2], ['cx', 2, 1], ['h', 1], ['h', 1], ['cx', 0, 1], ['h', 2], ['cx', 2, 1], ['s', 1], ['x', 0], ['s', 2]]], ['+XYI', '+ZXX', '-ZZZ']], ['repair check: random clifford 7', [3, [['cx', 0, 2], ['cx', 2, 1], ['s', 0], ['cx', 0, 2], ['cx', 2, 1], ['z', 1], ['z', 0], ['h', 1], ['x', 1]]], ['+ZII', '+ZXI', '+IIZ']], ['control: random clifford 19', [2, [['h', 0], ['cx', 1, 0], ['cx', 1, 0], ['cx', 0, 1], ['h', 0], ['cx', 1, 0], ['cx', 1, 0], ['cx', 0, 1], ['cx', 0, 1], ['cx', 1, 0], ['cx', 0, 1]]], ['+XZ', '-YY']], ['control: random clifford 20', [3, [['cx', 2, 0], ['h', 2], ['z', 0], ['cx', 2, 1], ['cx', 0, 2], ['cx', 2, 1]]], ['+ZIX', '+ZZI', '+IIX']], ['control: random clifford 22', [3, [['h', 2], ['h', 0], ['cx', 1, 0], ['s', 1], ['cx', 0, 1], ['cx', 1, 0], ['s', 0], ['cx', 2, 1]]], ['+IXI', '+ZII', '+IXX']], ['control: random clifford 24', [1, [['x', 0]]], ['-Z']]], [['regression: random clifford 52', [1, [['h', 0], ['h', 0], ['s', 0], ['x', 0], ['x', 0], ['x', 0], ['z', 0], ['s', 0], ['h', 0], ['s', 0]]], ['-Y']], ['regression: random clifford 54', [1, [['h', 0], ['h', 0], ['x', 0], ['s', 0], ['h', 0], ['s', 0], ['h', 0], ['h', 0], ['h', 0], ['h', 0]]], ['-Y']], ['repair check: random clifford 13', [1, [['z', 0], ['x', 0], ['z', 0], ['z', 0], ['s', 0], ['x', 0], ['h', 0], ['h', 0], ['z', 0], ['h', 0]]], ['+X']], ['control: random clifford 25', [2, [['cx', 1, 0], ['cx', 1, 0]]], ['+ZI', '+IZ']], ['control: random clifford 27', [2, [['cx', 1, 0], ['x', 0], ['h', 0], ['cx', 1, 0], ['cx', 1, 0], ['cx', 1, 0], ['h', 0], ['cx', 0, 1], ['cx', 0, 1], ['h', 0], ['z', 1], ['h', 1]]], ['-XX', '+IX']], ['control: random clifford 32', [3, [['z', 1], ['x', 1], ['cx', 1, 0], ['cx', 1, 2], ['cx', 2, 1], ['x', 0], ['cx', 1, 2], ['z', 1], ['z', 1], ['cx', 2, 1], ['z', 2], ['x', 0], ['cx', 0, 2]]], ['+IIZ', '-ZIZ', '+ZZZ']], ['control: random clifford 34', [1, [['z', 0], ['h', 0], ['z', 0], ['h', 0]]], ['-Z']]]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
H followed by S on |0> reports the stabilizer -Y instead of +Y.

Input [n, gates] with gates h, s, x, z (["g", q]) and cx (["cx", c, t]). Track the n stabilizer generators of |0...0> (initially Z on each qubit) under the Aaronson-Gottesman update rules and return them as signed strings such as "+XX", character q describing qubit q.

split: open-access


prompt:
The CNOT sign update fires for generators such as X_c Z_t that should keep their sign, and misses X_c Y_t style cases.

Input [n, gates] with gates h, s, x, z (["g", q]) and cx (["cx", c, t]). Track the n stabilizer generators of |0...0> (initially Z on each qubit) under the Aaronson-Gottesman update rules and return them as signed strings such as "+XX", character q describing qubit q.

split: open-access