0% found this document useful (0 votes)
85 views17 pages

Quantum Manual

This document provides an overview of single qubit quantum gates. It begins by introducing quantum gates and how they can change the state of a qubit. It then discusses some important single qubit gates like the X, Y, Z, H, S, T, and Phase gates. For each gate, it provides the matrix representation and explains how it rotates the qubit state on the Bloch sphere. It includes examples using the Qiskit programming library to apply gates like the X gate and visualize their effects. The document concludes with a brief discussion of quantum mechanics and how quantum computing will be revolutionary due to quantum objects following different rules than classical ones.

Uploaded by

Uma maheswari K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views17 pages

Quantum Manual

This document provides an overview of single qubit quantum gates. It begins by introducing quantum gates and how they can change the state of a qubit. It then discusses some important single qubit gates like the X, Y, Z, H, S, T, and Phase gates. For each gate, it provides the matrix representation and explains how it rotates the qubit state on the Bloch sphere. It includes examples using the Qiskit programming library to apply gates like the X gate and visualize their effects. The document concludes with a brief discussion of quantum mechanics and how quantum computing will be revolutionary due to quantum objects following different rules than classical ones.

Uploaded by

Uma maheswari K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

QUANTUM

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 X Gate on a Qubit and calculating in output state.


To summarize, the X Gate changed the state of the Qubit from |0> to |1>
Effect of Quantum Gates

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.

Quantum Effect on the Bloch


Gate Symbol Sphere Comments

It is also known as NOT Gate and Bit


Rotates the State vector by flip gate because it reverses the
π radians about the X-axis probabilities of measuring 0 and 1 on
X X in anti-clockwise direction. measurement.

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.

Rotates the State vector by


π radians about the Z-axis It is also known as Phase flip gate
Z Z in anti-clockwise direction. because it flips the phase of a Qubit.

It is useful when no operation is to be


Identity I or Id No effect on State vector. done on a Qubit.

Rotates the State vector by


π radians about the XZ-axis It maps X-axis to Z-axis and vice
Hadamard H in anti-clockwise direction. versa.
Quantum Effect on the Bloch
Gate Symbol Sphere Comments

Rotates the State vector by


given radians about the X- It is a parameterized Gate. It performs
axis in anti-clockwise rotations about X-axis by different
RX RX direction. amounts depending on the parameter.

Rotates the State vector by


given radians about the Y- It is a parameterized Gate. It performs
axis in anti-clockwise rotations about Y-axis by different
RY RY direction. amounts depending on the parameter.

Rotates the State vector by


given radians about the Z- It is a parameterized Gate. It performs
axis in anti-clockwise rotations about Z-axis by different
RZ RZ direction. amounts depending on the parameter.

Rotates the State vector by


given radians about the Z- It is a parameterized Gate. It performs
axis in anti-clockwise rotations about Z-axis by different
Phase P direction. amounts depending on the parameter.

Rotates the State vector


by π/2 radians about the Z- It is also known as the Square-root of Z
axis in anti-clockwise Gate. This is because applying S Gate
S S direction. twice has the same effect as a Z Gate.

Rotates the State vector


by π/2 radians about the Z-
S Dagger Sdg or S axis in clockwise direction. It is the inverse of S Gate.

Rotates the State vector It is also known as the fourth-root of Z


by π/4 radians about the Z- Gate. This is because applying S Gate
axis in anti-clockwise four times has the same effect as a Z
T T direction. Gate.

Rotates the State vector


by π/4 radians about the Z-
T Dagger Tdg or T axis in clockwise direction. It is the inverse of T Gate.

SX SX Rotates the State vector It is also known as the Square-root of X


Quantum Effect on the Bloch
Gate Symbol Sphere Comments

by π/2 radians about the X-


axis in anti-clockwise Gate. This is because applying SX Gate
direction. twice has the same effect as an X Gate.

Rotates the State vector


SXdg or by π/2 radians about the X-
SX Dagger SX axis in clockwise direction. It is the inverse of SX 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.

Single Qubit Gates


