Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying A Practical Guide to Quantum Computing
  • Table Of Contents Toc
A Practical Guide to Quantum Computing

A Practical Guide to Quantum Computing

By : Elías F. Combarro Fernández-Combarro Álvarez, Samuel González Castillo
3 (1)
close
close
A Practical Guide to Quantum Computing

A Practical Guide to Quantum Computing

3 (1)
By: Elías F. Combarro Fernández-Combarro Álvarez, Samuel González Castillo

Overview of this book

This book is an introduction, from scratch, to quantum computing and the most important and foundational quantum algorithms—ranging from humble protocols such as Deutsch’s algorithm to ones with far-reaching potential, such as Shor’s factoring algorithm—offering clear explanations and a hands-on approach with runnable code on simulators and real hardware. The book is self-contained and does not assume any previous experience in quantum computing. Starting with a single qubit, it scales to algorithms using superposition and entanglement. At every step, examples of applications are provided, including how to create quantum money that is impossible to forge, quantum cryptography that cannot be broken, and algorithms for searching and factoring that are much faster than those that regular, non-quantum computers can use. Code for each of these algorithms is provided (and explained in detail) using Qiskit 2.1. After reading this book, you will understand how quantum algorithms work, how to write your own quantum programs, and how to run them on quantum simulators and actual quantum computers. You will also be prepared to take the jump into quantum algorithms for optimization and artificial intelligence, like those presented in our previous book, A Practical Guide to Quantum Machine Learning and Quantum Optimization.
Table of Contents (29 chapters)
close
close
Preface
chevron up
Lock Free Chapter
1
Part 1 One Qubit to Rule Them All: Working with One Qubit
6
Part 2 Qubit Meets Qubit: Two Qubits and Entanglement
10
Part 3 Working with Many Qubits
14
Part 4 The Stars of the Show: Main Quantum Algorithms
18
Part 5 Ad Astra: The Road to Quantum Utility and Advantage
21
Bibliography
23
Index
3
Appendix C Measuring the Complexity of Algorithms
5
Appendix E Production Notes

Preface

Nature isn’t classical, dammit, and if you want to make a simulation of nature, you’d better make it quantum mechanical, and by golly it’s a wonderful problem, because it doesn’t look so easy.
Richard Feynman

Almost three years ago, we sat down to write a little book (well, at that time, we thought it would be little) titled A Practical Guide to Quantum Machine Learning and Quantum Optimization . It was a new, exciting and unforgettable adventure, and we had tons and tons of fun because we made it  for us.

It is a clich é to say that you should write the book that you would like to read, but, what can we say? We are all for clich és and that’s what we did. We wrote the book that we would’ve liked to read when we started studying quantum machine learning and quantum optimization. A book with mathematical rigor, because you cannot understand quantum computing without all the formulas, but also with code that you can run to obtain results, because quantum computing should be, first and foremost, about computing .

So we wrote the book mainly for us  and we still can’t believe how many people found our way of explaining quantum computing useful and even entertaining. Since the book was published, we’ve received feedback from many readers that liked the book and, to our surprise, wanted more.

At the same time, quantum computing has surged in popularity. In the last few years, more and more people have became interested in learning how to program quantum computers and the number of courses on the topic offered by universities all over the world has grown exponentially. Moreover, with 2025 proclaimed by the United Nations as the International Year of Quantum Science and Technology, this trend will very likely continue and multiply.

For all these reasons, even if we believed that writing A Practical Guide to Quantum Machine Learning and Quantum Optimization had been a once-in-a-lifetime adventure, when the wonderful people at Packt reached to us again wondering whether we’d be interested in writing a new book, we thought that it was a brilliant idea. In fact, we still had a thing or two to write about quantum computing, so why not?

In our previous book, we decided to focus on what we call “modern” quantum algorithms: variational algorithms, quantum annealing, and other techniques that try to put the kind of quantum computers that are available today to good use in tasks such as data classification and combinatorial optimization. But, in fact, the development of quantum computing as a field did not start with these kinds of applications in mind. Algorithms such as the ones proposed by Grover, Shor, and other visionaries, are quite different from the ones that we presented in our previous book  but equally important and fascinating.

