August 15, 2023
TNO Quantum Variational Classifier: Powering ML workflows with quantum
The following is a guest post by Esteban Aguilera and Robert Wezeman from TNO, and Jacob Senior-Williams and Erik van Mulligen from S[&]T, showcasing an application of the TNO Quantum Variational Classifier to seabed mapping using satellite images.
Inspired by the potential of quantum machine learning, we at TNO, an independent research organization in the Netherlands, have recently released the TNO Quantum Variational Classifier, an open-source Python package compatible with PennyLane, which implements a variational quantum classifier. In this blog post we'll explain why and how this package can be used for real-world quantum machine learning (QML) applications.
Contents
Goal of the VC package
When working to develop new proofs of concept and determine which applications can benefit from quantum technologies, we at TNO consider it key to work together with partners from other fields, from both industry and the public sector. A typical step in this process is to onboard the partners' domain experts, so that they can master the basics of quantum and actively contribute to the project. Two questions are usually (and oftentimes indirectly) posed by the non-quantum experts:
- Where does the quantum algorithm fit in my current workflow?
- How does the quantum algorithm interact with classical algorithms and data?
To date, excellent tutorials have been made available (e.g., PennyLane demos) to help us answer these questions, and they continue to be invaluable educational and inspirational resources, especially for outsiders to the field. In addition, PennyLane also facilitates integration with well-known libraries, such as PyTorch and TensorFlow. Nevertheless, we believe these resources can be complemented by additional packages, so that the two questions above can be answered in a context that end-users are most familiar with.
Our team at TNO recently collaborated with S&T to show how this model can be implemented with a variational quantum classifier approach that makes use of multispectral Sentinel-2 data.
With this in mind, we'll explain how a variational quantum classifier can fit into the familiar scikit-learn machine learning workflows and be applied to seabed mapping. In addition, we'll show you how to look inside a scikit-learn classifier to find out how tasks and data can be offloaded to a quantum algorithm.
Where does the quantum algorithm fit in your current workflow?
Our Variational Classifier package has been implemented in accordance with the scikit-learn estimator API. As a consequence, it can be used as any other (binary or multiclass) scikit-learn classifier and combined with transforms through pipelines. Also, the package leverages PennyLane and hence provides support for devices and plugins.
How does the quantum algorithm interact with classical algorithms and data?
In order to understand how the Variational Classifier works under the hood, we need to go to the docs and, if you're up for it, to the source code. As per the scikit-learn estimator API, you will find that two methods have been implemented: fit and predict.
As you will notice, neither of these methods does anything particularly quantum. In this case, quantum and classical classifiers look exactly the same on the outside, and they can directly fit in your current workflows.
For example, in the fit
method a function is defined to map features to classes, weights are initialized, an optimizer is selected, and a model
is trained in batches based on the input parameters and training data. This is conveniently familiar and also
in line with the question of where this quantum package fits into a non-quantum workflow.
If we really want to find out how data reaches the quantum algorithm, we need to drill down a level deeper, which
we can do by going to the models module.
In this module, we will find definitions of quantum circuits as well as strategies for classical post-processing of measurements.
As described in the documentation, three models are currently supported:
expected_values_model
, modulo_model
, and parity_model
. The choice of model will affect the number of classes
the classifier can handle, the way features are mapped to classes, and the achievable accuracy.
We encourage you to look at the documentation and source code of these
models,
and experiment by making modifications to the quantum circuits and post-processing strategies, as defined
in their respective get_qfunc
method.
Installation and use
The Variational Classifier package (currently in version 2.0.2) can be installed using PyPi, as follows:
$ pip install tno.quantum.ml.classifiers.vc
We can also install the (optional) package that enables us to load sample datasets:
$ pip install tno.quantum.ml.datasets
With this, we're all set to train the classifier; for example, we can use the Iris dataset:
from tno.quantum.ml.classifiers.vc import VariationalClassifier from tno.quantum.ml.datasets import get_iris_dataset # Load training and validation datasets X_training, y_training, X_validation, y_validation = get_iris_dataset() # Create a classifier instance vc = VariationalClassifier() # Train the default model vc = vc.fit(X_training, y_training, n_iter=100) # Make some predictions predictions_validation = vc.predict(X_validation)
Seabed mapping
Now that we understand how our package (that implements the variational quantum classifier) interacts with data and fits into a machine learning workflow, we are able to apply it to a specific problem — in our case, seabed mapping.
Seabed mapping is a technique used by hydrographers to survey shallow waters and coastal regions in order to create maps of underwater depth and nautical charts. With the advent of satellite remote sensing that allows access to vast amounts of data about the Earth's surface (e.g., using Sentinel-2), conventional mapping systems such as echosounders or airborne lasers have been extended by the frequent, large-scale water depth measurements derived from satellite imagery.
Using supervised machine learning, the process of estimating water depth based on satellite data can be described in four steps:
- Conventional systems (e.g., echosounders or airborne lasers) are used to map the seabed topography of a reference area.
- Satellite images (e.g., multispectral or hyperspectral) are acquired for the same area.
- A machine learning model is defined and trained based on the data acquired in the two previous steps, so that water depth can be predicted from satellite imagery.
- Predictions of water depth are made based on imagery acquired at other (similar) locations and moments in time. In other words, a trained model allows us to make predictions.
The following diagram illustrates what the input and output of the quantum circuit would be for a water depth of -13 meters.
In this implementation, only one pixel, which corresponds to specific coordinates on Earth, is processed at a time.
For example, if we prepare a training/validation dataset with four features
(e.g., four different spectral bands),
where each sample corresponds to a pixel in the reference area, we could train the Variational Classifier
with the modulo_model
or parity_model
.
As a consequence, the input to the quantum model for each pixel would be a vector of reflectances that is derived from the obtained images, and the output the predicted water depth.
Once the classification has been completed for every single pixel, the predictions can be visualized as an image:
To read more about this project, you can read our summary post (in Dutch).
What's next
The TNO Quantum team will keep maintaining and improving the Variational Classifier package on GitHub and expanding its documentation. In the near future, we plan to add support for quantum error mitigation, explore new machine learning models, and continue our collaborative research to quantify the impact of the variational classifier in more challenging environments, such as areas affected by varying sea levels due to floods. If you have questions or want to share your experience with the current models, let us know by opening an issue.
About the authors
Esteban Aguilera
Esteban works at TNO as Consultant on Quantum Applications. He has a degree in Computer Science and a Ph.D. in the field of airborne and spaceborne radar imaging. His research interests are anything and everything related to quantum, space technologi...
Robert Wezeman
Robert is a research scientist specializing in quantum algorithms at TNO in the Netherlands. His research focuses on early applications of quantum computing; in particular, he studies applications in machine learning and optimization.
Jacob Senior-Williams
Jacob is a Brexit Island escapee and now Senior Earth Observation Data Scientist at S&T in Delft. His focus is on the utilisation of remote sensing data to monitor the Earth and beyond...
Erik van Mulligen
Erik combines the role of leading the data science team of S[&]T in Delft with an academic position at the ErasmusMC. As such, he has an interest in new developments, particularly in the field of machine learning applied to satellite images and texts...