# -*- coding: utf-8 -*-
"""Copy of Randomisation Benchmarking Protocol.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1S9Ky-5DfRVYSnaGA9N82FX7TTk3lHny3
"""

!pip install qiskit

from qiskit import QuantumCircuit, transpile, assemble, Aer, execute

# Create a quantum circuit with three qubits: Alice's, Bob's, and the shared entangled qubit
q = QuantumCircuit(3, 3)

# Alice prepares the state to be teleported
q.h(0)  # Apply Hadamard gate to Alice's qubit
q.s(0)  # Apply S gate to Alice's qubit
q.barrier()

# Create entanglement between Alice's qubit (q1) and the shared qubit (q2)
q.h(1)  # Apply Hadamard gate to q2
q.cx(1, 2)  # Apply CNOT gate with q1 as the control and q2 as the target
q.barrier()

# Alice performs Bell measurement
q.cx(0, 1)  # Apply CNOT gate with q0 as the control and q1 as the target
q.h(0)  # Apply Hadamard gate to q0
q.measure(0, 0)  # Measure q0 and store the result in classical bit 0
q.measure(1, 1)  # Measure q1 and store the result in classical bit 1
q.barrier()

# Apply teleportation correction gates on Bob's qubit
q.x(2).c_if(0, 1)  # Apply X gate to q2 if the result of measurement 0 is 1
q.z(2).c_if(1, 1)  # Apply Z gate to q2 if the result of measurement 1 is 1
q.measure(2, 2)  # Measure q2 and store the result in classical bit 2

!pip install qiskit-aer

# Simulate the circuit
simulator = Aer.get_backend('qasm_simulator')
compiled_circuit = transpile(q, simulator)
job = execute(compiled_circuit, simulator, shots=1)
result = job.result()
counts = result.get_counts(q)

print("Quantum Teleportation Result:", counts)

