deskmerc/ quantum

Byte protection / KINGSTON

Quantum Field Report

A checksum for one teleported bit

Compare physical repair, a majority vote and keeping only clean syndrome checks.

IBM job ID
dc0fmqmq4uuc73a2i3eg
Submitted
20 Nov 2026 · 20:01 CST
QPU charge
2 seconds
Backend
ibm_kingston
Sampling
256 shots per recorded setting/case
Provenance
Quantum Field Report, page 12.

The question

Compare physical repair, a majority vote and keeping only clean syndrome checks.

Circuit & method

Encode zero as 000 and one as 111, teleport three carriers, then compare active correction on and off. Each input/correction case has 256 shots. The JSON’s primary output is the center rail; majority voting is a separate software score.

PrepareState, codeword or problem instance
Run on KingstonRecorded physical circuit and settings
Measure & checkCounts, decoding and classical verification

Results

With correction off, majority voting was right 489/512 times; with it on, 483/512. Whole-word agreement rose from 356/512 to 432/512. Clean-check majority accuracy was 360/367 and 363/375 respectively.

Measured outcomesAll-shot success; each bar runs from 0% to 100%.
1 · repair off · center233/256 · 91.0%
1 · repair on · center235/256 · 91.8%
0 · repair off · center241/256 · 94.1%
0 · repair on · center242/256 · 94.5%

What this supports

Accepted-shot accuracy changes the denominator. Classical repetition protects these known basis bits; this experiment alone does not test arbitrary quantum-state phase protection.

Percentages are rounded for reading. The original integer counts, physical layouts, settings and available uncertainty calculations remain in the records below. Sampling intervals do not account for drift or every systematic error.

Full experiment record

Every top-level field from the primary hardware JSON is reproduced below, including the complete saved measurement distributions where present. Field names and outcome strings retain their original order and spelling.

