WikiQuantum

Quantum Chat: a reproducible local superdense-coding simulator

Two-way terminal chat over simulated superdense coding, with framing, checksums, ACK/retry, a noise model and executed notebooks. Version 0.1.1.

Updated

HZᶻXˣHA |0⟩B |0⟩zxBell pair, shared firstsender encodesreceiver decodes
Superdense coding circuit. H and CNOT make a Bell pair. The sender applies Zᶻ then Xˣ to qubit A and sends it. The receiver applies CNOT then H and measures z on A and x on B, as implemented in Quantum Chat.

MHP Build · Software release 0.1.1 (research preview), 16 November 2026 · MIT licence · Code: mhpbuild/Quantum-Chat

Abstract

We present Quantum Chat, an open-source simulator that carries UTF-8 text messages between two terminal users by superdense coding. Each two-bit symbol is encoded on one qubit of a fresh Bell pair and decoded jointly after that qubit is transferred. Messages are wrapped in a bounded frame with a SHA-256 checksum, and delivery is confirmed by a classical ACK with retry. A depolarising channel on the transferred qubit and bit errors on the ACK give a noise model with a closed-form confirmation probability. In 100 synthetic messages per condition, all 100 were received and confirmed without noise. With per-qubit depolarisation p = 0.002 and ACK bit error q = 0.0002, 94 were received exactly and 93 confirmed within five attempts. All numbers come from executed notebooks in the repository. The simulator is educational: it models an established protocol and makes no claim of physical quantum communication.

1. Introduction

Superdense coding, introduced by Bennett and Wiesner [1], sends two classical bits by transmitting one qubit, provided the sender and receiver already share an entangled pair. It is one of the simplest protocols in which entanglement is a resource that can be counted and spent.

Most demonstrations stop at four symbols on a circuit diagram. Quantum Chat follows the protocol all the way to a usable application: arbitrary text, two directions, corrupted frames, lost acknowledgements and retries. Every resource is accounted for, including the overhead that a fair comparison needs. The quantum part runs on Cirq and qsimcirq [4]; the terminals talk to the simulator over classical localhost TCP.

2. Protocol

The basis order is A, B: |00⟩, |01⟩, |10⟩, |11⟩. The sender holds qubit A and the receiver holds B after an initial distribution. The shared Bell pair is

∣Φ+⟩=CNOTA→B (HA⊗IB) ∣00⟩=12(∣00⟩+∣11⟩).|\Phi^+\rangle = \mathrm{CNOT}_{A\to B}\,(H_A \otimes I_B)\,|00\rangle = \tfrac{1}{\sqrt 2}\big(|00\rangle + |11\rangle\big).

To send bits z,xz, x, the sender applies ZzZ^z and then XxX^x to A, so the total operator is XxZzX^x Z^z. After A arrives, the receiver applies CNOT and then H on A, and measures both qubits:

(HA⊗IB) CNOTA→B (XAxZAz⊗IB) ∣Φ+⟩=eiθ ∣z x⟩.(H_A \otimes I_B)\,\mathrm{CNOT}_{A\to B}\,(X_A^{x} Z_A^{z} \otimes I_B)\,|\Phi^+\rangle = e^{i\theta}\,|z\,x\rangle .

The global phase eiθe^{i\theta} is unobservable, so the measurement returns zz on A and xx on B. The circuit at the top of this page shows the three stages.

No signalling. For every encoded state the receiver’s qubit alone is maximally mixed,

ρB=Tr⁡A(∣ψzx⟩⟨ψzx∣)=12I,\rho_B = \operatorname{Tr}_A\big(|\psi_{zx}\rangle\langle\psi_{zx}|\big) = \tfrac{1}{2} I ,

so P(B=0)=P(B=1)=12P(B=0) = P(B=1) = \tfrac12 whatever the sender chose [3]. More samples of B, or a classifier trained on them, cannot recover the message. Qubit A must arrive.

3. Implementation

The simulator separates the logical path into modules with explicit data boundaries. The receiving endpoint sees only bytes built from measurement outcomes, never the sender’s text, encoding choices or the global state.

Module Responsibility
densechat/quantum.py Bell preparation, Z/X encoding, A-ownership transfer, one-shot measurements
densechat/protocol.py Bounded UTF-8 frame, sequence and length, SHA-256, ACK binding
densechat/session.py Endpoints, deduplication, retry and resource ledger
densechat/server.py Classical loopback control server with real TCP byte counters
densechat/cli.py Demo mode and terminal participants
viewer.py Independent observer replay with privileged access to the global state

Quantum Chat architecture: terminal sender, trusted simulator, frame and checksum, Bell pairs and encoding, A transfer, joint measurement, validation, ACK and retry

Frame. A frame is a 15-byte header (magic, version, 64-bit sequence, 32-bit length), the UTF-8 payload of at most 4096 bytes, and a 32-byte SHA-256 digest. An ACK is 75 bytes, or 600 bits. The checksum detects accidental corruption; it is not authentication or encryption.