In A Practical Guide to Quantum Machine Learning and Quantum Optimization we decided to skip many wonderful applications of quantum computing to focus on these modern quantum algorithms. And, though we of course love all the new developments that the quantum computing community has come up with in recent years, we’ve always had a bit of a regret for not having been able to include other, more foundational algorithms and protocols.

Understanding how the quantum Fourier transform works or how quantum teleportation is achieved is not only fascinating in itself, but crucial to comprehend what quantum computers can do and how they do it. It is obviously great to be able to apply variational circuits to learn patters in datasets or to find ground states of Hamiltonians, but if you’ve never heard of Deutsch’s algorithm or you do not know how to implement Grover’s search, your grasp of quantum computing will be inevitably incomplete.

With the book that you now hold in your hands, we try to put a remedy to that. Our focus is, now, on the foundations of quantum computing. In some sense, you could think of this new book as a prequel to our previous one. If you’ve already read A Practical Guide to Quantum Machine Learning and Quantum Optimization , you will find here some concepts that you already know about. And you will learn much more about them, in the same way that you learned much more about Obi-Wan Kenobi and Anakin Skywalker when you watched The Phantom Menace after being acquainted with them from the original Star Wars trilogy 1 . And the great thing is that, if you’ve never read our previous book, you will not miss anything! 2

Our approach to explaining the topics covered in this book is, essentially, the same that we followed in A Practical Guide to Quantum Machine Learning and Quantum Optimization . We start completely from scratch and we do not assume any knowledge of quantum physics. In fact, we can assure you that quantum physics is even less necessary to understand this book than it was for our previous one. And you don’t need to know a lot of math either—just some basic algebraic concepts, such as what a matrix and a vector are, and how to multiply them. By the way, if you need a refresher on these or other mathematical concepts, you can always refer to the Appendices at the end of the book.

Another key characteristic of our approach to introducing concepts is that we firmly believe in the importance of a gradual progression—from simple ideas to more complex ones—allowing you to build confidence and understanding step by step. We start very humbly, focusing on a simple qubit. And we spend a lot of time studying one-qubit systems before moving further. But we think you’ll find this approach helpful in developing a deep understanding that serves as a solid foundation for more complex algorithms and techniques.

In A Practical Guide to Quantum Machine Learning and Quantum Optimization , most chapters included a mix of mathematical concepts and code. However, in this new book, we have decided to split into different chapters the abstract discussion of the algorithms and protocols that we introduce, and their practical implementation through code. We feel that this works better in this case, because most algorithms are self-contained and it is better to explore them as a whole before attempting to fully implement them.

The quantum programming framework that we have selected for our implementations is Qiskit, concretely version 2.1. Qiskit is, by far, the most popular quantum computing platform out there and it is especially suitable for the kind of algorithms and protocols that we study in this book. Additionally, over the last few years, Qiskit has reached a much bigger stability and maturity, making it even more appealing to implement foundational quantum algorithms.

The style of our exposition is mainly informal, without following the usual structure of definition-theorem-proof-corollary of many mathematical texts, but without sacrificing rigor at any point in the book. Whenever possible, we give detailed derivations that justify the mathematical properties that we use in our developments and analyses (or, at least, we provide an argument that may be extended to a full proof by just adding some small technical details). In the cases that proving a particular fact is beyond the scope of the book, we provide references in which a full treatment can be found.

Throughout all the text, we propose exercises that will help you understand important concepts and develop practical skills for manipulating formulas and writing your own quantum code. They are intended to be readily solved (we try to give useful hints for those exercises that are a little bit more challenging), but, at the end of the book, we provide full, detailed solutions so that you can check your understanding of the subject.

Quantum computing is a field in constant evolution, so we feel that it is especially important to give pointers to new developments, to variants of the algorithms that we present in the book, and to alternative approaches to solve the kind of problems that we study. We do this by including numerous boxes with the label “To learn more …”. You can skip these boxes if you wish, as they are not necessary to follow the main text. However, we strongly recommend reading them, since they help to situate in a wider context the topics under study. Other boxes that we use throughout the book serve to highlight important facts, to give warnings about subtle points, or to remind you of central definitions and formulas. These should not be skipped. They are labeled “Important note” for a reason!