stage
done
backend
ibm_kingston
layout
{
  "source": [
    91,
    107,
    127
  ],
  "alice": [
    98,
    108,
    128
  ],
  "bob": [
    111,
    109,
    129
  ],
  "checks": [
    110,
    118
  ],
  "encode": [
    [
      107,
      97
    ],
    [
      97,
      87
    ],
    [
      87,
      88
    ],
    [
      88,
      89
    ],
    [
      89,
      90
    ],
    [
      90,
      91
    ],
    [
      107,
      106
    ],
    [
      106,
      105
    ],
    [
      105,
      117
    ],
    [
      117,
      125
    ],
    [
      125,
      126
    ],
    [
      126,
      127
    ],
    [
      125,
      126
    ],
    [
      117,
      125
    ],
    [
      105,
      117
    ],
    [
      106,
      105
    ],
    [
      107,
      106
    ],
    [
      89,
      90
    ],
    [
      88,
      89
    ],
    [
      87,
      88
    ],
    [
      97,
      87
    ],
    [
      107,
      97
    ]
  ]
}
used
[
  87,
  88,
  89,
  90,
  91,
  97,
  98,
  105,
  106,
  107,
  108,
  109,
  110,
  111,
  117,
  118,
  125,
  126,
  127,
  128,
  129
]
cases
[
  {
    "bit": 1,
    "correct": false,
    "native_counts": {
      "rz": 132,
      "sx": 66,
      "cz": 32,
      "measure_2": 8,
      "if_else": 6,
      "barrier": 3,
      "measure": 3,
      "x": 1
    }
  },
  {
    "bit": 1,
    "correct": true,
    "native_counts": {
      "rz": 132,
      "sx": 66,
      "cz": 32,
      "if_else": 9,
      "measure_2": 8,
      "barrier": 3,
      "measure": 3,
      "x": 1
    }
  },
  {
    "bit": 0,
    "correct": false,
    "native_counts": {
      "rz": 132,
      "sx": 66,
      "cz": 32,
      "measure_2": 8,
      "if_else": 6,
      "barrier": 3,
      "measure": 3
    }
  },
  {
    "bit": 0,
    "correct": true,
    "native_counts": {
      "rz": 132,
      "sx": 66,
      "cz": 32,
      "if_else": 9,
      "measure_2": 8,
      "barrier": 3,
      "measure": 3
    }
  }
]
fast_mid_measure
True
shots_per_case
256
tag
three-rail-teleport-checksum-20261120-v1
primary
Bob center rail after optional physical repair
job_id
dc0fmqmq4uuc73a2i3eg
counts
[
  {
    "11100001010": 4,
    "11100100101": 8,
    "10111000110": 2,
    "01100010110": 1,
    "11100111111": 2,
    "11100101100": 4,
    "11100110001": 2,
    "11100101110": 4,
    "11100100100": 4,
    "01110011010": 2,
    "11100010000": 4,
    "11100111110": 5,
    "10111000111": 1,
    "11001010100": 2,
    "00101010000": 1,
    "11100100000": 5,
    "11100111001": 2,
    "11100000111": 4,
    "11100110011": 2,
    "01110111011": 1,
    "11100010101": 7,
    "11100001100": 3,
    "11100000101": 2,
    "01110001001": 1,
    "00101010010": 1,
    "11100000011": 1,
    "11100101000": 5,
    "11100011000": 2,
    "01110110000": 1,
    "11100101111": 4,
    "01110010110": 2,
    "11001000110": 2,
    "11100011100": 4,
    "11100111011": 4,
    "01110010101": 1,
    "01110111001": 1,
    "11100101011": 3,
    "01010001111": 1,
    "11001000011": 1,
    "01110010001": 1,
    "10100100100": 1,
    "10111110010": 1,
    "01110011111": 1,
    "11100110111": 3,
    "11100101010": 3,
    "11100001110": 2,
    "11001000000": 1,
    "11100110100": 2,
    "11100001101": 3,
    "11100000001": 2,
    "11100011111": 4,
    "11100100010": 2,
    "11100001001": 2,
    "10111110101": 1,
    "11001100011": 1,
    "11100011011": 3,
    "01110010010": 2,
    "11100000000": 2,
    "10011101011": 1,
    "11100111000": 3,
    "01110111110": 1,
    "01110100000": 1,
    "11001110111": 4,
    "11001111001": 2,
    "11000111000": 1,
    "11100010111": 3,
    "01100110001": 1,
    "11100011010": 2,
    "00110011010": 1,
    "11100100001": 2,
    "11100111101": 5,
    "10111101100": 1,
    "11100000100": 3,
    "11100000010": 1,
    "01110100110": 2,
    "11100100111": 2,
    "01110001100": 3,
    "01110000101": 1,
    "11000001101": 1,
    "01110100101": 1,
    "10111001010": 1,
    "11100011101": 3,
    "11001100000": 2,
    "10111011011": 1,
    "01110010000": 1,
    "10111010110": 1,
    "11001011010": 1,
    "11100101001": 1,
    "11001010011": 1,
    "11001101100": 1,
    "10111000000": 1,
    "01110001000": 1,
    "11100100110": 2,
    "11001011110": 1,
    "11100010011": 1,
    "01110110011": 1,
    "10111010001": 1,
    "11100010110": 2,
    "11100001000": 1,
    "00000110100": 1,
    "11100111100": 1,
    "11100110000": 1,
    "00101000111": 1,
    "00110000110": 1,
    "11100010010": 1,
    "11100001111": 2,
    "01110010011": 1,
    "11001111010": 1,
    "01011101011": 1,
    "01110001010": 1,
    "11110000000": 1,
    "01110000011": 1,
    "01110100100": 2,
    "11100010100": 2,
    "10100111111": 1,
    "11001011111": 1,
    "00101001001": 1,
    "01110000010": 2,
    "11100110110": 2,
    "01110000000": 1,
    "11100101101": 1,
    "11100000110": 1,
    "01110101000": 1,
    "01110011110": 1,
    "00101001011": 1,
    "01110011001": 1,
    "01110000100": 1,
    "11000011001": 1,
    "00000001010": 1,
    "01110001110": 1,
    "11110110110": 1,
    "11001000100": 1,
    "01110011101": 1,
    "11100100011": 2,
    "01111101110": 1,
    "01100000101": 1,
    "11101111101": 1,
    "11000000110": 1,
    "01110101001": 1,
    "11001011000": 1
  },
  {
    "00000100000": 1,
    "11111100001": 1,
    "11100000101": 2,
    "11100010111": 3,
    "11001100100": 1,
    "11100011100": 1,
    "01100101011": 1,
    "11010101010": 2,
    "11110010000": 1,
    "11100111100": 4,
    "11100100010": 4,
    "11100011011": 4,
    "11100110100": 3,
    "11100101111": 5,
    "11100111001": 2,
    "11100010000": 2,
    "11101100111": 1,
    "11100101110": 6,
    "11110000011": 2,
    "11100100110": 5,
    "11111001110": 2,
    "01101101001": 1,
    "11100000001": 3,
    "00000100011": 1,
    "11110110001": 2,
    "00001101011": 1,
    "11111111110": 1,
    "11100010100": 4,
    "11100010110": 3,
    "11100001100": 4,
    "11100110000": 2,
    "11100000110": 1,
    "11101010001": 1,
    "11110111101": 1,
    "01101000011": 1,
    "11100001010": 5,
    "11000011000": 1,
    "11110010101": 1,
    "11100100100": 5,
    "11100000000": 4,
    "00000100100": 1,
    "11001101101": 1,
    "11101000011": 1,
    "11001001011": 1,
    "11100111111": 2,
    "01110010011": 1,
    "11100100000": 2,
    "01100111110": 3,
    "11100011111": 2,
    "11100000010": 2,
    "11100001110": 2,
    "11000110110": 1,
    "11100001111": 3,
    "00010001100": 1,
    "11100101101": 4,
    "11100110110": 2,
    "11100101001": 3,
    "11110111000": 3,
    "11100111101": 3,
    "11100010001": 3,
    "11100001101": 3,
    "11101000000": 1,
    "11100110101": 1,
    "11111011100": 1,
    "11100111110": 3,
    "11110111011": 1,
    "10110110101": 1,
    "00000111011": 1,
    "00010110111": 1,
    "11100100011": 2,
    "11110100101": 1,
    "11110110011": 1,
    "11100001001": 2,
    "11111111111": 1,
    "11101111110": 1,
    "10100101111": 1,
    "00000110001": 1,
    "11100010011": 3,
    "11101111101": 1,
    "11100000111": 3,
    "11110011001": 2,
    "11101010110": 1,
    "11100100101": 2,
    "10100000001": 1,
    "11100100001": 4,
    "11100101011": 3,
    "11110010110": 2,
    "11100101010": 1,
    "11101010011": 1,
    "11101000110": 1,
    "01100111011": 1,
    "11100110111": 2,
    "11100001011": 3,
    "11000101001": 1,
    "01100011100": 1,
    "11100101000": 6,
    "11100111011": 1,
    "11101000101": 1,
    "11001011001": 1,
    "11100110001": 1,
    "11000001101": 1,
    "10100110000": 1,
    "11100101100": 1,
    "11000100001": 1,
    "11100000100": 3,
    "11100011101": 1,
    "11101101100": 1,
    "01100001100": 1,
    "00011110000": 1,
    "11100110010": 1,
    "11001100010": 1,
    "11101010100": 1,
    "11111000101": 1,
    "00000111100": 1,
    "00010100100": 1,
    "11100011000": 1,
    "10001000001": 1,
    "11001110010": 1,
    "11110111110": 1,
    "01001011110": 1,
    "11101111001": 1,
    "11101010111": 1,
    "11100011001": 1,
    "11101111010": 1,
    "00000000101": 1,
    "11111101111": 1,
    "11110000101": 2,
    "11101101001": 1,
    "01100100010": 1,
    "11101111000": 1,
    "11110101110": 1,
    "11101101011": 1,
    "11111010100": 1,
    "11110110111": 1,
    "11110110101": 1,
    "11111100101": 1,
    "01101101011": 1,
    "10100100000": 1,
    "11100011010": 1,
    "01110110000": 1,
    "11110011011": 1,
    "00010110100": 1,
    "01100100111": 1,
    "00001001010": 1,
    "11000101111": 1,
    "01101101100": 1,
    "11110010010": 1,
    "00000100111": 1,
    "11100010010": 1,
    "11001101100": 1,
    "11101011110": 1
  },
  {
    "00000101010": 2,
    "00000101110": 6,
    "00000010110": 3,
    "10010001101": 2,
    "00000011100": 3,
    "00000100110": 2,
    "01011111000": 1,
    "00000010100": 6,
    "10010111110": 1,
    "00000001010": 4,
    "00101000110": 2,
    "00000110110": 3,
    "00000010111": 4,
    "10010111001": 2,
    "00000000011": 3,
    "00000010000": 7,
    "00000110101": 4,
    "00000111001": 3,
    "11001100101": 1,
    "10111011110": 2,
    "10010011110": 1,
    "00000101001": 3,
    "00000010010": 5,
    "00000100101": 8,
    "00000001011": 3,
    "00001000000": 1,
    "00000101111": 3,
    "00000100001": 2,
    "00000100000": 3,
    "00000011001": 1,
    "01011111011": 1,
    "00000000100": 2,
    "10010100110": 1,
    "00000111011": 3,
    "00100111110": 1,
    "00010001010": 1,
    "00000110010": 3,
    "00000001111": 2,
    "00000001100": 5,
    "01010000101": 1,
    "00000000000": 4,
    "00000011010": 2,
    "00000101100": 5,
    "10010000011": 1,
    "00000011111": 2,
    "00101100010": 1,
    "00101010001": 1,
    "00000011110": 3,
    "10010001100": 1,
    "00000110000": 1,
    "10010110011": 1,
    "10000010010": 1,
    "00101011001": 1,
    "00000011011": 3,
    "01011010001": 1,
    "00000001110": 6,
    "00000001000": 2,
    "00000000110": 6,
    "10010100010": 1,
    "00000101011": 2,
    "00000000101": 4,
    "00000100111": 2,
    "00000110100": 2,
    "11100001100": 1,
    "00000111000": 4,
    "00000100011": 3,
    "00000111010": 3,
    "00000111111": 1,
    "00000000001": 6,
    "10010111101": 1,
    "00101111001": 1,
    "01011010100": 1,
    "10010111111": 1,
    "00000011101": 3,
    "11100101101": 1,
    "00000100100": 2,
    "00111111001": 1,
    "00000011000": 4,
    "00000110011": 1,
    "10010000100": 1,
    "00000001101": 4,
    "00000110001": 3,
    "10111011010": 1,
    "00101001010": 1,
    "00000101000": 4,
    "00101001000": 1,
    "00000111101": 1,
    "10010000101": 1,
    "00000010011": 4,
    "10111001111": 1,
    "11100100011": 1,
    "01011010000": 1,
    "00010011111": 1,
    "00000010001": 2,
    "10010110111": 1,
    "00001011001": 1,
    "00000010101": 2,
    "00000101101": 2,
    "00001011011": 1,
    "10000000011": 1,
    "10010010111": 1,
    "00101101111": 1,
    "10111111101": 1,
    "10010101001": 1,
    "10010100001": 1,
    "11100000001": 1,
    "00000000111": 2,
    "00000111100": 1,
    "01011001100": 1,
    "00101011010": 1,
    "10010010001": 1,
    "01011100010": 1,
    "00010101100": 1,
    "00101110010": 1,
    "10010000010": 1,
    "00000001001": 1,
    "10010110100": 1,
    "00101000010": 1,
    "10010001011": 1,
    "01000001010": 1,
    "11100010101": 1,
    "10010001110": 1
  },
  {
    "00000011001": 2,
    "00000110010": 1,
    "00000100100": 3,
    "00010101101": 1,
    "00000100101": 3,
    "00000010000": 2,
    "00000100110": 2,
    "00000001010": 4,
    "00000101011": 2,
    "00000111011": 2,
    "00000000101": 4,
    "11100001011": 1,
    "00000000000": 4,
    "00010110111": 1,
    "00000001000": 1,
    "00000101100": 5,
    "10000110010": 1,
    "00011011011": 1,
    "00000001011": 3,
    "00010011111": 2,
    "00000111101": 5,
    "00000001001": 1,
    "10010010011": 1,
    "00000000111": 3,
    "00000101001": 4,
    "00000000100": 4,
    "00000011110": 7,
    "00000011010": 3,
    "00100110000": 1,
    "00000010010": 3,
    "00011100100": 1,
    "11000110101": 1,
    "00000110111": 4,
    "00000010100": 5,
    "00001001000": 1,
    "00000110011": 4,
    "00000010101": 3,
    "00010111010": 1,
    "00000011100": 3,
    "00000101111": 5,
    "00000101010": 6,
    "00000000010": 4,
    "00000011011": 2,
    "00000111001": 3,
    "11110111100": 1,
    "00010111011": 2,
    "00000100011": 3,
    "00000010111": 6,
    "00010111100": 1,
    "00000000110": 2,
    "00000000011": 2,
    "00001101011": 1,
    "00000101101": 4,
    "00000110100": 2,
    "11111000000": 1,
    "00000100111": 4,
    "00011100000": 1,
    "00010011100": 1,
    "00000101000": 3,
    "00010001110": 2,
    "10000100001": 1,
    "00100100111": 1,
    "11100100101": 1,
    "00000110001": 2,
    "00000001100": 7,
    "00010001100": 2,
    "00000111000": 2,
    "00000000001": 2,
    "00001101111": 1,
    "01000000100": 1,
    "00010100111": 2,
    "11110000010": 1,
    "00000010110": 1,
    "11111001111": 1,
    "00000110000": 2,
    "11111100010": 1,
    "00000010001": 2,
    "00001010010": 1,
    "00000110110": 1,
    "00000100010": 1,
    "00010110101": 1,
    "10000110001": 1,
    "00000100001": 3,
    "00010100001": 1,
    "00010101100": 2,
    "00001010101": 1,
    "00000011101": 3,
    "00010001010": 1,
    "00010101110": 1,
    "00001110110": 2,
    "00000101110": 3,
    "00000111010": 1,
    "00000001111": 2,
    "00000001110": 5,
    "00000001101": 2,
    "00000110101": 3,
    "00010100101": 1,
    "11010001000": 1,
    "00000111110": 2,
    "10001011110": 1,
    "00011100110": 1,
    "00001000001": 1,
    "00000100000": 2,
    "00010100000": 1,
    "00110111101": 1,
    "00101000010": 1,
    "00000011000": 1,
    "00001110000": 1,
    "00100100000": 1,
    "00011101110": 1,
    "00000111100": 3,
    "10010000101": 1,
    "00100101100": 1,
    "00001000110": 1,
    "00010001111": 1,
    "00010100011": 1,
    "00000010011": 1,
    "00001100100": 1,
    "11101101100": 1,
    "10000010110": 1,
    "11000101100": 1,
    "11101000111": 1,
    "01010100001": 1,
    "00011010000": 1,
    "00011001111": 1,
    "00000011111": 1,
    "00101111010": 1
  }
]
rows
[
  {
    "bit": 1,
    "correct": false,
    "native_counts": {
      "rz": 132,
      "sx": 66,
      "cz": 32,
      "measure_2": 8,
      "if_else": 6,
      "barrier": 3,
      "measure": 3,
      "x": 1
    },
    "bit_correct": 233,
    "whole_word_correct": 160,
    "syndromes": [
      168,
      29,
      45,
      14
    ]
  },
  {
    "bit": 1,
    "correct": true,
    "native_counts": {
      "rz": 132,
      "sx": 66,
      "cz": 32,
      "if_else": 9,
      "measure_2": 8,
      "barrier": 3,
      "measure": 3,
      "x": 1
    },
    "bit_correct": 235,
    "whole_word_correct": 204,
    "syndromes": [
      177,
      34,
      34,
      11
    ]
  },
  {
    "bit": 0,
    "correct": false,
    "native_counts": {
      "rz": 132,
      "sx": 66,
      "cz": 32,
      "measure_2": 8,
      "if_else": 6,
      "barrier": 3,
      "measure": 3
    },
    "bit_correct": 241,
    "whole_word_correct": 196,
    "syndromes": [
      199,
      16,
      28,
      13
    ]
  },
  {
    "bit": 0,
    "correct": true,
    "native_counts": {
      "rz": 132,
      "sx": 66,
      "cz": 32,
      "if_else": 9,
      "measure_2": 8,
      "barrier": 3,
      "measure": 3
    },
    "bit_correct": 242,
    "whole_word_correct": 228,
    "syndromes": [
      198,
      16,
      32,
      10
    ]
  }
]
bit_order
b2 b1 b0 | s1 s0 | a5 ... a0
metrics
{
  "caller": "qiskit",
  "qiskit_version": "qiskit_ibm_runtime-0.52.1,qiskit-2.6.2*,qiskit_aer-0.17.2*",
  "timestamps": {
    "created": "2026-11-21T02:01:14.761801Z",
    "finished": "2026-11-21T02:01:20.673419Z",
    "running": "2026-11-21T02:01:16.291471Z"
  },
  "usage": {
    "qpu_charge_time_seconds": 2,
    "value": 0.033022,
    "unit": "resource_units",
    "status": "complete",
    "details": [
      {
        "value": 0.033022,
        "unit": "resource_units",
        "metric": {
          "id": "caffe3ca-729c-5750-8777-df63bbf8bfd9",
          "value": 2
        }
      }
    ]
  },
  "circuits_execution_time_ns": 273257728
}

