Quantum K Means Algorithm
Total Page:16
File Type:pdf, Size:1020Kb
DEGREE PROJECT IN INFORMATION AND COMMUNICATION TECHNOLOGY, SECOND CYCLE, 30 CREDITS STOCKHOLM, SWEDEN 2019 Quantum K means Algorithm SUMSAM U. KHAN KTH ROYAL INSTITUTE OF TECHNOLOGY SCHOOL OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE Quantum K-means Algorithm SUMSAM U. KHAN Master in Computer Science Date: August 27, 2019 Supervisor KTH: Baptiste Cavarec Examiner: Mats Bengtsson School of Electrical Engineering and Computer Science Host company: Ericsson AB Supervisor Ericsson: Gemma Vall Llosera and Ahsan Javed Awan iii Abstract Quantum algorithms are being extensively researched nowadays seeing the potential of providing exponential speed up when compared to classical algo- rithm execution. This speed-up can play a big role in machine learning where training a model is usually very slow. Training a machine learning model re- quires manipulating large vectors and quantum computers inherently are re- ally fast at manipulating and computing large vectors and tensor products. However, current quantum computers have certain limitations with respect to qubit’s coherence times and noise. These barriers reduce their effectiveness in solving problems with high accuracy. In pursuit of having better results on cur- rent term noisy quantum computers, implementations of quantum algorithms with simpler circuits are desired. To address this problem, three different novel methods of the quantum version of the K-means clustering algorithm are pre- sented with optimized shallow depth quantum circuit design. Experimental results on the quantum computer IBMQX2 are demonstrated which show a significant improvement in the accuracy of the quantum K-means algorithm. iv Sammanfattning Forskning inom kvantalgoritmer har ökat kraftig under de senaste åren p.g.a. en lovande exponentiell speed up för visa beräkningar som kräver en mängd stor data och tar en lång tida i en klassikt dator. Den här speed up:en kan spela en stor roll i maskininlärning där träningen av en modell är vanligtvis mycket långsam. Träning av en maskininlärningsmodell kräver att man mani- pulerar stora vektorer och kvantdatorer är i själva verket snabba att manipu- lera och beräkna stora vektorer och tensorprodukter. Nuvarande kvantdatorer har emellertid vissa begränsningar med avseende på qubit-koherens och brus. Dessa hindrar deras effektivitet vid att lösa problem med hög noggrannhet. I strävan efter att ha bättre resultat på de befintliga brus-påverkade kvantdatorer, är det önskvärt att implementera kvantalgoritmer med enklare kvantkretsar. Vi adresserar problematiken med tre olika nya metoder för kvant K-means algo- rithm som har en optimerad grunddjupkvantkretsdesign. Experimentella re- sultat på kvantmaskinen IBMQX2 visas och de visar en betydande förbättring av precision hos kvant K-means algoritmen. Contents 1 Introduction 1 1.1 Problem . .3 1.2 Objective . .3 1.3 Methodology . .3 2 Background and Related Work 5 2.1 Quantum Computation . .5 2.1.1 Qubit . .5 2.1.2 Entanglement . .7 2.1.3 Quantum Gates . .8 2.1.4 Quantum Circuit Model . 11 2.1.5 Amplitude Encoding . 11 2.1.6 Interference . 12 2.2 K-Means Clustering Algorithm . 13 2.2.1 K-Means . 13 2.2.2 Quantum K Means . 14 2.2.3 Distance Based Classifier . 16 3 Quantum K-means Implementations 19 3.1 Quantum K-means using distance based classifier . 19 3.1.1 Basic Implementation . 19 3.1.2 Optimized 4 qubit model . 21 3.1.3 Multi-cluster Quantum K-means . 28 3.2 Constant Depth circuit using Negative Rotations . 35 3.3 Distance Calculation using Destructive Interference . 38 4 Evaluation Methodology 43 4.1 Input Data . 43 4.1.1 Random Dataset . 43 4.1.2 Iris Dataset . 44 v vi CONTENTS 4.1.3 MNIST Dataset . 45 4.2 Execution Environment . 47 4.2.1 IBM Qiskit Simulator . 47 4.2.2 IBMQX2 quantum machine . 48 4.3 Evaluation Metric . 49 5 Results and discussion 50 5.1 Basic Implementation . 50 5.2 Optimized 4 qubit Model . 52 5.3 Multi Cluster Quantum K-means . 53 5.4 Constant Depth circuit using Negative Rotations . 55 5.5 Distance Calculation using Destructive Interference . 56 5.6 Analysis . 56 6 Conclusion 59 Bibliography 60 List of Figures 2.1 Qubit on a unit circle. .6 2.2 Quantum Circuit for 2 qubit entanglement . 11 2.3 SwapTest circuit . 15 2.4 Distance Based Classifier Circuit for loading two training vec- tors and one test vector(test and training vectors taken from Iris Dataset [33]). Step B: Load test vector; Step C: Load train- ing vector 1; Step D: Load training vector 2; Step E: Flip the class label for training vector 2; Step F: Interference and measurement [29]. 18 3.1 Distance Based Classifier Circuit with arbitrary training vec- tors Step B: Load test vector; Step C: Load training vector 1; Step D: Load training vector 2; Step E: Flip the class label for training vector 2; Step F: Interference and measurement . 21 3.2 Optimized Interference Circuit . 22 3.3 Original Configuration. θ = jθt − θcj ............. 23 3.4 New Configuration. θ = jθt − θcj ............... 23 3.5 Original Configuration with 2 training vectors c1 and c2 and ◦ ◦ ◦ one test vector t. θt = 45 , θc1 = 0 and θc2 = 180 ...... 25 3.6 Interfering vectors from fig. 3.5 . 26 3.7 Quantum state transition of vector ~t from equation (3.7) . 26 3.8 Quantum state transition of vector ~t0 from equation (3.8) . 26 3.9 Quantum state transition of vector ~c1 from equation (3.9) . 27 3.10 Quantum state transition of vector ~c2 from equation (3.10) . 27 3.11 Combined final state of the interfering vectors . 27 3.12 Quantum state transition flow of input vectors . 28 3.13 Arbitrary State preparation circuit. Implemented using Qiskit’s from Ref. [34]. 30 vii viii LIST OF FIGURES 3.14 Flowchart for quantum K-means. (Blue: Classical Processes, Green: Quantum Process) . 32 3.15 Multi cluster QK means strategy . 33 3.16 Sequence Diagram . 34 3.17 Possible parallelization of QK means algorithm for multi clus- tering problem. Small blue boxes represent input vectors. QC block is a quantum chip and C block is a classical computer. Small yellow boxes represent the state of the algorithm. 35 3.18 Vectors 180o apart . 36 3.19 2 qubit Negative Rotations Quantum Circuit . 37 3.20 K qubit negative rotation circuit . 37 3.21 nk qubit negative rotation circuit . 38 3.22 Generic n qubit Quantum Interference Circuit. Step A: Pre- pare the desired state; Step B: Interference and Measurement . 39 3.23 2 qubit quantum interference circuit Step A: Prepare the de- sired state Step B: Interference and Measurement . 40 3.24 2 qubit quantum interference circuit with equal relative angu- lar difference Step A: Prepare the desired state Step B: Inter- ference and Measurement . 41 3.25 Swap Gate Breakdown . 41 4.1 Randomly Generated Dataset . 43 4.2 Randomly Generated Dataset Normalized . 44 4.3 Iris Dataset left: Standardized , right: Standardized and Nor- malized . 44 4.4 MNIST Dataset sample images . 45 4.5 PCA reduced MNIST dataset with true class labels . 46 4.6 PCA reduced MNIST dataset with true class labels containing digits 0,3,4,7 . 47 4.7 IBMQX2 qubit connectivity taken from [40] . 48 5.1 Results basic implementation on IBM’s quantum simulator . 51 5.2 Results basic implementation on IBMQX2 . 51 5.3 Results of optimized circuit IBM’s quantum simulator . 52 5.4 Results of optimized circuit on IBM’s quantum chip IBMQX2 52 5.5 Result for Iris dataset left: Multi Cluster quantum K-means on simulator, right: Scikit-learn K-means . 53 5.6 Result Iris Dataset multi cluster quantum K-means IBMQX2 . 54 5.7 Result: left: multi cluster quantum K-means right: scikit- learn kmeans . 54 LIST OF FIGURES ix 5.8 Result MNIST multi cluster quantum K-means IBMQX2 . 55 5.9 Result: left: Iris dataset right: MNIST dataset . 55 5.10 Result: left: Iris dataset right: MNIST dataset . 56 Chapter 1 Introduction Quantum computers are known to solve certain difficult problems exponen- tially faster than classical computers do. Integer factorization on a classical computer is one such problem that grows exponentially in time with the in- crease on input data but it can be solved in polynomial time using Shor’s algo- rithm [1] on a Quantum Computer. Similarly, Grover’s algorithm [2] provides a quadratic speed up on searching an item from an unsorted array. The list of such algorithms that provide a Quantum Speedup has grown over the duration of last two decades ([3] cites more than 250 quantum algorithms) and scien- tists have developed and tested algorithms that theoretically provide a quantum speed-up [4]. Another quantum discipline where quantum computing promises a speed- up is Machine learning (ML). Quantum Machine Learning (QML) has gained a lot of prominence and an increasing number of published literature that cov- ers the principles and techniques of QML is being produced [5]. Significant work has been done to take advantage of quantum processing power for ma- chine learning tasks. QML techniques are being developed by researchers that can solve ML problems faster than the best known classical algorithms for the respective problems. Supervised (e.g. support vector machines), unsuper- vised (e.g. clustering) and reinforcement quantum machine learning methods have been proposed that provide exponential speed-ups as compared to their classical counterparts [6, 7, 8, 9]. The gap between mathematical models and actual implementations of the algorithms has been reduced over the past few years. There has been a lot of development in the Quantum software world and there are well over fifty 1 2 CHAPTER 1. INTRODUCTION open-source software platforms available for quantum development. A list of these development platforms is available at [10].