Working with QxBranch’s Quantum Feature Detector Library

In a recent blog post,
we announced the release of QxBranch’s Quantum Feature Detector library (QxQFD)
on the Rigetti Quantum Cloud Services (QCS) platform. In this post, we will
work through an example of how to use the library to perform a simple
classification task.

If you’d like to work
through this example yourself, or experiment with the code to try and get a
better result, you can download QxQFD from PyPI here, and the example as an iPython notebook here.

The first step is to
import the packages we will need, including generic python packages as well as
QxQFD itself.

For this example, we will use a simple toy problem, classifying which of two synthetic distributions a data point belongs to. The following code generates and plots this data as a blue set and a red set:

QFDs operate as complex, nonlinear functions where classical information is encoded into a quantum circuit, the circuit is run, and the measured results are decoded back to classical information. Using the features generated by transforming our training data using these quantum circuits is expected to help increase accuracy.

Let’s see how this model performs when we build the same logistic regression model on top of the QFD transformed data.

The next cell runs the quantum circuits we’ve generated on the Forest SDK QVM. If you’re running this on your local machine, please ensure you’ve started the QVM with the “qvm -S” command. On a Forest QMI, there should be no need to manually activate the QVM.

Please be mindful that the process of running the data through the quantum circuits during training and testing can take a few minutes.

# Train the model on the quantum-transformed data.
# By default, the underlying classical model is a logistic regression
model.train(training_data=train_data, data_labels=train_labels)
# Score the accuracy of the model on our previously-generated test data
metrics.accuracy_score(test_labels, model.predict(test_data))

0.9333333333333333

A much better result. This is because the QFD’s are able to capture non-linear features. There are other methods of performing non-linear feature detection, and it remains an open research question whether quantum methods such as this provide advantages over classical methods.

If you’re interested
in learning more about QxBranch’s Quantum Feature Detector library, or
downloading and using it yourself, check out the documentation, including a getting started section, and a collection of example notebooks, such as this one.