Simulation & checks

These are the supplied simulator records and their preserved variants. Their model, seed, settings and results appear exactly as saved. Shared simulator references on fresh-map pages describe the ideal graph protocol, rather than a new hardware-matched calibration.

field-report/outputs/Checksum-teleport-simulator.json · full record
{
  "model": "ideal Aer stabilizer",
  "shots_each": 256,
  "rows": [
    {
      "bit": 0,
      "correct": false,
      "injected_flip": null,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        256,
        0,
        0,
        0
      ]
    },
    {
      "bit": 0,
      "correct": false,
      "injected_flip": 0,
      "bit_correct": 256,
      "whole_word_correct": 0,
      "syndromes": [
        0,
        256,
        0,
        0
      ]
    },
    {
      "bit": 0,
      "correct": false,
      "injected_flip": 1,
      "bit_correct": 0,
      "whole_word_correct": 0,
      "syndromes": [
        0,
        0,
        0,
        256
      ]
    },
    {
      "bit": 0,
      "correct": false,
      "injected_flip": 2,
      "bit_correct": 256,
      "whole_word_correct": 0,
      "syndromes": [
        0,
        0,
        256,
        0
      ]
    },
    {
      "bit": 0,
      "correct": true,
      "injected_flip": null,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        256,
        0,
        0,
        0
      ]
    },
    {
      "bit": 0,
      "correct": true,
      "injected_flip": 0,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        0,
        256,
        0,
        0
      ]
    },
    {
      "bit": 0,
      "correct": true,
      "injected_flip": 1,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        0,
        0,
        0,
        256
      ]
    },
    {
      "bit": 0,
      "correct": true,
      "injected_flip": 2,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        0,
        0,
        256,
        0
      ]
    },
    {
      "bit": 1,
      "correct": false,
      "injected_flip": null,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        256,
        0,
        0,
        0
      ]
    },
    {
      "bit": 1,
      "correct": false,
      "injected_flip": 0,
      "bit_correct": 256,
      "whole_word_correct": 0,
      "syndromes": [
        0,
        256,
        0,
        0
      ]
    },
    {
      "bit": 1,
      "correct": false,
      "injected_flip": 1,
      "bit_correct": 0,
      "whole_word_correct": 0,
      "syndromes": [
        0,
        0,
        0,
        256
      ]
    },
    {
      "bit": 1,
      "correct": false,
      "injected_flip": 2,
      "bit_correct": 256,
      "whole_word_correct": 0,
      "syndromes": [
        0,
        0,
        256,
        0
      ]
    },
    {
      "bit": 1,
      "correct": true,
      "injected_flip": null,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        256,
        0,
        0,
        0
      ]
    },
    {
      "bit": 1,
      "correct": true,
      "injected_flip": 0,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        0,
        256,
        0,
        0
      ]
    },
    {
      "bit": 1,
      "correct": true,
      "injected_flip": 1,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        0,
        0,
        0,
        256
      ]
    },
    {
      "bit": 1,
      "correct": true,
      "injected_flip": 2,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        0,
        0,
        256,
        0
      ]
    }
  ]
}
noise-wall/results/Checksum-teleport-simulator.json · full record
{
  "model": "ideal Aer stabilizer",
  "shots_each": 256,
  "rows": [
    {
      "bit": 0,
      "correct": false,
      "injected_flip": null,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        256,
        0,
        0,
        0
      ]
    },
    {
      "bit": 0,
      "correct": false,
      "injected_flip": 0,
      "bit_correct": 256,
      "whole_word_correct": 0,
      "syndromes": [
        0,
        256,
        0,
        0
      ]
    },
    {
      "bit": 0,
      "correct": false,
      "injected_flip": 1,
      "bit_correct": 0,
      "whole_word_correct": 0,
      "syndromes": [
        0,
        0,
        0,
        256
      ]
    },
    {
      "bit": 0,
      "correct": false,
      "injected_flip": 2,
      "bit_correct": 256,
      "whole_word_correct": 0,
      "syndromes": [
        0,
        0,
        256,
        0
      ]
    },
    {
      "bit": 0,
      "correct": true,
      "injected_flip": null,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        256,
        0,
        0,
        0
      ]
    },
    {
      "bit": 0,
      "correct": true,
      "injected_flip": 0,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        0,
        256,
        0,
        0
      ]
    },
    {
      "bit": 0,
      "correct": true,
      "injected_flip": 1,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        0,
        0,
        0,
        256
      ]
    },
    {
      "bit": 0,
      "correct": true,
      "injected_flip": 2,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        0,
        0,
        256,
        0
      ]
    },
    {
      "bit": 1,
      "correct": false,
      "injected_flip": null,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        256,
        0,
        0,
        0
      ]
    },
    {
      "bit": 1,
      "correct": false,
      "injected_flip": 0,
      "bit_correct": 256,
      "whole_word_correct": 0,
      "syndromes": [
        0,
        256,
        0,
        0
      ]
    },
    {
      "bit": 1,
      "correct": false,
      "injected_flip": 1,
      "bit_correct": 0,
      "whole_word_correct": 0,
      "syndromes": [
        0,
        0,
        0,
        256
      ]
    },
    {
      "bit": 1,
      "correct": false,
      "injected_flip": 2,
      "bit_correct": 256,
      "whole_word_correct": 0,
      "syndromes": [
        0,
        0,
        256,
        0
      ]
    },
    {
      "bit": 1,
      "correct": true,
      "injected_flip": null,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        256,
        0,
        0,
        0
      ]
    },
    {
      "bit": 1,
      "correct": true,
      "injected_flip": 0,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        0,
        256,
        0,
        0
      ]
    },
    {
      "bit": 1,
      "correct": true,
      "injected_flip": 1,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        0,
        0,
        0,
        256
      ]
    },
    {
      "bit": 1,
      "correct": true,
      "injected_flip": 2,
      "bit_correct": 256,
      "whole_word_correct": 256,
      "syndromes": [
        0,
        0,
        256,
        0
      ]
    }
  ]
}

