Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
A Practical Guide to Quantum Machine Learning and Quantum Optimization

You're reading from  A Practical Guide to Quantum Machine Learning and Quantum Optimization

Product type Book
Published in Mar 2023
Publisher Packt
ISBN-13 9781804613832
Pages 680 pages
Edition 1st Edition
Languages
Authors (2):
Elías F. Combarro Elías F. Combarro
Profile icon Elías F. Combarro
Samuel González-Castillo Samuel González-Castillo
Profile icon Samuel González-Castillo
View More author details

Table of Contents (27) Chapters

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

1.5 Working with multiple qubits and universality

Now that we have mastered working with two-qubit systems, it will be fairly straightforward to generalize all the notions that we have been studying to the case in which the number of qubits in our circuits is arbitrarily big. You know the drill: we will start by defining, mathematically, what a multi-qubit system is, we will then learn how to measure it and, finally, we will introduce quantum gates that act on many qubits at the same time.

1.5.1 Multi-qubit systems

With all that we have learned so far, it will now be very easy to understand how to work with multi-qubit systems.

As you may have already deduced, if we have n qubits, the states that constitute the computational basis are

\begin{matrix} {\left| 0 \right\rangle \otimes \left| 0 \right\rangle \otimes \cdots \otimes \left| 0 \right\rangle,} & \\ {\left| 0 \right\rangle \otimes \left| 0 \right\rangle \otimes \cdots \otimes \left| 1 \right\rangle,} & \\ {\vdots} & \\ {\left| 1 \right\rangle \otimes \left| 1 \right\rangle \otimes \cdots \otimes \left| 1 \right\rangle.} & \\ \end{matrix}

We usually omit the \otimes symbol to write

\begin{matrix} {\left| 0 \right\rangle\left| 0 \right\rangle\cdots\left| 0 \right\rangle,} & \\ {\left| 0 \right\rangle\left| 0 \right\rangle\cdots\left| 1 \right\rangle,} & \\ {\left| 1 \right\rangle\left| 1 \right\rangle\cdots\left| 1 \right\rangle} & \\ \end{matrix}

or

\left| {00\cdots 0} \right\rangle,\left| {00\cdots 1} \right\rangle,\ldots,\left| {11\cdots 1} \right\rangle

or simply

\left| 0 \right\rangle,\left| 1 \right\rangle,\ldots,\left| {2^{n} - 1} \right\rangle.

Important note

When using the \left| 0 \right\rangle,\left| 1 \right\rangle,\ldots,\left| {2^{n} - 1} \right\rangle notation for basis states, the total number of qubits must be clear from context. Otherwise, a state like, for example, \left| 2 \right\rangle might mean either \left| {10} \right\rangle, \left| {010} \right\rangle, \left| {0010} \right\rangle, or any string with leading zeroes and ending in 10…and that would be an intolerable ambiguity!

Of course, a generic state of the system will then be of the form

\left| \psi \right\rangle = a_{0}\left| 0 \right\rangle + a_{1}\left| 1 \right\rangle + \ldots + a_{2^{n} - 1}\left| {2^{n} - 1} \right\rangle

subject to the only condition that the amplitudes a_{i} should be complex numbers such that {\sum}_{l = 0}^{2^{n} - 1}\left| a_{l} \right|^{2} = 1. Our dear old friend, the normalization condition!

To learn more

Notice that the number of parameters describing the general state of an n-qubit system is exponential in n. For highly entangled states, we do not know how to represent all this information in a more succinct way and it is strongly suspected that it is not possible. Part of the power of quantum computing comes from this possibility of implicitly working with 2^{n} complex numbers by manipulating just n qubits.

Exercise 1.18

Check that the basis state \left| j \right\rangle is represented by a 2^{n}-dimensional column vector whose j-th component is 1, while the rest are 0 (Hint: Use, repeatedly, the expression for the tensor product of column vectors that we discussed in Section 1.4.1 and the fact that the tensor product is associative). Deduce that any n-qubit state can be represented by a 2^{n}-dimensional column vector with unit length.

If we decide to measure all the qubits of the system in the computational basis, we will obtain m with probability \left| a_{m} \right|^{2}. If that is the case, then the state will collapse to \left| m \right\rangle. But if we only measure one of the qubits, say the j-th one, then we will obtain 0 with probability

\sum\limits_{l \in J_{0}}\left| a_{l} \right|^{2},

where J_{0} is the set of numbers whose j-th bit is 0. In this scenario, the state of the system after measuring 0 would be

\frac{\sum\limits_{l \in J_{0}}a_{l}\left| l \right\rangle}{\sqrt{\sum\limits_{l \in J_{0}}\left| a_{i} \right|^{2}}}.

Exercise 1.19

Derive the formulas for the case in which the result of the measurement is 1.

Exercise 1.20

What is the probability of getting 0 when we measure the second qubit of \left. (1\slash 2)\left| {100} \right\rangle + (1\slash 2)\left| {010} \right\rangle + \sqrt{\left. 1\slash 2 \right.}\left| {001} \right\rangle \right.? What will the state be after the measurement if we indeed get 0?

Computing inner products of n-qubit systems in Dirac notation is very similar to doing it with two-qubit systems. The procedure is analogous to the one we showed in Section 1.4.1, but taking into account that

\left( {\left\langle \psi_{1} \right| \otimes \ldots \otimes \left\langle \psi_{n} \right|} \right)\left( {\left| \varphi_{1} \right\rangle \otimes \ldots \otimes \left| \varphi_{n} \right\rangle} \right) = \left\langle \psi_{1} \middle| \varphi_{1} \right\rangle\ldots\left\langle \psi_{n} \middle| \varphi_{n} \right\rangle.

