Reduce computing time from a few years to minutes. Understanding quantum machine learning

I have been interested in quantum computing for a long time and write programs for 5- and 14-qubit IBM Q Experience quantum computers. Today I will talk about technologies that can be applied in machine learning after quantum computing will conquer the world. Spoiler for the date of Scientists: in the future you will not be able to start the model and leave to drink coffee for half a day. A quantum computer clicks on machine learning tasks at once, and excuses like “model learns” no longer work. It will be necessary to launch not one model, but at least a million.



image



Many have heard that with the help of quantum computers, cybercriminals can break into modern encryption systems. Unlike classic computers, for which RSA and similar cryptographic algorithms are a good barrier to hacking, quantum computers find simple factors in a matter of minutes. This means that the information intercepted by hackers will sooner or later be decrypted.



Of course, some of these applications scare away from quantum computers. In this article, we will focus on the positive side and consider what quantum computing will be able to give a new one for a field such as machine learning.



What is quantum machine learning and what is its difference from ordinary



In modern computers, including for machine learning, calculations are performed using classical bits. In quantum computers, which have recently gained popularity and are actively developing, bits of a special kind are used - quantum bits, or abbreviated qubits.



For a classical bit, there are two states - 0 and 1, while for a qubit an infinite number of combinations of two states is possible - this is the so-called superposition. If the Schrödinger cat from a well-known thought experiment, before it is opened, is alive and dead at the same time, then the qubit, before it is measured, can be in superposition, that is, equal to zero and one at the same moment.



If several qubits are used, then the number of possible states grows exponentially: for two qubits that are in superposition, the number of states is four:







|ψ rangle=k1|00 rangle+k2|01 rangle+k3|10 rangle+k4|11 rangle









And for three qubits, there are already eight states:







|ψ rangle=k1|000 rangle+k2|001 rangle+k3|010 rangle+k4|011 rangle+k5|100 rangle+k6|101 rangle+k7|110 rangle+k8|111 rangle









These states cannot be directly measured, but they can be controlled. In this case, the quantum circuit is with different probability in several states at the same time, which can be used for parallel computing.



The factors at the values ​​of qubits are called amplitudes - these are complex numbers. If we calculate the amplitude modulus and square it, then we get the probability of the state. The sum of the probabilities of all combinations of qubit states, as expected, should ultimately be equal to unity.



image



As examples of different states of a qubit, one can cite the electron spin or the polarization of a photon, but other options are also possible. The main thing is that quantum effects can also be observed in them. Thus, almost any particle can be a qubit: an electron, a photon, an ion, and so on.



How can a particle be in two states at the same time, and why is the information about one of the states completely lost when measuring a qubit? The most common are two interpretations:



The Copenhagen interpretation claims that explaining the position of a particle before its measurement does not make sense, since physics is a science based on accurate measurements, and should not explain those phenomena that cannot be observed. Thus, if we accept the Copenhagen interpretation, we can conclude that there is no objective reality at the physical micro level.



Some scientists adhere to a multi-world interpretation , according to which there is an infinite number of parallel universes, and in some fraction of these universes a particle can take the zero state, and in the rest it can take a single state. The most detailed description and philosophical justification for a multi-world interpretation can be found in David Deutsch's book, The Structure of Reality.



In any case, regardless of which of these interpretations you prefer, we can assume that when measuring a qubit, the wave function collapses (that is, it ceases to behave like a wave and exhibits the properties of a particle), while the qubit takes one of the states, then there is actually becoming a classic bit.



In general, classical bits are a subset of qubits, so classical Computer Science could be considered a subset of the science of quantum computing. As mentioned above, any qubit after measurement becomes a classic bit, which, however, can later be transferred to a superposition state.



In order to still get at least some information about the qubit superposition, you can use a fairly simple life hack: create the same superposition many times (act on the qubit with the same operators) and measure the qubit every time. From the distribution of zeros and ones obtained during measurements, one can get an idea of ​​the probabilities, that is, find out what the moduli of amplitudes of qubit states can be approximately equal to.



What are the benefits of quantum machine learning



