deskmerc/ quantum

Byte protection / KINGSTON

Quantum Field Report

Eight parallel paths carry the letter A

Count how often a complete unprotected ASCII byte arrives intact.

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

The question

Count how often a complete unprotected ASCII byte arrives intact.

Circuit & method

Send A (01000001) through eight parallel teleportation channels. In the same job, prepare the same byte directly on Bob’s receiver qubits as a local control.

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

Results

The teleported byte was exact on 162/256 shots (63.3%). Direct preparation and readout passed 247/256 (96.5%).

Measured outcomesAll-shot success; each bar runs from 0% to 100%.
teleport162/256 · 63.3%
direct247/256 · 96.5%

What this supports

Whole-byte accuracy requires all eight bits correct in the same shot; it cannot be replaced by an average per-bit score.

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.

backend
ibm_kingston
modes
[
  "teleport",
  "direct"
]
triples_from_least_significant_bit
[
  [
    48,
    49,
    50
  ],
  [
    106,
    105,
    117
  ],
  [
    148,
    149,
    150
  ],
  [
    108,
    109,
    118
  ],
  [
    55,
    59,
    75
  ],
  [
    36,
    41,
    40
  ],
  [
    93,
    94,
    95
  ],
  [
    4,
    5,
    6
  ]
]
fast_mid_measure
True
input_byte
01000001
native_counts
[
  {
    "rz": 96,
    "sx": 48,
    "cz": 16,
    "measure_2": 16,
    "if_else": 16,
    "measure": 8,
    "x": 2,
    "barrier": 1
  },
  {
    "measure": 8,
    "x": 2
  }
]
stage
done
tag
ascii-A-8-triples-kingston-20261120
shots_per_circuit
256
job_id
dc0fvnmq4uuc73a2iig0
counts
[
  {
    "010000011001111100010000": 1,
    "010000010111011100101100": 1,
    "011000011110110110111011": 1,
    "010100010110010111010001": 1,
    "010000111100110110001011": 1,
    "010000010000000011110110": 1,
    "010000010111100100111101": 1,
    "010100111011010111111101": 1,
    "010000011001110101111010": 1,
    "010000011111010000001111": 1,
    "010000011111001101010001": 1,
    "010000011011011100111110": 1,
    "010000001110100101011110": 1,
    "010000011100101011110001": 1,
    "011000011100001001111000": 1,
    "010000010001111000110000": 1,
    "010000010010000010001010": 1,
    "010000011000110001111101": 1,
    "010000010111011000100100": 1,
    "011000011001000000000010": 1,
    "000000010000001001010110": 1,
    "010000111001011100110111": 1,
    "010001011011011101100101": 1,
    "010000000100111110111001": 1,
    "010000010000111100000101": 1,
    "010000011011000010110000": 1,
    "010000011110110000111000": 1,
    "010000010001001011000001": 1,
    "010000011101110101101110": 1,
    "010000011000111001010010": 1,
    "010000010001101100111010": 1,
    "011000011110011100001011": 1,
    "000000010111111100001001": 1,
    "010001011111011101111101": 1,
    "010000111100101000111000": 1,
    "010000010011100101010110": 1,
    "110000011001011111010100": 1,
    "010000010110111000110011": 1,
    "011000001000011011110100": 1,
    "010000011101101110010101": 1,
    "011100111100010100110010": 1,
    "000000010011110000100100": 1,
    "000010011110110010101111": 1,
    "010000011110110000001000": 1,
    "010000011111110011111101": 1,
    "000000011010101101010000": 1,
    "010000010100110110010010": 1,
    "010000010000110111111010": 1,
    "010000011011110010010010": 1,
    "010000011000011011111111": 1,
    "010000010110111101011000": 1,
    "010000011010011000111010": 1,
    "010000010100100110011000": 1,
    "010000011000010010110111": 1,
    "010000000010000110000111": 1,
    "010000011101111100111100": 1,
    "000000010011101101101000": 1,
    "010000010001001011111010": 1,
    "010000010100100111001110": 1,
    "010000011100001101010111": 1,
    "010000010000000000000010": 1,
    "010000011001101111101010": 1,
    "010000011101110111110111": 1,
    "010000011110100100000000": 1,
    "000000011001111101101011": 1,
    "000000011010000110000111": 1,
    "010000011001101011101011": 1,
    "010000010010000111100100": 1,
    "010100010010101000010000": 1,
    "010001011000000110100000": 1,
    "010000010011001111001011": 1,
    "010000010101100101100111": 1,
    "010000011111111110000011": 1,
    "010000010100100100000111": 1,
    "010000011100101111101010": 1,
    "010000001000110010101110": 1,
    "010000010101101111010101": 1,
    "010000011001100110001111": 1,
    "010000011111100010000010": 1,
    "010001001001111111011101": 1,
    "100000011000111110110011": 1,
    "110010011001010111000000": 1,
    "010000010000110111110110": 1,
    "010100011110010111000101": 1,
    "010000011101101011101011": 1,
    "010000010111100111111111": 1,
    "110000010010000101100101": 1,
    "010000011001110100101011": 1,
    "010000010001010111111100": 1,
    "010000011011001110001110": 1,
    "010000011100111111011000": 1,
    "010000010111001110001010": 1,
    "000000010010011100110010": 1,
    "010000010111011100101110": 1,
    "010000010111111000011000": 1,
    "010000011101100101110111": 1,
    "010000010010101111011000": 1,
    "010000011010100101101010": 1,
    "010000011000001111100000": 1,
    "010000011000000011100101": 1,
    "010000010010011100111010": 1,
    "000000010110001000001101": 1,
    "010000011101000001101001": 1,
    "000000011100110101011100": 1,
    "000000011111100010011010": 1,
    "010000010001001001100100": 1,
    "010000011001001000110001": 1,
    "010001011100001001111011": 1,
    "000000010011100010010111": 1,
    "010000011011111111010111": 1,
    "010000010011000000101110": 1,
    "010000011111010110101000": 1,
    "010000011110110011101110": 1,
    "011001011001001111001001": 1,
    "010000011101011010101101": 1,
    "010000110001101100000001": 1,
    "010000011011010000000001": 1,
    "010001110110100100011001": 1,
    "110001010100110001011000": 1,
    "010000010100100100001101": 1,
    "110000010111000111010100": 1,
    "010000010111111100000110": 1,
    "010000011001101101001101": 1,
    "010000011110001001110100": 1,
    "010000011010101001000110": 1,
    "000000010000110100010100": 1,
    "010000010100100100001000": 1,
    "010010011110001000011000": 1,
    "000000010010100100010010": 1,
    "010000010010111100011111": 1,
    "010000010001011000101011": 1,
    "010000011010111100101111": 1,
    "010000011101011010100001": 1,
    "010000010111000001000100": 1,
    "010000011100111010000000": 1,
    "010000011011100111000101": 1,
    "010000010011111000111010": 1,
    "010000011000001100110110": 1,
    "011000011010010000101100": 1,
    "010000010100100101000000": 1,
    "000010011000100110000111": 1,
    "010000011101011111101001": 1,
    "000000010110011101000000": 1,
    "010000010010111001101010": 1,
    "011000011010010101001011": 1,
    "010000010010110101011100": 1,
    "010000010011100100100010": 1,
    "010000010001111111011101": 1,
    "000000011011010111110011": 1,
    "010000010011110000110111": 1,
    "010000010110011110000111": 1,
    "010000011000110101011010": 1,
    "010000011011000001001111": 1,
    "010000011011000011001011": 1,
    "010000011110010100100000": 1,
    "010000010001000001101000": 1,
    "010000010001010000011001": 1,
    "010000011000001101110010": 1,
    "010000011010001111110000": 1,
    "010000101010000010101110": 1,
    "010000001011000001000011": 1,
    "010000010011011110011000": 1,
    "010000010011110111011000": 1,
    "010000111101101010100010": 1,
    "010000010110010011111111": 1,
    "000000010000110100100010": 1,
    "010000011011100100111111": 1,
    "010000011011001101100001": 1,
    "000000010100101100011100": 1,
    "010000011101101110010111": 1,
    "010000011011000000110100": 1,
    "010000110100000110010111": 1,
    "000000010010110111010101": 1,
    "010000010111110011010011": 1,
    "010000111111110010110101": 1,
    "010000011000000011110111": 1,
    "010000011000001011111010": 1,
    "010000010101011110010101": 1,
    "010000011001011101101000": 1,
    "010100010101111010110011": 1,
    "010000010100110010011101": 1,
    "000000011001111101111100": 1,
    "010000001000011000001001": 1,
    "011010001110000111010011": 1,
    "010000011111010110110101": 1,
    "010000110111100010011101": 1,
    "010000010010000100111110": 1,
    "010000000101010101111110": 1,
    "010000010110010000010101": 1,
    "011000011001111011101000": 1,
    "110000011000101111110000": 1,
    "010000011111000001001110": 1,
    "010000010000100110001001": 1,
    "110000010001101110111111": 1,
    "010000000010101100011110": 1,
    "000000010101010100111011": 1,
    "010000011111010111001110": 1,
    "010000011100010111010110": 1,
    "010000011011011111001011": 1,
    "010000010011001001111001": 1,
    "010000010011110110010011": 1,
    "010000011000011110000101": 1,
    "011000011010100010001111": 1,
    "010000011101100100001100": 1,
    "010000010110110101001101": 1,
    "010000010011110100010100": 1,
    "011000010101101111010010": 1,
    "110000011011001011000011": 1,
    "010000110011011001110101": 1,
    "010000010010001000000101": 1,
    "110000011011111011100110": 1,
    "010000010101100000101001": 1,
    "010001010110001111011011": 1,
    "010000011001101011100001": 1,
    "010000011100101000101011": 1,
    "000000010001100100001011": 1,
    "010000011111011000000010": 1,
    "010000011001001100111010": 1,
    "010000010001110100110011": 1,
    "011000010101010010100111": 1,
    "010000010010100100101011": 1,
    "010000010101100010011110": 1,
    "010000011101100010010100": 1,
    "010000010111111011001110": 1,
    "010000011000101001010111": 1,
    "010000010000111011010110": 1,
    "011000011011110100000101": 1,
    "010000010101000011010011": 1,
    "011000011101010000001011": 1,
    "010000010001000100011100": 1,
    "010000011000000001001001": 1,
    "010000010010010110001101": 1,
    "001000011111110101111001": 1,
    "010000011010011010000000": 1,
    "000000011111001100100001": 1,
    "010000011011111011001101": 1,
    "000000110111111001011100": 1,
    "010010011000111000010011": 1,
    "110000011110000110000010": 1,
    "010010010001110010011100": 1,
    "000000010111101001111110": 1,
    "010000011100111110011111": 1,
    "010000010111011111011101": 1,
    "011000011111011011010101": 1,
    "011100011111011101111000": 1,
    "010000011000010101100001": 1,
    "010000011111110010001101": 1,
    "010000001001100011110111": 1,
    "010000010000011100101100": 1,
    "010000110100110111001001": 1,
    "010000011011110001100010": 1,
    "010000010110111101100100": 1,
    "010000010000000010100001": 1,
    "000000011000111010110100": 1,
    "010000110101000010101111": 1,
    "010000011011001011001111": 1
  },
  {
    "010000010000000000000000": 247,
    "010000000000000000000000": 1,
    "010100010000000000000000": 1,
    "000000010000000000000000": 3,
    "010001010000000000000000": 1,
    "010000110000000000000000": 2,
    "110000010000000000000000": 1
  }
]
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:20:14.7283Z",
    "finished": "2026-11-21T02:20:20.178981Z",
    "running": "2026-11-21T02:20:15.912873Z"
  },
  "usage": {
    "qpu_charge_time_seconds": 2,
    "value": 0.030636,
    "unit": "resource_units",
    "status": "complete",
    "details": [
      {
        "value": 0.030636,
        "unit": "resource_units",
        "metric": {
          "id": "caffe3ca-729c-5750-8777-df63bbf8bfd9",
          "value": 2
        }
      }
    ]
  },
  "circuits_execution_time_ns": 134095872
}
rows
[
  {
    "byte_counts": {
      "01000001": 162,
      "01100001": 13,
      "01010001": 4,
      "01000011": 11,
      "01010011": 1,
      "01000000": 9,
      "00000001": 25,
      "01000101": 5,
      "11000001": 8,
      "01100000": 1,
      "01110011": 1,
      "00001001": 2,
      "01000100": 1,
      "10000001": 1,
      "11001001": 1,
      "01100101": 1,
      "01000111": 1,
      "11000101": 1,
      "01001001": 3,
      "01000010": 1,
      "01101000": 1,
      "00100001": 1,
      "00000011": 1,
      "01110001": 1
    },
    "exact": 162
  },
  {
    "byte_counts": {
      "01000001": 247,
      "01000000": 1,
      "01010001": 1,
      "00000001": 3,
      "01000101": 1,
      "01000011": 2,
      "11000001": 1
    },
    "exact": 247
  }
]

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/ASCII-A-simulator.json · full record
{
  "modes": [
    "teleport",
    "direct"
  ],
  "shots_per_circuit": 256,
  "input_byte": "01000001",
  "seed": 20261121,
  "rows": [
    {
      "byte_counts": {
        "01000001": 256
      },
      "exact": 256
    },
    {
      "byte_counts": {
        "01000001": 256
      },
      "exact": 256
    }
  ]
}
noise-wall/results/ASCII-A-simulator.json · full record
{
  "modes": [
    "teleport",
    "direct"
  ],
  "shots_per_circuit": 256,
  "input_byte": "01000001",
  "seed": 20261121,
  "rows": [
    {
      "byte_counts": {
        "01000001": 256
      },
      "exact": 256
    },
    {
      "byte_counts": {
        "01000001": 256
      },
      "exact": 256
    }
  ]
}

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/teleport_ascii_a.py · complete source
"""Transfer the eight bits of ASCII A in parallel and score Bob's whole byte."""
import getpass
import logging
import sys
import traceback
from collections import Counter
from pathlib import Path

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

