Quantum Open Source Foundation Application
"Reality is that which, when you stop believing in it, does not go away." P. Dick

Quantum Open Source Foundation Application

I am glad to share that I have been selected as mentee in the Quantum Open Source Foundation Mentorship Program Cohort 7. I will be working with Satyadhyan Chickerur , Ph.D. as mentor on Quantum Machine Learning Applications for the Healthcare System. However, the scope of this article is to show the solution I came up with to solve the screening task the Program asked us to solve.

After submitting our proposals, we were asked to choose one of the following tasks to solve.:

Task 1 find the largest number

You have two integers, either positive or negative, and the challenge is to generate a quantum algorithm that returns which is the larger number. Consider an appropriate number of qubits and explain why your proposal is valid for all kinds of numbers in case.

Task 2 Is Rectangle?

Given four positive integers A, B, C, D, determine if there’s a rectangle such that the lengths of its sides are A, B, C and D (in any order).

If any such rectangle exist return 1 else return 0.

Task 3 QSVM

Generate a Quantum Support Vector Machine (QSVM) using the iris dataset and try to propose a kernel from a parametric quantum circuit to classify the three classes(setosa, versicolor, virginica) using the one-vs-all format, the kernel only works as binary classification. Identify the proposal with the lowest number of qubits and depth to obtain higher accuracy. You can use the UU?(U dagger) format or using the Swap-Test.

Task 4 Random Circuits

Design a function that generates a random quantum circuit by considering as parameters the number of qubits, the number of depths, and the base of gates to be used. You could only use the quantum gates of 1 and 2 qubits.


I chose to solve the Task 3, the Quantum Support Vector Machine Problem. I've been learning ML for some time at with Carlos Ruiz at Colegio de Matemáticas Bourbaki, so I thought this would be my best chance.


Now, let's talk about SVM and QSVM.

Support vector machines are supervised learning models with associated learning algorithms that analyze data for classification and regression analysis. SVMs can efficiently perform a non-linear classification using what is called the kernel trick, implicitly mapping their inputs into high-dimensional feature spaces. More formally, a support vector machine constructs a hyperplane or set of hyper-planes in a high or infinite-dimensional space, which can be used for classification, regression, or other tasks like outliers detection Intuitively, a good separation is achieved by the hyperplane that has the largest distance to the nearest training-data point of any class (so-called functional margin), since in general the larger the margin, the lower the generalization error of the classifier. Whereas the original problem may be stated in a finite-dimensional space, it often happens that the sets to discriminate are not linearly separable in that space. For this reason, it was proposed that the original finite-dimensional space be mapped into a much higher-dimensional space, presumably making the separation easier in that space. To keep the computational load reasonable, the mappings used by SVM schemes are designed to ensure that dot products of pairs of input data vectors may be computed easily in terms of the variables in the original space, by defining them in terms of a kernel function k(x,y) selected to suit the problem. The hyper-planes in the higher-dimensional space are defined as the set of points whose dot product with a vector in that space is constant, where such a set of vectors is an orthogonal (and thus minimal) set of vectors that defines a hyperplane. The vectors defining the hyper-planes can be chosen to be linear combinations with parameters α i of images of feature vectors xi that occur in the data base. With this choice of a hyperplane, the points x in the feature space that are mapped into the hyperplane are defined by the relation ∑ αi k (xi, x) = constant . [1]

Summing up, the key is to find a vector space in which the features can be easily linearly separable. We accomplish this with the help of a kernel function. In many cases the topology behind these problem is an euclidean space.

If we talk about Quantum Support Vector Machines, we use the quantum feature maps V(Φ(???)) to translate the classical data ??? (features) into quantum states and build the Kernel of the SVM out of these quantum states. After calculating the Kernel matrix on the quantum computer they can train the Quantum SVM the same way as a classical SVM [2]. You can check this process in the following image.

No alt text provided for this image
Source: Quantum Support Vector Machines for Continuum Suppression in B Meson Decays [3]


One of the key differences here is that we are moving into the Hilbert Space, a complex vector space that is infinite-dimensional. This is a significant departure from the finite-dimensional vector spaces we typically work with in classical computing. The Hilbert Space is a big, big place, and its infinite dimensionality allows us to model and simulate complex quantum systems.

What is a Quantum Kernel?

A quantum feature map naturally gives rise to a quantum kernel, which we can think of as a measure of similarity.

When considering finite data, we can represent the quantum kernel as a matrix. We can calculate each element of this kernel matrix on a quantum computer by calculating the transition amplitude.

Assuming the feature map is a parameterized quantum circuit (PQC), which can be described as a unitary transformation on qubits. This provides us with an estimate of the quantum kernel matrix, which we can then use in a kernel machine learning algorithm, such as support vector classification. [4]


Now, we can move on with the problem solution.

