← Quantum Store · Guides · Lessons · Glossary · Packages · About · Türkçe

Quantum Store editors

Quantum teleportation and superdense coding

ProtocolQuantum communicationLicence: MITVersion: 1.0.05.1 KB
Download ZIP (free)

Quantum teleportation, which transfers an unknown qubit state using entanglement, and superdense coding, which sends 2 bits with one qubit. Tested with Qiskit, explained step by step.

What quantum teleportation is (and is not)

No matter is moved, as in science fiction. What moves is the state of a qubit, the quantum information it holds. Moreover:

(Ayşe and Bora are the Turkish Alice and Bob used in the code.)

The example in this package

isinlama.py runs two protocols.

1. Teleportation: Ayşe prepares a random state (angles TETA and FI). Ayşe and Bora share an entangled pair of qubits in advance. Ayşe measures her two qubits together and tells Bora the result; Bora applies X and/or Z accordingly. The program computes the similarity (fidelity) of Bora's qubit to the original state: the result is 1.000000, so the state was transferred exactly.

We wrote the classical communication step in the code as controlled gates, using the "deferred measurement" principle. It is mathematically equivalent and makes the circuit easy to run on any simulator.

2. Superdense coding: The reverse of teleportation. Thanks to previously shared entanglement, Ayşe sends two classical bits (00, 01, 10, 11) by sending a single qubit. All four messages were decoded correctly in 200 out of 200 trials.

In the real world

Teleportation is a basic building block of the quantum internet and of quantum repeaters. In 2017 teleportation over more than 1,400 km was achieved with China's Micius satellite.

Next steps

  1. Change the values of TETA and FI; the fidelity always stays 1.
  2. Delete the line qc.cz(0, 2) and see how Bora loses the state if he skips the correction.
  3. Then move on to the "BB84 quantum key distribution" package.

Installation and running

pip install qiskit
python isinlama.py

Tested with: qiskit 2.5.2, Python 3.12.

Links

Package contents

Licence

This package was prepared by the Quantum Store editors and is distributed under the MIT licence.


Quantum Store — https://hakanerdogan.com/en

Example code

The example shipped in the package, run and checked. Comments and printed messages are in Turkish; the code is the same in any language. Everything is in the ZIP.

isinlama.py

"""Kuantum ışınlama ve süper yoğun kodlama (Qiskit).

Çalıştırma:
    pip install qiskit
    python isinlama.py
"""

from math import pi

from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler
from qiskit.quantum_info import Statevector, partial_trace, state_fidelity

# --- Kuantum ışınlama -------------------------------------------------------
# Ayşe (q0) elindeki bilinmeyen kübit durumunu, önceden paylaştıkları dolanık
# çift (q1 Ayşe'de, q2 Bora'da) yardımıyla Bora'ya aktarır. Kübitin kendisi
# yolculuk etmez; Ayşe'nin kopyası ölçümle yok olur (kopyalama yasağı).
TETA, FI = 1.1, 0.7  # Işınlanacak rastgele bir durum

hedef = QuantumCircuit(1)
hedef.ry(TETA, 0)
hedef.rz(FI, 0)
hedef_durum = Statevector(hedef)

qc = QuantumCircuit(3)
qc.ry(TETA, 0)
qc.rz(FI, 0)
qc.h(1)  # Dolanık çift: q1 Ayşe'de, q2 Bora'da
qc.cx(1, 2)
qc.cx(0, 1)  # Ayşe'nin Bell ölçümü
qc.h(0)
# Ayşe ölçüm sonuçlarını (2 klasik bit) Bora'ya gönderir; Bora bunlara göre X/Z uygular.
# Burada "ertelenmiş ölçüm" ilkesiyle bu klasik kontrolü kontrollü kapılarla yazıyoruz.
qc.cx(1, 2)
qc.cz(0, 2)
print(qc.draw(output="text"))

bora = partial_trace(Statevector(qc), [0, 1])
benzerlik = state_fidelity(bora, hedef_durum)
print(f"Bora'nın kübiti ile orijinal durumun benzerliği (fidelity): {benzerlik:.6f}")
assert abs(benzerlik - 1) < 1e-9, benzerlik

# --- Süper yoğun kodlama ------------------------------------------------------
# Tersi: önceden paylaşılmış dolanık çift sayesinde tek kübit göndererek 2 klasik bit aktar.
sampler = StatevectorSampler(seed=3)
for mesaj in ["00", "01", "10", "11"]:
    sd = QuantumCircuit(2)
    sd.h(0)
    sd.cx(0, 1)
    if mesaj[0] == "1":
        sd.x(0)
    if mesaj[1] == "1":
        sd.z(0)
    # q0 Bora'ya gönderilir; Bora iki kübiti birlikte çözer.
    sd.cx(0, 1)
    sd.h(0)
    sd.measure_all()
    sayim = sampler.run([sd], shots=200).result()[0].data.meas.get_counts()
    print(f"Gönderilen {mesaj} → Bora'nın ölçtüğü {dict(sayim)}")
    assert sayim == {mesaj: 200}, (mesaj, sayim)

print(f"Tamam: durum aynen aktarıldı ve tek kübitle 2 bit gönderildi (π ≈ {pi:.2f}).")

Related concepts

← All packages

Share: X · LinkedIn