Writing this book was a lot of fun. Again, this is the kind of book that we would have liked to have read when we first delved into the field of quantum computing. We wrote it, mainly, for ourselves. But we hope that you find it useful too. Enjoy the ride!

Who this book is for

This book would be ideal for university-level students in computer science, mathematics, physics, or other STEM fields taking introductory-level courses on quantum computing. It would also suit professionals, researchers, and self-learners with a STEM background. Potential readers of our previous book, A Practical Guide to Quantum Machine Learning and Quantum Optimization , will benefit from first building foundational quantum computing skills with this book.

More broadly, this book would also be a good fit for people who are curious about quantum computing and want to understand it from a rigorous and hands-on perspective, exploring the details of the most well-known quantum algorithms.

What this book covers

This book is organized into five parts, an afterword, and some appendices, as follows:

Part  I, One Qubit to Rule Them All: Working with One Qubit

Chapter  1, What Is (and What Is Not) a Quantum Computer , serves as an introduction to the rest of the book, clarifying what a quantum computer is, how it is different from a classical computer, and why quantum algorithms can outperform classical ones on some tasks.

Chapter  2, Qubits, Gates, and Measurements , discusses what single-qubit systems are and how they can be represented, measured, and transformed. This chapter lays down the most basic theoretical foundation for working with quantum algorithms, as qubits are the fundamental unit of quantum information (analogous to bits in classical computing). The remaining chapters in the book build upon this one.

Chapter  3, Applications and Protocols with One Qubit , explores how, while a humble qubit may not seem like much, it already enables a few practical applications. In this chapter, we show how one-qubit systems can be used to implement key distribution schemes and quantum money that is impossible to forge.

Chapter  4, Coding One-Qubit Protocols in Qiskit , introduces the Qiskit framework and we briefly mention and discuss other platforms for quantum computing. We also show how one-qubit protocols can actually be implemented and run using Qiskit.

Part  II, Qubit Meets Qubit: Two Qubits and Entanglement

Chapter  5, How to Work with Two Qubits , takes one step further in generality and introduces two-qubit systems. In a structure analogous to that of Chapter  2, we discuss how the state of a two-qubit system can be represented and how these systems can be measured and transformed.

Chapter  6, Applications and Protocols with Two Qubits , looks at how, following the introduction of two-qubit systems, we can exploit new quantum phenomena such as entanglement, and we are in a position to unlock new and very interesting applications; this is what this chapter is devoted to. The applications that we discuss in this chapter are not just appealing in and of themselves, but they also give us an opportunity to discuss how quantum algorithms take advantage of quantum phenomena in the construction of quantum algorithms.

Chapter  7, Coding Two-Qubit Algorithms in Qiskit , succinctly reviews the core principles of the Qiskit framework and introduces how two-qubit systems can be handled in Qiskit. Then we show how the protocols and algorithms discussed in Chapter  6 can be implemented and run using Qiskit.

Part  III, Working with Many Qubits

Chapter  8, How to Work with Many Qubits , allows us to capitalize on having mastered two-qubit systems, and with a full understanding of how to work with them, we are in a position to take the final step in our inductive journey and unleash the full power of quantum computing, introducing systems with an arbitrarily large number of qubits. This chapter introduces multi-qubit systems as a generalization of two-qubit systems, showing how they can be represented, measured, and transformed.

Chapter  9, The Full Power of Quantum Algorithms, introduces some simple quantum algorithms that fully demonstrate how quantum superposition, entanglement, and interference can be used in practice. These algorithms perfectly illustrate the capabilities and limitations of quantum computing, and they serve as a foundational step towards the more sophisticated algorithms that are introduced in the following chapters.

Chapter  10, Coding with Many Qubits in Qiskit , culminates our inductive introduction to Qiskit by showing how to work with an arbitrary number of qubits in it. As a means of illustrating this and reviewing the content covered in the previous chapter, we show how the Deutsch-Jozsa and Bernstein-Vazirani algorithms can be implemented in Qiskit.

Part  IV, The Stars of the Show: Main Quantum Algorithms