Exercise 1.21

Compute the inner product of \left| x \right\rangle and \left| y \right\rangle, where x and y are both binary strings of length n. Use your result to prove that {\{\left| x \right\rangle\}}_{x \in {\{ 0,1\}}^{n}} is, indeed, an orthonormal basis.

Exercise 1.22

Compute the inner product of the states \sqrt{\left. 1\slash 2 \right.}\left( {\left| {000} \right\rangle + \left| {111} \right\rangle} \right) and \left. 1\slash 2\left( {\left| {000} \right\rangle + \left| {011} \right\rangle + \left| {101} \right\rangle + \left| {110} \right\rangle} \right) \right..

We can now turn to the question of how to operate on many qubits at once. Let's define multi-qubit gates!

1.5.2 Multi-qubit gates

Since n-qubit states are represented by 2^{n}-dimensional column vectors, n-qubit gates can be identified with 2^{n} \times 2^{n} unitary matrices. Similar to the two-qubit case, we can construct n-qubit gates by taking the tensor product of gates on a smaller number of qubits. Namely, if U_{1} is an n_{1}-qubit gate and U_{2} is an n_{2}-qubit gate, then U_{1} \otimes U_{2} is an (n_{1} + n_{2})-qubit gate and its matrix is given by the tensor product of the matrices U_{1} and U_{2}.

To learn more

The expression for the tensor product of two matrices A and B is

\begin{pmatrix} a_{11} & {\ldots} & a_{1q} \\ {\vdots} & \ddots & {\vdots} \\ a_{p1} & {\ldots} & a_{pq} \\ \end{pmatrix} \otimes B = \begin{pmatrix} {a_{11}B} & {\ldots} & {a_{1q}B} \\ {\vdots} & \ddots & {\vdots} \\ {a_{p1}B} & {\ldots} & {a_{pq}B} \\ \end{pmatrix}.

However, there are n-qubit gates that cannot be constructed as tensor products of smaller gates. One such example is the Toffoli or CCNOT gate, a three-qubit gate that acts on the computational basis as

\text{CCNOT}\left| x \right\rangle\left| y \right\rangle\left| z \right\rangle = \left| x \right\rangle\left| y \right\rangle\left| {z \oplus \left( {x \land y} \right)} \right\rangle,

where \oplus is the XOR function and \land is the symbol for the AND Boolean function. Thus, CCNOT applies a doubly controlled (in this case, by the first two qubits) NOT gate to the third qubit — hence the name!

Exercise 1.23

Obtain the matrix for the CCNOT gate and verify that it is unitary.

The Toffoli gate is important because, using it and with the help of auxiliary qubits, we can construct any classical Boolean operator. For instance, \text{CCNOT}\left| 1 \right\rangle\left| 1 \right\rangle\left| z \right\rangle = \left| 1 \right\rangle\left| 1 \right\rangle\left| {\neg z} \right\rangle (where \neg z is the negation of z) and \text{CCNOT}\left| x \right\rangle\left| y \right\rangle\left| 0 \right\rangle = \left| x \right\rangle\left| y \right\rangle\left| {x \land y} \right\rangle. This shows that, with quantum circuits, we can simulate the behavior of any classical digital circuit at the cost of using some additional ancillary qubits, since any Boolean function can be built with just negations and conjunctions. This is somewhat surprising, because we know that all quantum gates are invertible, while not all Boolean functions are. It then follows that we could make all of our digital circuits reversible just by implementing a classical version of the Toffoli gate!

We will not be studying any other concrete examples of gates that act on three (or more!) qubits because, in fact, we can simulate their behavior with circuits that only use one- and two-qubit gates. Keep on reading to know how!

1.5.3 Universal gates in quantum computing

Current quantum computers can't implement every possible quantum gate. Instead, they rely on universality results that show how any unitary operation can be decomposed as a circuit that uses a reduced set of primitive gates. In previous sections, we mentioned, for instance, that any one-qubit gate can be obtained by using just R_{Z} and R_{Y} rotations. It turns out that similar results exist for the general case of n-qubit quantum gates.

To us, it will be important to know that, for any unitary operation, we can construct a circuit that implements it using only one-qubit gates and the CNOT gate. For this reason, we say that those gates are universal — in the same sense that, for example, negation and conjunction are universal for Boolean logic. This fact will be crucial for our study of feature maps and variational forms in connection to quantum neural networks and other quantum machine learning models.

To learn more

In addition to one-qubit gates plus CNOT, there are many other sets of universal gates. For instance, it can be shown that the three gates H, T, and CNOT can be used to approximate any unitary operation to any desired accuracy — and they are universal in that sense. See Section 4.5 of the book by Nielsen and Chuang [69] for proofs of these facts and for more examples of universal gate sets.

To illustrate how CNOT and one-qubit gates can be used to implement any other quantum gate, the following circuit shows a possible decomposition of the Toffoli gate targeting the top qubit:

HTTTTHTTT††† .

Exercise 1.24

Verify that the preceding circuit implements the Toffoli gate by checking its action on the states of the computational basis.

This concludes our review of the fundamentals of quantum computing. We've come a long way since the beginning of this chapter, but by now we have mastered all the mathematics that we will need in order to study quantum machine learning and quantum optimization algorithms. Soon, we will see all these concepts in action!

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 $15.99/month. Cancel anytime}