Quantum Manual
Quantum Manual
MANUAL
PREPARED BY
Dr.K.UMAMAHESWARI
Associate Professor,
ECE Department,
SRM TRP Engineering College
Contents
1. Qiskit Quantum Gates
2. The Pauli Gates
2.1 The X-Gate
2.2 The Y & Z-Gates
3. Digression: The X, Y & Z-Bases
4. The Hadamard Gate
5. Digression: Measuring in Different
Bases
6. The P-gate
7. The I, S and T-gates
7.1 The I-Gate
7.2 The S-Gate
7.3 The T-Gate
8. The General U-gate
9. References
Introduction
Qiskit: Quantum Gates
Like Classical Computing, Quantum Computing also has gates. To differentiate them from
their classical counterparts, we will frequently refer to them as Quantum Gates. Quantum
Gates are used for manipulating the state of a Qubit. A Quantum Gate applied on a Qubit in a
particular state can change the state of a Qubit. Although in some cases, a particular gate
might not change the state of a Qubit in a particular state. In this chapter of the Qiskit
Tutorial, you will get a brief overview of the various Single Qubit Quantum Gates. The
following chapters will discuss some important Single Qubit Quantum Gates in detail.
Several Quantum Gates also act on multiple Qubits, these will be covered in a later chapter.
Quantum Gates
Quantum Gates can be represented by a matrix. This matrix can be used to determine the
effect of the Quantum Gate on a particular state. The new state of the Qubit can be known by
multiplying the matrix for the Quantum Gate by the state of the Qubit.
Example
In the following example, we calculate the new state of a Qubit after the application of X
Gate on a Qubit in the state |0>. The new state ψ is calculated by multiplying the matrix for X
Gate, represented by X with the state vector of the Qubit. The new state of the Qubit is |1>.
Applying Quantum Gates on a Qubit can have an effect on the state of those Qubits. This
change of state can be represented by the change in the state-vector of the Qubit or its
representation on the Bloch Sphere.
Example
In the following example, we consider the effect of the application of the X Gate on its Bloch
Sphere Representation. The original state of the Qubit is |0>. After the application of X Gate,
the state of the Qubit changes to |1>. This change can be seen in the state-vector
representation of the Qubit. In the original state |0>, the state-vector pointed along the
positive Z-axis. In the final state |1>, the state-vector pointed along the negative Z-axis.
Effect of the application of Quantum Gates on the Bloch Sphere Representation of the state
of Qubit
It’s alright if you don’t know what is X Gate. You will get to know about the X Gate and
various other gates in the following chapters. It is sufficient to know for now that applying
Quantum Gates on Qubits can change the state of the Qubit.
Table of Single Qubit Quantum Gates
The following table covers various Single Qubit Quantum Gates in brief.
Rotates the State vector by It is also known as Bit and Phase flip
π radians about the Y-axis gate because it performs both, phase
Y Y in anti-clockwise direction. flip like Z Gate and bit flip like X Gate.
The RZ and Phase Gates have the same effect on a Qubit when applied with the same
parameter. The difference between them is that their multi-Qubit versions have different
effects. For example, a CP Gate will have a different effect as compared to a CRZ Gate.
Quantum mechanics sounds challenging on understanding the behaviour of balls and bananas
than atoms or electrons. Though quantum objects are random follow a different set of rules.
Quantum computing will be the most revolutionary example of this.
plot_bloch_multivector() which takes a qubit's state vector instead of the Bloch vector.
Y=[0−ii0] Z=[100−1]
Y=−i|0⟩⟨1|+i|1⟩⟨0|
Z=|0⟩⟨0|−|1⟩⟨1|
They also perform rotations by π around the y and z-axis of the Bloch sphere.
Below is a widget that displays a qubit’s state on the Bloch sphere, pressing one of the
buttons will perform the gate on the qubit:
H|0⟩=|+⟩ H|1⟩=|−⟩
This can be thought of as a rotation around the Bloch vector [1,0,1] (the line between the x &
z-axis), or as transforming the state of the qubit between the X and Z bases.
You can play around with these gates using the widget below:
Quick Exercise
1. Write the H-gate as the outer products of vectors |0⟩, |1⟩, |+⟩ and |−⟩.
2. Show that applying the sequence of gates: HZH, to any qubit state is equivalent to
applying an X-gate.
3. Find a combination of X, Z and H-gates that is equivalent to a Y-gate (ignoring global
phase).
X=HZH
Starting in the Z-basis, the H-gate switches our qubit to the X-basis, the Z-gate performs a
NOT in the X-basis, and the final H-gate returns our qubit to the Z-basis. We can verify this
always behaves like an X-gate by multiplying the matrices:
We initialized our qubit in the state |−⟩, but we can see that, after the measurement, we have
collapsed our qubit to the state |1⟩. If you run the cell again, you will see the same result,
since along the X-basis, the state |−⟩ is a basis state and measuring it along X will always
yield the same result.
Quick Exercises
1. If we initialize our qubit in the state |+⟩, what is the probability of measuring it in state |
−⟩?
2. Use Qiskit to display the probability of measuring a |0⟩ qubit in the states |+⟩ and |
−⟩ (Hint: you might want to use .get_counts() and plot_histogram()).
3. Try to create a function that measures in the Y-basis.
For example, if we put our qubit in the state |0⟩|0⟩, our measurement in the Z-basis is certain
to be |0⟩|0⟩, but our measurement in the X-basis is completely random! Similarly, if we put
our qubit in the state |−⟩|−⟩, our measurement in the X-basis is certain to be |−⟩|−⟩, but now
any measurement in the Z-basis will be completely random.
More generally: Whatever state our quantum system is in, there is always a measurement
that has a deterministic outcome.
The introduction of the H-gate has allowed us to explore some interesting phenomena, but we
are still very limited in our quantum operations. Let us now introduce a new type of gate:
5. The P-gate
The P-gate (phase gate) is parametrised, that is, it needs a number (ϕ) to tell it exactly what
to do. The P-gate performs a rotation of ϕ around the Z-axis direction. It has the matrix form:
P(ϕ)=[100eiϕ]P(ϕ)=[100eiϕ]
Where ϕ is a real number, the P-gate, specify ϕ using the slider:
qc = QuantumCircuit(1)
qc.p(pi/4, 0)
qc.draw()
The Z-gate is a special case of the P-gate, with ϕ=π. In fact there are three more commonly
referenced gates we will mention in this chapter, all of which are special cases of the P-gate:
I=[1001]
Applying the identity gate anywhere in your circuit should have no effect on the qubit state,
considered a gate. There are two main reasons behind this, one is that it is often used in
calculations, for example: proving the X-gate is its own inverse:
I=XX
The second, is that it is often useful when considering real hardware to specify a ‘do-nothing’
or ‘none’ operation.
qc = QuantumCircuit(1)
qc.s(0) # Apply S-gate to qubit 0
qc.sdg(0) # Apply Sdg-gate to qubit 0
qc.draw()
qc = QuantumCircuit(1)
qc.t(0) # Apply T-gate to qubit 0
qc.tdg(0) # Apply Tdg-gate to qubit 0
qc.draw()
7. The U-gate
As we saw earlier, the I, Z, S & T-gates were all special cases of the more general P-gate. In
the same way, the U-gate is the most general of all single-qubit quantum gates. It is a
parametrised gate of the form:
U(θ,ϕ,λ)=[cos(θ2)−eiλsin(θ2)eiϕsin(θ2)ei(ϕ+λ)cos(θ2)]U(θ,ϕ,λ)=[cos(θ2)−eiλsin(θ2)e
iϕsin(θ2)ei(ϕ+λ)cos(θ2)]
Every gate in this chapter could be specified as U(θ,ϕ,λ)U(θ,ϕ,λ), but it is unusual to see
this in a circuit diagram, possibly due to the difficulty in reading this.
As an example, we see some specific cases of the U-gate in which it is equivalent to the H-
gate and P-gate respectively.
U(π2,0,π)=1√ 2 [111−1]=HU(0,0,λ)=[100eiλ]=PU(π2,0,π)=12[111−1]=HU(0,0,λ)
=[100eiλ]=P
# Let's have U-gate transform a |0> to |+> state
qc = QuantumCircuit(1)
qc.u(pi/2, 0, pi, 0)
qc.draw()
It should be obvious from this that there are an infinite number of possible gates, and that this
also includes Rx and Ry-gates, although they are not mentioned here. It must also be noted that
there is nothing special about the Z-basis, except that it has been selected as the standard
computational basis. Qiskit also provides the X equivalent of the S and Sdg-gate i.e. the SX-
gate and SXdg-gate respectively. These gates do a quarter-turn with respect to the X-axis
around the Bloch sphere and are a special case of the Rx-gate.
Before running on real IBM quantum hardware, all single-qubit operations are compiled
down to I , X, SX and Rz . For this reason they are sometimes called the physical gates.
References
1. https://deeplearninguniversity.com/qiskit/qiskit-x-gate/
2. M. A. Neilsen and I. L. Chuang, Quantum Computation
and Quantum Information, Cambridge University Press
(2000).
3. E. Riefell and W. Polak, ACM Computing Surveys
(CSUR) 32, 300 (2000). [3] Y. Uesaka, Mathematical
Principle of Quantum Computation, Corona Publishing,
Tokyo, in Japanese (2000).
4. W. K. Wootters and W. H. Zurek, Nature 299, 802 (1982).
5. D. Dieks, Phys. Lett. A 92, 271 (1982).
6. D. Bouwmeester et al., Nature 390, 575 (1997).
7. D. Boschi et al., Phys. Rev. Lett. 80, 1121 (1998).
8. I. Marcikic et al., Nature 421, 509 (2003).
9. R. Ursin et al., Nature 430, 849 (2004).
10. A. Furusawa et al., Science 282, 706 (1998).
11. M. A. Nielsen et al., Nature 396, 52 (1998).
12. M. Riebe et al., Nature 429, 734 (2004).
13. M. D. Barret et al., Nature 429, 737 (2004).
14. A. Barenco et al., Phys. Rev. A 52, 3457 (1995).
15. Vivek V. Shende, Stephen S. Bullock, Igor L. Markov,
Synthesis of Quantum Logic Circuits,
https://arxiv.org/pdf/quant-ph/0406176.pdf.
16. IBM qiskit-tutorial - Summary of Quantum Operations
https://github.com/Qiskit/qiskit-tutorials/blob/master/tutor
ials/circuits/ 3 summary of quantum operations.ipynb