from graph156 import save
from run_switch_puzzles import ROOT, SHOTS, execute, load

VALUE = ord("A")
MODES = ("teleport", "direct")
SEED = 20261121
SIM = ROOT/"ASCII-A-simulator.json"
HW = ROOT/"ASCII-A-Kingston.json"
TAG = "ascii-A-8-triples-kingston-20261120"


def circuit(mode, fast=False, value=VALUE, width=8):
    q = QuantumCircuit(3*width,3*width,name="ascii_"+mode)
    for i in range(width):
        src, alice, bob = range(3*i,3*i+3)
        if (value>>i)&1:
            q.x(src if mode=="teleport" else bob)
        if mode=="teleport":
            q.h(alice)
            q.cx(alice,bob)
            q.cx(src,alice)
            q.h(src)
    if mode=="teleport":
        for i in range(width):
            for role in (0,1):
                wire,flag = 3*i+role,2*i+role
                if fast:
                    q.append(MidCircuitMeasure(),[wire],[flag])
                else:
                    q.measure(wire,flag)
        for i in range(width):
            with q.if_test((q.clbits[2*i+1],1)):
                q.x(3*i+2)
            with q.if_test((q.clbits[2*i],1)):
                q.z(3*i+2)
        q.barrier()
    for i in range(width):
        q.measure(3*i+2,2*width+i)
    return q


