IBM Quantum Challenge: Spring 2023 — Lab 2

Exploring the World of Quantum Computing: IBM’s Quantum Challenge Spring 2023 -Quantum Teleportation

Monit Sharma
10 min readMay 28, 2023
IBM Quantum

Introduction:

Welcome back to our blog series on the recently concluded IBM Quantum Challenge of Spring 2023! In this series, we are delving into the exciting world of quantum computing and exploring the various lab exercises that participants tackled during the challenge. In this second article, we will be focusing on Lab 2, which centres around the intriguing concept of Quantum Teleportation. We will dive into the theory behind the problem of transmitting a quantum message without destroying it upon observation and explore the elegant solution known as Teleportation.

Schematics of Quantum Teleportation circuit, the |psi> is the one which is teleported from the first to the third qubit.

Understanding Quantum Teleportation:

Quantum Teleportation is a groundbreaking protocol that allows for the transfer of quantum information from one location to another, even though the quantum state itself cannot be physically transported. This protocol tackles the challenge of transmitting a quantum message without destroying it upon observation, a phenomenon known as the no-cloning theorem. Quantum Teleportation relies on the concept of entanglement to faithfully recreate the quantum state at the receiving end.

The No-Cloning Theorem

To comprehend the motivation behind Quantum Teleportation, it is essential to grasp the no-cloning theorem. This theorem states that it is impossible to create an identical copy of an arbitrary unknown quantum state. In the context of sending quantum messages, this poses a significant challenge, as any attempt to measure the state in order to transmit it would cause its collapse, thereby destroying the original message.

The Concept of Entanglement:

Entanglement plays a crucial role in Quantum Teleportation. It is a phenomenon in which two or more quantum particles become correlated in such a way that the state of one particle is intrinsically tied to the state of another, regardless of the distance between them. This non-local correlation enables the faithful transfer of quantum information without physically moving the original quantum state.

The Teleportation Protocol:

The Teleportation Protocol is the elegant solution to the problem of transmitting quantum information without directly measuring and destroying the original state. It involves the joint manipulation of the original quantum state, an entangled pair of qubits, and a classical communication channel. By leveraging entanglement and performing specific operations on the constituent qubits, the protocol allows for the faithful recreation of the original quantum state at a distant location.

A quantum teleportation circuit that teleports the qubit q00 to q02. Run on IBMs Qiskit.

Lab 2: Quantum Teleportation

In the second lab, we were given a problem to solve between Alice and Bob. Alice possesses a qubit in an unknown state and she wishes to transfer this quantum state to Bob. But they are very far apart. Although they do share an entangled qubit pair. Can this task be done?

Absolutely, using the entangled qubit pair, she can transfer her qubit state to Bob by sending two bits of classical information, and this process is called teleportation, because, by the end of it, Bob will possess the information that Alice wants to share, but Alice will no longer have it.

Some Background

As I’ve already explained in the above section, Quantum teleportation is a protocol that allows the transfer of quantum information from one qubit to another using entanglement and classical communication. It was proposed by Charles Bennett, Gilles Brassard, Claude Crépeau, Richard Jozsa, Asher Peres, and William Wootters in 1993. The process does not transmit the qubit itself but rather transfers the quantum state from the source qubit to the target qubit.

This protocol requires three qubits:

  1. The qubit to be teleported (Alice’s qubit)
  2. One half of an entangled pair of qubits (Alice’s second qubit)
  3. The other half of the entangled pair (Bob’s qubit)

and this whole process can be summarized in the following steps:

  1. Create an entangled pair of qubits (Bell pair) shared between Alice and Bob.
  2. Alice performs a Bell basis measurement on her two qubits.
  3. Alice sends the classical results of her measurement to Bob.
  4. Bob applies appropriate quantum gates based on Alice’s measurement results to obtain the teleported state.

Implementation

To make the teleportation successful, Alice and Bob need the help of a pair of entangled qubits, then Alice carries out certain operations on her qubit and shares the results with Bob through a classical communication channel. In the end, Bob performs a series of operations on his qubit to successfully obtain Alice’s qubit.

Our quantum circuit will have 3 qubits and 3 classical bits.

  • s : The “source” qubit containing the state |psi⟩ which Alice wishes to transmit to Bob.
  • a : The qubit which will initially store Alice’s half of the entangled Bell pair.
  • b : The qubit which will initially store Bob’s half of the entangled Bell pair.

The teleportation actually requires only 2 classical bits, but we include a third one since that will be used to measure Bob’s final state.

  • c0: The classical bit that Alice uses to measure a.
  • c1: The classical bit that Alice uses to measure s.
  • c2: The classical bit that Bob uses to measure b.

Exercise 1

For the first exercise, use two qubits to generate an entangled Bell pair, in this problem, qubit a is allocated to Alice and b is for Bob.