Chapter  11, Finding the Period and Factoring Numbers , looks at Shor’s factoring algorithm—probably the best-known quantum algorithm. It has been a crucial reason why social interest in quantum computing has risen quickly over the last few decades. In this chapter, we introduce Shor’s algorithm, first explaining why it is significant, with a special emphasis on its implications in cybersecurity. We then discuss all the details of the algorithm, taking a rigorous approach, but with plenty of informal and intuitive explanations.

Chapter  12, Searching and Counting with a Quantum Computer , discusses Grover’s algorithm, which is a quantum search algorithm. We begin by introducing the problem of searching for elements through an unsorted list, commenting on the computational complexity of this problem for classical computers. This sets the scene for the introduction of Grover’s algorithm, which can provide a quadratic speedup over classical methods. We also discuss how the quantum Fourier transform that we covered in the previous chapter can fit with Grover’s algorithm in order to allow search results to be counted.

Chapter  13, Coding Shor and Grover’s Algorithms in Qiskit, explores how Grover and Shor’s algorithm will have far-reaching applications in real-world scenarios once quantum hardware becomes powerful enough to support them. In this chapter, we show how these algorithms can be programmed with Qiskit. We also include a section devoted to the implementation of the quantum Fourier transform in Qiskit.

Part  V, Ad Astra: The Road to Quantum Utility and Advantage

Chapter  14, Quantum Error Correction and Fault Tolerance , introduces quantum error correction, which could pave the road towards fault-tolerant computation and thus may be a cornerstone in the development of useful quantum computers. This chapter begins with a discussion on the necessity for quantum error correction, which is followed by the introduction and implementation of a simple quantum error-correcting code. The chapter finishes with some remarks on fault-tolerant computing and how quantum error correction can help enable it.

Chapter  15, Experiments for Quantum Advantage , is devoted to understanding quantum advantage, specifically recent experiments with random circuit sampling. We unpack the main concepts involved in these experiments and we give some clarifying examples using Qiskit. In addition to this, and as a way of wrapping up the book, we take the chance to sketch some ideas about what lies ahead in the road of quantum computing.

Appendices

Appendix  A, Mathematical Tools , provides a refresher on the fundamentals of linear algebra, including vectors and matrices, and important notions such as bases and eigenvalues. In addition, it gives a quick recap of the most relevant properties of complex numbers and how to operate with them, and it even covers some concepts from modular arithmetic.

Appendix  B, The Bra-Ket Notation and Other Foundational Notions , explores in depth the details behind the “bra-ket” notation that we use throughout the book and that is ubiquitous in the quantum computing literature. We will also briefly touch upon a very widely used tool to represent one-qubit states: the Bloch sphere.

Appendix  C, Measuring the Complexity of Algorithms , serves as a quick introduction to measuring the resources needed to solve problems with algorithms. It defines some important concepts that are used throughout the book, such as the big O notation.

Appendix  D, Installing the Tools , guides you through the process of installing the libraries needed in order to run the code included in this book.

Appendix  E, Production Notes , gives a glimpse of the process of writing a technical book like this one, including the software used to typeset and prepare the content.

Solutions contains the solutions to all the exercises proposed in the main text.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, filenames, file extensions, URLs, and user input. Here is an example: “We could create a QuantumCircuit object and directly use its draw method”.

A block of code is set as follows:

 from qiskit import QuantumCircuit 
 circuit = QuantumCircuit (1)

Important ideas are highlighted in boxes like the following:

Important note

I am a box. I feel important. That’s because I am important.

We sometimes include material for those of you who want to learn more. We format it as follows:

To learn more

You don’t have to read me if you don’t want to.

There are a few exercises in the text, which are displayed as follows:

Exercise 0.1. Prove that every even number greater than two can be written as the sum of two prime numbers.

To get the most out of this book

The concepts explained in this book are better understood by implementing algorithms that solve practical problems and by running them on simulators (or actual quantum computers!). You will learn how to do all that starting from the very beginning of the book, but in order to run the code you will need to install some tools.

We recommend that you download the Jupyter notebooks from the link provided in the following section and that you follow the instructions given in Appendix  B.2 to get your environment ready to rock!

Download the example code files

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/A-Practical-Guide-to-Quantum-Computing. In case there’s an update to the code, it will be uploaded to the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
A Practical Guide to Quantum Computing
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon