{"abstract":"rz on qubit 1 before and after cx(0,1) are merged although they do not commute.","category":"Quantum circuit simulation","checks":7,"contract":"Input a gate list: [\"rz\", q, angle] (angle in units of pi as a fraction string), [\"x\", q], [\"h\", q], [\"cx\", c, t]. Scan left to right; a new gate looks back to the last op touching its qubit, except that rz may look past a cx whose control is that qubit. rz merges into a found rz, angles normalized to (-1, 1] and zero rotations dropped; x or h cancels a found identical gate. Return the optimized list with angles as fraction strings.","evaluation_group":"w2-quantum_circuit_simulation-rz-merge-peephole","failed_approach":"The attempted repair skips the cx when the qubit is either control or target.","family":"w2-quantum_circuit_simulation-rz-merge-peephole-commutation-through-cnot","id":"FA-91276","implementations":{"attempt":{"sha256":"a7a2041411205fabb27949c13ea4c828ada12c5ecaf78a68565cd174728001af","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nfrom fractions import Fraction\nN = 1\nobservations = []\ndef solve(x):\n    ops = x\n    out = []\n    def touches(op, q):\n        if op[0] == 'cx':\n            return q in (op[1], op[2])\n        return op[1] == q\n    def norm(a):\n        a = a % 2\n        if a > 1:\n            a -= 2\n        return a\n    for op in ops:\n        name = op[0]\n        if name == 'cx':\n            out.append(['cx', op[1], op[2]])\n            continue\n        q = op[1]\n        j = len(out) - 1\n        while j >= 0:\n            prev = out[j]\n            if not touches(prev, q):\n                j -= 1\n                continue\n            if name == 'rz' and prev[0] == 'cx' and q in (prev[1], prev[2]):\n                j -= 1\n                continue\n            break\n        if name == 'rz':\n            ang = Fraction(op[2])\n            if j >= 0 and out[j][0] == 'rz':\n                merged = norm(out[j][2] + ang)\n                if merged == 0:\n                    out.pop(j)\n                else:\n                    out[j][2] = merged\n            else:\n                ang = norm(ang)\n                if ang != 0:\n                    out.append(['rz', q, ang])\n        elif name in ('x', 'h') and j >= 0 and out[j][0] == name:\n            out.pop(j)\n        else:\n            out.append([name, q])\n    return [[o[0], o[1], str(o[2])] if o[0] == 'rz' else o for o in out]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[['regression: rz commutes through cx control', [['rz', 0, '1/4'], ['cx', 0, 1], ['rz', 0, '1/4']], [['rz', 0, '1/2'], ['cx', 0, 1]]], ['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['regression: random peephole 16', [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '5/4'], ['cx', 0, 1], ['rz', 1, '3/2']], [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '-3/4'], ['cx', 0, 1], ['rz', 1, '-1/2']]], ['control: rz merges to pi', [['rz', 0, '1/2'], ['rz', 0, '1/2']], [['rz', 0, '1']]], ['control: merge cancels to zero', [['rz', 0, '3/4'], ['rz', 0, '5/4']], []], ['control: unnormalized single rz', [['rz', 2, '5/2']], [['rz', 2, '1/2']]], ['control: rz of pi alone', [['rz', 0, '1']], [['rz', 0, '1']]]], [['regression: random peephole 16', [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '5/4'], ['cx', 0, 1], ['rz', 1, '3/2']], [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '-3/4'], ['cx', 0, 1], ['rz', 1, '-1/2']]], ['regression: random peephole 31', [['rz', 2, '7/4'], ['rz', 2, '-1/4'], ['cx', 2, 0], ['rz', 2, '7/4'], ['h', 1]], [['rz', 2, '-3/4'], ['cx', 2, 0], ['h', 1]]], ['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['control: x on different qubits', [['x', 0], ['x', 1]], [['x', 0], ['x', 1]]], ['control: x cancels across other qubit', [['x', 0], ['h', 1], ['x', 0]], [['h', 1]]], ['control: h blocked by rz', [['h', 0], ['rz', 0, '1/2'], ['h', 0]], [['h', 0], ['rz', 0, '1/2'], ['h', 0]]], ['control: random peephole 0', [['rz', 0, '1/2'], ['rz', 0, '-1/2'], ['rz', 1, '3/2'], ['rz', 2, '0'], ['rz', 1, '2'], ['x', 2], ['cx', 1, 0], ['x', 2]], [['rz', 1, '-1/2'], ['cx', 1, 0]]]], [['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['regression: random peephole 7', [['rz', 1, '3/2'], ['cx', 2, 0], ['rz', 0, '0'], ['rz', 0, '3/2'], ['cx', 0, 1], ['rz', 0, '3'], ['rz', 2, '-1'], ['rz', 0, '3/2']], [['rz', 1, '-1/2'], ['cx', 2, 0], ['cx', 0, 1], ['rz', 2, '1']]], ['regression: random peephole 16', [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '5/4'], ['cx', 0, 1], ['rz', 1, '3/2']], [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '-3/4'], ['cx', 0, 1], ['rz', 1, '-1/2']]], ['control: random peephole 1', [['cx', 2, 0], ['x', 0]], [['cx', 2, 0], ['x', 0]]], ['control: random peephole 2', [['h', 1], ['h', 0], ['h', 1]], [['h', 0]]], ['control: random peephole 3', [['x', 0], ['rz', 1, '1/2'], ['rz', 1, '1/4'], ['rz', 0, '-1'], ['cx', 2, 0], ['rz', 0, '0'], ['h', 0], ['cx', 1, 2]], [['x', 0], ['rz', 1, '3/4'], ['rz', 0, '1'], ['cx', 2, 0], ['h', 0], ['cx', 1, 2]]], ['control: random peephole 4', [['rz', 2, '5/4'], ['rz', 2, '-1/2'], ['rz', 1, '1/4'], ['rz', 1, '3'], ['cx', 1, 0], ['cx', 2, 0]], [['rz', 2, '3/4'], ['rz', 1, '-3/4'], ['cx', 1, 0], ['cx', 2, 0]]]], [['regression: random peephole 31', [['rz', 2, '7/4'], ['rz', 2, '-1/4'], ['cx', 2, 0], ['rz', 2, '7/4'], ['h', 1]], [['rz', 2, '-3/4'], ['cx', 2, 0], ['h', 1]]], ['regression: rz commutes through cx control', [['rz', 0, '1/4'], ['cx', 0, 1], ['rz', 0, '1/4']], [['rz', 0, '1/2'], ['cx', 0, 1]]], ['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['control: random peephole 5', [['x', 2], ['rz', 2, '3/2'], ['rz', 2, '1'], ['x', 1]], [['x', 2], ['rz', 2, '1/2'], ['x', 1]]], ['control: random peephole 6', [['rz', 1, '-1/4'], ['rz', 0, '1'], ['x', 0], ['x', 1], ['cx', 1, 0], ['rz', 0, '1'], ['rz', 2, '1/4'], ['x', 0]], [['rz', 1, '-1/4'], ['rz', 0, '1'], ['x', 0], ['x', 1], ['cx', 1, 0], ['rz', 0, '1'], ['rz', 2, '1/4'], ['x', 0]]], ['control: random peephole 8', [['rz', 2, '1/4'], ['rz', 2, '3/4'], ['rz', 2, '1'], ['x', 0], ['rz', 2, '3/4']], [['x', 0], ['rz', 2, '3/4']]], ['control: random peephole 9', [['cx', 2, 1], ['rz', 1, '-1/4'], ['rz', 0, '-1'], ['rz', 2, '0'], ['x', 0], ['rz', 1, '-1/2'], ['cx', 2, 1]], [['cx', 2, 1], ['rz', 1, '-3/4'], ['rz', 0, '1'], ['x', 0], ['cx', 2, 1]]]], [['regression: random peephole 7', [['rz', 1, '3/2'], ['cx', 2, 0], ['rz', 0, '0'], ['rz', 0, '3/2'], ['cx', 0, 1], ['rz', 0, '3'], ['rz', 2, '-1'], ['rz', 0, '3/2']], [['rz', 1, '-1/2'], ['cx', 2, 0], ['cx', 0, 1], ['rz', 2, '1']]], ['regression: random peephole 16', [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '5/4'], ['cx', 0, 1], ['rz', 1, '3/2']], [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '-3/4'], ['cx', 0, 1], ['rz', 1, '-1/2']]], ['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['control: random peephole 10', [['cx', 1, 2], ['rz', 0, '5/4'], ['rz', 2, '7/4'], ['rz', 0, '-1/4'], ['h', 1], ['rz', 0, '3/2'], ['rz', 0, '7/4'], ['x', 2]], [['cx', 1, 2], ['rz', 0, '1/4'], ['rz', 2, '-1/4'], ['h', 1], ['x', 2]]], ['control: random peephole 11', [['rz', 0, '-1/2'], ['h', 1], ['x', 2], ['cx', 0, 1], ['rz', 1, '3/2'], ['h', 1], ['cx', 2, 0], ['cx', 1, 0]], [['rz', 0, '-1/2'], ['h', 1], ['x', 2], ['cx', 0, 1], ['rz', 1, '-1/2'], ['h', 1], ['cx', 2, 0], ['cx', 1, 0]]], ['control: random peephole 12', [['x', 2], ['h', 0]], [['x', 2], ['h', 0]]], ['control: random peephole 13', [['h', 1], ['rz', 0, '1/2'], ['rz', 2, '5/4']], [['h', 1], ['rz', 0, '1/2'], ['rz', 2, '-3/4']]]]]\nfor label, args, expected in fixtures[N-1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"broken":{"sha256":"d1b29fd7029cc277ab6fbf857c0915ad5c859365af546326658bb0ea6cb93744","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nfrom fractions import Fraction\nN = 1\nobservations = []\ndef solve(x):\n    ops = x\n    out = []\n    def touches(op, q):\n        if op[0] == 'cx':\n            return q in (op[1], op[2])\n        return op[1] == q\n    def norm(a):\n        a = a % 2\n        if a > 1:\n            a -= 2\n        return a\n    for op in ops:\n        name = op[0]\n        if name == 'cx':\n            out.append(['cx', op[1], op[2]])\n            continue\n        q = op[1]\n        j = len(out) - 1\n        while j >= 0:\n            prev = out[j]\n            if not touches(prev, q):\n                j -= 1\n                continue\n            if name == 'rz' and prev[0] == 'cx' and prev[2] == q:\n                j -= 1\n                continue\n            break\n        if name == 'rz':\n            ang = Fraction(op[2])\n            if j >= 0 and out[j][0] == 'rz':\n                merged = norm(out[j][2] + ang)\n                if merged == 0:\n                    out.pop(j)\n                else:\n                    out[j][2] = merged\n            else:\n                ang = norm(ang)\n                if ang != 0:\n                    out.append(['rz', q, ang])\n        elif name in ('x', 'h') and j >= 0 and out[j][0] == name:\n            out.pop(j)\n        else:\n            out.append([name, q])\n    return [[o[0], o[1], str(o[2])] if o[0] == 'rz' else o for o in out]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[['regression: rz commutes through cx control', [['rz', 0, '1/4'], ['cx', 0, 1], ['rz', 0, '1/4']], [['rz', 0, '1/2'], ['cx', 0, 1]]], ['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['regression: random peephole 16', [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '5/4'], ['cx', 0, 1], ['rz', 1, '3/2']], [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '-3/4'], ['cx', 0, 1], ['rz', 1, '-1/2']]], ['control: rz merges to pi', [['rz', 0, '1/2'], ['rz', 0, '1/2']], [['rz', 0, '1']]], ['control: merge cancels to zero', [['rz', 0, '3/4'], ['rz', 0, '5/4']], []], ['control: unnormalized single rz', [['rz', 2, '5/2']], [['rz', 2, '1/2']]], ['control: rz of pi alone', [['rz', 0, '1']], [['rz', 0, '1']]]], [['regression: random peephole 16', [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '5/4'], ['cx', 0, 1], ['rz', 1, '3/2']], [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '-3/4'], ['cx', 0, 1], ['rz', 1, '-1/2']]], ['regression: random peephole 31', [['rz', 2, '7/4'], ['rz', 2, '-1/4'], ['cx', 2, 0], ['rz', 2, '7/4'], ['h', 1]], [['rz', 2, '-3/4'], ['cx', 2, 0], ['h', 1]]], ['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['control: x on different qubits', [['x', 0], ['x', 1]], [['x', 0], ['x', 1]]], ['control: x cancels across other qubit', [['x', 0], ['h', 1], ['x', 0]], [['h', 1]]], ['control: h blocked by rz', [['h', 0], ['rz', 0, '1/2'], ['h', 0]], [['h', 0], ['rz', 0, '1/2'], ['h', 0]]], ['control: random peephole 0', [['rz', 0, '1/2'], ['rz', 0, '-1/2'], ['rz', 1, '3/2'], ['rz', 2, '0'], ['rz', 1, '2'], ['x', 2], ['cx', 1, 0], ['x', 2]], [['rz', 1, '-1/2'], ['cx', 1, 0]]]], [['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['regression: random peephole 7', [['rz', 1, '3/2'], ['cx', 2, 0], ['rz', 0, '0'], ['rz', 0, '3/2'], ['cx', 0, 1], ['rz', 0, '3'], ['rz', 2, '-1'], ['rz', 0, '3/2']], [['rz', 1, '-1/2'], ['cx', 2, 0], ['cx', 0, 1], ['rz', 2, '1']]], ['regression: random peephole 16', [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '5/4'], ['cx', 0, 1], ['rz', 1, '3/2']], [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '-3/4'], ['cx', 0, 1], ['rz', 1, '-1/2']]], ['control: random peephole 1', [['cx', 2, 0], ['x', 0]], [['cx', 2, 0], ['x', 0]]], ['control: random peephole 2', [['h', 1], ['h', 0], ['h', 1]], [['h', 0]]], ['control: random peephole 3', [['x', 0], ['rz', 1, '1/2'], ['rz', 1, '1/4'], ['rz', 0, '-1'], ['cx', 2, 0], ['rz', 0, '0'], ['h', 0], ['cx', 1, 2]], [['x', 0], ['rz', 1, '3/4'], ['rz', 0, '1'], ['cx', 2, 0], ['h', 0], ['cx', 1, 2]]], ['control: random peephole 4', [['rz', 2, '5/4'], ['rz', 2, '-1/2'], ['rz', 1, '1/4'], ['rz', 1, '3'], ['cx', 1, 0], ['cx', 2, 0]], [['rz', 2, '3/4'], ['rz', 1, '-3/4'], ['cx', 1, 0], ['cx', 2, 0]]]], [['regression: random peephole 31', [['rz', 2, '7/4'], ['rz', 2, '-1/4'], ['cx', 2, 0], ['rz', 2, '7/4'], ['h', 1]], [['rz', 2, '-3/4'], ['cx', 2, 0], ['h', 1]]], ['regression: rz commutes through cx control', [['rz', 0, '1/4'], ['cx', 0, 1], ['rz', 0, '1/4']], [['rz', 0, '1/2'], ['cx', 0, 1]]], ['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['control: random peephole 5', [['x', 2], ['rz', 2, '3/2'], ['rz', 2, '1'], ['x', 1]], [['x', 2], ['rz', 2, '1/2'], ['x', 1]]], ['control: random peephole 6', [['rz', 1, '-1/4'], ['rz', 0, '1'], ['x', 0], ['x', 1], ['cx', 1, 0], ['rz', 0, '1'], ['rz', 2, '1/4'], ['x', 0]], [['rz', 1, '-1/4'], ['rz', 0, '1'], ['x', 0], ['x', 1], ['cx', 1, 0], ['rz', 0, '1'], ['rz', 2, '1/4'], ['x', 0]]], ['control: random peephole 8', [['rz', 2, '1/4'], ['rz', 2, '3/4'], ['rz', 2, '1'], ['x', 0], ['rz', 2, '3/4']], [['x', 0], ['rz', 2, '3/4']]], ['control: random peephole 9', [['cx', 2, 1], ['rz', 1, '-1/4'], ['rz', 0, '-1'], ['rz', 2, '0'], ['x', 0], ['rz', 1, '-1/2'], ['cx', 2, 1]], [['cx', 2, 1], ['rz', 1, '-3/4'], ['rz', 0, '1'], ['x', 0], ['cx', 2, 1]]]], [['regression: random peephole 7', [['rz', 1, '3/2'], ['cx', 2, 0], ['rz', 0, '0'], ['rz', 0, '3/2'], ['cx', 0, 1], ['rz', 0, '3'], ['rz', 2, '-1'], ['rz', 0, '3/2']], [['rz', 1, '-1/2'], ['cx', 2, 0], ['cx', 0, 1], ['rz', 2, '1']]], ['regression: random peephole 16', [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '5/4'], ['cx', 0, 1], ['rz', 1, '3/2']], [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '-3/4'], ['cx', 0, 1], ['rz', 1, '-1/2']]], ['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['control: random peephole 10', [['cx', 1, 2], ['rz', 0, '5/4'], ['rz', 2, '7/4'], ['rz', 0, '-1/4'], ['h', 1], ['rz', 0, '3/2'], ['rz', 0, '7/4'], ['x', 2]], [['cx', 1, 2], ['rz', 0, '1/4'], ['rz', 2, '-1/4'], ['h', 1], ['x', 2]]], ['control: random peephole 11', [['rz', 0, '-1/2'], ['h', 1], ['x', 2], ['cx', 0, 1], ['rz', 1, '3/2'], ['h', 1], ['cx', 2, 0], ['cx', 1, 0]], [['rz', 0, '-1/2'], ['h', 1], ['x', 2], ['cx', 0, 1], ['rz', 1, '-1/2'], ['h', 1], ['cx', 2, 0], ['cx', 1, 0]]], ['control: random peephole 12', [['x', 2], ['h', 0]], [['x', 2], ['h', 0]]], ['control: random peephole 13', [['h', 1], ['rz', 0, '1/2'], ['rz', 2, '5/4']], [['h', 1], ['rz', 0, '1/2'], ['rz', 2, '-3/4']]]]]\nfor label, args, expected in fixtures[N-1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"},"fixed":{"sha256":"9484e415fb06913e848b4bfdf70425dc3203bd2cd437cf541bf32df30b87e0dc","source":"\"\"\"Failure Map reference implementation. Python standard library only.\"\"\"\nimport json\nfrom fractions import Fraction\nN = 1\nobservations = []\ndef solve(x):\n    ops = x\n    out = []\n    def touches(op, q):\n        if op[0] == 'cx':\n            return q in (op[1], op[2])\n        return op[1] == q\n    def norm(a):\n        a = a % 2\n        if a > 1:\n            a -= 2\n        return a\n    for op in ops:\n        name = op[0]\n        if name == 'cx':\n            out.append(['cx', op[1], op[2]])\n            continue\n        q = op[1]\n        j = len(out) - 1\n        while j >= 0:\n            prev = out[j]\n            if not touches(prev, q):\n                j -= 1\n                continue\n            if name == 'rz' and prev[0] == 'cx' and prev[1] == q:\n                j -= 1\n                continue\n            break\n        if name == 'rz':\n            ang = Fraction(op[2])\n            if j >= 0 and out[j][0] == 'rz':\n                merged = norm(out[j][2] + ang)\n                if merged == 0:\n                    out.pop(j)\n                else:\n                    out[j][2] = merged\n            else:\n                ang = norm(ang)\n                if ang != 0:\n                    out.append(['rz', q, ang])\n        elif name in ('x', 'h') and j >= 0 and out[j][0] == name:\n            out.pop(j)\n        else:\n            out.append([name, q])\n    return [[o[0], o[1], str(o[2])] if o[0] == 'rz' else o for o in out]\ndef check(label, actual, expected):\n    observations.append({\"check\": label, \"actual\": actual, \"expected\": expected, \"passed\": actual == expected})\nfixtures = [[['regression: rz commutes through cx control', [['rz', 0, '1/4'], ['cx', 0, 1], ['rz', 0, '1/4']], [['rz', 0, '1/2'], ['cx', 0, 1]]], ['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['regression: random peephole 16', [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '5/4'], ['cx', 0, 1], ['rz', 1, '3/2']], [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '-3/4'], ['cx', 0, 1], ['rz', 1, '-1/2']]], ['control: rz merges to pi', [['rz', 0, '1/2'], ['rz', 0, '1/2']], [['rz', 0, '1']]], ['control: merge cancels to zero', [['rz', 0, '3/4'], ['rz', 0, '5/4']], []], ['control: unnormalized single rz', [['rz', 2, '5/2']], [['rz', 2, '1/2']]], ['control: rz of pi alone', [['rz', 0, '1']], [['rz', 0, '1']]]], [['regression: random peephole 16', [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '5/4'], ['cx', 0, 1], ['rz', 1, '3/2']], [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '-3/4'], ['cx', 0, 1], ['rz', 1, '-1/2']]], ['regression: random peephole 31', [['rz', 2, '7/4'], ['rz', 2, '-1/4'], ['cx', 2, 0], ['rz', 2, '7/4'], ['h', 1]], [['rz', 2, '-3/4'], ['cx', 2, 0], ['h', 1]]], ['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['control: x on different qubits', [['x', 0], ['x', 1]], [['x', 0], ['x', 1]]], ['control: x cancels across other qubit', [['x', 0], ['h', 1], ['x', 0]], [['h', 1]]], ['control: h blocked by rz', [['h', 0], ['rz', 0, '1/2'], ['h', 0]], [['h', 0], ['rz', 0, '1/2'], ['h', 0]]], ['control: random peephole 0', [['rz', 0, '1/2'], ['rz', 0, '-1/2'], ['rz', 1, '3/2'], ['rz', 2, '0'], ['rz', 1, '2'], ['x', 2], ['cx', 1, 0], ['x', 2]], [['rz', 1, '-1/2'], ['cx', 1, 0]]]], [['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['regression: random peephole 7', [['rz', 1, '3/2'], ['cx', 2, 0], ['rz', 0, '0'], ['rz', 0, '3/2'], ['cx', 0, 1], ['rz', 0, '3'], ['rz', 2, '-1'], ['rz', 0, '3/2']], [['rz', 1, '-1/2'], ['cx', 2, 0], ['cx', 0, 1], ['rz', 2, '1']]], ['regression: random peephole 16', [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '5/4'], ['cx', 0, 1], ['rz', 1, '3/2']], [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '-3/4'], ['cx', 0, 1], ['rz', 1, '-1/2']]], ['control: random peephole 1', [['cx', 2, 0], ['x', 0]], [['cx', 2, 0], ['x', 0]]], ['control: random peephole 2', [['h', 1], ['h', 0], ['h', 1]], [['h', 0]]], ['control: random peephole 3', [['x', 0], ['rz', 1, '1/2'], ['rz', 1, '1/4'], ['rz', 0, '-1'], ['cx', 2, 0], ['rz', 0, '0'], ['h', 0], ['cx', 1, 2]], [['x', 0], ['rz', 1, '3/4'], ['rz', 0, '1'], ['cx', 2, 0], ['h', 0], ['cx', 1, 2]]], ['control: random peephole 4', [['rz', 2, '5/4'], ['rz', 2, '-1/2'], ['rz', 1, '1/4'], ['rz', 1, '3'], ['cx', 1, 0], ['cx', 2, 0]], [['rz', 2, '3/4'], ['rz', 1, '-3/4'], ['cx', 1, 0], ['cx', 2, 0]]]], [['regression: random peephole 31', [['rz', 2, '7/4'], ['rz', 2, '-1/4'], ['cx', 2, 0], ['rz', 2, '7/4'], ['h', 1]], [['rz', 2, '-3/4'], ['cx', 2, 0], ['h', 1]]], ['regression: rz commutes through cx control', [['rz', 0, '1/4'], ['cx', 0, 1], ['rz', 0, '1/4']], [['rz', 0, '1/2'], ['cx', 0, 1]]], ['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['control: random peephole 5', [['x', 2], ['rz', 2, '3/2'], ['rz', 2, '1'], ['x', 1]], [['x', 2], ['rz', 2, '1/2'], ['x', 1]]], ['control: random peephole 6', [['rz', 1, '-1/4'], ['rz', 0, '1'], ['x', 0], ['x', 1], ['cx', 1, 0], ['rz', 0, '1'], ['rz', 2, '1/4'], ['x', 0]], [['rz', 1, '-1/4'], ['rz', 0, '1'], ['x', 0], ['x', 1], ['cx', 1, 0], ['rz', 0, '1'], ['rz', 2, '1/4'], ['x', 0]]], ['control: random peephole 8', [['rz', 2, '1/4'], ['rz', 2, '3/4'], ['rz', 2, '1'], ['x', 0], ['rz', 2, '3/4']], [['x', 0], ['rz', 2, '3/4']]], ['control: random peephole 9', [['cx', 2, 1], ['rz', 1, '-1/4'], ['rz', 0, '-1'], ['rz', 2, '0'], ['x', 0], ['rz', 1, '-1/2'], ['cx', 2, 1]], [['cx', 2, 1], ['rz', 1, '-3/4'], ['rz', 0, '1'], ['x', 0], ['cx', 2, 1]]]], [['regression: random peephole 7', [['rz', 1, '3/2'], ['cx', 2, 0], ['rz', 0, '0'], ['rz', 0, '3/2'], ['cx', 0, 1], ['rz', 0, '3'], ['rz', 2, '-1'], ['rz', 0, '3/2']], [['rz', 1, '-1/2'], ['cx', 2, 0], ['cx', 0, 1], ['rz', 2, '1']]], ['regression: random peephole 16', [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '5/4'], ['cx', 0, 1], ['rz', 1, '3/2']], [['cx', 2, 0], ['h', 0], ['cx', 2, 0], ['cx', 1, 0], ['rz', 1, '-3/4'], ['cx', 0, 1], ['rz', 1, '-1/2']]], ['regression: rz blocked by cx target', [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']], [['rz', 1, '1/4'], ['cx', 0, 1], ['rz', 1, '1/4']]], ['control: random peephole 10', [['cx', 1, 2], ['rz', 0, '5/4'], ['rz', 2, '7/4'], ['rz', 0, '-1/4'], ['h', 1], ['rz', 0, '3/2'], ['rz', 0, '7/4'], ['x', 2]], [['cx', 1, 2], ['rz', 0, '1/4'], ['rz', 2, '-1/4'], ['h', 1], ['x', 2]]], ['control: random peephole 11', [['rz', 0, '-1/2'], ['h', 1], ['x', 2], ['cx', 0, 1], ['rz', 1, '3/2'], ['h', 1], ['cx', 2, 0], ['cx', 1, 0]], [['rz', 0, '-1/2'], ['h', 1], ['x', 2], ['cx', 0, 1], ['rz', 1, '-1/2'], ['h', 1], ['cx', 2, 0], ['cx', 1, 0]]], ['control: random peephole 12', [['x', 2], ['h', 0]], [['x', 2], ['h', 0]]], ['control: random peephole 13', [['h', 1], ['rz', 0, '1/2'], ['rz', 2, '5/4']], [['h', 1], ['rz', 0, '1/2'], ['rz', 2, '-3/4']]]]]\nfor label, args, expected in fixtures[N-1]:\n    check(label, solve(args), expected)\nprint(json.dumps({\"observations\": observations, \"passed\": all(x[\"passed\"] for x in observations)}, ensure_ascii=False))\nraise SystemExit(0 if all(x[\"passed\"] for x in observations) else 1)\n"}},"limitations":"A deterministic bounded teaching model with a stipulated toy contract; amplitudes are rounded to fixed decimals for strict JSON output. It is not a production quantum SDK and claims no standards conformance. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.","method":"Deterministic executable model with adversarial boundary fixtures.","provenance":{"created_by":"Failure Map","dependencies":"Python standard library","family":"w2-quantum_circuit_simulation-rz-merge-peephole-commutation-through-cnot","generated_at":"2026-09-29T14:51:34.385908+00:00","license":"CC0-1.0","python":"3.12.14","seed":1,"split":"open-access"},"relevance":"Rotation merging and cancellation are the cheapest transpiler wins; commutation or normalization slips change circuit semantics.","repair":"Only skip a cx whose control is the rz qubit.","root_cause":"The look-back skip tests prev[2] == q (target) instead of prev[1] == q (control).","sha256":"a632ce18e12236b1116878f4a820325e44327109e839a2fc04b352404ebadfa0","title":"Rotation merger lets rz slide past a CNOT target · case 01","variant":1,"variant_policy":"Five numbered records share a model and may reuse boundary fixtures.","verification":{"attempt":{"elapsed_ms":42.267,"exit_code":1,"observations":[{"actual":[["rz",0,"1/2"],["cx",0,1]],"check":"regression: rz commutes through cx control","expected":[["rz",0,"1/2"],["cx",0,1]],"passed":true},{"actual":[["rz",1,"1/2"],["cx",0,1]],"check":"regression: rz blocked by cx target","expected":[["rz",1,"1/4"],["cx",0,1],["rz",1,"1/4"]],"passed":false},{"actual":[["cx",2,0],["h",0],["cx",2,0],["cx",1,0],["rz",1,"3/4"],["cx",0,1]],"check":"regression: random peephole 16","expected":[["cx",2,0],["h",0],["cx",2,0],["cx",1,0],["rz",1,"-3/4"],["cx",0,1],["rz",1,"-1/2"]],"passed":false},{"actual":[["rz",0,"1"]],"check":"control: rz merges to pi","expected":[["rz",0,"1"]],"passed":true},{"actual":[],"check":"control: merge cancels to zero","expected":[],"passed":true},{"actual":[["rz",2,"1/2"]],"check":"control: unnormalized single rz","expected":[["rz",2,"1/2"]],"passed":true},{"actual":[["rz",0,"1"]],"check":"control: rz of pi alone","expected":[["rz",0,"1"]],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression: rz commutes through cx control\", \"actual\": [[\"rz\", 0, \"1/2\"], [\"cx\", 0, 1]], \"expected\": [[\"rz\", 0, \"1/2\"], [\"cx\", 0, 1]], \"passed\": true}, {\"check\": \"regression: rz blocked by cx target\", \"actual\": [[\"rz\", 1, \"1/2\"], [\"cx\", 0, 1]], \"expected\": [[\"rz\", 1, \"1/4\"], [\"cx\", 0, 1], [\"rz\", 1, \"1/4\"]], \"passed\": false}, {\"check\": \"regression: random peephole 16\", \"actual\": [[\"cx\", 2, 0], [\"h\", 0], [\"cx\", 2, 0], [\"cx\", 1, 0], [\"rz\", 1, \"3/4\"], [\"cx\", 0, 1]], \"expected\": [[\"cx\", 2, 0], [\"h\", 0], [\"cx\", 2, 0], [\"cx\", 1, 0], [\"rz\", 1, \"-3/4\"], [\"cx\", 0, 1], [\"rz\", 1, \"-1/2\"]], \"passed\": false}, {\"check\": \"control: rz merges to pi\", \"actual\": [[\"rz\", 0, \"1\"]], \"expected\": [[\"rz\", 0, \"1\"]], \"passed\": true}, {\"check\": \"control: merge cancels to zero\", \"actual\": [], \"expected\": [], \"passed\": true}, {\"check\": \"control: unnormalized single rz\", \"actual\": [[\"rz\", 2, \"1/2\"]], \"expected\": [[\"rz\", 2, \"1/2\"]], \"passed\": true}, {\"check\": \"control: rz of pi alone\", \"actual\": [[\"rz\", 0, \"1\"]], \"expected\": [[\"rz\", 0, \"1\"]], \"passed\": true}], \"passed\": false}\n"},"broken":{"elapsed_ms":42.111,"exit_code":1,"observations":[{"actual":[["rz",0,"1/4"],["cx",0,1],["rz",0,"1/4"]],"check":"regression: rz commutes through cx control","expected":[["rz",0,"1/2"],["cx",0,1]],"passed":false},{"actual":[["rz",1,"1/2"],["cx",0,1]],"check":"regression: rz blocked by cx target","expected":[["rz",1,"1/4"],["cx",0,1],["rz",1,"1/4"]],"passed":false},{"actual":[["cx",2,0],["h",0],["cx",2,0],["cx",1,0],["rz",1,"3/4"],["cx",0,1]],"check":"regression: random peephole 16","expected":[["cx",2,0],["h",0],["cx",2,0],["cx",1,0],["rz",1,"-3/4"],["cx",0,1],["rz",1,"-1/2"]],"passed":false},{"actual":[["rz",0,"1"]],"check":"control: rz merges to pi","expected":[["rz",0,"1"]],"passed":true},{"actual":[],"check":"control: merge cancels to zero","expected":[],"passed":true},{"actual":[["rz",2,"1/2"]],"check":"control: unnormalized single rz","expected":[["rz",2,"1/2"]],"passed":true},{"actual":[["rz",0,"1"]],"check":"control: rz of pi alone","expected":[["rz",0,"1"]],"passed":true}],"passed":false,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression: rz commutes through cx control\", \"actual\": [[\"rz\", 0, \"1/4\"], [\"cx\", 0, 1], [\"rz\", 0, \"1/4\"]], \"expected\": [[\"rz\", 0, \"1/2\"], [\"cx\", 0, 1]], \"passed\": false}, {\"check\": \"regression: rz blocked by cx target\", \"actual\": [[\"rz\", 1, \"1/2\"], [\"cx\", 0, 1]], \"expected\": [[\"rz\", 1, \"1/4\"], [\"cx\", 0, 1], [\"rz\", 1, \"1/4\"]], \"passed\": false}, {\"check\": \"regression: random peephole 16\", \"actual\": [[\"cx\", 2, 0], [\"h\", 0], [\"cx\", 2, 0], [\"cx\", 1, 0], [\"rz\", 1, \"3/4\"], [\"cx\", 0, 1]], \"expected\": [[\"cx\", 2, 0], [\"h\", 0], [\"cx\", 2, 0], [\"cx\", 1, 0], [\"rz\", 1, \"-3/4\"], [\"cx\", 0, 1], [\"rz\", 1, \"-1/2\"]], \"passed\": false}, {\"check\": \"control: rz merges to pi\", \"actual\": [[\"rz\", 0, \"1\"]], \"expected\": [[\"rz\", 0, \"1\"]], \"passed\": true}, {\"check\": \"control: merge cancels to zero\", \"actual\": [], \"expected\": [], \"passed\": true}, {\"check\": \"control: unnormalized single rz\", \"actual\": [[\"rz\", 2, \"1/2\"]], \"expected\": [[\"rz\", 2, \"1/2\"]], \"passed\": true}, {\"check\": \"control: rz of pi alone\", \"actual\": [[\"rz\", 0, \"1\"]], \"expected\": [[\"rz\", 0, \"1\"]], \"passed\": true}], \"passed\": false}\n"},"fixed":{"elapsed_ms":42.926,"exit_code":0,"observations":[{"actual":[["rz",0,"1/2"],["cx",0,1]],"check":"regression: rz commutes through cx control","expected":[["rz",0,"1/2"],["cx",0,1]],"passed":true},{"actual":[["rz",1,"1/4"],["cx",0,1],["rz",1,"1/4"]],"check":"regression: rz blocked by cx target","expected":[["rz",1,"1/4"],["cx",0,1],["rz",1,"1/4"]],"passed":true},{"actual":[["cx",2,0],["h",0],["cx",2,0],["cx",1,0],["rz",1,"-3/4"],["cx",0,1],["rz",1,"-1/2"]],"check":"regression: random peephole 16","expected":[["cx",2,0],["h",0],["cx",2,0],["cx",1,0],["rz",1,"-3/4"],["cx",0,1],["rz",1,"-1/2"]],"passed":true},{"actual":[["rz",0,"1"]],"check":"control: rz merges to pi","expected":[["rz",0,"1"]],"passed":true},{"actual":[],"check":"control: merge cancels to zero","expected":[],"passed":true},{"actual":[["rz",2,"1/2"]],"check":"control: unnormalized single rz","expected":[["rz",2,"1/2"]],"passed":true},{"actual":[["rz",0,"1"]],"check":"control: rz of pi alone","expected":[["rz",0,"1"]],"passed":true}],"passed":true,"stderr":"","stdout":"{\"observations\": [{\"check\": \"regression: rz commutes through cx control\", \"actual\": [[\"rz\", 0, \"1/2\"], [\"cx\", 0, 1]], \"expected\": [[\"rz\", 0, \"1/2\"], [\"cx\", 0, 1]], \"passed\": true}, {\"check\": \"regression: rz blocked by cx target\", \"actual\": [[\"rz\", 1, \"1/4\"], [\"cx\", 0, 1], [\"rz\", 1, \"1/4\"]], \"expected\": [[\"rz\", 1, \"1/4\"], [\"cx\", 0, 1], [\"rz\", 1, \"1/4\"]], \"passed\": true}, {\"check\": \"regression: random peephole 16\", \"actual\": [[\"cx\", 2, 0], [\"h\", 0], [\"cx\", 2, 0], [\"cx\", 1, 0], [\"rz\", 1, \"-3/4\"], [\"cx\", 0, 1], [\"rz\", 1, \"-1/2\"]], \"expected\": [[\"cx\", 2, 0], [\"h\", 0], [\"cx\", 2, 0], [\"cx\", 1, 0], [\"rz\", 1, \"-3/4\"], [\"cx\", 0, 1], [\"rz\", 1, \"-1/2\"]], \"passed\": true}, {\"check\": \"control: rz merges to pi\", \"actual\": [[\"rz\", 0, \"1\"]], \"expected\": [[\"rz\", 0, \"1\"]], \"passed\": true}, {\"check\": \"control: merge cancels to zero\", \"actual\": [], \"expected\": [], \"passed\": true}, {\"check\": \"control: unnormalized single rz\", \"actual\": [[\"rz\", 2, \"1/2\"]], \"expected\": [[\"rz\", 2, \"1/2\"]], \"passed\": true}, {\"check\": \"control: rz of pi alone\", \"actual\": [[\"rz\", 0, \"1\"]], \"expected\": [[\"rz\", 0, \"1\"]], \"passed\": true}], \"passed\": true}\n"}},"verified":true,"visibility":"public"}