1.4 Working with two qubits and entanglement
Now that we have mastered the inner workings of solitary qubits, we are ready to up the ante. In this section, we will learn about systems of two qubits and how they can become entangled. We will first define the mathematical representation of two-qubit systems and how we can measure them. After that, we will study different quantum gates that can act on two qubits at once and we will have a look at some of their very interesting and slightly puzzling properties. We will conclude with a simple but enlightening example of a two-qubit circuit. We promise that the ride is going to be amazing!
1.4.1 Two-qubit states
So far, we have worked with qubits in isolation. But the real power of quantum computing cannot be unleashed unless qubits can talk to each other. We will start by considering the simplest case of quantum systems in which there is qubit interaction: two-qubit systems.
Of course, in a two-qubit system, each of the qubits can be in state or in state
. Thus, for the two qubits, we have four possible combinations: both are in state
, the first one is in state
and the second one in state
, the first one is in state
and the second one in state
, or both are in state
. These four possibilities form a basis (called the computational basis) of a
-dimensional space and we denote them, respectively, by
Here, is the symbol for the tensor product. The tensor product of two column vectors is defined by
Hence, the four basis states can be represented by four-dimensional column vectors given by
Usually, we omit the symbol and just write
or
or even
Obviously, in this last case, the number of qubits that we are using must be clear from the context in order not to mistake the state of a one-qubit system with the state
of a two-qubit system — or, as we will see soon, any other multi-qubit system!
As we have mentioned, these four states constitute a basis of the vector space of possible states for a two-qubit system. The general expression for the state of such a system is
where ,
,
, and
are complex numbers (called amplitudes, remember?) such that
.
If we measure in the computational basis both qubits at this generic state that we are considering, we will obtain with probability
,
with probability
,
with probability
, and
with probability
. In all those cases, the state will collapse to the state corresponding to the outcome of the measurement, just as with one-qubit systems.
Let's now say that we only measure one of the qubits. What happens then? Suppose that we measure the first qubit. Then, the probability of obtaining will be
, which is the sum of the probabilities of all the outcomes in which the first qubit can be
. If we measure the first qubit and the result turns out to be
, the system will not collapse completely, but it will remain in the state
where we have divided by to keep the state normalized. The situation in which the result of the measurement is
is analogous.
Exercise 1.10
Derive the formulas for the probability of measuring on the first qubit in a general two-qubit state and for the state of the system after the measurement.
Dirac notation is also useful to compute inner products of two-qubit states. We only need to notice that
apply distributivity and remember to conjugate the complex coefficients when obtaining a bra from a ket.
Then, for instance, we can notice that the inner product of and
is
since and
.
1.4.2 Two-qubit gates: tensor products
Of course, the operations that we can conduct on two-qubit systems need to be unitary. Thus, two-qubit quantum gates are unitary matrices that act on 4-dimensional column vectors. The simplest way to construct such matrices is by taking the tensor product of two one-qubit quantum gates. Namely, if we consider two one-qubit gates
and
and two one-qubit states
and
, we can form a two-qubit gate
that acts on
as
By linearity, we can extend to any combination of two-qubit states and we can associate a matrix to
. In fact, said matrix is given by the tensor product of the matrices associated to
and
. More concretely, the expression for the tensor product,
, of the
matrices
and
is
Now it is easy to verify that this operation is indeed unitary and, hence, deserves the name of quantum gate.
Exercise 1.11
Check that, given any pair of unitary matrices and
, the inverse of
is
and that
.
Tensor products of gates occur naturally when we have circuits with two qubits and pairs of individual one-qubit gates are acting on each of them. For instance, in the following circuit, the gate acts on the two qubits and then it is followed by the gate
, where
is the identity gate:
Exercise 1.12
Explicitly compute the matrices for the gates and
.
You may complain that we haven't done anything new so far. And you would be right! In fact, quantum gates that are obtained as the tensor product of one-qubit gates can be seen as operations on isolated qubits that just happen to be applied at the same time. But wait and see! In the next subsection, we will introduce a completely different way of acting on two-qubit systems.
1.4.3 The CNOT gate
By taking tensor products of one-qubit gates, we can only obtain operations that act on each qubit individually. But this just leaves us with a (rather boring) subset of all the possible two-qubit gates. There are many unitary matrices that cannot be written as the tensor product of other simple matrices. In the two-qubit case, probably the most important one is the controlled-NOT (or controlled-) gate, usually called the CNOT gate, given by the unitary matrix
It is illuminating to see how this gate acts on the elements of the two-qubit computational basis. As you can easily check, we get
This means that the value of the second qubit is flipped if and only if the value of the first qubit is . Or, to put it in other words, the application of a NOT gate on the second qubit (that we call the target) is controlled by the first qubit. Now the name of this gate makes much more sense, doesn't it?
In a quantum circuit, the CNOT gate is represented as follows:
Notice that the control qubit is indicated by a solid black circle and the target qubit is indicated by the symbol (the symbol for an
gate can also be used instead of
).
Sometimes, technical difficulties restrict the number of CNOT gates that can be actually implemented on a quantum computer. For instance, on a certain quantum chip you may have the possibility of applying a CNOT gate targeting qubit and controlled by qubit
, but not the other way around. If you find yourself in such a situation, there's no need to panic. If you use the circuit
you are effectively applying a CNOT gate with target in the top qubit and control in the bottom one. And that's how you can save the day!
The CNOT gate can also be used to interchange or swap the states of two qubits, by using the following circuit:
Exercise 1.13
Check these equivalences in two different ways: by computing the matrices of the circuits and by obtaining the result of using them with qubits in states ,
,
, and
.
In any case, the most prominent use of the CNOT gate is, without a doubt, the ability to create entanglement, an intriguing property of quantum systems that we will study next.
1.4.4 Entanglement
Oddly enough, in order to define when a quantum system is entangled, we first need to define when it is not entangled. We say that a state is a product state if it can be written as the tensor product of two other states
and
, each of at least one qubit,
as in
If is not a product state, we say that it is entangled.
For example, is a product state, because we know that it is just another way of writing
. Also,
is a product state, because we can factor
on the second qubit to obtain
On the other hand, is an entangled state. No matter how hard you try, it is impossible to write it as a product of two one-qubit states. Suppose, for sake of contradiction, that it were possible. Then, you would have
But this forces to be
, because we have no
component in
. Then, either
, in which case
is
, or
, from which
follows. In both cases, it is impossible to reach the equality that we needed. Thus, it follows that the state is entangled.
Exercise 1.14
Is entangled? And what about
?
When measured, entangled states can show correlations that go beyond what can be explained with classical physics. For instance, if we have the entangled state and we measure the first qubit, we can obtain
or
, each with probability
. However, if we measure the second qubit afterwards, the result will be completely determined by the value obtained when measuring the first qubit and, in fact, will be exactly the same. If we invert the order and measure first the second qubit, then the result will be
or
, with equal probability. But, in this case, the result of a subsequent measurement of the first qubit will be completely determined!
This still happens even if we separate the two qubits thousands of light years apart, as if one qubit could somehow know what the result of measuring the other qubit was. This curious behavior haunted many physicists during the 20th century, including Albert Einstein, who called it a "spooky action at a distance" (see [34]). Nevertheless, the effects of entanglement have been repeatedly demonstrated in uncountable experiments (in fact, the Nobel Prize in Physics 2022 was awarded to Alain Aspect, John F. Clauser, and Anton Zeilinger, pioneers in studying and testing this phenomenon in practice [10, 25, 41, 19]). And, very importantly for us, entanglement is one of the most powerful resources available in quantum computing.
But entanglement is, by no means, the only puzzling feature of qubit systems. In the next subsection, we are going to mathematically prove that copying quantum information, an operation that you may have taken for granted, is not possible in general. These qubits are, indeed, full of surprises!
1.4.5 The no-cloning theorem
Another peculiar property of quantum systems is that, in general, they don't allow us to copy information. Surprising as this may seem, it is just an easy consequence of the linearity of quantum gates. To show why, let us be more precise about what we would need in order to copy information, for instance with just two qubits. We would like to have a two-qubit quantum gate that will be able to copy the first qubit into the second. That is, for any given quantum state
, we would need
Then, and
and, by linearity,
We should highlight that the state that we have obtained is entangled, as we proved in the previous subsection.
Nevertheless, notice that, in our original state, we can factor the second out to obtain
Then, in virtue of the action of , we should have
which is a product state. However, we had obtained earlier that , which is entangled! This contradiction implies that, alas, no such
exists.
This remarkable result is called the no-cloning theorem and we should explain its meaning in a little more detail. On the one hand, notice that this does not imply that we cannot copy classical information. In fact, if is just
or
, we can easily achieve
by taking
to be the CNOT gate. On the other hand, the theorem applies to unknown states
. If we know what
is — that is, if we know a circuit that prepares
starting from
— then, of course, we can create as many independent copies of it as we want. However, if
is handed to us without any additional information about its state, the no-cloning theorem shows that we cannot replicate its state in general.
To learn more…
The no-cloning theorem plays an important role in the security of quantum key distribution protocols such as the famous BB84, introduced in 1984 by Bennett and Brassard [13].
After this brief detour, let's return to our study of two-qubit quantum gates. In the next subsection, we will show how to construct many interesting two-qubit unitary operations whose action is controlled by one of their inputs.
1.4.6 Controlled gates
You may be wondering if, in addition to a controlled- (or CNOT) gate, there are also controlled-
, controlled-
, or controlled-
gates. The answer is a resounding yes and, in fact, for any quantum gate
, it is possible to define a controlled-
(or, simply,
) gate whose action on the computational basis is
Exercise 1.15
Check that the matrix of is
where is the matrix of
. Check also that
is unitary. What is the adjoint of
?
The circuit representation of a gate is similar to the one that we use for the CNOT gate, namely
,
where the solid black circle indicates the control and the box with inside indicates the target.
Constructing a controlled gate is simpler than it seems, provided your quantum computer already implements rotation gates and the two-qubit CNOT gate. In fact, from the decomposition in rotations that we mentioned at the end of Section 1.3.4, it can be proved (see the book by Nielsen and Chuang [69, Corollary 4.2]) that any one-qubit quantum gate can be written in the form
for some angle and gates
,
, and
such that
. Then, the following circuit implements
:
Sometimes, though, constructing a controlled gate is much easier. For instance, it can be shown that a controlled- gate can be obtained from a controlled-
and two
gates, as shown in the identity of the following circuits:
Exercise 1.16
Prove the preceding equivalence.
We now have everything we need in order to construct our first two-qubit quantum circuit. Let's get those qubits entangled!
1.4.7 Hello, entangled world!
To finish up with our study of two-qubit systems, let us show how to create entangled states with the help of the CNOT gate. Consider the following circuit:
Initially, the state of the system is . After we apply the
gate, we get into the state
. Finally, when we apply the CNOT gate, the state changes to
, which, as we proved in Section 1.4.4, is indeed an entangled state.
The state is known as a Bell state, of which there are four. The other three are
,
, and
. All of them are entangled, and they can be prepared with circuits similar to the preceding one.
Exercise 1.17
Show that all four Bell states are entangled. Obtain circuits to prepare them. Hint: you can use and
gates after the CNOT in the preceding circuit.
We are now ready for the big moment. In the next section, we will finally learn how to work with not just one or two qubits, but with as many as we can get in our quantum computers.