Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
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

3.3 Moving from Ising to QUBO and back

Consider the following problem. Let's say that you are given a set of integers and a target integer value , and you are asked whether there is any subset of whose sum is . For instance, if and , then the answer is affirmative, because . However, if and , the answer is negative because all the numbers in the set are even and they cannot add up to an odd number.

This problem, called the Subset Sum problem, is known to be -complete (see, for instance, Section 7.5 in the book by Sipser [90] for a proof). It turns out that we can reduce the Subset Sum problem to finding a spin configuration of minimal energy for an Ising model, (which is an -hard problem – see Section 3.1.3). This means that we can rewrite any instance of Subset Sum as an Ising ground state problem (check Appendix C, Computational Complexity, for a refresher on reductions).

However, it may not be directly evident how to do so.

In fact, it is much simpler to pose the Subset Sum problem as a minimization problem by using binary variables instead of variables that take or values. Indeed, if we are given and an integer , we can define binary variables , , and consider

c(x_{0},x_{1},\ldots,x_{m}) = \left( {a_{0}x_{0} + a_{1}x_{1} + \ldots + a_{m}x_{m} - T} \right)^{2}.

Clearly, the Subset Sum problem has a positive answer if and only if we can find binary values , , such that . In that case, the variables that are equal to will indicate which numbers from the set are selected for the sum. But is always non-negative, so we have reduced the Subset Sum problem to finding the minimum of : if the minimum is , the Subset Sum has a positive solution; otherwise, it doesn't.

For example, for the case of and that we considered previously, the problem would be

\begin{array}{rlrl} {\text{Minimize~}\quad} & {x_{0}^{2} + 8x_{0}x_{1} - 4x_{0}x_{2} - 4x_{0} + 16x_{1}^{2} - 16x_{1}x_{2} - 16x_{1} + 4x_{2}^{2} + 8x_{2} + 4\qquad} & & \qquad \\ {\text{subject~to~}\quad} & {x_{j} \in \{ 0,1\},\qquad j = 0,\ldots,m\qquad} & & \qquad \\ \end{array}

where we have expanded to obtain the expression to be optimized. If you wish, you can simplify it a little by taking into account that always holds for binary variables. In any case, would be an optimal solution for this problem.

Notice that, in all of these cases, the function that we need to minimize is a polynomial of degree on the binary variables . We can thus generalize this setting and define Quadratic Unconstrained Binary Optimization (QUBO) problems, which are of the form

\begin{array}{rlrl} {\text{Minimize~}\quad} & {q(x_{0},\ldots,x_{m})\qquad} & & \qquad \\ {\text{subject~to~}\quad} & {x_{j} \in \{ 0,1\},\qquad j = 0,\ldots,m\qquad} & & \qquad \\ \end{array}

where is a quadratic polynomial on the variables. The reason why these problems are called QUBO should now be clear: we are minimizing quadratic expressions over binary variables with no restrictions (because every combination of zeroes and ones is acceptable).

From the preceding reduction of the Subset Sum problem, it follows that QUBO problems are -hard. Indeed, the QUBO model is very flexible, and it enables us to formulate many optimization problems in a natural way. For example, it is quite easy to recast any Ising minimization problem as a QUBO instance. If you need to minimize

- \sum\limits_{j,k}J_{jk}z_{j}z_{k} - \sum\limits_{j}h_{j}z_{j}

with some variables , , taking values or , you can define new variables . Obviously, will be when is , and when is . Furthermore, if you make the substitutions , you obtain a quadratic polynomial in the binary variables that takes exactly the same values as the energy function of the original Ising model. If you minimize the polynomial for the variables , you can then recover the spin values that achieve the minimal energy.

In case you were wondering, yes, you can also use the substitution to transform Ising problems into QUBO formalism. In that case, values of equal to would be taken to values of equal to and values of equal to would be taken to in . However, we will stick to the transformation for the rest of the book.

For instance, if the Ising energy is given by , then, under the transformation , the corresponding QUBO problem will be the following:

\begin{array}{rlrl} {\text{Minimize~}\quad} & {- 2x_{0}x_{1} + x_{0} + x_{1} - 2x_{2} + \frac{1}{2}\qquad} & & \qquad \\ {\text{subject~to~}\quad} & {x_{j} \in \{ 0,1\},\qquad j = 0,1,2.\qquad} & & \qquad \\ \end{array}

You can also go from a QUBO problem to an Ising model instance by using the substitution. However, you will need to pay attention to a couple of details. Let's illustrate them with an example. Suppose that your QUBO problem is asking to minimize . Then, when you substitute the variables, you obtain

\frac{z_{0}^{2}}{4} + \frac{z_{0}z_{1}}{2} - z_{0} - \frac{z_{1}}{2} - \frac{9}{4}.

But the Ising model does not allow squared variables or independent terms! Fixing these problems is not difficult, though. Regarding the squared variables, we can simply notice that it always holds that , because is either or . Thus, we replace each squared variable with the constant value . In our case, we would get

\frac{1}{4} + \frac{z_{0}z_{1}}{2} - z_{0} - \frac{z_{1}}{2} - \frac{9}{4} = \frac{z_{0}z_{1}}{2} - z_{0} - \frac{z_{1}}{2} - 2.

Then, we can simply drop the independent term, because we are dealing with a minimization problem and it won't influence the choice of optimal variables (however, you should add it back when you want to recover the original value of the function to minimize). In the preceding example, the equivalent Ising minimization problem would then be the following:

\begin{array}{rlrl} {\text{Minimize~}\quad} & {\frac{z_{0}z_{1}}{2} - z_{0} - \frac{z_{1}}{2}\qquad} & & \qquad \\ {\text{subject~to~}\quad} & {z_{j} \in \{ 1, - 1\},\qquad j = 0,1,2.\qquad} & & \qquad \\ \end{array}

It is easy to check that this problem has two optimal solutions: and , both attaining the value. If we add back the independent term of value that we had dropped, we obtain an optimal cost of in the QUBO problem. These solutions correspond to and , respectively, which indeed evaluate to and are optimal for the original problem.

Exercise 3.5

Write the Subset Sum problem for and as a QUBO problem and transform it into an instance of the Ising model.

So now we know how to go from QUBO problems to Ising energy minimization problems and back, and we can use either formalism — whichever is more convenient at any given moment. In fact, as we will learn in Chapters 4 and 5, the Ising model is the preferred formulation when solving combinatorial optimization problems with quantum computers. Also, the software tools that we will be using (Qiskit and D-Wave's Ocean) will help us in rewriting our QUBO problems in the Ising formalism by using transformations like the ones we have described in this section.

We now have all the mathematical tools that we need in order to work with combinatorial optimization problems if we want to solve them with quantum computers. Let's play with our new, shiny toys and use them to write some important problems in QUBO formalism.

lock icon The rest of the chapter is locked
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