Source code

Original experiment and verification programs are preserved byte for byte. These are historical listings; dependencies, authentication prompts and machine-specific input paths may need adjustment before a rerun.

field-report/outputs/checksum_teleport.py · complete source
"""Teleport a bit-flip repetition code, measure both checks, and switch repair on or off."""
import getpass
import heapq
import itertools
import json
import logging
import math
from pathlib import Path
from collections import Counter
import random
import sys
import time
import traceback

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, transpile
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2
from qiskit_ibm_runtime.circuit import MidCircuitMeasure
from qiskit_ibm_runtime.accounts.exceptions import InvalidAccountError

from graph156 import ROOT, save

SHOTS, SEED = 256, 20317
SIM, HW = ROOT/"Checksum-teleport-simulator.json", ROOT/"Checksum-teleport-Kingston.json"
TAG="three-rail-teleport-checksum-20261120-v1"
LOGICAL={"source":[0,1,2],"alice":[3,4,5],"bob":[6,7,8],"checks":[9,10],
         "encode":[(1,0),(1,2)]}


def circuit(layout, bit, correct, fast=False, inject=None):
    used=sorted(set(layout["source"]+layout["alice"]+layout["bob"]+layout["checks"]+
                    [j for edge in layout["encode"] for j in edge]))
    q=QuantumRegister(len(used),"q")
    a,s,b=ClassicalRegister(6,"a"),ClassicalRegister(2,"s"),ClassicalRegister(3,"b")
    qc=QuantumCircuit(q,a,s,b)
    wire={p:q[i] for i,p in enumerate(used)}
    src,alice,bob,anc=[[wire[i] for i in layout[key]] for key in ("source","alice","bob","checks")]
    if bit:
        qc.x(src[1])
    for u,v in layout["encode"]:
        qc.cx(wire[u],wire[v])
    qc.barrier()
    for i in range(3):
        qc.h(alice[i])
        qc.cx(alice[i],bob[i])
        qc.cx(src[i],alice[i])
        qc.h(src[i])
    def read(w,c):
        if fast:
            qc.append(MidCircuitMeasure(),[w],[c])
        else:
            qc.measure(w,c)
    for i in range(3):
        read(src[i],a[2*i])
        read(alice[i],a[2*i+1])
    for i in range(3):
        with qc.if_test((a[2*i+1],1)):
            qc.x(bob[i])
        with qc.if_test((a[2*i],1)):
            qc.z(bob[i])
    qc.barrier()
    if inject is not None:
        qc.x(bob[inject])
    for i in range(2):
        qc.cx(bob[i],anc[i])
        qc.cx(bob[i+1],anc[i])
    for i in range(2):
        read(anc[i],s[i])
    if correct:
        for i,syndrome in enumerate((1,3,2)):
            with qc.if_test((s,syndrome)):
                qc.x(bob[i])
    qc.barrier()
    qc.measure(bob,b)
    return qc,used