What are the benefits of computing with superposition? If on a regular computer, when running multi-threaded programs, one logical processor is required for each thread, then in a quantum computer the number of threads can grow exponentially as the number of qubits in the circuit increases.



For example, if 1024 streams in a regular computer require the same number of logical processors, then in a quantum one it is only 10. True, you can only use these streams indirectly, that is, you won’t be able to directly monitor their work.



You must also understand that the algorithms that a quantum computer uses are different from the algorithms studied in Computer Science sections on classic computers. Of course, you cannot transfer the classical algorithm to a quantum computer without first changing it. Moreover, it is unlikely that the original algorithm will be something significant. Most likely, it will be thoroughly changed, so that only a general idea will remain from it (if at all something remains).



The same can be said about machine learning. For quantum computers, analogues of classical machine learning algorithms already exist (for example, Random Forest, KNN, neural networks). But, firstly, they are implemented in a different way, and secondly, sooner or later, completely new algorithms will appear that will take full advantage of the advantages of quantum computing.



All specialists in the field of big data and artificial intelligence are aware of situations when a scientist has to wait a long time for a model to learn.



Of course, there are simple models (such as linear regression) that train on small data in a matter of seconds, but in the case of more complex models, such as neural networks, training can last from a few minutes to several weeks. In order to sort out several options for such models, remarkable patience is required.



There are also such models that even the most patient Scientist date will refuse to use. In particular, models with a huge number of weights, or those where enumeration of an exponentially growing number of combinations is required. The use of quantum computers is suitable for such tasks, which can reduce the computation time from several years to several minutes.



Why artificial intelligence needs to speed up algorithms



In the last two or three years, there has been a rapid development of computer vision technologies, and over the past year a lot has been invented in the processing of natural language.



In this case, the training of complex models lasts a very long time. But if we assume that models of the same or even greater complexity would take an order of magnitude less time, then it would be possible to test hypotheses and test models much faster.



Accordingly, progress in these areas would occur at an accelerated pace: instead of one or two notable discoveries per month, we could hear about such daily. Double exponential growth in the progress of quantum computing can lead to the same rate of progress in machine learning.



Quantum computing mechanisms



A photon, electron, ion, or some other particle can act as a qubit. If this is an electron, then one can measure its spin (proper angular momentum) and thus obtain 0 or 1. In the Dirac notation, these states are denoted as follows:







|0 rangle,|1 rangle









The state of a qubit can also be expressed using a vector. This is a state vector of a qubit equal to 0:







|0 rangle= beginbmatrix10 endbmatrix









And this is a qubit vector equal to 1:







|1 rangle= beginbmatrix01 endbmatrix









An important role in quantum computing is played by the Hadamard operator:







H_1 = \ frac {1} {\ sqrt {2}} \ begin {bmatrix} 1 & 1 \\ 1 & -1 \ end {bmatrix}









One way to get a superposition is to apply the Hadamard operator to a qubit that is in one of two basic states. In this case, we will get a qubit state when the probabilities of getting 0 or 1 after the measurement are equal. This is how the superposition will be obtained if the initial state of the qubit is zero:







\\ H_1 \ cdot | 0 \ rangle = \ frac {1} {\ sqrt {2}} \ begin {bmatrix} 1 & 1 \\ 1 & -1 \ end {bmatrix} \ cdot \ begin {bmatrix} 1 \\ 0 \ end {bmatrix} = \ frac {1} {\ sqrt {2}} (| 0 \ rangle + | 1 \ rangle)









But such a superposition will turn out if the initial state is single:







\\ H_1 \ cdot | 1 \ rangle = \ frac {1} {\ sqrt {2}} \ begin {bmatrix} 1 & 1 \\ 1 & -1 \ end {bmatrix} \ cdot \ begin {bmatrix} 0 \\ 1 \ end {bmatrix} = \ frac {1} {\ sqrt {2}} (| 0 \ rangle - | 1 \ rangle)









Another common option for working with qubits is the use of quantum entanglement - such an interconnection between two qubits, when even when they are separated over a large distance, they show a 100 percent correlation. In direct correlation, if one of the qubits after a measurement assumes a certain state, then the other qubit acquires exactly the same state. With an inverse relationship, qubits assume opposite states after measurement.



