QuASK -- Quantum Advantage Seeker with Kernels

QuASK is a quantum machine learning software written in Python that supports researchers in designing, experimenting, and assessing different quantum and classical kernels performance. This software is package agnostic and can be integrated with all major quantum software packages (e.g. IBM Qiskit, Xanadu's Pennylane, Amazon Braket). QuASK guides the user through a simple preprocessing of input data, definition and calculation of quantum and classical kernels, either custom or pre-defined ones. From this evaluation the package provides an assessment about potential quantum advantage and prediction bounds on generalization error. Moreover, it allows for the generation of parametric quantum kernels that can be trained using gradient-descent-based optimization, grid search, or genetic algorithms. Projected quantum kernels, an effective solution to mitigate the curse of dimensionality induced by the exponential scaling dimension of large Hilbert spaces, are also calculated. QuASK can furthermore generate the observable values of a quantum model and use them to study the prediction capabilities of the quantum and classical kernels.


Introduction
Is there any clear benefit in using quantum kernels [1] to enhance machine learning applications? The definitive answer has still to be found [2]. The nofree lunch theorem guarantees that there is no best model in machine learning which outperforms all others, and efficiency is based on the type of training data distribution. Thus, there is no hope for a "universal" quantum kernel. However, quantum kernels have been proven to reach superior performance in learning from quantum experiments [3,4] and in solving artificially generated, classically intractable classification tasks [5]. Considering real-world data, they have been used to classify cosmological data with performance comparable to the classical Gaussian kernel [6]. Moreover, these can be effectively implemented on NISQ devices [6,7]. Quantum kernels must be carefully tailored to avoid problems related to the curse of dimensionality: the Hilbert space associated with a kernel scales exponentially in the number of qubits, leading to exponentially small inner products. This issue could be solved by projecting the data onto low-dimensional subspaces using projected quantum kernels [3].
The process of designing, experimenting, and evaluating different quantum kernels can be nontrivial, resulting in computationally intensive and errorprone calculations. The dataset must be appropriately preprocessed in order to reduce the number of features to accommodate the available resources of NISQ hardware and simulators. Furthermore, the features must be normalized and rebalanced according to the class distribution. The choice of the unitary transformation implementing the quantum feature map is arbitrary, as is the observable choice in projected quantum kernels. In addition, this unitary transformation may be parametric and optimization might be necessary according to some criteria [8]. Finally, the quantum kernel must be evaluated according to some metrics including the prediction accuracy, model complexity, and geometric difference [3].
The whole process described above can be automated with the proposed QuASK (Quantum Advantage Seeker with Kernel) library. This package, written in Python, implements a (quantum) machine learning pipeline that takes care of the most trivial but time-consuming part of working with quantum kernels. QuASK is available either as an interactive CLI (Command-Line Interface) or as a library whose components can be used to build new software. QuASK allows the complete reproducibility of the experiments, saving the information processed at any step of its pipeline. QuASK allows, also, the generation of data from quantum processes in order to study the performance of classical and quantum kernels using quantum data. Finally, in terms of results visualization, QuASK can generate a simple accuracy plot of all the trained kernel machines.

QuASK library
QuASK provides a library of elements that can be integrated with other projects. The library is composed of the following software modules.
quask.datasets and quask.metrics The quality of a quantum kernel can be empirically tested through the performance of a kernel machine with respect to a certain dataset, by evaluating some metrics. The quask.datasets module facilitates the researcher in choosing a suitable dataset, providing some of the most popular datasets from OpenML platform 1 and custom datasets generated also from quantum experiments (the latter allows us to reproduce results in [3]). The module quask.metrics contains the metrics to compare and evaluate the kernels, including the kernel polarity (i.e. Frobenius inner product between two Gram matrices), the targetkernel alignment [9], the training and testing accuracy of the Support Vector Machine with the precomputed kernel, the geometric difference [3] (which can be used to find a potential quantum advantage), and the model complexity [3].
quask.template pennylane and quask.template qiskit The quantum kernel requires the definition of a feature map φ which is implemented using a parameterized unitary transformation U φ (x). The Quantum Kernel Estimation algorithm [10] calculating the function k(x, x ) = φ(x)|φ(x ) is implemented through either the overlap test (Figure 1a) or the C-SWAP test (Figure 1b). The projected quantum kernel calculates classically the inner product between two feature vectors φ(x 1 ), φ(x 2 ), each one being the output of the quantum feature map φ(x) = 0|U † (x)HU (x)|0 (Figure 1c). The feature map crosses the quantum space first through U(x) and projects the data back in a classical representation when measuring with the Hermitian operator H. QuASK contains both some notable unitary transformations U from the literature and the code to use such unitary transformations as a kernel function through one of the three methods described above. The user can define its own unitary transformation and immediately get the kernel function. QuASK is agnostic with respect to the software framework used to define, simulate and execute the quantum circuits: we have implemented some unitary transformations in PennyLane (quask.template pennylane module) and some in Qiskit (quask.template qiskit). This allows also the use of the different functionalities offered by the different frameworks. For example, noiseless simulation with PennyLane can be speeded up using JAX 2 .

quask.kernels
The module quask.kernels keeps track of the quantum kernel available within the framework. The module quask.kernels contains the global object the kernel register, which is a list of kernels. This list is already filled with  The processing phase can analyze the system to find the best technique to analyze the system.
all the quantum kernels derived from the unitary transformations in modules quask.template xyz, while the user can add its own custom kernel too. The kernels do not need to be quantum. Such module can use trainable kernels (defined in quask.template pennylane) which are parametric quantum circuits that depend on both the input and some trainable parameters. These parameters are supposed to be trained with gradient-descent-based optimization algorithms. The user can take advantage of efficient optax optimization library. Nonetheless, the user can manually tune the parameters or even run a grid search. Furthermore, such an approach is extendable to optimization techniques that change the topology of the circuit itself such as genetic algorithms.

QuASK script
QuASK can be run as a standalone, interactive executable. The software is run with python3 -m quask <command>. The script implements the sequence of operation described in Figure 1d. The available commands are:

get-dataset command
The script is used to retrieve one of the datasets available in quask.datasets module. The output of the process is a pair of NumPy binary files representing the feature data and the corresponding labels.

preprocess-dataset command
The script can modify the dataset in several ways. Firstly, the user can vertically slice the dataset, keeping only a certain range of labels. Secondly, the user can apply dimensionality reduction techniques. These are especially important in the NISQ setting due to the lack of resources. The techniques available are PCA for numerical data and FAMD for mixed numerical and categorical data 3 . Thirdly, it is possible to fix the possible imbalanceness of the classes using random undersampling or random oversampling. When loading, the script already shows some statistics about the dataset, both for classification and regression tasks, which can guide the user through the preprocessing. The output of the process are the four files X train, y train, X test, y test which can now be fed to some kernel machine. > python3.9 -m quask preprocess-dataset Choose a random seed: 2323 Choose a random seed for splitting training and testing set: 3232 Where is the output folder: . Specify the path of classical feature data X (.npy array): iris_X. The user can use trainable quantum kernels. In this case, the user specifies the embedding and the variational form (and its number of repetitions), the optimizer (ADAM stochastic gradient descent or grid search), and the reward function to maximize.

plot-metric command
The script calculates the accuracy of a kernel machine using the training and testing Gram matrices given as input. The output is a plot comparing the different kernels. For each kernel matrix, the user specifies the label that appears at the x-axis of the plot. If multiple instances are specified with the same label these are interpreted as i.i.d. random experiments and will contribute to the error bars. The software also calculates, together with the accuracy, any metric present in quask.metrics.

Conclusions
We have introduced QuASK, a tool supporting researchers in creating powerful quantum kernels. The software takes care of the most time-consuming and errorprone aspects of the experimentation. It exploits theoretical metrics in QML, providing users with an environment to easily assess case for potential quantum advantage. This package offers the exciting perspective of testing these metrics on real-wolrd datasets. The QuASK project will be extended in future versions with a wider range of datasets and feature maps, both classical and quantum.