# doing the necessary imports
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.circuit import Qubit, Clbit


def create_bell_pair(qr: QuantumRegister, cr: ClassicalRegister) -> QuantumCircuit:
"""Creates a bell pair between qubits a and b."""
qc = QuantumCircuit(qr, cr) # our complete quantum circuit
# unpack qubits
# the first qubit is s but we won't be using it in this exercise
s, a, b = qr # the names of our qubits, where s is the target one

# ENTER YOUR CODE BELOW EACH COMMENT
# Put qubit a into state |+>
qc.h(a)
# CNOT with a as control and b as target
qc.cx(a, b)
# ENTER YOUR CODE ABOVE

return qc # For the grader

Plot the circuit:

qr = QuantumRegister(3, name="q")
cr = ClassicalRegister(3, name="c")
qc = create_bell_pair(qr, cr)

qc.draw("mpl") # to use mpl, try %pip install pylatexenc
The circuit represents the q1 as Alice’s qubit, q2 as Bob’s qubit and it’s made in such a manner that they both share an entangled pair amongst them, by applying a Hadamard and a CNOT

Submit it to the Grader:

# Submit your circuit

from qc_grader.challenges.spring_2023 import grade_ex2a

grade_ex2a(qc)

Now, since they share an entangled pair, assume they are some distance apart (or separated).

Exercise 2

In this exercise, Alice applies a CNOT gate to her qubit with the target qubit s or q0 as a control. This is also the state she intends to send to Bob. After this, she also applies a Hadamard gate to s.

def alice_gates(qr: QuantumRegister, cr: ClassicalRegister):
"""Creates Alices's gates"""
qc = create_bell_pair(qr, cr)
qc.barrier() # Use barrier to separate steps
s, a, b = qr

# ENTER YOUR CODE BELOW EACH COMMENT
# CNOT with source as control and a as target
qc.cx(s, a)
# Apply Hadamard on qubit s
qc.h(s)
# ENTER YOUR CODE ABOVE

return qc # For the grader

Let’s take a look at the circuit:

qc = alice_gates(qr, cr)
qc.draw("mpl")
Before the barrier is what we got from exercise 1. Now in Exercise 2, we applied a barrier, then added a CNOT with q0 being the control qubit and later applied a Hadamard gate to it as well.

Submit it to the grader:

# Submit your circuit

from qc_grader.challenges.spring_2023 import grade_ex2b

grade_ex2b(qc)

Exercise 3

Moving on, now Alice performs measurement on both the qubits (q0,q1) in her possession and saves the results in the corresponding classical bits. Later she sends these two bits to Bob.

def measure_and_send(qr: QuantumRegister, cr: ClassicalRegister):
"""Measures qubits a & b and 'sends' the results to Bob"""
qc = alice_gates(qr, cr)
qc.barrier() # Use barrier to separate steps
s, a, b = qr # the three qubits
c0, c1, c2 = cr # the three classical bits

# ENTER YOUR CODE BELOW EACH COMMENT
# Measure qubit a into classical bit 0
qc.measure(a, c0)
# Measure qubit s into classical bit 1
qc.measure(s, c1)
# ENTER YOUR CODE ABOVE

return qc # For the grader

Let’s see how our circuit looks:

qc = measure_and_send(qr, cr)
qc.draw("mpl", cregbundle=False)
In the third exercise, two measurements are applied that measure the qubit q0 to classical bit c1 and qubit q1 to classical bit c0 respectively. q1 is Alice’s qubit and q0 is what we want to teleport.

Submit it to the grader:

# Submit your circuit

from qc_grader.challenges.spring_2023 import grade_ex2c

grade_ex2c(qc)

Exercise 4

Now, Alice has done her part, she prepared the qubits, measured them and send them off in classical bits over to Bob. Now Bob, who is already in possession of qubit b (q2) , dynamically adds specific gates to the circuit based on the state that he received from Alice. How does this work?

If the bits are 00, no action is required. If they are 01, an 𝑋 gate (also known as a Pauli-X or a bit-flip gate) should be applied. For bits 10, a 𝑍 gate (also known as a Pauli-Z or a phase-flip gate) should be applied. Lastly, if the classical bits are 11, a combined 𝑍𝑋 gate should be applied, which involves applying both the 𝑍 and 𝑋 gates in sequence. Please note that this information transfer occurs solely through classical means.

# This function takes a QuantumCircuit (qc), integer (qubit)
# and ClassicalRegisters (crz & crx) to decide which gates to apply
def bob_gates(qr: QuantumRegister, cr: ClassicalRegister):
"""Uses qc.if_test to control which gates are dynamically added"""
qc = measure_and_send(qr, cr)
qc.barrier() # Use barrier to separate steps
s, a, b = qr
c0, c1, c2 = cr

