Introducing Qiskit Machine Learning

Qiskit
Qiskit
Published in
6 min readApr 6, 2021

By the Qiskit Applications Team

Machine Learning

Today, machine learning applications touch almost every angle of business, science, and private life, ranging from speech and image recognition to generative models to improve drug design. Machine learning’s primary goal is to train computers to make sense of an ever-expanding pool of data. However, in order to learn from these increasingly complex datasets, the underlying models, such as deep neural networks, also become more sophisticated and expensive to train.

This results in complicated models with very long training times that risk over-fitting without sufficient generalization. In other words, we must be vigilant that our models meaningfully understand our data, rather than merely memorizing what they have already seen. Therefore, a lot of effort is put into improving training algorithms of models, as well as dedicated classical hardware.

Quantum Machine Learning

Quantum computation offers another potential avenue to increase the power of machine learning models, and the corresponding literature is growing at an incredible pace. Quantum machine learning (QML) proposes new types of models that leverage quantum computers’ unique capabilities to, for example, work in exponentially higher-dimensional feature spaces to improve the accuracy of models.

A potential bottleneck for QML is the need to load large datasets into a quantum computer, which in some cases can cancel out a QML algorithm’s potential quantum advantage over classical machine learning. Thus, it is very important to analyze QML applications end–to-end. There exist multiple proposals that circumvent this problem, such as Quantum Support Vector Machines (QSVMs), Quantum Generative Adversarial Networks (QGANs) or Quantum Boltzmann Machines (QBMs). Researchers have proven theoretically that a QSVM can tackle certain classification problems that a classical computer cannot solve efficiently.

Another direction is to apply quantum machine learning directly to quantum data. This removes the potential bottleneck of data loading, since the data natively comes in the right format. Using classical and quantum machine learning models may allow researchers to better understand quantum chemistry and physics, opening up plenty of new applications and research directions. There could be a vast array of other ways quantum computing may impact machine learning as well.

Qiskit Machine Learning (code / tutorials)

Today, we announce the release of Qiskit Machine Learning. This new application module builds on top of Qiskit’s existing functionality to create and run (parametrized) quantum circuits, evaluate complex observables, and also automatically evaluate the corresponding gradients with respect to circuit parameters.

Qiskit Machine Learning introduces fundamental computational building blocks — such as Quantum Kernels and Quantum Neural Networks — used in different applications, including classification and regression. On the one hand, this design is very easy to use and allows users to rapidly prototype a first model without deep quantum computing knowledge. On the other hand, Qiskit Machine Learning is very flexible, and users can easily extend it to support cutting-edge quantum machine learning research.

In addition to the models provided directly in Qiskit Machine Learning, we also introduce the Torch Connector, which allows users to integrate all of our quantum neural networks directly into the PyTorch open source machine learning library. Thanks to Qiskit’s gradient framework, this includes automatic differentiation — the overall gradients computed by PyTorch during the backpropagation take into account quantum neural networks, too. The flexible design also allows the building of connectors to other packages in the future. Qiskit Machine Learning provides a collection of tutorials that introduce all of this functionality.

Figure 1: Qiskit Machine Learning provides a collection of computational units consisting of different families of quantum neural networks as well as quantum kernels. These can be used in a variety of classification and regression algorithms. Further, the neural networks can be plugged into the TorchConnector to use them as native PyTorch modules in larger PyTorch models.

Quantum Kernels (tutorial)

Many machine learning models rely on feature maps and their corresponding kernels to improve performance. The idea is to map given data into a higher-dimensional feature space where the problem at hand becomes easier to solve. Quantum computers offer the possibility to map data into exponentially higher-dimensional feature spaces and to efficiently evaluate the corresponding quantum kernels. It even has been shown that there exist problems that a Support Vector Machine (SVM) equipped with a Quantum Kernel can solve efficiently, while classically it is not possible to do better than random guessing.