What are the possibilities of quantum computing and quantum machine learning?



All specialists who want to save time will be able to use quantum computing for machine learning. Operations such as fast Fourier transform, finding the inverse matrix, calculating the eigenvalues ​​and matrix vectors on a quantum computer occur with exponential acceleration.



Of course, the work that is not very resource-intensive (for example, data visualization) can be continued to be done on a regular computer, but machine learning algorithms, or at least those parts that can be accelerated using qubits, can be given to a quantum computer.



One of the questions that bothers specialists: how to work with data in quantum computing? Imagine the situation that we have an image (to make it easier, let it be black and white), which we want to submit to the input of a quantum neural network. The image has a size of 256 by 256 pixels - quite a standard size for image recognition.



In order to represent this image as numbers, we encode each pixel with a 64-bit floating-point number (in fact, an 8-bit integer would be enough, but in practice, the matrix with pixel values ​​is scaled before applying to the input of the neural network, so the matrix is ​​filled with 32- or 64-bit numbers). Such an image can be represented in the form of a matrix of 65536 numbers, which will weigh 512 kilobytes (the neural network receives an uncompressed image as an input), i.e., 4194304 bits will be required.



If this image is encoded using qubits, then their number will be much smaller: we will translate n qubits into a superposition, and the value of each pixel can be represented as the amplitude for each of the possible states. The number of such states is two in degree n. To find n, we find the binary logarithm of the number of pixels.



As you can see, the actions are quite simple, so you don’t even have to write formulas. As a result, the number n turns out to be 16. That is how many qubits are required to encode this image, that is, 262144 times less than when using classical bits.



If we have 66 qubits at our disposal, then translating them into a superposition, we can encode more than a trillion color images in 4K format.



Thus, quantum coding allows one to achieve logarithmic compression of information. Accordingly, the acceleration of machine learning methods when working with such data can be exponential.



Specialized programming languages ​​and libraries



Today, many programming languages ​​have libraries for quantum computing. Some of these libraries work only with simulation of quantum computing, but many support real quantum computers, including cloud ones, as a backend.



If you operate directly with qubits, then this is akin to writing low-level assembler code on classic computers. Oddly enough, one of these “low-level” programming languages ​​used to program computations on quantum computers is Python.



One of the libraries for this language - Qiskit - works both on the simulator and on the quantum backend, and also allows performing operations on qubits at a low level. For higher-level programming, it’s convenient to use PennyLane , a library for quantum machine learning. The repository of this library contains examples of the implementation of machine learning algorithms, including a quantum neural network.



Prospects for Quantum Computing



In January 2019, the first commercial quantum computer, the IBM Q System One, was launched. Also now, for quantum computing, you can use cloud systems for both researchers and commercial companies.



Everyone can run their quantum algorithm on the IBM Q Experience cloud platform, and you don’t even need to know programming languages ​​to create a quantum scheme, since in addition to entering commands, you can use the graphical interface called Circuit Composer.



In September 2019, unofficial information appeared that Google had achieved quantum superiority by solving one of the problems on a quantum computer at a speed not available even to the most powerful supercomputer. Even if the news is premature, such reports suggest that quantum superiority is near.



Several IT giants are immediately searching for the best solutions for quantum computers. Some researchers predict that a law similar to Moore’s will apply to quantum computers.



True, the development speed, unlike classical computers, is most likely not to be an ordinary single exponent, but double, so programmers working with quantum computing will have to create a large number of programs in the near future.



As for the sphere of advertising and marketing, in which I am currently working, the applied machine learning models must undergo a complete transformation. What works on classic computers will be significantly inferior in terms of speed and quality to the models of the future.



The latest technologies will bring no less changes to the process of scanning target audiences. Elusive bots driven by quantum computers will plow open spaces of social networks, catching the smallest changes in the tastes and moods of the audience. Who knows, maybe advertising campaigns themselves can be launched only by expressing general wishes to the computer about their goals.



All Articles