{'fraction_non_alphanumeric': 0.030380114833926886, 'fraction_numerical': 0.008794243767715678, 'mean_word_length': 4.641656416564166, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Classification using a two-qubit quantum chip

Quantum computing has great potential for advancing machine learning algorithms beyond classical reach. Even though full-fledged universal quantum computers do not exist yet, its expected benefits for machine learning can already be shown using simulators and already available quantum hardware. In this work, we focus on distance-based classification using actual early stage quantum hardware. We extend earlier work and present a distance-based classification algorithm using only two qubits. We show that the results are similar to the theoretically expected results.


I. INTRODUCTION
Whether we are aware of it or not, machine learning has taken a prominent role in our lives. For example, various algorithms are used to process (handwritten) text [1], [2] and speech [3], [4]. Furthermore, machine learning algorithms exist to recognise patterns [5] and also more specifically focused on recognising faces [6]. These are just a few of the many applications of machine learning.
In general however, we can distinguish between three different types, being supervised, unsupervised and reinforced machine learning. In supervised machine learning, annotated data is given to the machine, which then trains a model to predict the label or annotation of unseen data. Examples of supervised machine learning are decision trees, support vector machines and neural networks. Unsupervised machine learning uses data without annotation and instead assigns the labels itself. Examples of unsupervised machine learning are clustering algorithms, such as k-means clustering. The third and last type is reinforced machine learning, or reinforcement learning, where a reward function is used that quantifies the 'goodness' of the solution. Reinforcement learning is for instance used to train AlphaGo, the first machine that beat a human at the game of Go [7]. Model parameters are consequently adjusted based on the value of this reward function. As annotated data is in general expensive to gather, often a fourth type is considered: semi-supervised learning. Here a model is initially trained with a small set of annotated data, after which the rest of the learning is done unsupervised with a larger set of data without labels.
Each of these types has its own challenges. Two common challenges across the four different types are however lack of data and intractability of the training phase, meaning that training the model is too complex. The intractability is often overcome by running the algorithms on stronger (clusters of) computers. Instead, we may also opt for a completely different way of computing: doing computations using quantum computers. With quantum computers, computations are doing using quantum bits (qubits) instead of classical bits. We can thereby exploit quantum mechanical principles such as superposition of definite classical states. In contrast to classical systems, quantum systems can be considered as complex linear combinations of definite classical states. Furthermore, quantum mechanics allows for entanglement between different states, which gives correlations beyond what is classically possible. Classical information can be extracted from a quantum computer by doing measurements. However, quantum measurement are probabilistic operations, where a single output is obtained from the respective possible results, with certain corresponding probabilities. The possible output states correspond to the states present in the superposition. The original state collapses into the measured state, and hence, information present in the original state might be lost. An introduction to quantum computing is given in [8].
These quantum mechanical properties can be used to enhance classical computing and machine learning specifically [9], [10]. Computationally expensive subroutines in classical algorithms can for instance be replaced by an efficient quantum equivalent, thereby enhancing the algorithm as a whole. Examples are sampling from probability distributions [11] and matrix inversion [12].
Another example of where quantum computing will provide improvements over classical algorithms is classification. Specifically for distance-based classification, where a label is assigned based on a distance measure evaluated on the features of the training points and of a new test point, the complexity is O(N M ), with N the number of data points and M the number of features. In [13] a quantum version of a distance-based classifier is proposed that has constant complexity O(1), independent of the size of the data set, while the same performance is obtained as classically.
In this work we extend upon this distance-based classifier. We present a non-trivial reduction of the algorithm to be used on few qubit quantum computers. The proposed algorithm classifies a data point based on two classes, each of a single data point. The algorithm can be used as benchmarking algorithm for comparison with classical devices. In this work we compare the classical theoretical results with the results obtained through quantum simulation and we running the algorithm of a two-qubit silicon-spin quantum chip. In

arXiv:2004.10426v2 [quant-ph] 22 Jul 2020
Section II we briefly explain the distance-based classifier presented in [13]. In Section III we present a non-trivial reduction of the algorithm to a two-qubit version. The results of running the algorithm on the hardware and on the simulator are presented in Section IV. These results are compared to the expected theoretical results. Conclusions are given in Section V.

II. DISTANCE-BASED CLASSIFIER
In this section we explain the quantum distance-based classifier proposed in [13] and consider the technicalities when implementing and using the algorithm. This algorithm classifies a new test point, based on its distances to data points in a data set. The output of the algorithm is a bit representing the label of the test point. Consider Letx ∈ R M be an unlabeled data point, the goal is to assign the new labelỹ to this data point x. The algorithm presented in [13], implements the threshold functionỹ where sgn : Without loss of generality we can assume that the data points in D are normalised. The data points can then be encoded in the qubits: x j |j , with x j the j-th coefficient of x and |j the j-th computational basis state. Suppose we start with the following quantum state Here the first register |i is an index register, indexing the data points. The second register is an ancilla qubit entangled with the new test point and the i-th data point. The fourth register encodes the label y m . In case of only two classes, the fourth register is only a single qubit and we identify y m = s with |y m = |(s + 1)/2 . The algorithm is now given by a Hadamard operation on the ancilla qubit, a measurement of that qubit and a measurement of the fourth register. Due to the probabilistic nature of quantum algorithms, multiple measurement rounds should be used. The label of the test point is assigned based on the measurement of the fourth register, conditional on the first measurement giving a 0. Results where the first measurement gives a 1 should be neglected.
After the Hadamard gate we are left with Measuring the ancilla qubit and only continuing with the algorithm if the |0 -state is measured, leaves us with Here, p acc is the probability of measuring 0, given by If instead 1 is measured, the algorithm should be restarted. This can also be taken care of in a post-processing step. The output bit is obtained by measuring the fourth register, which encodes the labels. The probability of obtainingỹ m = 1 is given by If both classes have the same number of data points and the data points are normalized, we have This algorithm thus implements the classifier of Eq. (1). Running multiple measurement rounds, the most likely class is obtained. Note that the constant complexity O(1) of this algorithm assumes an efficient state preparation, for instance using a quantum RAM [14]. In [15] implementations of the distancebased classifier are given and assumptions made in the original work are relaxed. In that same work, extensions are given towards non-balanced classes. In the next section we will reduce this algorithm to a two qubit version.

III. REDUCTION TO A TWO-QUBIT VERSION
In this section we present a non-trivial reduction of the distance-based classifier to a two qubit version. The algorithm proposed in this section produces the same probability distribution for the measured labels as the original distance-based classifier for a given data set. In our approach, we use the same qubit for both encoding the data points as well as encoding the labels.
For a two-qubit version of the algorithm, we consider a training set D = {(x 0 , −1), (x 1 , 1)} and a test pointx, all with two features. We can encode our data points as such that R y (θ) |0 = |x 0 . Without loss of generality we may assume θ = 0. Furthermore, note that for two data points, the index register and the label register have the same value. Hence, the two can be combined. This gives as initial state 1 2 |0 |0 |x + |1 |0 The ratio of the probabilities when measuring the first register is then given by with ω and φ depending on our data. Now, we reduce the algorithm to only two qubits. Let t = cos 2 ω 4 / cos 2 ω−φ

4
, then, we define if t = 1. If t = 1, both classes are equally likely and we define ω = 0. We propose the quantum circuit shown in Fig. 1, which produces the same probability distribution as the original classifier. The last Hadamard-gate and the measurements of both qubits shown in Fig. 1 remain the same as in the original algorithm. The other operations are state preparation. Note that state preparation gives The Hadamard-gate on the first qubit results in 1 2 (cos(ω /2) |00 + cos(ω /2) |10 + (1 + sin(ω /2)) |01 + (1 − sin(ω /2)) |11 ) .
When measuring the first (left-most) qubit and keeping only continuing if the |0 -state is measured, we have Here, p acc is the acceptance probability, given by Note that this acceptance probability differs from the one given in Eq. (5). Also note that the two qubit classification algorithm gives the same probability distribution as the original algorithm.

IV. RESULTS
In this section we present the results when running the algorithm on quantum hardware and on a quantum simulator. These results are compared to the results we should obtain theoretically. The theoretical values are obtained by determining the probability distribution from the quantum state in Eq. (10) and the acceptance probability from Eq. (11).
We used the Quantum Inspire platform [16], developed by QuTech to obtain our results. This online platform hosts two quantum chips: a 2-qubit silicon spin chip and a 5-qubit transmon chip. Furthermore, a quantum simulator based on the QX programming language is available [17]. We used the publicly available 2-qubit silicon spin chip for our results.
For the experiments we use the Iris flower dataset [18]. This data set contains 150 data points, equally distributed over three classes. Each data point has four features. We only consider the Setosa and Versicolor class and the first two features of the data points: the width and length of the sepal leaves. We standardize and normalize the data points and sample two data sets from them. For both data sets, we randomly select a data point from both classes and label them accordingly. For the first data set, we sample the test point from the Setosa class, for the second data set we sample the test point from the Versicolor class. The three data points of each data set can now be written as For both data sets, we determine t and ω and consequently run the circuit as shown in Fig. 1 on the quantum simulator and on the 2-qubit silicon spin chip. Furthermore, we compute the theoretically expected variables. The found probabilities are shown in Tab. I. This table also shows the acceptance probabilities. For both the quantum hardware and the quantum simulator, we determined the probabilities based on 2048 circuit evaluations. The shown probabilities for both labels are conditional on the ancilla qubit being in the |0 -state.
We see that the results obtained with the simulations match the theoretical values quite well. The differences between the simulation results and the quantum hardware results follow from the decoherence of the qubits and the noise in the algorithm execution. Note that in all cases, the correct label is assinged to the test point: label 0 for the first data set and label 1 for the second data set.

V. CONCLUSIONS
This paper presented a quantum algorithm for the practical problem of classification. The quantum distance-based classifier proposed in [13] was non-trivially extended to a two qubit version with which a data point can be classified in one of two classes, each containing a single data point. Each data point can also represent the mean of a large set of point, thereby allowing classification for arbitrarily large data sets, after preprocessing. As the obtained results can also be computed classically, the algorithm functions as a bench-mark for near-term quantum computers.
We found that the same probability distribution is produced as one would obtain with the original multi-qubit approach, however, less qubits are used. Due to effects such as noise and decoherence, the results for the hardware runs differ slightly from the simulated results. We tested the algorithm with two random data sets and in both cases, the correct label was assigned to the test point. The hardware used to produce these results was a two-qubit silicon-spin quantum chip, developed by QuTech and hosted publicly on the Quantum Inspire platform.