Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
A Practical Guide to Quantum Machine Learning and Quantum Optimization

You're reading from   A Practical Guide to Quantum Machine Learning and Quantum Optimization Hands-on Approach to Modern Quantum Algorithms

Arrow left icon
Product type Paperback
Published in Mar 2023
Publisher Packt
ISBN-13 9781804613832
Length 680 pages
Edition 1st Edition
Arrow right icon
Authors (2):
Arrow left icon
Elías F. Combarro Fernández-Combarro Álvarez Elías F. Combarro Fernández-Combarro Álvarez
Author Profile Icon Elías F. Combarro Fernández-Combarro Álvarez
Elías F. Combarro Fernández-Combarro Álvarez
Samuel González Castillo Samuel González Castillo
Author Profile Icon Samuel González Castillo
Samuel González Castillo
Arrow right icon
View More author details
Toc

Table of Contents (27) Chapters Close

Preface 1. Part I: I, for One, Welcome our New Quantum Overlords
2. Chapter 1: Foundations of Quantum Computing FREE CHAPTER 3. Chapter 2: The Tools of the Trade in Quantum Computing 4. Part II: When Time is Gold: Tools for Quantum Optimization
5. Chapter 3: Working with Quadratic Unconstrained Binary Optimization Problems 6. Chapter 4: Adiabatic Quantum Computing and Quantum Annealing 7. Chapter 5: QAOA: Quantum Approximate Optimization Algorithm 8. Chapter 6: GAS: Grover Adaptive Search 9. Chapter 7: VQE: Variational Quantum Eigensolver 10. Part III: A Match Made in Heaven: Quantum Machine Learning
11. Chapter 8: What Is Quantum Machine Learning? 12. Chapter 9: Quantum Support Vector Machines 13. Chapter 10: Quantum Neural Networks 14. Chapter 11: The Best of Both Worlds: Hybrid Architectures 15. Chapter 12: Quantum Generative Adversarial Networks 16. Part IV: Afterword and Appendices
17. Chapter 13: Afterword: The Future of Quantum Computing
18. Assessments 19. Bibliography
20. Index
21. Other Books You May Enjoy Appendix A: Complex Numbers
1. Appendix B: Basic Linear Algebra 2. Appendix C: Computational Complexity 3. Appendix D: Installing the Tools 4. Appendix E: Production Notes

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

\left| 0 \right\rangle \otimes \left| 0 \right\rangle,\,\left| 0 \right\rangle \otimes \left| 1 \right\rangle,\,\left| 1 \right\rangle \otimes \left| 0 \right\rangle,\,\left| 1 \right\rangle \otimes \left| 1 \right\rangle.

Here, is the symbol for the tensor product. The tensor product of two column vectors is defined by

\begin{pmatrix} a_{1} \\ a_{2} \\ {\vdots} \\ a_{n} \\ \end{pmatrix} \otimes \begin{pmatrix} b_{1} \\ b_{2} \\ {\vdots} \\ b_{m} \\ \end{pmatrix} = \begin{pmatrix} {a_{1}\begin{pmatrix} b_{1} \\ b_{2} \\ {\vdots} \\ b_{m} \\ \end{pmatrix}} \\ {a_{2}\begin{pmatrix} b_{1} \\ b_{2} \\ {\vdots} \\ b_{m} \\ \end{pmatrix}} \\ {\vdots} \\ {a_{n}\begin{pmatrix} b_{1} \\ b_{2} \\ {\vdots} \\ b_{m} \\ \end{pmatrix}} \\ \end{pmatrix} = \begin{pmatrix} {a_{1}b_{1}} \\ {a_{1}b_{2}} \\ {\vdots} \\ {a_{1}b_{m}} \\ {a_{2}b_{1}} \\ {a_{2}b_{2}} \\ {\vdots} \\ {a_{2}b_{m}} \\ {\vdots} \\ {a_{n}b_{1}} \\ {a_{n}b_{2}} \\ {\vdots} \\ {a_{n}b_{m}} \\ \end{pmatrix}.

Hence, the four basis states can be represented by four-dimensional column vectors given by