def analyze(counts):
    byte_counts=Counter()
    for word,n in counts.items():
        assert len(word)==24 and set(word)<={"0","1"}
        byte_counts[word[:8]]+=n
    assert sum(byte_counts.values())==SHOTS
    return {"byte_counts":dict(byte_counts),"exact":byte_counts[format(VALUE,"08b")]}


def simulate():
    sim=AerSimulator(method="stabilizer")
    result=sim.run([circuit(m) for m in MODES],shots=SHOTS,seed_simulator=SEED).result()
    counts=result.get_counts()
    rows=[analyze(c) for c in counts]
    assert all(row["exact"]==SHOTS for row in rows)
    for i in range(8):
        assert {((int(w,2)>>(2*i))&3) for w in counts[0]}==set(range(4))
    save(SIM,{"modes":MODES,"shots_per_circuit":SHOTS,"input_byte":"01000001","seed":SEED,"rows":rows})
    print([row["exact"] for row in rows])


def triples(backend, count=8, reserved=()):
    props=backend.properties(refresh=True)
    bad=set(props.faulty_qubits())
    bad_edges={tuple(sorted(g.qubits)) for g in props.faulty_gates() if len(g.qubits)==2}
    neighbors={i:{} for i in range(backend.num_qubits) if i not in bad}
    for u,v in backend.coupling_map.get_edges():
        if u in bad or v in bad or tuple(sorted((u,v))) in bad_edges:
            continue
        entry=backend.target["cz"].get((u,v)) or backend.target["cz"].get((v,u))
        if entry is not None and entry.error is not None:
            neighbors[u][v]=neighbors[v][u]=entry.error
    candidates=[]
    for alice,links in neighbors.items():
        for src in links:
            for bob in links:
                if src>=bob:
                    continue
                path=(src,alice,bob)
                cost=sum(props.readout_error(i) for i in path)+links[src]+links[bob]
                candidates.append((cost,path))
    used=set(reserved)
    result=[]
    for _,path in sorted(candidates):
        if used.isdisjoint(path):
            result.append(path)
            used.update(path)
        if len(result)==count:
            return result
    raise ValueError("Could not place the requested disjoint triples")


