1.3 Working with one qubit and the Bloch sphere
One of the advantages of using a computational model is that you can forget about the particularities of the physical implementation of your computer and focus instead on the properties of the elements on which you store information and the operations you can perform on them. For instance, we could define a qubit as a (physical) quantum system that is capable of being in two different states. In practice, it could be a photon with two possible polarizations, a particle with two possible values for its spin, or a superconducting circuit, whose current can be flowing in one of two directions. When using the quantum circuit model, we can forget about those implementation details and just define a qubit…as a mathematical vector!
1.3.1 What is a qubit?
In fact, a qubit (short for quantum bit, sometimes also written as qbit, Qbit or even q-bit) is the minimal information unit in quantum computing. In the same way that a bit (short for binary digit) can be in state or in state
, a qubit can be in state
or in state
. Here, we are using the so-called Dirac notation, where these funny-looking symbols surrounding
and
are called kets and are used to indicate that we are dealing with vectors instead of regular numbers. In fact,
and
are not the only possibilities for the state of a qubit and, in general, it could be in a superposition of the form
where and
are complex numbers, called amplitudes, such that
. The quantity
is called the norm or length of the state and, when it is equal to
, we say that the state is normalized.
To learn more…
If you need a refresher on complex numbers or vector spaces, please check Appendix A, Complex Numbers, and Appendix B, Basic Linear Algebra.
All these possible values for the state of a single qubit are vectors that live in a complex vector space of dimension 2 (in fact, they live in what is called a Hilbert space, but since we will be working only with finite dimensions, there is no real difference). Thus we shall fix the vectors and
as elements of a special basis, which we will refer to as the computational basis. We will represent these vectors, constituents of the computational basis, as the column vectors
and hence
If we are given a qubit and we want to determine or, rather, estimate its state, all we can do is perform a measurement and get one of two possible results: 0 or 1. We have nonetheless seen how a qubit can be in infinitely many states, so how does the state of a qubit determine the outcome of a measurement? As you likely already know, in quantum physics, these measurements are not deterministic, but probabilistic. In particular, given any qubit , the probability of getting
upon a measurement is
, while that of getting
is
. Naturally, these two probabilities must add up to 1, hence the need for the normalization condition
.
If upon measuring a qubit we get, let's say, , we then know that, after the measurement, the state of the qubit is
, and we say that the qubit has collapsed into that state. If we obtain
, the state collapses to
. Since we are obtaining results that correspond to
and
, we say that we are measuring in the computational basis.
Exercise 1.1
What is the probability of measuring 0 if the state of a qubit is ? And the probability of measuring 1? What if the state of the qubit is
? And if it is
?
So a qubit is, mathematically, just a 2-dimensional vector that satisfies a normalization condition. Who could have known? But the surprises do not end here. In the next subsection, we will see how we can use those funny-looking kets to compute inner products in a very easy way.
1.3.2 Dirac notation and inner products
Dirac notation can not only be used for column vectors, but also for row vectors. In that case, we talk of bras, which, together with kets, can be used to form bra-kets. This name is a pun, because, as we are about to show, bra-kets are, in fact, inner products that are written — you guessed it — between brackets. To be more mathematically precise, with each ket we can associate a bra that is its adjoint or conjugate transpose or Hermitian transpose. In order to obtain this adjoint, we take the ket's column vector, we transpose it and conjugate each of its coordinates (which are, as we already know, complex numbers). We use to denote the bra associated with
and
to denote the bra associated with
, so we have
and, in general,
where, as it is customary, we use the dagger symbol () for the adjoint.
Important note
When finding the adjoint, do not forget to conjugate the complex numbers! For instance, it holds that
One of the reasons why Dirac notation is so popular for working with quantum systems is that, by using it, we can easily compute the inner products of kets and bras. For instance, we can readily show that
This proves that and
are not just elements of any basis but of an orthonormal one, since
and
are orthogonal and of length 1. Thus, we can compute the inner product of two states
and
using Dirac notation by noting that
where and
are the complex conjugates of
and
.
Exercise 1.2
What is the inner product of and
? And the inner product of
and
?
To learn more…
Notice that, if , then
, which is the probability of measuring
if the state is
. This is not accidental. In Chapter 7, VQE: Variational Quantum Eigensolver, for example, we will use measurements in orthonormal bases other than the computational one, and we will see how, in that case, the probability of measuring the result associated to an element
of a given orthonormal basis is exactly
.
We now know what qubits are, how to measure them, and even how to benefit from Dirac notation for some useful computations. The only thing remaining is to study how to operate on qubits. Are you ready? It is time for us to get you introduced to the mighty quantum gates!
1.3.3 One-qubit quantum gates
So far, we have focused on how a qubit stores information in its state and on how we can access (part of) that information with measurements. But in order to develop useful algorithms, we also need some way of manipulating the state of qubits to perform computations.
Since a qubit is, fundamentally, a quantum system, its evolution follows the laws of quantum mechanics. More precisely, if we suppose that our system is isolated from its environment, it obeys the famous Schrödinger equation.
To learn more…
The time-independent Schrödinger equation can be written as
where is the Hamiltonian of the system,
is the state vector of the system at time
,
is the imaginary unit, and
is the reduced Planck constant.
We will talk more about Hamiltonians in Chapter 3, QUBO: Quadratic Unconstrained Binary Optimization, Chapter 4, Quantum Adiabatic Computing and Quantum Annealing, and Chapter 7, VQE: Variational Quantum Eigensolver.
Don't panic! To program a quantum computer, you don't need to know how to solve Schrödinger's equation. In fact, the only thing that you need to know is that its solutions are always a special type of linear transformations. For the purposes of the quantum circuit model, since we are working in finite-dimensional spaces and we have fixed a basis, the operations can be described by matrices that are applied to the vectors that represent the states of the qubits.
But not any kind of matrix does the trick. According to quantum mechanics, the only matrices that we can use are the so-called unitary matrices, which are the matrices such that
where is the identity matrix and
is the adjoint of
, that is, the matrix obtained by transposing
and replacing each element by its complex conjugate. This means that any unitary matrix
is invertible and its inverse is given by
. In the context of the quantum circuit model, the operations represented by these matrices are called quantum gates.
To learn more…
It is relatively easy to check that unitary matrices preserve vector lengths (see, for instance, Section 5.7.5 in Dancing with Qubits, by Robert Sutor [92]). That is, if is a unitary matrix and
is a quantum state (and, hence, its norm is
, as we already know) then
also is a valid quantum state because its norm is still
. For this reason, we can safely apply unitary matrices to our quantum states and rest assured that the resulting states will satisfy the normalization condition.
When we have just one qubit, our unitary matrices need to be of size because the state vector is of dimension 2. Thus, the simplest example of a quantum gate is the identity matrix of dimension 2, which transforms the state of the qubit by... well, by not transforming it at all. A less boring example is the
gate, whose matrix is given by
The gate is also called the NOT gate, because its action on the elements of the computational basis is
which is exactly what the NOT gate does in classical digital circuits.
Exercise 1.3
Check that the gate matrix is, indeed, unitary. What is the inverse of
? What is the action of
on a general qubit in a state of the form
?
A quantum gate with no classical analog is the Hadamard or gate, given by
This gate is extremely useful in quantum computing, for it can create superposition. To be precise, if we apply the gate on a qubit in state
, we obtain
This state is so important that it has its own name and symbol. It is called the plus state and it is denoted by . In a similar way, we have that
and, as you probably guessed, this state is called the minus state and it is denoted by .
Exercise 1.4
Check that the gate matrix is, indeed, unitary. What is the action of
on
and
? What is the action of
on
and
?
Of course, we can apply several gates to the same qubit one after the other. For instance, consider the following circuit:
We read gates from left to right, so in the preceding circuit we would first apply an gate, then an
gate and, finally, another
gate. You can easily check that, if the initial state of the qubit is
, it would end up again in state
. But were its initial state
, the final state would become
.
It turns out that this operation is also very important, and, of course, it has its own name: we call it the gate. From its action on
and
, we can tell that its matrix will be
something that we could have also deduced by multiplying the matrices of the gates ,
, and
one after the other.
Exercise 1.5
Check that and that
in two different ways. First, use Dirac notation and the actions of
and
(remember that we have defined
as
). Then, derive the same result by performing the matrix multiplication
Since there are and
gates, you may be wondering if there is also a
gate. Indeed, there is one, given by matrix
To learn more…
The set , known as the set of Pauli matrices, is of great importance in quantum computing. One of its many interesting properties is that it constitutes a basis of the vector space of
complex matrices. We will work with it in Chapter 7, VQE: Variational Quantum Eigensolver, for instance.
Other important one-qubit gates include the and
gates, whose matrices are
But, of course, there is an (uncountably!) infinite number of 2-dimensional unitary matrices and we cannot just list them all here. What we will do instead is introduce a beautiful geometrical representation of single-qubit states, and, with it, we will explain how all one-qubit quantum gates can, in fact, be understood as certain kinds of rotations. Enter the Bloch sphere!
Exercise 1.6
Check that . Then, use the most beautiful formula ever (i.e., Euler's identity
) to check that
. Check also that
and
are unitary. Express
and
as powers of
and
.
1.3.4 The Bloch sphere and rotations
The general state of a qubit is described with two complex numbers. Since each of those numbers has two real components, it would be natural to think that we would need a four-dimensional real space in order to represent the state of a qubit. Surprisingly enough, all the possible states of a qubit can be drawn on the surface of an old-school sphere, which is a two-dimensional object!
To show how it can be accomplished, we need to remember that a complex number can be written in polar coordinates as
where is a non-negative real number and
is an angle in
. Consider, then, a qubit in a state
and write
and
in polar coordinates as
We know that and, since
, there must exist an angle
in
such that
and
. The reason for considering
instead of
in the cosine and sine will be apparent in a moment. Notice that, by now, we have
Another crucial observation is that we can multiply by a complex number
with absolute value 1 without changing its state. Indeed, it is easy to see that
does not affect the probabilities of obtaining 0 and 1 when measuring in the computational basis (check it!) and, by linearity, it comes out when applying a quantum gate
(that is,
). Thus, there is no operation — either unitary transformation or measurement — that allows us to distinguish
from
. We call
a global phase and we have just shown that it is physically irrelevant.
Important note
Notice, however, that relative phases are, unlike global ones, really relevant! For instance, and
differ just in the phase of
, but we can easily distinguish between them by first applying
to those states and then measuring them in the computational basis.
We can, thus, multiply by
to obtain an equivalent representation
where we have defined .
In this way, we can describe the state of any qubit with just two numbers and
that we can interpret as a polar angle and an azimuthal angle, respectively (that is, we are using what are known as spherical coordinates). This gives us a three-dimensional point
that locates the state of the qubit on the surface of a sphere, called the Bloch sphere (see Figure 1.2).
Notice that runs from
to
to cover the whole range from the top to the bottom of the sphere. This is why we used
in the representation of our preceding qubit. We only needed to get up to
for our angles in the sines and cosines!
In the Bloch sphere, is mapped to the North pole and
to the South pole. In general, states that are orthogonal with respect to the inner product are antipodal on the sphere. For instance,
and
both lie on the equator, but on opposite points of the sphere. As we already know, the
gate takes
to
and
to
, but leaves
and
unchanged, at least up to an irrelevant global phase. In fact, this means that the
gate acts like a rotation of
radians around the
axis of the Bloch sphere…, so now you know why we use that name for the gate! In the same manner,
and
are rotations of
radians around the
and
axes, respectively.
We can generalize this behavior to obtain rotations of any angle around any axis of the Bloch sphere. For instance, for the ,
, and
axes we may define
where we use the symbol for equivalent action up to a global phase. Notice that
,
,
,
, and
.
Exercise 1.7
Check these equivalences by substituting the angles in the definitions of ,
, and
.
In fact, it can be proved (see, for instance, the book by Nielsen and Chuang [69]) that for any one-qubit gate there exists a unit vector
and an angle
such that
For example, choosing and
we can obtain the Hadamard gate, for it holds that
Additionally, it can also be proved that, again for any one-qubit gate , there exist three angles
,
, and
such that
In fact, you can obtain such a decomposition for any two rotation axes as long as they are not parallel, not just for and
.
Moreover, in some quantum computing architectures (including the ones used by companies such as IBM), it is common to use a universal one-qubit gate, called the -gate, that depends on three angles and is able to generate any other one-qubit gate. Its matrix is
Exercise 1.8
Show that is unitary. Check that
, that
and that, up to a global phase,
.
All these observations about how to construct one-qubit gates from rotations and parametrized families will be very important when we talk about variational forms and feature maps in Chapter 9, Quantum Support Vector Machines, and Chapter 10, Quantum Neural Networks, and also to construct controlled gates later in this chapter.
1.3.5 Hello, quantum world!
To put together everything that we have learned, we are going to create our very first complete quantum circuit. It looks like this:
It doesn't seem very impressive, but let's analyze it part by part. As you know, following convention, the initial state of our qubit is assumed to be , so that's what we have before we do anything. Then we apply the
gate, so the state changes to
. Finally, we measure the qubit. The probability of obtaining
will be
, and that of getting
will also be
, so we have created a circuit that — at least in theory — generates random bits following a perfectly uniform distribution.
To learn more…
Unbiased uniform bit distributions are of great relevance for multiple applications in simulation, cryptography, and even online gambling games. As we will learn in Chapter 2, The Tools of the Trade, current quantum computers deviate from this equilibrium because they are affected by noise and gate and measurement errors. However, protocols to extract perfect random bits even with noisy quantum computers have been proposed and could become one of the first practical applications of quantum computing (see, for instance, the paper by Acín and Masanes [3]).
We can modify the previous circuit to obtain any distribution over and
that we desire. If we want the probability of measuring
to be
, we just need to consider
and the following circuit:
Exercise 1.9
Check that, with the preceding circuit, the state before measurement is and, hence, the probability of measuring
is
and that of measuring
is
.
For now, this is all that we need to know about one-qubit states, gates, and measurements. Let us move on to two-qubit systems, where the mysteries of entanglement are awaiting to be revealed!