# ENTER YOUR CODE BELOW EACH COMMENT
# Add an X gate to the qubit wire if c0 measures 1
with qc.if_test((c0, 1)):
qc.x(b)
# Add a Z gate to the qubit wire if c1 measures 1
with qc.if_test((c1, 1)):
qc.z(b)
# ENTER YOUR CODE ABOVE

return qc # For the grader

Draw the circuit:

qc = bob_gates(qr, cr)
qc.draw("mpl", cregbundle=False)
So, after all the work done by Alice, now Bob applies two dynamic circuits based on the measurement of the classical bits.
# Submit your circuit

from qc_grader.challenges.spring_2023 import grade_ex2d

grade_ex2d(qc)

To check whether the task was successful, Bob measures his qubit into classical bit c2. After running the experiment multiple times, we can gather statistics on the result. This is what the complete circuit looks like:

teleportation_circuit = bob_gates(qr, cr)
s, a, b = qr
c0, c1, c2 = cr
teleportation_circuit.measure(b, c2)
teleportation_circuit.draw("mpl")
The complete Teleportation circuit, which teleports the state in q0 to q2.

Since we have our complete teleportation circuit, let’s create and teleport a quantum state and run this on a simulator.

Exercise 5:

Given the previous work, construct a full quantum teleportation circuit into the teleport_superposition_circuit variable. Prepare the qubit s by applying an Rx rotation with angle pi/4.

import math

teleport_superposition_circuit: QuantumCircuit

########## your code goes here #######

# Create a circuit that has the same structure as our teleportation circuit
state_prep = QuantumCircuit(qr, cr)

# Prepare the qubit
state_prep.rx(math.pi / 4, s)

# Put a barrier across all of the wires
state_prep.barrier()
# Add the teleportation circuit to the superposition circuit
teleport_superposition_circuit = state_prep.compose(teleportation_circuit)

teleport_superposition_circuit.draw("mpl", cregbundle=False)

Run it o a simulator and visualize the results:

from qiskit import transpile
from qiskit_aer import AerSimulator
from qiskit.visualization import plot_histogram

sim = AerSimulator()
transpiled_circuit = transpile(teleport_superposition_circuit, sim)

# run job
shots = 1000
job = sim.run(transpiled_circuit, shots=shots, dynamic=True)

# Get the results and display them
exp_result = job.result()
exp_counts = exp_result.get_counts()
plot_histogram(exp_counts)
The complete three-qubit measurement

Let’s compute the distribution of just Bob’s measurement

# trace out Bob's results on qubit 2
from qiskit.result import marginal_counts

bobs_counts = marginal_counts(exp_counts, [qr.index(b)])
plot_histogram(bobs_counts)
The margin distribution is somewhat close to the ideal probabilities.

Submit it to the grader:

from qc_grader.challenges.spring_2023 import grade_ex2e

grade_ex2e(bobs_counts)

Follow these steps if you want to run this on actual quantum hardware. (It may take some time)

from qiskit_ibm_provider import IBMProvider

provider = IBMProvider()
hub = "ibm-q-internal"
group = "deployed"
project = "default"

backend_name = "ibm_peekskill"
backend = provider.get_backend(backend_name, instance=f"{hub}/{group}/{project}")
# backend.target.add_instruction(IfElseOp, name="if_else") # Uncomment if necessary
qc_transpiled = transpile(teleport_superposition_circuit, backend)
job = backend.run(qc_transpiled, shots=1000, dynamic=True)
# Get the results and display them
exp_result = job.result()
exp_counts = exp_result.get_counts()
plot_histogram(exp_counts)
# trace out Bob's results on qubit 2
from qiskit.result import marginal_counts

bobs_qubit = 2
bobs_counts = marginal_counts(exp_counts, [bobs_qubit])
plot_histogram(bobs_counts)

The result will be similar, but a little worse than the simulator, since real hardware is noisy.

Congratulations!

You made it to the end of Lab 2 as well, now you have some intermediate knowledge of dynamic circuits and can implement them easily.

In this second lab of the IBM Quantum Challenge Spring 2023, participants were immersed in the fascinating world of Quantum Teleportation. By grappling with the theory behind the no-cloning theorem and understanding the power of entanglement, participants gained insights into the challenges of transmitting quantum information without destruction. Through the Teleportation Protocol, they discovered a clever solution that enables the faithful recreation of quantum states at remote locations, setting the stage for remarkable possibilities in quantum communication.

Stay tuned for our next article in this series, where we will explore Lab 3 of the IBM Quantum Challenge Spring 2023, delving into exciting topics related to iterative phase estimation. As the field of quantum computing continues to evolve rapidly, challenges like the IBM Quantum Challenge provide invaluable opportunities to deepen our understanding and push the boundaries of this cutting-edge technology.

Happy teleporting!

--

--