def prepare(backend, paths=None, modes=MODES, value=VALUE):
    paths=triples(backend) if paths is None else paths
    width=len(paths)
    layout=[w for path in paths for w in path]
    fast=all(backend.target.instruction_supported("measure_2",(w,)) for path in paths for w in path[:2])
    isa=transpile([circuit(m,fast,value,width) for m in modes],backend,initial_layout=layout,
                  routing_method="none",optimization_level=1,seed_transpiler=SEED,num_processes=1)
    for mode,q in zip(modes,isa):
        backend.check_faulty(q)
        measured={}
        controls=[]
        edges=[]
        for op in q.data:
            g=op.operation
            wires=[q.find_bit(w).index for w in op.qubits]
            if g.name!="barrier":
                assert set(wires)<=set(layout if mode=="teleport" else layout[2::3])
            if g.name in ("measure","measure_2"):
                measured[q.find_bit(op.clbits[0]).index]=wires[0]
            if g.name=="if_else":
                bit,val=g.condition
                assert val==1
                controls.append((q.find_bit(bit).index,wires[0]))
            if g.name=="cz":
                edges.append(tuple(sorted(wires)))
        expected={2*width+i:p[2] for i,p in enumerate(paths)}
        if mode=="teleport":
            expected.update({2*i+j:p[j] for i,p in enumerate(paths) for j in (0,1)})
        assert measured==expected
        assert sorted(controls)==([(2*i+j,p[2]) for i,p in enumerate(paths) for j in (0,1)] if mode=="teleport" else [])
        assert sorted(edges)==(sorted(tuple(sorted(e)) for p in paths for e in (p[:2],p[1:])) if mode=="teleport" else [])
    return paths,fast,isa


