Академический Документы
Профессиональный Документы
Культура Документы
QUANTUM COMPUTING
LAB RECORD
Submitted To
Prof. Pankaj Srivastava
Submitted By
B Rishvanth (2015IPG-017)
B Medha (2015IPG-018)
Kavitha Yadav (2015IPG-041)
K Avinash (2015IPG-042)
M Akash Kumar (2015IPG-051)
Exercise 1
Q. Study of various quantum logic gates.
Ans:
Single-Qubit Gates:
Single-qubit gates are (unsurprisingly) the simplest gate and can visualise the operation of any
single-qubit gate as the rotation of our qubit’s state to a different point on the Bloch Sphere.
The three most basic single-qubit gates are the Pauli X, Y and Z gates:
1. Pauli X ( ):
The Pauli X gate is directly analogous to the classical NOT gate; it transforms |0〉 to |1〉 and |1〉 to |0〉.
2. Pauli Y ( ):
4. Hadamard gate, H:
The Hadamard gate is particularly important as it can be used to create a superposition of the |0〉
and |1〉 states.
5. Phase Shift ( ):
The phase shift gate is a generic gate that has many useful implementations, most notably
the π/4, π/8 and Pauli-Z gates, which are generated by setting ϕ to π/2, π/4 and π, respectively.
Multi-Qubit Gates:
Multi-qubit gates work on two qubits or more.
1. SWAP gate:
The swap gate swaps two qubits. With respect to the basis |00〉, |01〉, |10〉, |11〉 it is
represented by the matrix,
We can construct the matrix for any controlled gate by taking the identity matrix and attaching it to
the top-left corner of the desired gate, then filling in the blank entries with zeroes.
2. CNOT Gate:
The controlled NOT gate (CNOT) acts on 2 qubits, and performs the NOT operation on the second
qubit only when the first qubit is |1〉, and otherwise leaves it unchanged.
CNOT Gate matrix Representation:
The Toffoli gate is defined for 3 qubits. If the first two bits are in the state |1〉 it applies a Pauli-X (or
NOT) on the third bit, else it does nothing.
Ans: XOR operation/swapping of qubit can be implemented in Quantum circuits by simply using
CNOT gate (Controlled NOT gate).
The CNOT gate flips the second (target) qubit if the first (control) qubit is ∣1⟩ and does nothing if the
control qubit is ∣ 0⟩.
i.e.
Using QCAD:
Circuit Diagram:
Explanation:
All the qubits except Q1 and Q3 are disabled and through these two qubits (Q1 and Q3) input is given to
CNOT gate.
Q1 is used as control qubit and Q3 is used as target qubit. As per the Control bit, action (swapping) on the
target qubit is performed. This is measured by placing a measurement gate (as shown in fig).
Output:
The above figure shows that both input qubits (Q1 and Q3) are enabled to ∣0⟩ and the probability of
output state being ∣0⟩ is 1 and in state ∣1⟩ is 0. i.e. the output state is purely ∣0⟩.
The above figure shows the input qubits, Q1=∣1⟩ and Q3=∣0⟩ and the probability of output being in
state ∣0⟩ is 0 and in state ∣1⟩ is 1. i.e. the output state is purely ∣1⟩.
The above figure shows that both input qubits (Q1 and Q3) are enabled to ∣1⟩ and the probability of
output state being ∣0⟩ is 1 and in state ∣1⟩ is 0. i.e. the output state is purely ∣0⟩.
Exercise 3
Q. Implement full adder and half adder using quantum gates.
Ans:
Half Adder:
In Half adder the summation is carried out without considering carry. The truth table of half adder
is as follows:
Carry
A B Sum(S)
(Cout)
∣0⟩ ∣0⟩ ∣0⟩ ∣0⟩
∣0⟩ ∣1⟩ ∣1⟩ ∣0⟩
∣1⟩ ∣0⟩ ∣1⟩ ∣0⟩
∣1⟩ ∣1⟩ ∣0⟩ ∣1⟩
Circuit Diagram:
A A
B S
∣0⟩ Cout
Using QCAD:
Circuit Diagram: (In QCAD)
Explanation:
Sum is calculated by applying CNOT gate for Q1 and Q2. The measurement gate across Q3 gives the
Sum.
S = Q1 Q2
Output Carry is calculated using Toffoli gates and one extra qubit which is set to a fixed value ∣0⟩.
Toffoli gate is applied across Q1, Q2 and ∣0⟩ where Q1 and Q2 are control bits.
Cout = Q1.Q2 ∣0⟩
= Q1.Q2
Output:
The above figure shows that the probability of output states Cout and S being in state ∣00⟩ is 1 and in
states ∣01⟩, ∣10⟩ and ∣11⟩ is 0 i.e. the output state is purely ∣00⟩ implies S = ∣0⟩ and Cout=∣0⟩.
2. Output when the input qubits are Q1=|0⟩, Q2=|1⟩
The above figure shows that the probability of output states Cout and S being in state ∣01⟩ is 1 and in
states ∣00⟩, ∣10⟩ and ∣11⟩ is 0 i.e. the output state is purely ∣00⟩ implies S = ∣1⟩ and Cout=∣0⟩.
The above figure shows that the probability of output states Cout and S being in state ∣01⟩ is 1 and in
states ∣00⟩, ∣10⟩ and ∣11⟩ is 0 i.e. the output state is purely ∣00⟩ implies S = ∣1⟩ and Cout=∣0⟩.
The above figure shows that the probability of output states Cout and S being in state ∣10⟩ is 1 and in
states ∣00⟩, ∣01⟩ and ∣11⟩ is 0 i.e. the output state is purely ∣00⟩ implies S = ∣0⟩ and Cout=∣1⟩.
Full Adder:
In Full adder the summation is carried out along with carry. The truth table of full adder is as
follows:
Input Output
A B Carry (Cin) Sum(S) Carry (Cout)
Circuit Diagram:
A A
B B
Cin S
∣0⟩ Cout
Using QCAD:
Explanation:
Bits Q1 and Q2 are the actual bits to be added and bit Q3 is the Input carry bit (C in).
The outputs, Sum and Output carry (Cout) is measured using measurement gates.
Sum is calculated by applying CNOT gate for Q1 and Q2 and then again applying CNOT gate for the
output produced by 1st CNOT gate and Q3(Cin). The measurement gate across Q3 gives the Sum.
S = Q1 Q2 Q3
Output Carry is calculated using Toffoli gates and one extra qubit which is set to a fixed value ∣0⟩.
First Toffoli gate is applied across Q1, Q2 and ∣0⟩ where Q1 and Q2 are control bits and 2nd Toffoli
gate is applied across output produced by 1st CNOT gate i.e Q1Q2, Cin and ∣0⟩ where Q1Q2 and
Cin are control bits.
Cout = Q1.Q2 ∣0⟩ + ((Q1Q2). Cin) ∣0⟩
= {Q1.Q2 + ((Q1Q2). Cin)} ∣0⟩
Output:
1. Output when the input qubits are Q1=|0⟩, Q2=|0⟩ and Cin= |0⟩
The above figure shows that the probability of output states Cout and S being in state ∣00⟩ is 1 and in
states ∣01⟩, ∣10⟩ and ∣11⟩ is 0 i.e. the output state is purely ∣00⟩ implies S = ∣0⟩ and Cout=∣0⟩.
2. Output when the input qubits are Q1=|0⟩, Q2=|0⟩ and Cin= |1⟩
The above figure shows that the probability of output states Cout and S being in state ∣01⟩ is 1 and in
states ∣00⟩, ∣10⟩ and ∣11⟩ is 0 i.e. the output state is purely ∣00⟩ implies S = ∣1⟩ and Cout=∣0⟩.
3. Output when the input qubits are Q1=|0⟩, Q2=|1⟩ and Cin= |0⟩
The above figure shows that the probability of output states Cout and S being in state ∣01⟩ is 1 and in
states ∣00⟩, ∣10⟩ and ∣11⟩ is 0 i.e. the output state is purely ∣00⟩ implies S = ∣1⟩ and Cout=∣0⟩.
4. Output when the input qubits are Q1=|0⟩, Q2=|1⟩ and Cin= |1⟩
The above figure shows that the probability of output states Cout and S being in state ∣10⟩ is 1 and in
states ∣00⟩, ∣01⟩ and ∣11⟩ is 0 i.e. the output state is purely ∣00⟩ implies S = ∣0⟩ and Cout=∣1⟩.
5. Output when the input qubits are Q1=|1⟩, Q2=|0⟩ and Cin= |0⟩
The above figure shows that the probability of output states Cout and S being in state ∣01⟩ is 1 and in
states ∣00⟩, ∣10⟩ and ∣11⟩ is 0 i.e. the output state is purely ∣00⟩ implies S = ∣1⟩ and Cout=∣0⟩.
6. Output when the input qubits are Q1=|1⟩, Q2=|0⟩ and Cin= |1⟩
The above figure shows that the probability of output states Cout and S being in state ∣10⟩ is 1 and in
states ∣00⟩, ∣01⟩ and ∣11⟩ is 0 i.e. the output state is purely ∣00⟩ implies S = ∣0⟩ and Cout=∣1⟩.
7. Output when the input qubits are Q1=|1⟩, Q2=|1⟩ and Cin= |0⟩
The above figure shows that the probability of output states Cout and S being in state ∣10⟩ is 1 and in
states ∣00⟩, ∣01⟩ and ∣11⟩ is 0 i.e. the output state is purely ∣00⟩ implies S = ∣0⟩ and Cout=∣1⟩.
8. Output when the input qubits are Q1=|1⟩, Q2=|1⟩ and Cin= |1⟩
The above figure shows that the probability of output states Cout and S being in state ∣11⟩ is 1 and in
states ∣00⟩, ∣01⟩ and ∣10⟩ is 0 i.e. the output state is purely ∣00⟩ implies S = ∣1⟩ and Cout=∣1⟩.
Exercise 4
Q. Implement Grover’s Algorithm using quantum gates.
Ans:
Grover’s Algorithm:
Grover’s algorithm demonstrates this capability. This algorithm can speed up an unstructured
search problem quadratically, but its uses extend beyond that; it can serve as a general trick or
subroutine to obtain quadratic run time improvements for a variety of other algorithms. This is
called the amplitude amplification trick.
Unstructured search:
Suppose you are given a large list of N items. Among these items there is one item with a unique
property that we wish to locate; we will call this one the winner ‘w’. Think of each item in the list as
a box of a particular color. Say all items in the list are gray except the winner ‘w’, which is pink.
Mathematically, consider a function which is always equal 0 except a single value w. How are we
going to find w?
Using classical computation, one would have to check on average N/2 of these boxes, and in the
worst case, all N of them. On a quantum computer, however, we can find the marked item in
roughly steps with Grover’s amplitude amplification trick.
Classical Quantum
Computing Computing
The Oracle:
How will the list items be provided to the quantum computer? A common way to encode such a list
is in terms of a function f which returns f(x)=0 for all unmarked items x and f(w)=1 for the winner.
To use a quantum computer for this problem, we must provide the items in superposition to this
function, so we encode the function into a unitary matrix called an oracle. First we choose a binary
encoding of the items so that ; now we can represent it in terms of qubits on
a quantum computer. Then we define the oracle matrix to act on any of the simple, standard
basis states |x⟩ by
⟩ ⟩
We see that if x is an unmarked item, the oracle does nothing to the state. However, when we
apply the oracle to the basis state |w⟩, it maps |w⟩= −|w⟩. Geometrically, this unitary matrix
corresponds to a reflection about the origin for the marked item in an dimensional vector
space.
Amplitude amplification:
So how does the algorithm work? Before looking at the list of items, we have no idea where the
marked item is. Therefore, any guess of its location is as good as any other, which can be expressed
in terms of a quantum state called a uniform superposition:
If at this point we were to measure in the standard basis {|x⟩}, this superposition would collapse,
according to the fifth quantum law, to any one of the basis states with the same probability
of 1/N=1/ . Our chances of guessing the right value w is therefore 1 in , as could be expected.
Hence, on average we would need to try about N= times to guess the correct item.
Enter the procedure called amplitude amplification, which is how a quantum computer significantly
enhances this probability. This procedure stretches out (amplifies) the amplitude of the marked
item, which shrinks the other items’ amplitude, so that measuring the final state will return the
right item with near-certainty.
This algorithm has a nice geometrical interpretation in terms of two reflections, which generate a
rotation in a two-dimensional plane. The only two special states we need to consider are the
winner |w⟩ and the uniform superposition |s⟩. These two vectors span a two-dimensional plane in
the vector space . They are not quite perpendicular because |w⟩ occurs in the superposition with
amplitude N−1/2 as well. We can, however, introduce an additional state |s′⟩ that is in the span of
these two vectors, which is perpendicular to |w⟩|w⟩ and is obtained from |s⟩ by removing |w⟩ and
rescaling.
step 0 The amplitude amplification procedure starts out in the uniform superposition |s⟩. (The
uniform superposition is easily constructed from |s⟩= ⟩ , as was shown in a previous
section.) At t=0 the initial state is | ⟩=|s⟩.
The left graphic corresponds to the two-dimensional plane spanned by |w⟩,|s⟩. The right graphic is
a bar graph of the amplitudes of the state | ⟩ for the case . The average amplitude is
indicated by a dashed line.
Geometrically this corresponds to a reflection of the state | ⟩ about −|w⟩. This transformation
means that the amplitude in front of the |w⟩ state becomes negative, which in turn means that the
average amplitude has been lowered.
step 2 We now apply an additional reflection Us about the state |s⟩. In the bra-ket notation this
reflection is written Us=2|s⟩⟨s|−1. This transformation maps the state to Us| ′ ⟩and completes the
transformation | ⟩= | ′ ⟩.
Two reflections always correspond to a rotation. The transformation rotates the initial
state |s⟩ closer towards the winner |w⟩. The action of the reflection in the amplitude bar
diagram can be understood as a reflection about the average amplitude. Since the average
amplitude has been lowered by the first reflection, this transformation boosts the negative
amplitude of |w⟩ to roughly three times its original value, while it decreases the other amplitudes.
We then go to step 1 to repeat the application. This procedure will be repeated several times to
zero in on the winner.
After t steps the state will have transformed to
| ⟩= | ⟩.
How many times do we need to apply the rotation? It turns out that roughly rotations suffice.
This becomes clear when looking at the amplitudes of the state | ⟩. We can see that the
amplitude of |w⟩ grows linearly with the number of applications ∼t . However, since we are
dealing with amplitudes and not probabilities, the vector space’s dimension enters as a square root.
Therefore it is the amplitude, and not just the probability, that is being amplified in this procedure.
Circuit Diagram:
Circuit diagram to search 00:
Output:
Circuit diagram to search 01:
Output:
Output:
Ans:
Shor’s Algorithm:
Shor's algorithm is a quantum algorithm for factoring a number N in O((log N)3) time and O(log N)
space, named after Peter Shor.
The algorithm is significant because it implies that public key cryptography might be easily broken,
given a sufficiently large quantum computer. RSA, for example, uses a public key N which is the
product of two large prime numbers. One way to crack RSA encryption is by factoring N, but with
classical algorithms, factoring becomes increasingly time-consuming as N grows large; more
specifically, no classical algorithm is known that can factor in time O((log N)k) for any k. By contrast,
Shor's algorithm can crack RSA in polynomial time. It has also been extended to attack many other
public key cryptosystems.
Like all quantum computer algorithms, Shor's algorithm is probabilistic: it gives the correct answer
with high probability, and the probability of failure can be decreased by repeating the algorithm.
Shor's algorithm was demonstrated in 2001 by a group at IBM, which factored 15 into 3 and 5,
using a quantum computer with 7 qubits.
Procedure
The problem we are trying to solve is that, given an integer N, we try to find another
integer p between 1 and N that divides N.
1. A reduction of the factoring problem to the problem of order-finding, which can be done on
a classical computer.
2. A quantum algorithm to solve the order-finding problem.
1. Start with a pair of input and output qubit registers with log2N qubits each, and initialize
them to
N − 1/2∑x∣x⟩∣0⟩
2. Construct f(x) as a quantum function and apply it to the above state, to obtain
N − 1/2∑x∣x⟩∣f(x)⟩
3. Apply the quantum Fourier transform on the input register. The quantum Fourier transform
on N points is defined by:
UQFT∣x⟩ = N − 1/2∑ye2πixy/N∣y⟩
This leaves us in the following state:
N − 1∑x∑ye2πixy/N∣y⟩∣f(x)⟩
4. Perform a measurement. We obtain some outcome y in the input register and f(x0) in the
output register. Since f is periodic, the probability to measure some y is given by
N − 1∣∑x : f(x) = f(x0)e2πixy/N∣2 = N − 1∣∑be2πi(x0 + rb)y/N∣2
Analysis now shows that this probability is higher, the closer yr/N is to an integer.
5. Turn y/N into an irreducible fraction, and extract the denominator r′, which is a candidate
for r.
6. Check if f(x) = f(x + r′). If so, we are done.
7. Otherwise, obtain more candidates for r by using values near y, or multiples of r′. If any
candidate works, we are done.
8. Otherwise, go back to step 1 of the subroutine.