def summarize(counts,bit):
    assert sum(counts.values())==SHOTS and all(len(w)==11 for w in counts)
    result={"bit_correct":0,"whole_word_correct":0,"syndromes":[0]*4}
    for w,n in counts.items():
        result["bit_correct"]+=n*(int(w[1])==bit)
        result["whole_word_correct"]+=n*(w[:3]==str(bit)*3)
        result["syndromes"][int(w[3:5],2)]+=n
    return result


def simulate():
    sim=AerSimulator(method="stabilizer")
    cases=list(itertools.product((0,1),(False,True),(None,0,1,2)))
    qs=[circuit(LOGICAL,bit,correct,inject=inj)[0] for bit,correct,inj in cases]
    counts=sim.run(qs,shots=SHOTS,seed_simulator=SEED).result().get_counts()
    rows=[]
    for (bit,correct,inj),raw in zip(cases,counts):
        c={w.replace(" ",""):n for w,n in raw.items()}
        out=summarize(c,bit)
        assert out["bit_correct"]==SHOTS*(correct or inj!=1)
        assert out["whole_word_correct"]==SHOTS*(correct or inj is None)
        assert out["syndromes"][0 if inj is None else (1,3,2)[inj]]==SHOTS
        rows.append(dict(bit=bit,correct=correct,injected_flip=inj,**out))
    save(SIM,{"model":"ideal Aer stabilizer","shots_each":SHOTS,"rows":rows})
    print("Verified both bits, both correction modes, clean and each single flip.")