def hardware():
    rec=load(HW)
    if rec.get("rows"):
        return
    if not sys.stdin.isatty() or not SIM.exists():
        raise RuntimeError("Run simulator first and use an interactive key prompt")
    while True:
        key=getpass.getpass("IBM Cloud API key (hidden): ").strip()
        if not key:
            return
        try:
            service=QiskitRuntimeService(channel="ibm_quantum_platform",token=key,plans_preference=["open"],region="us-east")
            break
        except InvalidAccountError:
            print("IBM instance lookup failed. Paste the key again or press Enter to exit.")
    backend=service.backend("ibm_kingston")
    isa=[]
    if not rec:
        paths,fast,isa=prepare(backend)
        rec=dict(backend=backend.name,modes=MODES,triples_from_least_significant_bit=paths,
                 fast_mid_measure=fast,input_byte="01000001",native_counts=[dict(q.count_ops()) for q in isa])
    rec=execute(service,backend,HW,TAG,rec,lambda:isa)
    assert len(rec["counts"])==2
    rec["rows"]=[analyze(c) for c in rec["counts"]]
    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"/"ascii-a-error.json",{"type":type(exc).__name__,"frames":frames})
            print(type(exc).__name__)
        input("Press Enter to close.")
field-report/work/verify_ascii_a.py · complete source
import json
from collections import Counter
from pathlib import Path
from scipy.stats import binomtest