Cost. Each byte is four two-bit symbols, and each symbol consumes a fresh Bell pair. For a frame of L bytes sent R times, the model spends

4LR Bell pairs,4LR A transfers,4LR initial B distributions,600R ACK bits.\begin{aligned} &4LR \text{ Bell pairs}, && 4LR \text{ A transfers}, \\ &4LR \text{ initial B distributions}, && 600R \text{ ACK bits}. \end{aligned}

A 25-byte message becomes a 72-byte frame, so one ideal attempt uses 288 Bell pairs. Real TCP control traffic is counted separately and is not part of the quantum ledger.

Receipt is not confirmation. A frame can be accepted while its ACK is lost (received = True, confirmed = False). Only a matching ACK stops retries, and a retry with the same sequence and fingerprint never adds a duplicate message.

4. Noise model

Transit of qubit A passes through a depolarising channel

Ep(ρ)=(1−p) ρ+p3(XρX+YρY+ZρZ),\mathcal{E}_p(\rho) = (1-p)\,\rho + \tfrac{p}{3}\big(X\rho X + Y\rho Y + Z\rho Z\big),

so the joint decoder returns the correct symbol with probability 1−p1-p and each wrong symbol with p/3p/3. With independent errors, an unchanged L-byte frame and an intact ACK (bit error qq) succeed together with probability ss, and confirmation within R attempts follows:

s=(1−p)4L (1−q)600,P(confirmed within R)=1−(1−s)R.s = (1-p)^{4L}\,(1-q)^{600}, \qquad P(\text{confirmed within } R) = 1 - (1-s)^R .

For example, at p = 0.002 and q = 0.0002 a 72-byte frame has s ≈ 0.50 per attempt and ≈ 0.97 within five attempts. Bell preparation, storage, B distribution and local gates are otherwise ideal.

5. Results

All results below were computed by the notebooks with seed 20261106 on Python 3.12.16, cirq-core 1.7.0 and qsimcirq 0.22.1.

Symbol check. Each of the four inputs was sent 32 times, one fresh pair per shot. All 128 shots decoded correctly, and P(B = 0) = P(B = 1) = 0.5 for every encoded state.

Transport experiment. 100 unique synthetic messages per condition, in both directions. Ideal: no noise, one attempt. Noisy: p = 0.002, q = 0.0002, at most five attempts.

Condition Trials Received exactly Confirmed 95% Wilson interval (confirmed) Mean attempts
Ideal 100 100 100 0.963 – 1.000 1.00
Noisy 100 94 93 0.863 – 0.966 2.42

Transport confirmation by condition, from notebook 02

Ensemble versus shots. For input 11 at p = 0.2, the exact density-matrix ensemble predicts 0.800 for the correct symbol and 0.0667 for each other. Across 512 independent one-shot runs, qsim returned 11 401 times (0.783), 10 47 times, 01 41 times and 00 23 times.

Exact ensemble probabilities against sampled shots, from notebook 03

The Wilson intervals describe this simulation sample only. They are not a statement about hardware reliability.

6. Limitations

  • Localhost TCP is a classical interface to a trusted simulator, not a physical quantum link.
  • Noise is modelled only on A transit and on the ACK. There is no erasure, storage noise, imperfect Bell distribution, latency or adversary.
  • The observer viewer reads the global state for diagnosis; no physical participant could.
  • SHA-256 without a key detects accidental corruption, not a malicious peer.
  • Messages are synthetic transport fixtures. Nothing here trains or evaluates a language model.
  • No faster-than-light communication, entanglement-only signalling or quantum encryption is claimed.

7. Reproducibility and code

The code, notebooks and figures are in mhpbuild/Quantum-Chat. The three executed notebooks are readable here on the site:

To reproduce, with Python 3.12:

git clone https://github.com/mhpbuild/Quantum-Chat.git && cd Quantum-Chat
python3.12 -m venv .venv && source .venv/bin/activate
python -m pip install --only-binary=:all: -r requirements.txt && python -m pip install --no-deps .
python -m unittest discover -s tests -v
python verify_chat.py
python scripts/execute_notebooks.py --output work/executed-notebooks

No API key, dataset download or model training is needed. Different backend versions or platforms can give different random sequences for the same seed.

References

  1. C. H. Bennett and S. J. Wiesner, “Communication via one- and two-particle operators on Einstein–Podolsky–Rosen states,” Physical Review Letters 69, 2881–2884 (1992). doi:10.1103/PhysRevLett.69.2881
  2. IBM Quantum Learning, “Superdense coding,” quantum.cloud.ibm.com (accessed 6 November 2026).
  3. IBM Quantum Learning, “Multiple systems and reduced states,” quantum.cloud.ibm.com (accessed 6 November 2026).
  4. Google Quantum AI, “Get started with qsimcirq,” quantumai.google; “Cirq DepolarizingChannel,” quantumai.google (accessed 6 November 2026).