def choose_layout(backend):
    props=backend.properties(refresh=True)
    excluded=set(props.faulty_qubits())
    bad_edges={tuple(sorted(g.qubits)) for g in props.faulty_gates() if len(g.qubits)==2}
    adj={i:set() for i in range(backend.num_qubits) if i not in excluded}
    err={}
    for u,v in backend.coupling_map.get_edges():
        if u not in adj or v not in adj or tuple(sorted((u,v))) in bad_edges:
            continue
        g=backend.target["cz"].get((u,v)) or backend.target["cz"].get((v,u))
        if g is not None and g.error is not None and g.error<1:
            err[u,v]=err[v,u]=-math.log1p(-g.error)
            adj[u].add(v)
            adj[v].add(u)
    readerr={i:-math.log(max(1e-8,1-props.readout_error(i))) for i in adj}
    def paths(p):
        if len(p)==5:
            if p[0]<p[-1]:
                yield p
            return
        for v in sorted(adj[p[-1]]-set(p)):
            yield from paths(p+[v])
    best=None
    for start in sorted(adj):
        for spine in paths([start]):
            bob=spine[::2]
            spine_set=set(spine)
            for alice in itertools.product(*(sorted(adj[i]-spine_set) for i in bob)):
                if len(set(alice))!=3:
                    continue
                reserved=spine_set|set(alice)
                for src in itertools.product(*(sorted(adj[i]-reserved) for i in alice)):
                    if len(set(src))!=3:
                        continue
                    # Grow a short encoding tree without touching Bob's data qubits.
                    root=src[1]
                    parent={root:None}
                    queue=[(0.,root,None)]
                    visited=set()
                    while queue and not set(src)<=visited:
                        dist,x,prev=heapq.heappop(queue)
                        if x in visited:
                            continue
                        visited.add(x)
                        parent[x]=prev
                        for v in adj[x]-visited-set(bob):
                            heapq.heappush(queue,(dist+.01+err[x,v],v,x))
                    if not set(src)<=visited:
                        continue
                    forward=[]
                    for end in (src[0],src[2]):
                        branch=[]
                        while parent[end] is not None:
                            branch.append((parent[end],end))
                            end=parent[end]
                        for edge in reversed(branch):
                            if edge not in forward:
                                forward.append(edge)
                    encode=forward+[e for e in reversed(forward) if e[1] not in src]
                    links=encode+list(zip(alice,bob))+list(zip(src,alice))+list(zip(spine,spine[1:]))
                    score=sum(.003+err[e] for e in links)+sum(readerr[i] for i in list(src)+list(alice)+spine)
                    if best is None or score<best[0]:
                        best=(score,dict(source=list(src),alice=list(alice),bob=bob,checks=spine[1::2],encode=encode))
    if best is None:
        raise RuntimeError("No connected layout")
    layout=best[1]
    ones={layout["source"][1]}
    for u,v in layout["encode"]:
        if u in ones:
            ones.symmetric_difference_update({v})
    assert ones==set(layout["source"])
    return layout


def prepare(backend,layout):
    measured_mid=layout["source"]+layout["alice"]+layout["checks"]
    fast=all(backend.target.instruction_supported("measure_2",(q,)) for q in measured_mid)
    cases=list(itertools.product((0,1),(False,True)))
    random.Random(SEED).shuffle(cases)
    compiled=[]
    details=[]
    for bit,correct in cases:
        q,used=circuit(layout,bit,correct,fast)
        isa=transpile(q,backend,initial_layout=used,routing_method="none",optimization_level=1,seed_transpiler=SEED)
        backend.check_faulty(isa)
        measured={}
        branches=[]
        for op in isa.data:
            physical=[isa.find_bit(w).index for w in op.qubits]
            assert op.operation.name=="barrier" or set(physical)<=set(used)
            if op.operation.name in ("measure","measure_2"):
                measured[isa.find_bit(op.clbits[0]).index]=physical[0]
            if op.operation.name=="if_else":
                test,value=op.operation.condition
                which=("s" if isinstance(test,ClassicalRegister) and test.name=="s" else isa.find_bit(test).index)
                branches.append((which,value,physical[0],op.operation.blocks[0].data[0].operation.name))
        expected={i:w for i,w in enumerate([v for pair in zip(layout["source"],layout["alice"]) for v in pair]+layout["checks"]+layout["bob"])}
        assert measured==expected
        assert [(k,v,p) for k,v,p,_ in branches]==[(j,1,layout["bob"][i]) for i in range(3) for j in (2*i+1,2*i)]+(
            [("s",v,p) for v,p in zip((1,3,2),layout["bob"])] if correct else [])
        compiled.append(isa)
        details.append(dict(bit=bit,correct=correct,native_counts=dict(isa.count_ops())))
    return compiled,details,fast,used


def hardware():
    if not sys.stdin.isatty() or not SIM.exists():
        raise RuntimeError("Use the private prompt after simulation")
    rec=json.loads(HW.read_text()) if HW.exists() else {}
    if rec.get("stage")=="done":
        return
    while True:
        key=getpass.getpass("IBM Cloud API key (hidden; Enter alone to exit): ").strip()
        if not key:
            return
        try:
            service=QiskitRuntimeService(channel="ibm_quantum_platform",token=key,plans_preference=["open"],region="us-east")
            break
        except InvalidAccountError as exc:
            cause=exc.__cause__
            print("IBM instance lookup failed.",type(cause).__name__,"HTTP status",getattr(cause,"code",None),
                  "Paste the key again or press Enter to exit.")
    if rec.get("job_id"):
        job=service.job(rec["job_id"])
    elif rec.get("stage")=="submitting":
        matches=service.jobs(job_tags=[TAG],limit=2)
        if len(matches)!=1:
            raise RuntimeError("Reconcile prior submission")
        job=matches[0]
    else:
        backend=service.backend("ibm_kingston")
        layout=choose_layout(backend)
        compiled,details,fast,used=prepare(backend,layout)
        rec=dict(stage="submitting",backend=backend.name,layout=layout,used=used,cases=details,
                 fast_mid_measure=fast,shots_per_case=SHOTS,tag=TAG,primary="Bob center rail after optional physical repair")
        sampler=SamplerV2(mode=backend,options={"max_execution_time":30,"environment":{"job_tags":[TAG]},
                          "twirling":{"enable_gates":False,"enable_measure":False},"dynamical_decoupling":{"enable":False}})
        with HW.open("x",encoding="utf8") as f:
            json.dump(rec,f,indent=2)
        job=sampler.run(compiled,shots=SHOTS)
    rec.update(stage="submitted",job_id=job.job_id())
    save(HW,rec)
    pubs=job.result()
    assert len(pubs)==4
    rec["counts"]=[dict(Counter(b+s+a for b,s,a in zip(pub.data.b.get_bitstrings(),
                          pub.data.s.get_bitstrings(),pub.data.a.get_bitstrings()))) for pub in pubs]
    rec["rows"]=[dict(case,**summarize(c,case["bit"])) for case,c in zip(rec["cases"],rec["counts"])]
    rec.update(stage="measured",bit_order="b2 b1 b0 | s1 s0 | a5 ... a0")
    save(HW,rec)
    for _ in range(120):
        metrics=job.metrics()
        if metrics.get("usage",{}).get("status")=="complete":
            break
        time.sleep(5)
    rec.update(stage="done",metrics=metrics)
    save(HW,rec)


if __name__=="__main__":
    if sys.argv[1:]==["simulate"]:
        simulate()
    elif sys.argv[1:]==["hardware"]:
        logging.disable(logging.CRITICAL)
        try:
            hardware()
        except Exception as exc:
            frames=[[Path(f.filename).name,f.lineno,f.name] for f in traceback.extract_tb(exc.__traceback__)]
            save(ROOT.parent/"work"/"checksum-teleport-error.json",dict(type=type(exc).__name__,frames=frames))
            print(type(exc).__name__)
        input("Press Enter to close.")
field-report/work/verify_checksum.py · complete source
import json
import math
from pathlib import Path

rec=json.loads((Path(__file__).resolve().parents[1]/"outputs"/"Checksum-teleport-Kingston.json").read_text())
cells={}
for r,c in zip(rec["rows"],rec["counts"]):
    exact=logical=flagged=0
    assert sum(c.values())==256
    for bits,n in c.items():
        v=int(bits,2)
        output=v>>8
        logical+=n*(((output>>1)&1)==r["bit"])
        exact+=n*(output==(7 if r["bit"] else 0))
        flagged+=n*bool((v>>6)&3)
    assert logical==r["bit_correct"] and exact==r["whole_word_correct"]
    assert flagged==256-r["syndromes"][0]
    cells[r["bit"],r["correct"]]=logical
    print(r["bit"],r["correct"],logical,exact,flagged,r["native_counts"]["cz"])
means=[sum(cells[b,c] for b in (0,1))/512 for c in (False,True)]
se=math.sqrt(sum((s/256)*(1-s/256)/(255*4) for s in cells.values()))
d=means[1]-means[0]
print("accuracy, delta and ci",means,d,(d-1.96*se,d+1.96*se))
print("job",rec["job_id"],"charge",rec["metrics"]["usage"],"layout",rec["layout"])
noise-wall/source/checksum_teleport.py · complete source
"""Teleport a bit-flip repetition code, measure both checks, and switch repair on or off."""
import getpass
import heapq
import itertools
import json
import logging
import math
from pathlib import Path
from collections import Counter
import random
import sys
import time
import traceback

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, transpile
from qiskit_aer import AerSimulator
from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2
from qiskit_ibm_runtime.circuit import MidCircuitMeasure
from qiskit_ibm_runtime.accounts.exceptions import InvalidAccountError

from graph156 import ROOT, save

SHOTS, SEED = 256, 20317
SIM, HW = ROOT/"Checksum-teleport-simulator.json", ROOT/"Checksum-teleport-Kingston.json"
TAG="three-rail-teleport-checksum-20261120-v1"
LOGICAL={"source":[0,1,2],"alice":[3,4,5],"bob":[6,7,8],"checks":[9,10],
         "encode":[(1,0),(1,2)]}


def circuit(layout, bit, correct, fast=False, inject=None):
    used=sorted(set(layout["source"]+layout["alice"]+layout["bob"]+layout["checks"]+
                    [j for edge in layout["encode"] for j in edge]))
    q=QuantumRegister(len(used),"q")
    a,s,b=ClassicalRegister(6,"a"),ClassicalRegister(2,"s"),ClassicalRegister(3,"b")
    qc=QuantumCircuit(q,a,s,b)
    wire={p:q[i] for i,p in enumerate(used)}
    src,alice,bob,anc=[[wire[i] for i in layout[key]] for key in ("source","alice","bob","checks")]
    if bit:
        qc.x(src[1])
    for u,v in layout["encode"]:
        qc.cx(wire[u],wire[v])
    qc.barrier()
    for i in range(3):
        qc.h(alice[i])
        qc.cx(alice[i],bob[i])
        qc.cx(src[i],alice[i])
        qc.h(src[i])
    def read(w,c):
        if fast:
            qc.append(MidCircuitMeasure(),[w],[c])
        else:
            qc.measure(w,c)
    for i in range(3):
        read(src[i],a[2*i])
        read(alice[i],a[2*i+1])
    for i in range(3):
        with qc.if_test((a[2*i+1],1)):
            qc.x(bob[i])
        with qc.if_test((a[2*i],1)):
            qc.z(bob[i])
    qc.barrier()
    if inject is not None:
        qc.x(bob[inject])
    for i in range(2):
        qc.cx(bob[i],anc[i])
        qc.cx(bob[i+1],anc[i])
    for i in range(2):
        read(anc[i],s[i])
    if correct:
        for i,syndrome in enumerate((1,3,2)):
            with qc.if_test((s,syndrome)):
                qc.x(bob[i])
    qc.barrier()
    qc.measure(bob,b)
    return qc,used


def summarize(counts,bit):
    assert sum(counts.values())==SHOTS and all(len(w)==11 for w in counts)
    result={"bit_correct":0,"whole_word_correct":0,"syndromes":[0]*4}
    for w,n in counts.items():
        result["bit_correct"]+=n*(int(w[1])==bit)
        result["whole_word_correct"]+=n*(w[:3]==str(bit)*3)
        result["syndromes"][int(w[3:5],2)]+=n
    return result


def simulate():
    sim=AerSimulator(method="stabilizer")
    cases=list(itertools.product((0,1),(False,True),(None,0,1,2)))
    qs=[circuit(LOGICAL,bit,correct,inject=inj)[0] for bit,correct,inj in cases]
    counts=sim.run(qs,shots=SHOTS,seed_simulator=SEED).result().get_counts()
    rows=[]
    for (bit,correct,inj),raw in zip(cases,counts):
        c={w.replace(" ",""):n for w,n in raw.items()}
        out=summarize(c,bit)
        assert out["bit_correct"]==SHOTS*(correct or inj!=1)
        assert out["whole_word_correct"]==SHOTS*(correct or inj is None)
        assert out["syndromes"][0 if inj is None else (1,3,2)[inj]]==SHOTS
        rows.append(dict(bit=bit,correct=correct,injected_flip=inj,**out))
    save(SIM,{"model":"ideal Aer stabilizer","shots_each":SHOTS,"rows":rows})
    print("Verified both bits, both correction modes, clean and each single flip.")


