Share E-Book

Quantum Computing in Action (Johan Vos)(Z-Library)

Author

Technology
Language English

Quantum computing is on the horizon and you can get started today! This practical, clear-spoken guide shows you don’t need a physics degree to write your first quantum software. In Quantum Computing in Action you will learn: • An introduction to the core concepts of quantum computing • Qubits and quantum gates • Superposition, entanglement, and hybrid computing • Quantum algorithms including Shor’s, Deutsch-jozsa, and Grover’s search

Format PDF
Size 18.9 MB
7
Views
0
Downloads
0.00
Total Donations
(First 20 pages)

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Page 1
M A N N I N G Johan Vos Examples in Java IN ACTION
Page 2
Quantum Computing in Action JOHAN VOS MANN I NG SHELTER ISLAND
Page 3
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email: orders@manning.com ©2022 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. The author and publisher have made every effort to ensure that the information in this book was correct at press time. The author and publisher do not assume and hereby disclaim any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from negligence, accident, or any other cause, or from any usage of the information herein. Development editor: Dustin Archibald Technical development editors: Jan Goyvaerts, Alain Couniot Manning Publications Co. Review editors: Ivan Martinović, Adriana Sabo 20 Baldwin Road Production editor: Andy Marinkovich PO Box 761 Copy editor: Tiffany Taylor Shelter Island, NY 11964 Proofreader: Melody Dolab Technical proofreader: Nick Watts Typesetter: Dennis Dalinnik Cover designer: Marija Tudor ISBN: 9781617296321 Printed in the United States of America
Page 4
brief contents PART 1 QUANTUM COMPUTING INTRODUCTION ........................1 1 ■ Evolution, revolution, or hype? 3 2 ■ “Hello World,” quantum computing style 19 3 ■ Qubits and quantum gates: The basic units in quantum computing 31 PART 2 FUNDAMENTAL CONCEPTS AND HOW THEY RELATE TO CODE.........................................................47 4 ■ Superposition 49 5 ■ Entanglement 68 6 ■ Quantum networking: The basics 88 PART 3 QUANTUM ALGORITHMS AND CODE ...........................113 7 ■ Our HelloWorld, explained 115 8 ■ Secure communication using quantum computing 137 9 ■ Deutsch-Jozsa algorithm 159 10 ■ Grover’s search algorithm 182 11 ■ Shor’s algorithm 207iii
Page 5
(This page has no text content)
Page 6
contents preface xi acknowledgments xiii about this book xv about the author xviii about the cover illustration xix PART 1 QUANTUM COMPUTING INTRODUCTION...............1 1 Evolution, revolution, or hype? 3 1.1 Expectation management 4 Hardware 4 ■ Software 6 ■ Algorithms 9 ■ Why start with QC today? 10 1.2 The disruptive parts of QC: Getting closer to nature 11 Evolutions in classical computers 12 ■ Revolution in quantum computers 12 ■ Quantum physics 12 1.3 Hybrid computing 13 1.4 Abstracting software for quantum computers 14 1.5 From quantum to computing or from computing to quantum 17v
Page 7
CONTENTSvi2 “Hello World,” quantum computing style 19 2.1 Introducing Strange 20 2.2 Running a first demo with Strange 20 2.3 Inspecting the code for HelloStrange 23 The build procedures 23 ■ The code 25 ■ Java APIs vs. implementations 27 2.4 Obtaining and installing the Strange code 28 Downloading the code 28 ■ A first look at the library 29 2.5 Next steps 29 3 Qubits and quantum gates: The basic units in quantum computing 31 3.1 Classic bit vs. qubit 32 3.2 Qubit notation 33 One qubit 34 ■ Multiple qubits 34 3.3 Gates: Manipulating and measuring qubits 37 3.4 A first [quantum] gate: Pauli-X 39 3.5 Playing with qubits in Strange 40 The QuantumExecutionEnvironment interface 41 ■ The Program class 41 ■ Steps and gates 41 ■ Results 42 3.6 Visualizing quantum circuits 43 PART 2 FUNDAMENTAL CONCEPTS AND HOW THEY RELATE TO CODE ...............................................47 4 Superposition 49 4.1 What is superposition? 50 4.2 The state of a quantum system as a probability vector 54 4.3 Introducing matrix gate operations 58 The Pauli-X gate as a matrix 59 ■ Applying the Pauli-X gate to a qubit in superposition 60 ■ A matrix that works for all gates 62 4.4 The Hadamard gate: The gate to superposition 63 4.5 Java code using the Hadamard gate 65
Page 8
CONTENTS vii5 Entanglement 68 5.1 Predicting heads or tails 69 5.2 Independent probabilities: The classic way 69 5.3 Independent probabilities: The quantum way 73 5.4 The physical concept of entanglement 75 5.5 A gate representation for quantum entanglement 79 Converting to probability vectors 79 ■ CNot gate 80 5.6 Creating a Bell state: Dependent probabilities 83 5.7 Mary had a little qubit 86 6 Quantum networking: The basics 88 6.1 Topology of a quantum network 90 6.2 Obstacles to quantum networking 92 Classical networking in Java 92 ■ No-cloning theorem 96 Physical limitations on transferring qubits 99 6.3 Pauli-Z gate and measurement 99 Pauli-Z gate 100 ■ Measurements 101 6.4 Quantum teleportation 102 The goal of quantum teleportation 102 ■ Part 1: Entanglement between Alice and Bob 102 ■ Part 2: Alice’s operations 103 Part 3: Bob’s operations 104 ■ Running the application 105 Quantum and classical communication 108 6.5 A quantum repeater 109 PART 3 QUANTUM ALGORITHMS AND CODE..................113 7 Our HelloWorld, explained 115 7.1 From hardware to high-level languages 116 7.2 Abstractions at different levels 118 7.3 Other languages for quantum computing simulators 119 Approaches 119 ■ Resources for other languages 119 7.4 Strange: High-level and low-level approaches 119 Top-level API 120 ■ Low-level APIs 121 ■ When to use what 122 7.5 StrangeFX: A development tool 123 Visualization of circuits 123 ■ Debugging Strange code 124
Page 9
CONTENTSviii7.6 Creating your own circuits with Strange 128 Quantum arithmetic as an introduction to Shor’s algorithm 128 Adding two qubits 128 ■ Quantum arithmetic with a carry bit 131 ■ Next steps 133 7.7 Simulators, cloud services, and real hardware 133 8 Secure communication using quantum computing 137 8.1 The bootstrap problem 137 Issues with sending bits over a network 138 ■ One-time pad to the rescue 140 ■ Sharing a secret key 141 8.2 Quantum key distribution 142 8.3 Naive approach 142 8.4 Using superposition 145 Applying two Hadamard gates 146 ■ Sending qubits in superposition 147 8.5 BB84 151 Confusing Eve 151 ■ Bob is confused, too 153 ■ Alice and Bob are talking 154 8.6 QKD in Java 155 The code 155 ■ Running the application 157 9 Deutsch-Jozsa algorithm 159 9.1 When the solution is not the problem 159 9.2 Properties of functions 161 Constant and balanced functions 162 9.3 Reversible quantum gates 165 Experimental evidence 165 ■ Mathematical proof 166 9.4 Defining an oracle 167 9.5 From functions to oracles 170 Constant functions 171 ■ Balanced functions 172 9.6 Deutsch algorithm 173 9.7 Deutsch-Jozsa algorithm 178 9.8 Conclusion 180
Page 10
CONTENTS ix10 Grover’s search algorithm 182 10.1 Do we need yet another search architecture? 183 Traditional search architecture 183 ■ What is Grover’s search algorithm? 184 10.2 Classical search problems 185 General preparations 186 ■ Searching the list 187 ■ Searching using a function 189 10.3 Quantum search: Using Grover’s search algorithm 191 10.4 Probabilities and amplitudes 193 Probabilities 193 ■ Amplitudes 195 10.5 The algorithm behind Grover’s search 196 Running the example code 197 ■ Superposition 199 Quantum oracle 200 ■ Grover diffusion operator: Increasing the probability 204 10.6 Conclusion 205 11 Shor’s algorithm 207 11.1 A quick example 207 11.2 The marketing hype 208 11.3 Classic factorization vs. quantum factorization 209 11.4 A multidisciplinary problem 211 11.5 Problem description 212 11.6 The rationale behind Shor’s algorithm 214 Periodic functions 214 ■ Solving a different problem 215 Classic period finding 218 ■ The post-processing step 219 11.7 The quantum-based implementation 222 11.8 Creating a periodic function using quantum gates 224 The flow and circuit 224 ■ The steps 225 11.9 Calculating the periodicity 226 11.10 Implementation challenges 227 appendix A Getting started with Strange 229 appendix B Linear algebra 234 index 239
Page 11
(This page has no text content)
Page 12
preface I started working on my PhD thesis in 1995 at Delft University of Technology in the Netherlands. My work was mainly focused on the acoustic wave equation, and I needed to combine theoretical models with experimental data, which, of course, required data processing and visualization. Around that same time, a new program- ming language named Java was unveiled. Several things made Java attractive for scien- tific work, including its portability to different platforms, which made it easy to create applications with a user interface and execute them on the various platforms I was working on. However, it occurred to me that there was a large gap between the scientific world and the IT world. While researchers in science are typically trying to find answers to difficult questions, ITers are working on implementing the results of science and deal- ing with scalability, failover, code reuse, and functional or object-oriented develop- ment. Often, ideas and models created by scientists need to be implemented by ITers. Scientists should not worry about unit tests, while ITers should not have knowledge of the Standard Model of physics; but somehow, the handover between the two areas should be smooth. I was privileged to be a frequent co-speaker with James Weaver, a long-time Java expert who became interested in quantum computing. Because of my background in science, he asked me to co-present on quantum computing. If you need to do a presentation about something, it often helps if you know at least something about the subject. Even though I had worked on the acoustic wave equation, quantum computing was something different. Hence, I was forced to learnxi
Page 13
PREFACExiiabout quantum computing. The best way to learn something is to work with it; so, to understand quantum computing, I created a simulator of a quantum computer in Java, named Strange. Step by step, I added functionality to Strange, and by imple- menting it, I got a better idea of what quantum computing means for developers. My general observation that scientists face different issues than developers turned out to be true for quantum computing. I believe that one of the significant challenges in quantum computing is finding ways for existing developers to use quantum computing without requiring them to understand the physics behind it. But it also works the other way: great algorithms that may lead to improvements in various areas often require a good understanding of modern IT development before they can be successful. It is my belief that quantum computing can lead to major breakthroughs in several domains, including healthcare and security. With this book, I hope to explain to developers how you can benefit from quantum computing without having to become experts in quantum physics.
Page 14
acknowledgments Thank you to my family for their constant support and patience, which has provided me the opportunity to write this book. I’d like to thank my colleagues at Gluon for their support, especially in many technical ways. Likewise, the continuous support and encouragement from the Java and JavaFX communities has motivated me to make this a book that is useful to developers. Many thanks to the entire Manning team who helped me realize this book. In par- ticular, I’d like to thank Mike Stephens, Andrew Waldron, Dustin Archibald, Alain Couniot, Jan Goyvaerts, and Candace Gillhoolley for your knowledge and guidance along the way. Thanks also to Tiffany Taylor, Keir Simpson, Melody Dolab, Meredith Mix, and Andy Marinkovich for guiding the book through production and for your com- mitment to making the book the best it can be. For obvious reasons, the past couple of years have been intense. We are certainly liv- ing in a strange time in which scientific work has become more relevant than ever. Study- ing quantum computing forced me to dive deep into the mysteries of nature. I am very grateful to all the scientists who are working to understand and explain the fundamental concepts of nature, so that hardware and software developers can work on concrete ben- efits based on those new insights. To all the reviewers: Aleksandr Erofeev, Alessandro Campeis, Antonio Magnaghi, Ariel Gamino, Carlos Aya-Moreno, David Lindelof, Evan Wallace, Flavio Diez, Girish Ahankari, Greg Wright, Gustavo Filipe Ramos Gomes, Harro Lissenberg, Jean-François Morin, Jens Christian Bredahl Madsen, Kelum Prabath Senanayake, Ken W. Alger,xiii
Page 15
ACKNOWLEDGMENTSxivMarcel van den Brink, Michael Wall, Nathan B Crocker, Patrick Regan, Potito Coluccelli, Rich Ward, Roberto Casadei, Satej Kumar Sahu, Vasile Boris, Vlad Navitski, William E. Wheeler, and William W. Fly; your suggestions helped make this a better book.
Page 16
about this book Most available resources about quantum computing are about either the mind-boggling physics that is used to enable quantum computing or the high-level consequences that can be expected when quantum computing becomes mainstream. In this book, we address the questions many developers ask: How will quantum computing affect my daily development, and how can I benefit from it? To answer this, we look at quantum computing from the perspective of a developer: we assume that hardware is or will be available (via native hardware or simulators), and we write code that is agnostic to mar- keting hype. Who should read this book? This book is written for developers who are interested in knowing whether and how they can benefit from quantum computing, now or in the future, or in general, what impact will quantum computing have on their work. The reader is not expected to know anything about quantum physics. The book explains the areas where quantum computing might lead to improvements and how developers can use it similarly to how they use modern hardware (such as GPUs) without knowing the internal details. How this book is organized: a roadmap This book contains three parts. Part 1 gives some basic information about quantum computing. Part 2 introduces the fundamental concepts that make quantum comput- ing different from classical computing. Part 3 covers algorithms and code that are directly applicable to existing developers, and that use quantum advantages.xv
Page 17
ABOUT THIS BOOKxviPart 1 introduces quantum computing: Chapter 1 discusses the importance of quantum computing without using buzz- words or participating in the hype. Down-to-earth developers often say, “Show me the code,” and that is what this book does. In chapter 2, we build our first Java application (the typical HelloWorld applica- tion) using the Java-based quantum simulator Strange. The Strange quantum simulator shields developers from the low-level details of quantum computing yet provides APIs that internally benefit from quantum concepts. Chapter 3 introduces the qubit as the fundamental building block in quantum computing, similar to the regular bit in classical computing. Part 2 introduces the relevant concepts of quantum computing: Chapter 4 discusses superposition, one of the core principles of quantum phys- ics. This chapter contains code that allows you to use quantum superposition in your Java applications. Chapter 5 explains how different qubits can stay connected via quantum entan- glement and what that means for applications. Chapter 6 introduces quantum networking as a specific application of quantum computing. Part 3 deals with code examples and gradually introduces more complex algorithms that are useful to developers. Although the focus is on explaining the use of the algo- rithms, some explanations of the internals of the algorithms are given, as well, to help you work on similar algorithms: Chapter 7 explains the HelloWorld application shown in chapter 2. This simple application has no direct benefits (similar to HelloWorld applications in gen- eral) but shows how quantum applications can be created. Chapter 8 builds on chapters 6 and 7 and shows how a Java application can be created that uses quantum networking and provides a secure communication channel between two parties. Chapter 9 explains the Deutsch-Jozsa algorithm. This algorithm is easy to imple- ment in Java with Strange, and it familiarizes you with some of the typical pat- terns in quantum computing. Chapter 10 discusses one of the most famous quantum algorithms: Grover’s search algorithm. This algorithm has real practical implications for developers. Chapter 11 is about Shor’s algorithm, which is probably the most popular exist- ing quantum algorithm. This algorithm requires a combination of classical and quantum computing, and is therefore a great topic to conclude the book.
Page 18
ABOUT THIS BOOK xviiAbout the code Throughout this book, many examples and demo applications are shown and refer- enced. Those applications use the Strange quantum simulator. Because Strange is an evolving project, the applications in the book are expected to evolve as well. The examples in the book depend on the latest public released version of Strange that was available at the time of this writing. This version is tagged and uploaded to well-known repositories (such as Maven Central). Because of this, the code in this book is expected to work in the future, even if the Strange APIs change. A snapshot of the code examples in this book at the time of publication is available at https://www .manning.com/books/quantum-computing-in-action. You can also get executable snip- pets of code from the liveBook (online) version of this book at https://livebook.manning .com/book/quantum-computing-in-action. The evolving code repository for the exam- ples is available at https://github.com/johanvos/quantumjava. This book contains many examples of source code, both in numbered listings and in line with normal text. In both cases, source code is formatted in a fixed-width font like this to separate it from ordinary text. In many cases, the original source code has been reformatted; we’ve added line breaks and reworked indentation to accommodate the available page space in the book. In rare cases, even this was not enough, and list- ings include line-continuation markers. Additionally, comments in the source code have often been removed from the listings when the code is described in the text. Code annotations accompany many of the listings, highlighting important concepts. liveBook discussion forum Purchase of Quantum Computing in Action includes free access to liveBook, Manning’s online reading platform. Using liveBook’s exclusive discussion features, you can attach comments to the book globally or to specific sections or paragraphs. It’s a snap to make notes for yourself, ask and answer technical questions, and receive help from the author and other users. To access the forum, go to https://livebook.manning.com/#!/book/ quantum-computing-in-action/discussion. You can also learn more about Manning’s forums and the rules of conduct at https://livebook.manning.com/#!/discussion. Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It is not a commitment to any specific amount of participation on the part of the author, whose contribution to the forum remains voluntary (and unpaid). We sug- gest you try asking the author some challenging questions lest his interest stray! The forum and the archives of previous discussions will be accessible from the publisher’s website for as long as the book is in print.
Page 19
about the author Johan Vos is a Java Champion, active OpenJDK contributor, project lead for OpenJDK Mobile, and co-spec lead for Open- JFX. Johan holds a PhD in applied physics from Delft University of Technology. He is a co-author of ProJava FX2/8/9 and of The Definitive Guide to Modern Java Clients with JavaFX. Johan has been active in the development of open source software. He was part of the Blackdown team that ported Java to Linux systems. Apart from his lead role in OpenJFX, he also contributes to a number of Java and JavaFX related libraries, including Strange and StrangeFX, which are discussed in this book. xviii
Page 20
about the cover illustration The figure on the cover of Quantum Computing in Action is captioned “Femme Dalécar- lie,” or Dalecarlian woman. The illustration is taken from a collection of dress cos- tumes from various countries by Jacques Grasset de Saint-Sauveur (1757–1810), titled Costumes de Différents Pays, published in France in 1797. Each illustration is finely drawn and colored by hand. The rich variety of Grasset de Saint-Sauveur’s collection reminds us vividly of how culturally apart the world’s towns and regions were just 200 years ago. Isolated from each other, people spoke different dialects and languages. In the streets or in the countryside, it was easy to identify where they lived and what their trade or station in life was just by their dress. The way we dress has changed since then and the diversity by region, so rich at the time, has faded away. It is now hard to tell apart the inhabitants of different conti- nents, let alone different towns, regions, or countries. Perhaps we have traded cultural diversity for a more varied personal life—certainly for a more varied and fast-paced technological life. At a time when it is hard to tell one computer book from another, Manning cele- brates the inventiveness and initiative of the computer business with book covers based on the rich diversity of regional life of two centuries ago, brought back to life by Grasset de Saint-Sauveur’s pictures.xix
The above is a preview of the first 20 pages. Register to read the complete e-book.

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay
Back to List