root=Path(__file__).resolve().parents[1]/"outputs"
d=json.loads((root/"ASCII-A-Kingston.json").read_text())
print(d["job_id"],d["metrics"]["usage"])
for mode,raw,summary in zip(d["modes"],d["counts"],d["rows"]):
    counter=Counter()
    for bits,n in raw.items():
        counter[int(bits,2)>>16]+=n
    assert sum(counter.values())==256 and summary["exact"]==counter[65]
    assert {int(k,2):v for k,v in summary["byte_counts"].items()}==dict(counter)
    wrongbits=sum((k^65).bit_count()*v for k,v in counter.items())
    oneoff=sum(v for k,v in counter.items() if (k^65).bit_count()==1)
    print(mode,counter[65],binomtest(counter[65],256).proportion_ci(method="wilson"),"bit accuracy",1-wrongbits/2048,
          "one-bit misses",oneoff,"hist",counter.most_common(6))
noise-wall/source/teleport_ascii_a.py · complete source
"""Transfer the eight bits of ASCII A in parallel and score Bob's whole byte."""
import getpass
import logging
import sys
import traceback
from collections import Counter
from pathlib import Path

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

from graph156 import save
from run_switch_puzzles import ROOT, SHOTS, execute, load

VALUE = ord("A")
MODES = ("teleport", "direct")
SEED = 20261121
SIM = ROOT/"ASCII-A-simulator.json"
HW = ROOT/"ASCII-A-Kingston.json"
TAG = "ascii-A-8-triples-kingston-20261120"


def circuit(mode, fast=False, value=VALUE, width=8):
    q = QuantumCircuit(3*width,3*width,name="ascii_"+mode)
    for i in range(width):
        src, alice, bob = range(3*i,3*i+3)
        if (value>>i)&1:
            q.x(src if mode=="teleport" else bob)
        if mode=="teleport":
            q.h(alice)
            q.cx(alice,bob)
            q.cx(src,alice)
            q.h(src)
    if mode=="teleport":
        for i in range(width):
            for role in (0,1):
                wire,flag = 3*i+role,2*i+role
                if fast:
                    q.append(MidCircuitMeasure(),[wire],[flag])
                else:
                    q.measure(wire,flag)
        for i in range(width):
            with q.if_test((q.clbits[2*i+1],1)):
                q.x(3*i+2)
            with q.if_test((q.clbits[2*i],1)):
                q.z(3*i+2)
        q.barrier()
    for i in range(width):
        q.measure(3*i+2,2*width+i)
    return q


def analyze(counts):
    byte_counts=Counter()
    for word,n in counts.items():
        assert len(word)==24 and set(word)<={"0","1"}
        byte_counts[word[:8]]+=n
    assert sum(byte_counts.values())==SHOTS
    return {"byte_counts":dict(byte_counts),"exact":byte_counts[format(VALUE,"08b")]}


def simulate():
    sim=AerSimulator(method="stabilizer")
    result=sim.run([circuit(m) for m in MODES],shots=SHOTS,seed_simulator=SEED).result()
    counts=result.get_counts()
    rows=[analyze(c) for c in counts]
    assert all(row["exact"]==SHOTS for row in rows)
    for i in range(8):
        assert {((int(w,2)>>(2*i))&3) for w in counts[0]}==set(range(4))
    save(SIM,{"modes":MODES,"shots_per_circuit":SHOTS,"input_byte":"01000001","seed":SEED,"rows":rows})
    print([row["exact"] for row in rows])