Qubits could be represented by 2D vectors, and that their states are limited to the form:
|q⟩=cosθ2|0⟩+eiϕsinθ2|1⟩
Where θ and ϕ are real numbers. In this section we will cover gates, the operations that
change a qubit between these states. Due to the number of gates and the similarities between
them.
The Atoms of Computation we came across some gates and used them to perform a classical
computation. An important feature of quantum circuits is that, between initialising the qubits
and measuring them, the operations (gates) are always reversible. These reversible gates can
be represented as matrices, and as rotations around the Bloch sphere.
from qiskit import QuantumCircuit, assemble, Aer
from math import pi, sqrt
from qiskit.visualization import plot_bloch_multivector, plot_histogram
sim = Aer.get_backend('aer_simulator')

1. The Pauli Gates


The Pauli matrices from the linear algebra section. The Pauli matrices can represent some
very commonly used quantum gates.

1.1 The X-Gate


The X-gate is represented by the Pauli-X matrix:
X=[0110]=|0⟩⟨1|+|1⟩⟨0|
To see the effect a gate has on a qubit, multiply the qubit’s state vector by the gate. The X-
gate switches the amplitudes of the states |0⟩ and |1⟩:
X|0⟩=[0110][10]=[01]=|1⟩

# Let's do an X-gate on a |0> qubit


qc = QuantumCircuit(1)
qc.x(0)
qc.draw()

plot_bloch_multivector() which takes a qubit's state vector instead of the Bloch vector.

# Let's see the result


qc.save_statevector()
qobj = assemble(qc)
state = sim.run(qobj).result().get_statevector()
plot_bloch_multivector(state)
The state of the qubit is |1⟩ as expected. Rotation by π radians around the x-axis of the Bloch
sphere. The X-gate is also often called a NOT-gate, referring to its classical analogue.

1.2 The Y & Z-gate


Similarly to the X-gate, the Y & Z Pauli matrices also act as the Y & Z-gates in our quantum
circuits:

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:

# Run the code in this cell to see the widget


from qiskit_textbook.widgets import gate_demo
gate_demo(gates='pauli')

n Qiskit, we can apply the Y and Z-gates to our circuit using:

qc.y(0) # Do Y-gate on qubit 0


qc.z(0) # Do Z-gate on qubit 0
qc.draw()
2. Digression: The X, Y & Z-Bases
The Z-gate appears to have no effect on our qubit when it is in either of these two states. This
is because the states |0⟩ and |1⟩ are the two eigenstates of the Z-gate. In fact,
the computational basis (the basis formed by the states |0⟩ and |1⟩ is often called the Z-basis.
This is not the only basis we can use, a popular basis is the X-basis, formed by the eigenstates
of the X-gate. We call these two vectors |+⟩ and |−⟩:
|+⟩=1√ 2 (|0⟩+|1⟩)=1√ 2 [11]
|−⟩=1√ 2 (|0⟩−|1⟩)=1√ 2 [1−1]

3.The Hadamard Gate


The Hadamard gate (H-gate) is a fundamental quantum gate. It allows us to move away from
the poles of the Bloch sphere and create a superposition of |0⟩ and |1⟩. It has the matrix:
H=1√ 2 [111−1]
We can see that this performs the transformations below:

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:

# Run the code in this cell to see the widget


from qiskit_textbook.widgets import gate_demo
gate_demo(gates='pauli+h')

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).

4. Digression: Measuring in Different Bases


We have seen that the Z-basis is not intrinsically special, and that there are infinitely many
other bases. Similarly with measurement, we don’t always have to measure in the
computational basis (the Z-basis), we can measure our qubits in any basis.
As an example, let’s try measuring in the X-basis. We can calculate the probability of
measuring either |+⟩ or |−⟩:
p(|+⟩)=|⟨+|q⟩|2, p(|−⟩)=|⟨−|q⟩|2
And after measurement, the superposition is destroyed. Since Qiskit only allows measuring in
the Z-basis, we must create our own using Hadamard gates:

# Create the X-measurement function:


