Unit - 2 (Quantum Computing)
Unit - 2 (Quantum Computing)
UNIT - II 1
[QUANTUM COMPUTING]
NO CLONING THEOREM
The no cloning theorem is a result of quantum mechanics which forbids the
creation of identical copies of an arbitrary unknown quantum state. It was stated
by Wootters, Zurek, and Dieks in 1982, and has profound implications
in quantum computing and related fields. The theorem follows from the fact
that all quantum operations must be unitary linear transformation on the state
(and potentially an ancilla) .
Proof
Suppose the state of a quantum system A is a qubit, which we wish to copy. The
state can be written (see bra-ket notation) as
The complex coefficients a and b are unknown to us. In order to make a copy,
we take a system B with an identical Hilbert space and initial state ∣e⟩B (which
must be independent of ∣ψ⟩A, of which we have no prior knowledge). The
composite system is then described by the tensor product, and its state is
∣ψ⟩A∣e⟩B
There are only two ways to manipulate the composite system. We could
perform an observation, which irreversibly collapses the system into
some eigenstate of the observable, corrupting the information contained in the
qubit. This is obviously not what we want. Alternatively, we could control
the Hamiltonian of the system, and thus the time evolution operator U(Δt),
which is linear. We must fix a time interval Δt, again independent of ∣ψ⟩A. Then
U(Δt) acts as a copier provided
for all ψ. This must then be true for the basis states as well, so
U(Δt)∣0⟩A∣e⟩B = ∣0⟩A∣0⟩B
UNIT - II 2
[QUANTUM COMPUTING]
U(Δt)∣1⟩A∣e⟩B = ∣1⟩A∣1⟩B
Consequences
If Alice wishes to transmit a "0", she measures the spin of her electron in
the z direction, collapsing Bob's state to either ∣z + ⟩B or ∣z − ⟩B. Bob creates
many copies of his electron's state, and measures the spin of each copy in
UNIT - II 3
[QUANTUM COMPUTING]
the z direction. Bob will know that Alice has transmitted a "0" if all his
measurements will produce the same result; otherwise, his measurements will
be split evenly between +1/2 and -1/2. This would allow Alice and Bob to
communicate across space-like separations, potentially violating causality.
QUANTUM TELEPORTATION
Alice wants to send quantum information to Bob. Specifically, suppose she
wants to send the qubit state |ψ⟩=α|0⟩+β|1⟩. This entails passing on
information about α and β to Bob.
There exists a theorem in quantum mechanics which states that you cannot
simply make an exact copy of an unknown quantum state. This is known as the
no-cloning theorem. As a result of this we can see that Alice can't simply
generate a copy of |ψ⟩ and give the copy to Bob. We can only copy classical
states (not superpositions).
However, by taking advantage of two classical bits and an entangled qubit pair,
Alice can transfer her state |ψ⟩ to Bob. We call this teleportation because, at
the end, Bob will have |ψ⟩ and Alice won't anymore.
UNIT - II 4
[QUANTUM COMPUTING]
We will describe the steps on a quantum circuit below. Here, no qubits are
actually ‘sent’, you’ll just have to imagine that part!
import numpy as np
UNIT - II 5
[QUANTUM COMPUTING]
try
and create our quantum circuit:
## SETUP
try
Step 1
A third party, Telamon, creates an entangled pair of qubits and gives one to Bob
and one to Alice.
UNIT - II 6
[QUANTUM COMPUTING]
The pair Telamon creates is a special pair called a Bell pair. In quantum circuit
language, the way to create a Bell pair between two qubits is to first transfer
one of them to the X-basis (|+⟩|+⟩ and |−⟩|−⟩) using a Hadamard gate, and then
to apply a CNOT gate onto the other qubit controlled by the one in the X-basis.
try
## SETUP
qr = QuantumRegister(3, name="q")
## STEP 1
create_bell_pair(teleportation_circuit, 1, 2)
UNIT - II 7
[QUANTUM COMPUTING]
teleportation_circuit.draw()
try
Let's say Alice owns q1 and Bob owns q2after they part ways.
Step 2
Alice applies a CNOT gate to q1, controlled by |ψ⟩ (the qubit she is trying to send
Bob). Then Alice applies a Hadamard gate to |ψ⟩. In our quantum circuit, the
qubit (|ψ⟩ Alice is trying to send is q0:
qc.cx(psi, a)
qc.h(psi)
try
## SETUP
qr = QuantumRegister(3, name="q")
## STEP 1
create_bell_pair(teleportation_circuit, 1, 2)
UNIT - II 8
[QUANTUM COMPUTING]
## STEP 2
alice_gates(teleportation_circuit, 0, 1)
teleportation_circuit.draw()
try
Step 3
Next, Alice applies a measurement to both qubits that she owns, q1and |ψ⟩, and
stores this result in two classical bits. She then sends these two bits to Bob.
qc.barrier()
qc.measure(a,0)
qc.measure(b,1)
try
## SETUP
qr = QuantumRegister(3, name="q")
UNIT - II 9
[QUANTUM COMPUTING]
## STEP 1
create_bell_pair(teleportation_circuit, 1, 2)
## STEP 2
alice_gates(teleportation_circuit, 0, 1)
## STEP 3
measure_and_send(teleportation_circuit, 0 ,1)
teleportation_circuit.draw()
try
Step 4
Bob, who already has the qubit q2, then applies the following gates depending
on the state of the classical bits:
00 →→ Do nothing
01 →→ Apply X gate
10 →→ Apply Z gate
11 →→ Apply ZX gate
(Note that this transfer of information is purely classical.)
UNIT - II 10
[QUANTUM COMPUTING]
try
## SETUP
qr = QuantumRegister(3, name="q")
## STEP 1
create_bell_pair(teleportation_circuit, 1, 2)
## STEP 2
UNIT - II 11
[QUANTUM COMPUTING]
alice_gates(teleportation_circuit, 0, 1)
## STEP 3
measure_and_send(teleportation_circuit, 0, 1)
## STEP 4
teleportation_circuit.draw()
try
And voila! At the end of this protocol, Alice's qubit has now teleported to Bob.
psi = random_statevector(2)
UNIT - II 12
[QUANTUM COMPUTING]
# Display it nicely
plot_bloch_multivector(psi)
try
|ψ⟩=[−0.38591−0.11057i−0.31966+0.85829i]
Let's create our initialization instruction to create |ψ⟩ from the state |0⟩|0⟩:
init_gate = Initialize(psi)
init_gate.label = "init"
try
(Initialize is technically not a gate since it contains a reset operation, and so is
not reversible. We call it an 'instruction' instead). If the quantum teleportation
circuit works, then at the end of the circuit the qubit |q2⟩ will be in this state.
We will check this using the statevector simulator.
## SETUP
## STEP 0
qc.append(init_gate, [0])
qc.barrier()
## STEP 1
create_bell_pair(qc, 1, 2)
qc.barrier()
## STEP 2
alice_gates(qc, 0, 1)
## STEP 3
measure_and_send(qc, 0, 1)
UNIT - II 14
[QUANTUM COMPUTING]
## STEP 4
qc.draw()
try
We can see below, using the statevector obtained from the aer simulator, that
the state of |q2⟩ is the same as the state |ψ⟩ we created above, while the states
of |q0⟩ and |q1⟩ have been collapsed to either |0⟩|0⟩ or |1⟩|1⟩. The
state |ψ⟩ has been teleported from qubit 0 to qubit 2.
sim = Aer.get_backend('aer_simulator')
qc.save_statevector()
out_vector = sim.run(qc).result().get_statevector()
plot_bloch_multivector(out_vector)
try
You can run this cell a few times to make sure. You may notice that the qubits 0
& 1 change states, but qubit 2 is always in the state |ψ⟩.
UNIT - II 15
[QUANTUM COMPUTING]
inverse_init_gate = init_gate.gates_to_uncompute()
try
This operation has the property:
## SETUP
UNIT - II 16
[QUANTUM COMPUTING]
## STEP 0
qc.append(init_gate, [0])
qc.barrier()
## STEP 1
create_bell_pair(qc, 1, 2)
qc.barrier()
## STEP 2
alice_gates(qc, 0, 1)
## STEP 3
measure_and_send(qc, 0, 1)
## STEP 4
UNIT - II 17
[QUANTUM COMPUTING]
## STEP 5
qc.append(inverse_init_gate, [2])
qc.draw()
try
We can see the inverse_init_gate appearing, labelled 'disentangler' on the
circuit diagram. Finally, we measure the third qubit and store the result in the
third classical bit:
cr_result = ClassicalRegister(1)
qc.add_register(cr_result)
qc.measure(2,2)
qc.draw()
UNIT - II 18
[QUANTUM COMPUTING]
try
and we run our experiment:
t_qc.save_statevector()
counts = sim.run(t_qc).result().get_counts()
plot_histogram(qubit_counts)
try
We can see we have a 100% chance of measuring q2 (the purple bar in the
histogram) in the state |0⟩|0⟩. This is the expected result, and indicates the
teleportation protocol has worked properly.
Step 1
Quantum Teleportation begins with the fact that Alice needs to
transmit |ψ⟩=α|0⟩+β|1⟩ (a random qubit) to Bob. She doesn't know the state of
the qubit. For this, Alice and Bob take the help of a third party (Telamon).
Telamon prepares a pair of entangled qubits for Alice and Bob. The entangled
qubits could be written in Dirac Notation as:
|e⟩=1√ 2 (|00⟩+|11⟩)
Alice and Bob each possess one qubit of the entangled pair (denoted as A and B
respectively),
UNIT - II 19
[QUANTUM COMPUTING]
|e⟩=1√ 2 (|0⟩A|0⟩B+|1⟩A|1⟩B)
This creates a three qubit quantum system where Alice has the first two qubits
and Bob the last one.
Step 2
Now according to the protocol Alice applies CNOT gate on her two qubits
followed by Hadamard gate on the first qubit. This results in the state:
(H⊗I⊗I)(CNOT⊗I)(|ψ⟩⊗|e⟩)=(H⊗I⊗I)(CNOT⊗I)1√ 2 (α|000⟩+α|011⟩+β|10
0⟩+β|111⟩)=(H⊗I⊗I)1√ 2 (α|000⟩+α|011⟩+β|110⟩+β|101⟩)=12(α(|000⟩+|011⟩
+|100⟩+|111⟩)+β(|010⟩+|001⟩−|110⟩−|101⟩))
Which can then be separated and written as:
=12(|00⟩(α|0⟩+β|1⟩)+|01⟩(α|1⟩+β|0⟩)+|10⟩(α|0⟩−β|1⟩)+|11⟩(α|1⟩−β|0⟩))=
Step 3
Alice measures the first two qubit (which she owns) and sends them as two
classical bits to Bob. The result she obtains is always one of the four standard
basis states |00⟩,|01⟩,|10⟩,|00⟩,|01⟩,|10⟩, and |11⟩|11⟩ with equal
probability.
On the basis of her measurement, Bob's state will be projected
to,|00⟩→(α|0⟩+β|1⟩)|01⟩→(α|1⟩+β|0⟩)|10⟩→(α|0⟩−β|1⟩)|11⟩→(α|1⟩−β|0⟩)
Step 4
Bob, on receiving the bits from Alice, knows he can obtain the original
state |ψ⟩ by applying appropriate transformations on his qubit that was once
part of the entangled pair.
The transformations he needs to apply are:
UNIT - II 20
[QUANTUM COMPUTING]
After this step Bob will have successfully reconstructed Alice's state.
Any benefits of measuring early are hardware related: If we can measure early,
we may be able to reuse qubits, or reduce the amount of time our qubits are in
their fragile superposition. In this example, the early measurement in quantum
teleportation would have allowed us to transmit a qubit state without a direct
quantum communication channel.
qc.cx(b, c)
qc.cz(a, c)
try
UNIT - II 21
[QUANTUM COMPUTING]
qc = QuantumCircuit(3,1)
qc.append(init_gate, [0])
qc.barrier()
create_bell_pair(qc, 1, 2)
qc.barrier()
alice_gates(qc, 0, 1)
qc.barrier()
new_bob_gates(qc, 0, 1, 2)
qc.append(inverse_init_gate, [2])
UNIT - II 22
[QUANTUM COMPUTING]
qc.measure(2,0)
qc.draw()
try
5.2 Executing
# First, see what devices we are allowed to use by loading our saved accounts
IBMQ.load_account()
provider = IBMQ.get_provider(hub='ibm-q')
try
# get the least-busy backend at IBM and run the quantum circuit there
backend = least_busy(provider.backends(filters=lambda b:
b.configuration().n_qubits >= 3 and
UNIT - II 23
[QUANTUM COMPUTING]
job = backend.run(t_qc)
try
Job Status: job has successfully run
exp_result = job.result()
exp_counts = exp_result.get_counts(qc)
print(exp_counts)
plot_histogram(exp_counts)
try
{'0': 894, '1': 130}
As we see here, there are a few results in which we measured |1⟩|1⟩. These
arise due to errors in the gates and the qubits. In contrast, our simulator in the
earlier part of the notebook had zero errors in its gates, and allowed error-free
teleportation.
UNIT - II 24
[QUANTUM COMPUTING]
try
The experimental error rate : 12.695%
P (X = Y) + P (Y = Z) + P (Z = X) ≥ 1
UNIT - II 25
[QUANTUM COMPUTING]
The primitive gates are represented by boxes that cover the lines of the qubits
that the gates operate on. Gates that act on a single qubit are represented by
squares, gates that act on two adjacent qubits by rectangles etc. The left
boundary of the circuit corresponds to the initial state |Ψinitial⟩=|0…0⟩, the
right boundary to the final state |Ψfinal⟩ and the subsequent measurement of
all qubits. Gates that operate on different qubits (= disjoint boxes) can be
applied in parallel so that the circuit above can be compactified as follows:
However, it is crucial that the sequence of gates matters (they do not commute).
So the following circuits are not equivalent in general and produce different final
states (and measurement outcomes):
UNIT - II 27
[QUANTUM COMPUTING]
A quantum circuit simulator is a tool that allows you to construct and simulate
simple quantum circuits graphically, i.e., without actually writing code. Every
primitive gate is represented by a unique symbol that covers one, two, or three
qubits, depending on the gate. The symbols can be dragged with the mouse and
dropped onto the quantum circuit to construct a quantum algorithm. Our
quantum circuit simulator then translates this graphical representation into an
equivalent textual representation, a programming language known
as OpenQASM. This code is sent to and run by our servers that simulate a
quantum computer. The measurement results are then sent back to your
browser and displayed by the quantum circuit simulator.
Beware:
The quantum circuit representation is only useful for simple quantum algorithms
(with few qubits and gates). However, it can be very helpful to illustrate the
operation of a quantum computer and to develop new algorithms. To
implement “real” algorithms on hundreds or thousands of qubits, one would
write OpenQASM code directly.
Here we describe how our quantum circuit simulator works step by step:
UNIT - II 28
[QUANTUM COMPUTING]
Step I
Use the + and - buttons in the Quantum circuit box to set the number of qubits
(1–10 qubits are possible). The qubits are labeled as q[i] with index i=0,1,...,N-
1 for N qubits (in informatics, indices typically start from 0 and not 1).
Step II
Use your mouse to drag quantum gates from the Gates box into the Quantum
circuit box. Drop the gate on the horizontal line that corresponds to the qubit
that the gate should be applied to. You can insert gates before other gates by
“squeezing” them in gaps between gates. To delete gates, grab them and pull
them out of the quantum circuit.
Step III
Whenever you change the quantum circuit, the quantum circuit simulator
automatically translates the circuit into an equivalent OpenQASM code
representation (shown in the QASM code box).
Step IV
After the OpenQASM code has been updated, it is automatically sent to our
QRydDemo API at the University of Stuttgart and queued in the job list of our
classical simulator. You can also manually submit a new job by clicking
the Manual submit button. This is useful to observe the statistical fluctuations
of the measurement outcomes.
UNIT - II 29
[QUANTUM COMPUTING]
Step V
Our simulator of a quantum computer executes your quantum circuit 200 times
and accumulates the measurement outcomes. The simulator runs on dedicated
graphics cards to accelerate the computations. When our quantum computer is
up and running, this simulation can be replaced by a quantum computation on
a real quantum computer.
Step VI
The accumulated measurement results are sent back to the quantum circuit
simulator in your browser.
Step VII
The results are displayed in the Histogram box of the quantum circuit simulator.
The y-axis shows the number of shots that resulted in a specific qubit
configuration after measurement (all bars therefore add up to 200). On the x-
axis the 2 possible measurement outcomes are shown (for qubits). For
example, the label 0010=q[3]q[2]q[1]q[0] corresponds to the measured
state |0⟩=|0010⟩.
UNIT - II 30