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 1. Part I: I, for One, Welcome our New Quantum Overlords
2. Chapter 1: Foundations of Quantum Computing 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

Chapter 10
Quantum Neural Networks

The mind is not a vessel to be filled, but a fire to be kindled.
— Plutarch

In the previous chapter, we explored our first family of quantum machine learning models: quantum support vector machines. Now it is time for us to take one step further and consider yet another family of models, that of Quantum Neural Networks (QNNs).

In this chapter, you will learn how the notion of a quantum neural network can arise naturally from the ideas behind classical neural networks. Of course, you will also learn how quantum neural networks work and how they can be trained. Then, you will explore how quantum neural networks can actually be implemented, run, and trained using the two quantum frameworks that we have been working with so far: Qiskit and PennyLane.

These are the contents of this chapter:

  • Building and training quantum neural networks

  • Quantum neural networks in PennyLane

  • Quantum neural networks in Qiskit: a commentary

Quantum support vector machines...

10.1 Building and training a quantum neural network

Just like quantum support vector machines, quantum neural networks are what we called ”CQ models” back in Chapter 8, What is Quantum Machine Learning?, — models with purely classical inputs and outputs that use quantum computing at some stage. However, unlike QSVMs, quantum neural networks are not a ”particular case” of any classical model, although their behavior is inspired by that of classical neural networks. What is more, as we will soon see, quantum neural networks are ”purely quantum” models, in the sense that their execution will only require classical computing for the preparation of circuits and the statistical analysis of measurements. Nevertheless, just like QSVMs, quantum neural networks will depend on classical parameters that will be optimized classically.

To learn more

As you surely know by now, (quantum) machine learning is a vast field in which terms hardly...

10.2 Quantum neural networks in PennyLane

We are now ready to implement and train our first quantum neural network with PennyLane. The PennyLane framework is great for many applications, but it shines the most when it comes to the implementation of quantum neural network models. This is all due to its flexibility and good integration with classical machine learning frameworks. We, in particular, are going to be using PennyLane in conjunction with TensorFlow to train a QNN-based binary classifier. All that effort that we invested in Chapter 8, What is Quantum Machine Learning?, is finally going to pay off!

Important note

Remember that we are using version 2.9.1 of the TensorFlow package and version 0.26 of PennyLane.

Let’s begin by importing PennyLane, NumPy, and TensorFlow and setting some seeds for these packages, just to make sure that our results are reproducible. We can achieve this with the following piece of code:

import pennylane as qml 
 
import numpy as np 
 
import...

10.3 Quantum neural networks in Qiskit: a commentary

In the previous section, we had a chance to explore in great depth the implementation and training of quantum neural networks in PennyLane. We won’t do an analogous discussion for Qiskit in such a level of detail, but we will at least give you a few ideas about how to get started should you ever need to use Qiskit in order to work with quantum neural networks.

PennyLane provides a very homogeneous and flexible experience. No matter if you’re training a simple binary classifier or a complex hybrid architecture like the ones we will study in the following chapter, it’s all done in the same way.

Qiskit, by contrast, provides a more ”structural” approach. It gives you a suite of classes that can be used to train different kinds of neural networks and that allow you to define your networks in different ways. It’s difficult to judge whether this is a better or worse approach; in the end, it’...

Summary

This has been a long journey, hasn’t it? In this chapter, we first introduced quantum neural networks as quantum analogs of classical neural networks. We have seen how the training of a quantum neural network is very similar to that of a classical one, and we’ve also explored the differentiation methods that make this possible.

With the theory out of the way, we got our keyboards ready to do some work. We learned how to implement and train a quantum neural network using PennyLane, and we also discussed some technicalities about this framework, such as details about the differentiation methods that it provides.

PennyLane comes with some wonderful simulators, but — as we already mentioned in Chapter 2, The Tools of the Trade in Quantum Computing — it’s also integrated with quantum hardware platforms such as Amazon Braket and IBM Quantum. Thus, your ability to train quantum neural networks on actual quantum computers is at your fingertips!

We concluded...

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