DEV Community

Keisuke Sato
Keisuke Sato

Posted on

Quantum-Classical Machine learning: QuClassi

This post is about the paper "QuClassi: A Hybrid Deep Neural Network Architecture based on Quantum State Fidelity" and was written according to my understanding and thoughts. Please see the paper by yourself if you are interested.

Introduction

Quantum computers are computers following quantum mechanics. They possibly solve many problems at a higher speed than classical ones. Many scientists have been working on the study. Here are small lists of quantum algorithms:

  • Shor's algorithm
  • Grover's algorithm
  • quantum phase estimation algorithm
  • Harrow-Hassidim-Lloyd algorithm

Those are well-known algorithms, so there is much information you can access on google or chatGPT!

Many people believe that quantum computers could change our lives in the future, and the field of machine learning is no exception. Many scientists have been working in the quantum machine learning field. I will introduce one of the quantum machine learning papers in this post. The paper is QuClassi: A Hybrid Deep Neural Network Architecture based on Quantum State Fidelity. The first version was submitted to quant-ph on 21 March 2021, and the latest version was on 31 March 2022. it is clearly not today's latest paper, but some of the authors submitted a new one to quant-ph on 11 October 2022. The new one is QuCNN : A Quantum Convolutional Neural Network with Entanglement Based Backpropagation, and it looks like the proposed quantum CNN architecture has similar parts to QuClassi. I believe understanding about QuClassi helps to understand QuCNN, which I might write the introduction post in the future.

I assume the reader has the foundation of quantum computing such as bracket notation and basic quantum gates, as well as qiskit, which is the Python library for quantum computing. If you are not sure what they are, I recommend that you get the knowledge first. The foundation is not difficult so you would understand them easily if you have the foundation of linear algebra.

Concept of QuClassi

QuClassi is a quantum neural network for both binary and multi-class classification. This architecture is a hybrid quantum-classic design, which means it uses a classical computer for some preparation and a quantum one for calculation. The key points of QuClassi are as follows.

  • has three different quantum layers
  • has a quantum state fidelity based cost function
  • encodes two-dimensional data into one qubit

Technically, the last one might have already been suggested in another paper, but the method relates to the quantum layers, so we have to know it. The quantum part of QuClassi, obviously, is implemented as a quantum circuit. Basically, the quantum circuit can be broken down into two parts: the data loading and the classifier generating ones. QuClassi outputs the likelihoods of the categories from input data by calculating fidelity between a loaded state and a classifier state. The input data are classified into the category whose corresponding fidelity is maximum. So, the classifier states have to be trained by the dataset to generate appropriate ones before classifying unknown data.

Encoding Method

Input data is encoded into a loaded state. But how? I would like to avoid going through mathematical equations in this post, but here, the equations would help us to understand the method more than just only sentences.

Image description

So, the rotation angle of the gates applied to the loaded state for every element of input data is obtained by the above transform. If the dimensionality of the input data is not an even number, then you can extend the data by zero-padding.

Quantum Fidelity Based Cost Function

Basically, quantum fidelity is the measure of similarity between two quantum states and, at the very least, in this case, the equation is just the squared inner product between two states. In QuClassi architecture, quantum fidelity is obtained by the well-known quantum algorithm SWAP test. The test requires measuring one qubit only once. Measuring many qubits could impose a large error so far, so doing it only once helps to keep the error small.

Quantum Layers

The circuit can have three different layers. The actual structure is decided by users. The following image is just one example, which has all the different layers.

Image description

The input data size is four-dimension. The encoding method requires that the number of qubits is half of the input data; The number is two in this case. The classifier state must be the same size as the loaded state. To obtain the quantum fidelity between the classifier state and the loaded state, the circuit needs one more qubit. That is why the circuit has 5 (2 + 2 + 1) qubits. Inside of red and blue rectangles are the classifier-generating and data-loading parts, respectively. (By the way, I am sorry the words in the image and the ones in this post are not the same. "trained_qubit"'s corresponds to the classifier state and "loaded_qubit"'s does to loaded state.) QuClassi updates the rotation parameters of gates applied to the classifier state during learning time. I put each layer's name in the image: single qubit unitary layer, dual qubit unitary layer and controlled qubit unitary layer. Users combine arbitrary numbers of all or part of them in arbitrary order to create a good structure for their dataset. Unfortunately, the paper does not include a careful argument about the layer structure, however, they apparently prefer to use the architecture with only the single qubit unitary layer. It could depend on each dataset. The investigation of the layers would be useful.

we went through some key points of QuClassi architecture so far, but, as you may have already noticed, the circuit can keep only one classifier state. Obviously, one classifier state corresponds to one category. It means n circuits must be prepared for n categories. But do not worry. We do not need to run the all circuits at once and their layers' sequence (not parameters) must be the same, which means the minimum number of qubits that QuClassi runs without problems is the same as for one circuit to run without any problems even during training the circuits.

On Learning

We do not go through the algorithm in detail but roughly do it without mathematical equations. Learning circuits aim to obtain the parameters to represent the classifier states well. So, the rotation angles keep on updating by the quantum fidelity between the classifier state and the loaded state.

On Reported Result

With the MNIST and Iris datasets, the author reported QuClassi achieved state-of-the-art performance and the performance compared to classical counterparts is also better in the sense of the number of parameters. They also reported the result of the performance on the actual quantum computer IBM-Q, which means we can try to train and classify data with QuClassi on the quantum computer freely! Note that, that is a brilliant chance, but it would take a long time even if the combination of layers and dataset are simple.

My thoughts

Basically, QuClassi is the architecture classifying data into an appropriate category by similarity, which is quantum fidelity. Quantum fidelity is an inner product between two unit vectors as every quantum state is expressed as a complex unit vector. So, that sounds like the best performance for the dataset is achieved by the architecture with only the single qubit unitary layer whose the parameters obtained by averaging all encoded data belonging to the same category because the parameters create the state located in the centre among the data. In that sense, the initial parameters should probably be chosen near the averaged parameters. It would help to reduce the number of epochs.

I am curious about how much the different layers affect the performance with other datasets. In the paper, their results related to compare to QuClassi's that have different layers are not rich. So, it might help us to understand the effect of each layer to try to learn and evaluate with other datasets.

Conclusion

We roughly went through QuClassi architecture. I have already tried to use QuClassi as a simulation actually and succeeded in seeing similar results with MNIST and Iris datasets as well as breast cancer and wine datasets. It takes a massive time to train the parameters if the amount of data increases. Of course, the increase is natural but the time is so longer than the classical counterpart due to the limit of the quantum computing device and simulation. I am looking forward to the day we can access quantum computers without any concern.

You also run QuClassi on our computer as a simulation with Python. The following list is my best knowledge about the implementation.

I might write a post about the above my git repository one day.

I would really appreciate it if you tell me my miss understanding, ask me questions or comment below.

Top comments (0)