The task requires a quantum kernel that can separate the three classes in Fisher's dataset. The IBM Quantum Qiskit SDK includes a QuantumKernel class that can accomplish this. However, before we explore the quantum approach, we will perform some exploratory data analysis and solve the problem classically using an SVM.

The EDA is shown below:

No alt text provided for this image
Iris Data Set Exploratory Data Analysis
No alt text provided for this image
Iris Data Set Exploratory Data Analysis

To solve this problem classically, we can use the SVM class from scikit-learn and then print a classification report using the targets and predictions. Please refer to the code below for implementation details.

Hybrid Quantum Classification

First Approach: Quantum Kernel Machine Learning (UU?)

The QSVM algorithm is shown in the next image:

No alt text provided for this image
Source: Qiskit Machine Learning Tutorial


Basically, we build the train and test quantum kernel matrixes by:

  • For each pair of data points in the training dataset, apply the feature map and measure the transition probability.
  • For each training data point and testing point, apply the feature map and measure the transition probability
  • Use the train and test quantum kernel matrices in a classical support vector machine classification algorithm. [5]

The feature map used is the ZZFeatureMap. We can see its image here:

No alt text provided for this image
ZZFeature Map


We use four qubits because the dataset has four features. Later on, we will explore if there is a better approach. Firstly, we will combine the QSVC Qiskit class with the classical kernel class (SVC) and then, fit and train the model.

Second Approach: Quantum Kernel Alignment

QKA is a technique that iteratively adapts a parametrized quantum kernel to a dataset while converging to the maximum SVM margin. Essentially, we add Pauli Y rotation gates to the n qubits before the ZZFeatureMap to optimize the circuit. So, more or less, the walk-road is similar but with the difference that we are going to optimize the circuit with an optimizer, SPSA. This is analogous to kernel alignment in classical machine learning [6].

The composed feature map is showed below:

No alt text provided for this image
RY gates on the four qubits with the ZZFeatureMap

By calling different Qiskit classes and optimizing the ansatz, we obtain the results.

The results are presented here:

  • QSVC accuracy score: 0.933
  • QKA accuracy score: 0.933

The results of our quantum kernel for the Fisher's iris dataset were promising, with an accuracy of approximately 93%. While this may not be the most efficient approach to solving this particular classification problem, it demonstrates the potential of quantum computing in machine learning applications.

Is there a better approach?

Yes, arbitrary encoding. Arbitrary encoding encodes N features as rotations on N parameterized gates on n qubits, where n<=N. Like angle encoding, it only encodes one data point at a time, rather than a whole dataset. It also uses a constant depth quantum circuit and n<=N qubits, meaning it can be run on current quantum hardware[7].

For this case, we use the Qiskit EfficientSU2 circuit to encode the 4 features of the iris dataset, which only requires 1 qubit.

We present two new ansatz for the QSVC and QKA approach, respectively:

No alt text provided for this image
QSVC EfficientSU2 circuit for one qubit. The R gates encode the 4 features of the dataset.
No alt text provided for this image
QKA EfficientSU2 circuit for one qubit. The RY gate is composed with the EfficientSU2.


The results are presented here with new ansatz's:

  • QSVC accuracy score: 0.900
  • QKA accuracy score: 0.966


In conclusion, we have presented a solution to the QOSF Mentorship Program Cohort 7 task 3, which involved developing a quantum kernel to classify the Fisher's iris dataset. We explored both classical and quantum approaches and demonstrated the effectiveness of quantum machine learning in solving this problem.

The solution involved using the Qiskit library and various quantum circuits to encode the features of the dataset. We also explored different ansatz's and demonstrated how they can improve the accuracy of our model.

Overall, this task has been a valuable learning experience and I am excited to continue exploring the potential of quantum machine learning in future projects. Thanks to the QOSF and my mentor for this opportunity.

This is all for now. You can check out my code solution at this GitHub repo[8].

Feel free to leave your comments if you have any.


References:

[1] - Support Vector Machines

[2] - Introduction into Quantum Support Vector Machines

[3] - Quantum Support Vector Machines for Continuum Suppression in B Meson Decays

[4] - Qiskit Quantum Kernels

[5] - Qiskit Quantum Support Vector Classification

[6] - Qiskit Quantum Kernel Alignment

[7] - Qiskit Data Encoding

[8] - GitHub Repo QOSF-QSVC

Hashtags:

#quantumcomputing

#quantumtechnology

#python

#qiskit

Alberto M.

ex Qiskit community Advocate Intern /Qiskit Advocate @ IBM Quantum | Mentor @ QOSF Mentorship Program and Womanium in quantum | Ambassador @ Unitary Fund | Admin @ Quantum Universal Education

1 年

Great! and Thank you so much for share your solution, you should upload your solution here https://github.com/qosf/monthly-challenges

Carlos Ruiz

Matemático & Co-Founder @ Colegio de Matemáticas Bourbaki

1 年

?Qué gusto!

要查看或添加评论,请登录

社区洞察

其他会员也浏览了