def x_measurement(qc, qubit, cbit):
"""Measure 'qubit' in the X-basis, and store the result in 'cbit'"""
qc.h(qubit)
qc.measure(qubit, cbit)
return qc
initial_state = [1/sqrt(2), -1/sqrt(2)]
# Initialize our qubit and measure it
qc = QuantumCircuit(1,1)
qc.initialize(initial_state, 0)
x_measurement(qc, 0, 0) # measure qubit 0 to classical bit 0
qc.draw()

Create an X-gate by sandwiching our Z-gate between two H-gates:

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:

HZH=1√ 2 [111−1][100−1]1√ 2 [111−1]=[0110]=X


Following the same logic, create an X-measurement by transforming from the X-basis to the
Z-basis before our measurement. Since the process of measuring can have different effects
depending on the system (e.g. some systems always return the qubit to |0⟩ after measurement,
whereas others may leave it as the measured state), the state of the qubit post-measurement is
undefined and we must reset it if we want to use it again.
There is another way to see why the Hadamard gate indeed takes us from the Z-basis to the
X-basis. Suppose the qubit we want to measure in the X-basis is in the (normalized) state a|
0⟩+b|1⟩. To measure it in X-basis, we first express the state as a linear combination of |
+⟩ and |−⟩. Using the relations |0⟩=|+⟩+|−⟩√ 2 and |1⟩=|+⟩−|−⟩√ 2 , the state becomes a+b√ 2 |+⟩
+a−b√ 2 |−⟩. Observe that the probability amplitudes in X-basis can be obtained by applying a
Hadamard matrix on the state vector expressed in Z-basis.
Let’s now see the results:

qobj = assemble(qc) # Assemble circuit into a Qobj that can be run


counts = sim.run(qobj).result().get_counts() # Do the simulation, returning the state vector
plot_histogram(counts) # Display the output on measurement of state vector

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.

Measuring in different bases allows us to see Heisenberg’s famous uncertainty principle in


action. Having certainty of measuring a state in the Z-basis removes all certainty of
measuring a specific state in the X-basis, and vice versa. A common misconception is that the
uncertainty is due to the limits in our equipment, but here we can see the uncertainty is
actually part of the nature of the qubit.

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:

# Run the code in this cell to see the widget


from qiskit_textbook.widgets import gate_demo
gate_demo(gates='pauli+h+p')

In Qiskit, we specify a P-gate using p(phi, qubit):

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:

6. The I, S and T-gates


6.1 The I-gate
First comes the I-gate (aka ‘Id-gate’ or ‘Identity gate’). This is simply a gate that does
nothing. Its matrix is the identity matrix:

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.

6.2 The S-gates


The next gate to mention is the S-gate (sometimes known as the √ Z -gate), this is a P-gate
with ϕ=π/2. It does a quarter-turn around the Bloch sphere. It is important to note that unlike
every gate introduced in this chapter so far, the S-gate is not its own inverse. As a result, you
will often see the S†-gate, (also “S-dagger”, “Sdg” or √ Z †-gate). The S†-gate is clearly an P-
gate with ϕ=−π/2:
S=[100eiπ2],S†=[100e−iπ2]
The name "√ Z -gate" is due to the fact that two successively applied S-gates has the same
effect as one Z-gate:
SS|q⟩=Z|q⟩
This notation is common throughout quantum computing.

To add an S-gate in Qiskit:

qc = QuantumCircuit(1)
qc.s(0) # Apply S-gate to qubit 0
qc.sdg(0) # Apply Sdg-gate to qubit 0
qc.draw()

6.3 The T-gate


The T-gate is a very commonly used gate, it is an P-gate with ϕ=π/4:
T=[100eiπ4],T†=[100e−iπ4]
As with the S-gate, the T-gate is sometimes also known as the 4√ Z -gate.
In Qiskit:

qc = QuantumCircuit(1)
qc.t(0) # Apply T-gate to qubit 0
qc.tdg(0) # Apply Tdg-gate to qubit 0
qc.draw()

All the gates introduced in this chapter so far:

# Run the code in this cell to see the widget


from qiskit_textbook.widgets import gate_demo
gate_demo()

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()

# Let's see the result


qc.save_statevector()
qobj = assemble(qc)
state = sim.run(qobj).result().get_statevector()
plot_bloch_multivector(state)

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

You might also like