Qiskit Machine Learning provides the QuantumKernel class that can be easily used to directly compute kernel matrices for given datasets or can be passed to a Quantum Support Vector Classifier (QSVC) or Quantum Support Vector Regressor (QSVR) to quickly start solving classification or regression problems. It also can be used with many other existing kernel-based machine learning algorithms from established classical frameworks.

Quantum Neural Networks (tutorial)

Feature maps also find applications in certain quantum neural network (QNN) architectures to load input data onto a quantum computer, which has the potential to lead to more powerful models than those available classically. Note that this technique avoids some of the issues discussed above regarding data loading on quantum computers.

Qiskit Machine Learning defines a generic interface for neural networks that is implemented by different quantum neural networks. Multiple implementations are readily provided, such as the OpflowQNN, the TwoLayerQNN, and the CircuitQNN. The OpflowQNN allows users to combine parametrized quantum circuits with quantum mechanical observables. The circuits can be constructed using, for example, building blocks from Qiskit’s circuit library, and the QNN’s output is given by the expected value of the observable. The TwoLayerQNN is a special case of the OpflowQNN that takes as input a feature map and an ansatz. The CircuitQNN directly takes the quantum circuit’s measurements as output without an observable. The output can be used either as a batch of samples, i.e., a list of bitstrings measured from the circuit’s qubits, or as a sparse vector of the resulting sampling probabilities for each bitstring. The former is of interest in learning distributions resulting from a given quantum circuit, while the latter finds application, e.g., in regression or classification. A post-processing step can be used to interpret a given bitstring in a particular context, e.g. translating it into a set of classes.

The neural networks include the functionality to evaluate them for a given input as well as to compute the corresponding gradients, which is important for efficient training. To train and use neural networks, Qiskit Machine Learning provides a variety of learning algorithms such as the NeuralNetworkClassifier and NeuralNetworkRegressor. Both take a QNN as input and then use it in a classification or regression context. To allow an easy start, two convenience implementations are provided — the Variational Quantum Classifier (VQC) as well as the Variational Quantum Regressor (VQR). Both take just a feature map and an ansatz and construct the underlying QNN automatically.

Qiskit Machine Learning’s design allows users to easily construct their own QNNs and test them with the Neural Network Classifier or Regressor. Thanks to the generic interface, it is also compatible with completely different QNN architectures, including Quantum Boltzmann machines. All algorithms follow established interfaces that are easy to use.

Connecting Qiskit Machine Learning to PyTorch (tutorial)

In addition to the classification and regression algorithms to use the provided QNNs, Qiskit Machine Learning also introduces the TorchConnector. This takes any QNN and makes it available as a PyTorch Module. Since Qiskit Machine Learning QNNs provide a forward pass as well as a backward pass, users can seamlessly integrate QNNs into a PyTorch workflow including the backpropagation to compute gradients. Thus, they can be part of a bigger complex computation, such as a deep neural network that consists of classical as well as quantum layers. This opens endless opportunities to investigate the potential power of QNNs for a vast number of applications.

How to get started

Qiskit, Qiskit Machine Learning, as well as all other Qiskit Application modules are open-source libraries free for everybody to download and to use. Tutorials illustrate the different features and provide examples to quickly run first tests. Qiskit not only provides performant simulators to test quantum machine learning models on classical computers, but it also enables users to test them on real quantum devices, including IBM’s publicly available quantum systems. This first release of Qiskit Machine Learning already provides a large variety of models, and we will continuously grow it to include exciting new research results! You can get started with the documentation here.

A special thanks to the core contributors (in alphabetical order): Panagiotis Barkoutsos, Bei Chen, Anton Dekusar, Bryce Fuller, Julien Gacon, Ikko Hamamura, Takashi Imamichi, John Lapeyre, Dariusz Lasecki, Manoel Marques, Atsushi Matsuo, Anna Phan, Max Rossmannek, Ivano Tavernelli, Stefan Woerner, Steve Wood, Christa Zoufal

--

--

Qiskit
Qiskit

An open source quantum computing framework for writing quantum experiments and applications