def triples(backend, count=8, reserved=()):
    props=backend.properties(refresh=True)
    bad=set(props.faulty_qubits())
    bad_edges={tuple(sorted(g.qubits)) for g in props.faulty_gates() if len(g.qubits)==2}
    neighbors={i:{} for i in range(backend.num_qubits) if i not in bad}
    for u,v in backend.coupling_map.get_edges():
        if u in bad or v in bad or tuple(sorted((u,v))) in bad_edges:
            continue
        entry=backend.target["cz"].get((u,v)) or backend.target["cz"].get((v,u))
        if entry is not None and entry.error is not None:
            neighbors[u][v]=neighbors[v][u]=entry.error
    candidates=[]
    for alice,links in neighbors.items():
        for src in links:
            for bob in links:
                if src>=bob:
                    continue
                path=(src,alice,bob)
                cost=sum(props.readout_error(i) for i in path)+links[src]+links[bob]
                candidates.append((cost,path))
    used=set(reserved)
    result=[]
    for _,path in sorted(candidates):
        if used.isdisjoint(path):
            result.append(path)
            used.update(path)
        if len(result)==count:
            return result
    raise ValueError("Could not place the requested disjoint triples")


def prepare(backend, paths=None, modes=MODES, value=VALUE):
    paths=triples(backend) if paths is None else paths
    width=len(paths)
    layout=[w for path in paths for w in path]
    fast=all(backend.target.instruction_supported("measure_2",(w,)) for path in paths for w in path[:2])
    isa=transpile([circuit(m,fast,value,width) for m in modes],backend,initial_layout=layout,
                  routing_method="none",optimization_level=1,seed_transpiler=SEED,num_processes=1)
    for mode,q in zip(modes,isa):
        backend.check_faulty(q)
        measured={}
        controls=[]
        edges=[]
        for op in q.data:
            g=op.operation
            wires=[q.find_bit(w).index for w in op.qubits]
            if g.name!="barrier":
                assert set(wires)<=set(layout if mode=="teleport" else layout[2::3])
            if g.name in ("measure","measure_2"):
                measured[q.find_bit(op.clbits[0]).index]=wires[0]
            if g.name=="if_else":
                bit,val=g.condition
                assert val==1
                controls.append((q.find_bit(bit).index,wires[0]))
            if g.name=="cz":
                edges.append(tuple(sorted(wires)))
        expected={2*width+i:p[2] for i,p in enumerate(paths)}
        if mode=="teleport":
            expected.update({2*i+j:p[j] for i,p in enumerate(paths) for j in (0,1)})
        assert measured==expected
        assert sorted(controls)==([(2*i+j,p[2]) for i,p in enumerate(paths) for j in (0,1)] if mode=="teleport" else [])
        assert sorted(edges)==(sorted(tuple(sorted(e)) for p in paths for e in (p[:2],p[1:])) if mode=="teleport" else [])
    return paths,fast,isa


def hardware():
    rec=load(HW)
    if rec.get("rows"):
        return
    if not sys.stdin.isatty() or not SIM.exists():
        raise RuntimeError("Run simulator first and use an interactive key prompt")
    while True:
        key=getpass.getpass("IBM Cloud API key (hidden): ").strip()
        if not key:
            return
        try:
            service=QiskitRuntimeService(channel="ibm_quantum_platform",token=key,plans_preference=["open"],region="us-east")
            break
        except InvalidAccountError:
            print("IBM instance lookup failed. Paste the key again or press Enter to exit.")
    backend=service.backend("ibm_kingston")
    isa=[]
    if not rec:
        paths,fast,isa=prepare(backend)
        rec=dict(backend=backend.name,modes=MODES,triples_from_least_significant_bit=paths,
                 fast_mid_measure=fast,input_byte="01000001",native_counts=[dict(q.count_ops()) for q in isa])
    rec=execute(service,backend,HW,TAG,rec,lambda:isa)
    assert len(rec["counts"])==2
    rec["rows"]=[analyze(c) for c in rec["counts"]]
    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"/"ascii-a-error.json",{"type":type(exc).__name__,"frames":frames})
            print(type(exc).__name__)
        input("Press Enter to close.")

Personal comments

Personal comments will be added here.