\left| 0 \right\rangle \otimes \left| 0 \right\rangle = \begin{pmatrix} 1 \\ 0 \\ 0 \\ 0 \\ \end{pmatrix},\qquad\left| 0 \right\rangle \otimes \left| 1 \right\rangle = \begin{pmatrix} 0 \\ 1 \\ 0 \\ 0 \\ \end{pmatrix},\qquad\left| 1 \right\rangle \otimes \left| 0 \right\rangle = \begin{pmatrix} 0 \\ 0 \\ 1 \\ 0 \\ \end{pmatrix},\qquad\left| 1 \right\rangle \otimes \left| 1 \right\rangle = \begin{pmatrix} 0 \\ 0 \\ 0 \\ 1 \\ \end{pmatrix}.

Usually, we omit the symbol and just write

\left| 0 \right\rangle\left| 0 \right\rangle,\,\left| 0 \right\rangle\left| 1 \right\rangle,\,\left| 1 \right\rangle\left| 0 \right\rangle,\,\left| 1 \right\rangle\left| 1 \right\rangle

or

\left| {00} \right\rangle,\,\left| {01} \right\rangle,\,\left| {10} \right\rangle,\,\left| {11} \right\rangle

or even

\left| 0 \right\rangle,\,\left| 1 \right\rangle,\,\left| 2 \right\rangle,\,\left| 3 \right\rangle.

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

\left| \psi \right\rangle = a_{00}\left| {00} \right\rangle + a_{01}\left| {01} \right\rangle + a_{10}\left| {10} \right\rangle + a_{11}\left| {11} \right\rangle

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

\frac{a_{00}\left| {00} \right\rangle + a_{01}\left| {01} \right\rangle}{\sqrt{\left| a_{00} \right|^{2} + \left| a_{01} \right|^{2}}},

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

\left( {\left\langle \psi_{1} \right| \otimes \left\langle \psi_{2} \right|} \right)\left( {\left| \varphi_{1} \right\rangle \otimes \left| \varphi_{2} \right\rangle} \right) = \left\langle \psi_{1} \middle| \varphi_{1} \right\rangle\left\langle \psi_{2} \middle| \varphi_{2} \right\rangle,

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

\begin{array}{rlrl} & {\left( {\frac{4}{5}\left\langle {01} \right| - \frac{3i}{5}\left\langle {11} \right|} \right)\left( {\frac{1}{\sqrt{2}}\left| {00} \right\rangle + \frac{1}{\sqrt{2}}\left| {11} \right\rangle} \right) = \qquad} & & \qquad \\ & {\quad\frac{4}{5\sqrt{2}}\left\langle 01 \middle| 00 \right\rangle + \frac{4}{5\sqrt{2}}\left\langle 01 \middle| 11 \right\rangle - \frac{3i}{5\sqrt{2}}\left\langle 11 \middle| 00 \right\rangle - \frac{3i}{5\sqrt{2}}\left\langle 11 \middle| 11 \right\rangle = \qquad} & & \qquad \\ & {\quad\frac{4}{5\sqrt{2}}\left\langle 0 \middle| 0 \right\rangle\left\langle 1 \middle| 0 \right\rangle + \frac{4}{5\sqrt{2}}\left\langle 0 \middle| 1 \right\rangle\left\langle 1 \middle| 1 \right\rangle - \frac{3i}{5\sqrt{2}}\left\langle 1 \middle| 0 \right\rangle\left\langle 1 \middle| 0 \right\rangle - \frac{3i}{5\sqrt{2}}\left\langle 1 \middle| 1 \right\rangle\left\langle 1 \middle| 1 \right\rangle = - \frac{3i}{5\sqrt{2}},\qquad} & & \qquad \\ \end{array}

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

\left( {U_{1} \otimes U_{2}} \right)\left( {\left| \psi_{1} \right\rangle \otimes \left| \psi_{2} \right\rangle} \right) = \left( {U_{1}\left| \psi_{1} \right\rangle} \right) \otimes \left( {U_{2}\left| \psi_{2} \right\rangle} \right).

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