def choose_layout(backend):
    props=backend.properties(refresh=True)
    excluded=set(props.faulty_qubits())
    bad_edges={tuple(sorted(g.qubits)) for g in props.faulty_gates() if len(g.qubits)==2}
    adj={i:set() for i in range(backend.num_qubits) if i not in excluded}
    err={}
    for u,v in backend.coupling_map.get_edges():
        if u not in adj or v not in adj or tuple(sorted((u,v))) in bad_edges:
            continue
        g=backend.target["cz"].get((u,v)) or backend.target["cz"].get((v,u))
        if g is not None and g.error is not None and g.error<1:
            err[u,v]=err[v,u]=-math.log1p(-g.error)
            adj[u].add(v)
            adj[v].add(u)
    readerr={i:-math.log(max(1e-8,1-props.readout_error(i))) for i in adj}
    def paths(p):
        if len(p)==5:
            if p[0]<p[-1]:
                yield p
            return
        for v in sorted(adj[p[-1]]-set(p)):
            yield from paths(p+[v])
    best=None
    for start in sorted(adj):
        for spine in paths([start]):
            bob=spine[::2]
            spine_set=set(spine)
            for alice in itertools.product(*(sorted(adj[i]-spine_set) for i in bob)):
                if len(set(alice))!=3:
                    continue
                reserved=spine_set|set(alice)
                for src in itertools.product(*(sorted(adj[i]-reserved) for i in alice)):
                    if len(set(src))!=3:
                        continue
                    # Grow a short encoding tree without touching Bob's data qubits.
                    root=src[1]
                    parent={root:None}
                    queue=[(0.,root,None)]
                    visited=set()
                    while queue and not set(src)<=visited:
                        dist,x,prev=heapq.heappop(queue)
                        if x in visited:
                            continue
                        visited.add(x)
                        parent[x]=prev
                        for v in adj[x]-visited-set(bob):
                            heapq.heappush(queue,(dist+.01+err[x,v],v,x))
                    if not set(src)<=visited:
                        continue
                    forward=[]
                    for end in (src[0],src[2]):
                        branch=[]
                        while parent[end] is not None:
                            branch.append((parent[end],end))
                            end=parent[end]
                        for edge in reversed(branch):
                            if edge not in forward:
                                forward.append(edge)
                    encode=forward+[e for e in reversed(forward) if e[1] not in src]
                    links=encode+list(zip(alice,bob))+list(zip(src,alice))+list(zip(spine,spine[1:]))
                    score=sum(.003+err[e] for e in links)+sum(readerr[i] for i in list(src)+list(alice)+spine)
                    if best is None or score<best[0]:
                        best=(score,dict(source=list(src),alice=list(alice),bob=bob,checks=spine[1::2],encode=encode))
    if best is None:
        raise RuntimeError("No connected layout")
    layout=best[1]
    ones={layout["source"][1]}
    for u,v in layout["encode"]:
        if u in ones:
            ones.symmetric_difference_update({v})
    assert ones==set(layout["source"])
    return layout


def prepare(backend,layout):
    measured_mid=layout["source"]+layout["alice"]+layout["checks"]
    fast=all(backend.target.instruction_supported("measure_2",(q,)) for q in measured_mid)
    cases=list(itertools.product((0,1),(False,True)))
    random.Random(SEED).shuffle(cases)
    compiled=[]
    details=[]
    for bit,correct in cases:
        q,used=circuit(layout,bit,correct,fast)
        isa=transpile(q,backend,initial_layout=used,routing_method="none",optimization_level=1,seed_transpiler=SEED)
        backend.check_faulty(isa)
        measured={}
        branches=[]
        for op in isa.data:
            physical=[isa.find_bit(w).index for w in op.qubits]
            assert op.operation.name=="barrier" or set(physical)<=set(used)
            if op.operation.name in ("measure","measure_2"):
                measured[isa.find_bit(op.clbits[0]).index]=physical[0]
            if op.operation.name=="if_else":
                test,value=op.operation.condition
                which=("s" if isinstance(test,ClassicalRegister) and test.name=="s" else isa.find_bit(test).index)
                branches.append((which,value,physical[0],op.operation.blocks[0].data[0].operation.name))
        expected={i:w for i,w in enumerate([v for pair in zip(layout["source"],layout["alice"]) for v in pair]+layout["checks"]+layout["bob"])}
        assert measured==expected
        assert [(k,v,p) for k,v,p,_ in branches]==[(j,1,layout["bob"][i]) for i in range(3) for j in (2*i+1,2*i)]+(
            [("s",v,p) for v,p in zip((1,3,2),layout["bob"])] if correct else [])
        compiled.append(isa)
        details.append(dict(bit=bit,correct=correct,native_counts=dict(isa.count_ops())))
    return compiled,details,fast,used


def hardware():
    if not sys.stdin.isatty() or not SIM.exists():
        raise RuntimeError("Use the private prompt after simulation")
    rec=json.loads(HW.read_text()) if HW.exists() else {}
    if rec.get("stage")=="done":
        return
    while True:
        key=getpass.getpass("IBM Cloud API key (hidden; Enter alone to exit): ").strip()
        if not key:
            return
        try:
            service=QiskitRuntimeService(channel="ibm_quantum_platform",token=key,plans_preference=["open"],region="us-east")
            break
        except InvalidAccountError as exc:
            cause=exc.__cause__
            print("IBM instance lookup failed.",type(cause).__name__,"HTTP status",getattr(cause,"code",None),
                  "Paste the key again or press Enter to exit.")
    if rec.get("job_id"):
        job=service.job(rec["job_id"])
    elif rec.get("stage")=="submitting":
        matches=service.jobs(job_tags=[TAG],limit=2)
        if len(matches)!=1:
            raise RuntimeError("Reconcile prior submission")
        job=matches[0]
    else:
        backend=service.backend("ibm_kingston")
        layout=choose_layout(backend)
        compiled,details,fast,used=prepare(backend,layout)
        rec=dict(stage="submitting",backend=backend.name,layout=layout,used=used,cases=details,
                 fast_mid_measure=fast,shots_per_case=SHOTS,tag=TAG,primary="Bob center rail after optional physical repair")
        sampler=SamplerV2(mode=backend,options={"max_execution_time":30,"environment":{"job_tags":[TAG]},
                          "twirling":{"enable_gates":False,"enable_measure":False},"dynamical_decoupling":{"enable":False}})
        with HW.open("x",encoding="utf8") as f:
            json.dump(rec,f,indent=2)
        job=sampler.run(compiled,shots=SHOTS)
    rec.update(stage="submitted",job_id=job.job_id())
    save(HW,rec)
    pubs=job.result()
    assert len(pubs)==4
    rec["counts"]=[dict(Counter(b+s+a for b,s,a in zip(pub.data.b.get_bitstrings(),
                          pub.data.s.get_bitstrings(),pub.data.a.get_bitstrings()))) for pub in pubs]
    rec["rows"]=[dict(case,**summarize(c,case["bit"])) for case,c in zip(rec["cases"],rec["counts"])]
    rec.update(stage="measured",bit_order="b2 b1 b0 | s1 s0 | a5 ... a0")
    save(HW,rec)
    for _ in range(120):
        metrics=job.metrics()
        if metrics.get("usage",{}).get("status")=="complete":
            break
        time.sleep(5)
    rec.update(stage="done",metrics=metrics)
    save(HW,rec)


if __name__=="__main__":
    if sys.argv[1:]==["simulate"]:
        simulate()
    elif sys.argv[1:]==["hardware"]:
        logging.disable(logging.CRITICAL)
        try:
            hardware()
        except Exception as exc:
            frames=[[Path(f.filename).name,f.lineno,f.name] for f in traceback.extract_tb(exc.__traceback__)]
            save(ROOT.parent/"work"/"checksum-teleport-error.json",dict(type=type(exc).__name__,frames=frames))
            print(type(exc).__name__)
        input("Press Enter to close.")

Personal comments

Personal comments will be added here.