Quantum Data Teleportation using Qiskit, Quantum Gates and the principles of Superposition and Entanglement.
- Clone the repository
$ git clone https://github.com/vaishnav-mk/quantum-teleportation.git
$ cd quantum-teleportation
- Create and activate a conda virtual environment
$ conda env create -f environment.yml
$ conda activate quantum-env
- Run the
communication.py
script
$ python communication.py
This should run the Quantum Data Teleportation simulation and display the results as shown below.
*** Example usage with a file ***
Processing 1 characters (8 bits)...
Processing characters: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 8/8 [00:02<00:00, 3.74char/s]
Time taken: 2.143385171890259 seconds.
Received Data: A
Sent Data == Received Data: True
*** Example usage with a string ***
Processing 13 characters (200 bits)...
Processing characters: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 200/200 [00:01<00:00, 180.10char/s]
Time taken: 1.112023115158081 seconds.
Received Data: Hello, World!
file_path = "data/text.txt"
quantum_communication = QuantumDataTeleporter(file_path=file_path, shots=1)
received_data, is_data_match = quantum_communication.run_simulation()
print(f"Received Data: {received_data}")
print(f"Sent Data == Received Data: {is_data_match}")
text = "Hello, World!"
quantum_communication = QuantumDataTeleporter(text_to_send=text, shots=1)
received_data, is_data_match = quantum_communication.run_simulation()
print(f"Received Data: {received_data}")
print(f"Sent Data == Received Data: {is_data_match}")
QuantumDataTeleporter
Class
The class is initialized with the following parameters:
separator
: The separator used for binary encoding.shots
: The number of shots for the quantum simulation.file_path
: The path to the file for reading text data.text_to_send
: The text data to be sent if file_path is not provided.
The system utilizes the principles of superposition and entanglement in quantum mechanics. Superposition allows a qubit to exist in multiple states simultaneously, and entanglement establishes correlations between qubits, even when separated by large distances.
┌───┐ ░ ░ ┌───┐ ░ ┌─┐
q_0: ┤ X ├─░────────────░───■──┤ H ├─░─┤M├─────────■────
└───┘ ░ ┌───┐ ░ ┌─┴─┐└───┘ ░ └╥┘┌─┐ │
q_1: ──────░─┤ H ├──■───░─┤ X ├──────░──╫─┤M├──■───┼────
░ └───┘┌─┴─┐ ░ └───┘ ░ ║ └╥┘┌─┴─┐ │ ┌─┐
q_2: ──────░──────┤ X ├─░────────────░──╫──╫─┤ X ├─■─┤M├
░ └───┘ ░ ░ ║ ║ └───┘ └╥┘
c: 3/═══════════════════════════════════╩══╩══════════╩═
0 1 2
The quantum circuits created by the Quantum Data Teleporter employ various quantum gates, such as the Hadamard gate (H), controlled-X gate (CX), controlled-Z gate (CZ), and Pauli-X gate (X). These gates manipulate qubits to perform encoding, transmission, and decoding operations.
The protocol that allows the transfer of quantum information from one qubit to another works as follows:
- The sender and receiver share an entangled pair of qubits.
- The sender encodes the classical data into a qubit using the Pauli-X gate and the Hadamard gate.
- The sender applies a controlled-X gate and a controlled-Z gate to the qubit and the entangled qubit, respectively.
- The sender measures the qubit and the entangled qubit and sends the measurement results to the receiver.
- The receiver applies the appropriate gates to the entangled qubit based on the measurement results to obtain the original qubit.
░ ░ ┌───┐ ░ ┌─┐
q_0: ──────░────────────░───■──┤ H ├─░─┤M├─────────■────
┌───┐ ░ ┌───┐ ░ ┌─┴─┐└───┘ ░ └╥┘┌─┐ │
q_1: ┤ X ├─░─┤ H ├──■───░─┤ X ├──────░──╫─┤M├──■───┼────
└───┘ ░ └───┘┌─┴─┐ ░ └───┘ ░ ║ └╥┘┌─┴─┐ │ ┌─┐
q_2: ──────░──────┤ X ├─░────────────░──╫──╫─┤ X ├─■─┤M├
░ └───┘ ░ ░ ║ ║ └───┘ └╥┘
c: 3/═══════════════════════════════════╩══╩══════════╩═
0 1 2
circuit.x(1 if self.binary_text[i] == "1" else 0)
This gate (X
gate) flips the qubit from the |0⟩ state to the |1⟩ state if the bit is 1.
- If the X gate is on Qubit 0, the teleported data on
Qubit 0
becomes1
{'100': 252, '111': 259, '110': 263, '101': 250}
- The same applies to Qubit 1 as well; if the X gate is on Qubit 1, the probability of
0
, increases
{'000': 255, '001': 304, '010': 238, '011': 227}
circuit.barrier()
This adds a barrier to the circuit, visually separating the encoding and transmission stages.
circuit.h(1)
circuit.cx(1, 2)
The Hadamard gate (H
gate) creates a superposition of the |0⟩ and |1⟩ states, and the controlled-X gate (CX
gate) entangles the qubits by flipping the target qubit if the control qubit is in the |1⟩ state.
circuit.barrier()
Another barrier for visual separation.
circuit.cx(0, 1)
circuit.h(0)
Another controlled-X gate between qubits 0 and 1 and a Hadamard gate to qubit 0 are applied to the qubit to prepare it for measurement.
circuit.barrier()
Yet another barrier.
circuit.measure([0, 1], [0, 1])
Measurement of the qubits 0 and 1 is performed, and the results are stored in classical bits 0 and 1, respectively.
circuit.cx(1, 2)
circuit.cz(0, 2)
CX gate and CZ gate are applied, transforming the state of qubit 2 based on the measurement results of qubits 0 and 1. This is a crucial step in the teleportation process as it allows the receiver to obtain the original qubit.
circuit.measure([2], [2])
The final measurement is performed on qubit 2, and the result is stored in classical bit 2. This measurement completes the teleportation.