\begin{array}{rlrl} {\begin{pmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \\ \end{pmatrix} \otimes \begin{pmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \\ \end{pmatrix}} & {= \begin{pmatrix} {a_{11}\begin{pmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \\ \end{pmatrix}} & {a_{12}\begin{pmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \\ \end{pmatrix}} \\ {a_{21}\begin{pmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \\ \end{pmatrix}} & {a_{22}\begin{pmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \\ \end{pmatrix}} \\ \end{pmatrix}\qquad} & & \qquad \\ & {= \begin{pmatrix} {a_{11}b_{11}} & {a_{11}b_{12}} & {a_{12}b_{11}} & {a_{12}b_{12}} \\ {a_{11}b_{21}} & {a_{11}b_{22}} & {a_{12}b_{21}} & {a_{12}b_{22}} \\ {a_{21}b_{11}} & {a_{21}b_{12}} & {a_{22}b_{11}} & {a_{22}b_{12}} \\ {a_{21}b_{21}} & {a_{21}b_{22}} & {a_{22}b_{21}} & {a_{22}b_{22}} \\ \end{pmatrix}.\qquad} & & \qquad \\ \end{array}

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:

XHX

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

\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ \end{pmatrix}.

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

\text{CNOT}\left| {00} \right\rangle = \left| {00} \right\rangle,\qquad\text{CNOT}\left| {01} \right\rangle = \left| {01} \right\rangle,\qquad\text{CNOT}\left| {10} \right\rangle = \left| {11} \right\rangle,\qquad\text{CNOT}\left| {11} \right\rangle = \left| {10} \right\rangle.

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

HHHH

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

\left| \psi \right\rangle = \left| \psi_{1} \right\rangle \otimes \left| \psi_{2} \right\rangle.

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

\frac{1}{\sqrt{2}}(\left| {00} \right\rangle + \left| {10} \right\rangle) = \left( {\frac{1}{\sqrt{2}}\left( {\left| 0 \right\rangle + \left| 1 \right\rangle} \right)} \right)\left| 0 \right\rangle.

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

\begin{array}{rlrl} {\frac{1}{\sqrt{2}}\left( {\left| {00} \right\rangle + \left| {11} \right\rangle} \right)} & {= \left( {a\left| 0 \right\rangle + b\left| 1 \right\rangle} \right)\left( {c\left| 0 \right\rangle + d\left| 1 \right\rangle} \right)\qquad} & & \qquad \\ & {= ac\left| {00} \right\rangle + ad\left| {01} \right\rangle + bc\left| {01} \right\rangle + bd\left| {11} \right\rangle.\qquad} & & \qquad \\ \end{array}

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

U\left| \psi \right\rangle\left| 0 \right\rangle = \left| \psi \right\rangle\left| \psi \right\rangle.

Then, and and, by linearity,

U\left( {\frac{1}{\sqrt{2}}(\left| {00} \right\rangle + \left| {10} \right\rangle)} \right) = \frac{1}{\sqrt{2}}\left( {U\left| {00} \right\rangle + U\left| {10} \right\rangle} \right) = \frac{1}{\sqrt{2}}\left( {\left| {00} \right\rangle + \left| {11} \right\rangle} \right).

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

\frac{1}{\sqrt{2}}(\left| {00} \right\rangle + \left| {10} \right\rangle) = \left( \frac{\left| 0 \right\rangle + \left| 1 \right\rangle}{\sqrt{2}} \right)\left| 0 \right\rangle.

Then, in virtue of the action of , we should have

U\left( {\frac{1}{\sqrt{2}}(\left| {00} \right\rangle + \left| {10} \right\rangle)} \right) = U\left( {\left( \frac{\left| 0 \right\rangle + \left| 1 \right\rangle}{\sqrt{2}} \right)\left| 0 \right\rangle} \right) = \frac{(\left| 0 \right\rangle + \left| 1 \right\rangle)}{\sqrt{2}}\frac{(\left| 0 \right\rangle + \left| 1 \right\rangle)}{\sqrt{2}},

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

\text{C}U\left| {00} \right\rangle = \left| {00} \right\rangle,\qquad\text{C}U\left| {01} \right\rangle = \left| {01} \right\rangle,\qquad\text{C}U\left| {10} \right\rangle = \left| 1 \right\rangle U\left| 0 \right\rangle,\qquad\text{C}U\left| {11} \right\rangle = \left| 1 \right\rangle U\left| 1 \right\rangle.

Exercise 1.15

Check that the matrix of is

\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & u_{11} & u_{12} \\ 0 & 0 & u_{21} & u_{22} \\ \end{pmatrix},

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

U ,

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

U = e^{i\theta}AXBXC

for some angle and gates , , and such that . Then, the following circuit implements :

RCBA (𝜃) Z

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:

Z HH

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:

|H|00⟩⟩

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.

You have been reading a chapter from
A Practical Guide to Quantum Machine Learning and Quantum Optimization
Published in: Mar 2023
Publisher: Packt
ISBN-13: 9781804613832
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image