Data re-uploading for a universal quantum classifier

A single qubit provides sufficient computational capabilities to construct a universal quantum classifier. This fact may be surprising since a single qubit only offers a simple superposition of two states and single qubit gates only make a rotation in the Bloch sphere. The key ingredient to circumvent these limitations is to allow for multiple data re-uploading. A quantum circuit can then be organized as a series of data re-uploading and single-qubit processing units. Furthermore, both data re-uploading and measurements can accommodate multiple dimensions in the input and multiple categories in the output, so as to conform a universal quantum classifier. The extension of this idea to several qubits enhances the efficiency of the strategy as entanglement expands the superpositions carried along the classification. Extensive benchmarking on different examples of the single- and multi- qubit quantum classifier validates its ability to describe and classify complex data.


I. INTRODUCTION
Quantum circuits that make use of a small amount of quantum resources are of most importance to the field of quantum computation. Indeed, algorithms that need few qubits may prove relevant even if they do not attempt any quantum advantage, as they may be useful parts of larger circuits.
A reasonable question to ask is what is the lower limit of quantum resources needed to achieve a given computation. A naive estimation for the quantum cost of a new proposed quantum algorithm is often made based on analogies with classical algorithms. But this may be misleading, as classical computation can play with memory in a rather different way as quantum computers do. The question then turns to the more refined problem of establishing the absolute minimum of quantum resources for a problem to be solved.
We shall here explore the power and minimal needs of quantum circuits to carry out a general supervised classification task. Three elements in the computation need renewed attention. The obvious first concern is to find the way to upload data in a quantum computer. Then, it is necessary to find an optimal processing of information, followed by an optimal measurement strategy. We shall revisit these three issues in turn. The non-trivial step we take here is to combine the first two, that is data uploading and processing, in a non-trivial way.
There exist several proposals to construct a quantum classifier. These can be divided into two families: those that are inspired in classical classification algorithmsi.e. support vector machines and perceptons [1][2][3][4][5][6][7] -and those that use parametrized quantum circuits [8][9][10]. The latter are promising candidates to be implemented in a Noisy Intermediate Scale Quantum computer. In these proposals, the quantum circuit is designed in a way that will be hardly simulated by a classical computer with the goal to achieve quantum advantage once applied to a large amount of qubits. The quantum classifiers introduced in those papers are designed to perform binary classification or, equivalently, to represent Boolean functions. The desired non-linearities of the functions are introduced by using the properties of tensor product. In contrast, we focus on the smaller possible circuit that is capable of performing a classification task consisting on two or more classes. The data non-linearities are achieved by re-uploading the data points along the circuit.
The main result of this work is, indeed, to show that there is a trade-off between the number of qubits needed to perform a classification and multiple data reuploading. That is, we may use less qubits at the price of re-entering data several times along the quantum computation. Quantum computers can not copy data, but classical devices can. Therefore, it makes sense to re-upload classical data along a quantum computation to bypass the limitations established by the no-cloning theorem on the quantum circuit. By following this line of thought, we present an equivalence between data re-uploading and the Universal Approximation Theorem applied to artificial neural networks [11]. Just as a network composed of a single hidden layer with enough neurons can reproduce any continuous function, a single-qubit classifier can in principle achieve the same by re-uploading the data enough times.
The single-qubit classifier illustrates the computational power that a single qubit can handle. This proposal is to be added to other few-qubit benchmarks in machine learning [12]. The input redundancy has also been proposed to construct complex encoding in parametrized quantum circuits [13]. These and other proposals mentioned in the previous paragraphs are focused in representing classically intractable or very complex Kernel functions with few qubits. On the contrary, the focus of this work is to distill the minimal amount of quantum resources needed for a given classification task quantified in terms of the number of qubits and unitary operations.
We shall illustrate the power of a single-and multiqubit classifiers with data re-uploading with a series of examples. First, we classify points in a plane which is divided in two areas. Then, we extend successfully the number of regions on a plane to be classified. Next, we consider the classification of multi-dimensional patterns and, finally, we benchmark this quantum classifier with non-convex figures. For every example, we train a parametrized quantum circuit that carries out the task and we analyze its performance in terms of the circuit architecture, i.e. for single-and multi-qubit classifers with and without entanglement between qubits.
This paper is structured as follows. First, in section II, we present the basic structure of a single-qubit quantum classifier. Data and processing parameters are uploaded and re-uploaded using one-qubit general rotations. For each data point, the final state of the circuit is compared with the target state assigned to its class and the free parameters of the circuit are updated accordingly using a classical minimization algorithm. Second, in section III, we motivate the data re-uploading approach by using the Universal Approximation Theorem of artificial neural networks. In section IV, we introduce the extension of this classifier to multiple qubits. Then, in section V, we detail the minimization methods used to train the quantum classifiers. Finally, in section VI, we benchmark single-and multi-qubit quantum classifiers defined previously with problems of different dimensions and complexity and present a comparison with respect to classical classification techniques. The conclusions of this proposal for a quantum classifier are exposed in section VII.

II. STRUCTURE OF A SINGLE-QUBIT QUANTUM CLASSIFIER
The global structure of any quantum circuit can be divided into three elements: uploading of information onto a quantum state, processing of the quantum state, and measurement of the final state. It is far from obvious how to implement each of these elements in an optimal way to perform a specific operation. We shall now address them one at a time for the task of classification.

A. Re-uploading classical information
To load classical information onto a quantum circuit is a highly non-trivial task [1]. A critical example is the processing of big data. While there is no in-principle obstruction to upload large amounts of data onto a state, it is not obvious how to do it.
The problem we address here is not related to a large amount of data. It is thus possible to consider a quantum circuit where all data are loaded in the coefficients of the initial wave function [6,8,9,12,13]. In the simplest of cases, data are uploaded as rotations of qubits in the computational basis. A quantum circuit would then follow that should perform some classification.
This strategy would be insufficient to create a universal quantum classifier with a single qubit. A first limitation is that a single qubit only has two degrees of freedom, thus only allowing to represent data in a two-dimensional space. No quantum classifier in higher dimensions can be created if this architecture is to be used. A second limitation is that, once data is uploaded, the only quantum circuit available is a rotation in the Bloch sphere. It is easy to prove that a single rotation cannot capture any non-trivial separation of patterns in the original data.
We need to turn to a different strategy, which turns out to be inspired by neural networks. In the case of feedforward neural networks, data are entered in a network in such a way that they are processed by subsequent layers of neurons. The key idea is to observe that the original data are processed several times, one for each neuron in the first hidden layer. Strictly speaking, data are reuploaded onto the neural network. If neural networks were affected by some sort of no-cloning theorem, they could not work as they do. Coming back to the quantum circuit, we need to design a new architecture where data can be introduced several times into the circuit.
The central idea to build a universal quantum classifier with a single qubit is thus to re-upload classical data along with the computation. Following the comparison with an artificial neural network with a single hidden layer, we can represent this re-upload diagramatically as shows Fig. 1. Data points in a neural network are introduced in each processing unit, represented with squares, which are the neurons of the hidden layer. After the neurons process these data, a final neuron is necessary to construct the output to be analyzed. Similarly, in the single-qubit quantum classifier, data points are introduced in each processing unit which this time correspond with a unitary rotation. However, each processing unit is affected by the previous one and the input data reintroduced. The final output is a quantum state to be analyzed as it will be explained in the next subsections.
The explicit form of this single-qubit classifier is shown in Fig. 2. Classical data are re-introduced several times in a sequence interspaced with processing units. We shall consider the introduction of data as a rotation of the qubit. This means that data from a three-dimensional space, x, can be re-uploaded using unitaries that rotate the qubit U ( x). Later processing units will also be rotations as discussed later on. The whole structure needs to be trained to the classification of patterns.
As we shall see, the performance of the single-qubit quantum classifier will depend on the number of reuploads of classical data. This fact will be explored in the results section.  In the neural network, every neuron receives the input from all neurons of the previous layer. In contrast with that, the single-qubit classifier receives information from the previous processing unit and from the input (introduced classically). It processes everything altogether and the final output of the computation is a quantum state encoding several repeats of input up-loadings and processing parameters.

B. Processing along re-uploading
The single-qubit classifier belongs to the category of parametrized quantum circuits. The performance of the circuit is quantified by a figure of merit, some specific χ 2 to be minimized and defined later. We need, though, to specify the processing gates present in the circuit in terms of a classical set of parameters.
Given the simple structure of a single-qubit circuit presented in Fig. 2, the data is introduced in a simple rotation of the qubit, which is easy to characterize. We just need to use arbitrary single-qubit rotations U (φ 1 , φ 2 , φ 3 ) ∈ SU(2). By an abuse of language, we will write U ( φ) with φ = (φ 1 , φ 2 , φ 3 ). Then, the structure of the universal quantum classifier made with a single qubit is which acts as The final classification of patterns will come from the results of measurements on |ψ . We may introduce the concept of processing layer as the combination so that a more complex and more robust classifier corresponds to where the depth of the circuit is 2N . The more layers the more representation capabilities the circuit will have, and the more powerful the classifier will become. Again, Figure 2: Single-qubit classifier with data re-uploading. The quantum circuit is divided into layer gates L(i) which constitutes the classifier building blocks. In the upper circuit, each of these layers is composed by a U ( x) gate, which uploads the data, and a parametrized unitary gate U ( φ). We apply this building block N times and finally compute a cost function which is related with the fidelity of the final state of the circuit with the corresponding target state of its class. This cost function may be minimized by tunning the φi parameters. Eventually, data and tunable parameters can be introduced with a single unitary gate, as illustrates the bottom circuit.
this follows from the analogy to neural networks, where the size of the intermediate hidden layer of neurons is key to represent complex functions. There is a way to compactify the quantum circuit into a shorter one. This can be done if we incorporate data and processing angles in a single step. Then, a layer would only need a single rotation to introduce data and tunable parameters, i.e. L(i) = U ( φ, x). In addition, each data point can be uploaded with some weight w i . These weights will play a similar role as weights in artificial neural networks, as we will see in the next section. Altogether, each layer gate can be taken as where is the Hadamard product of two vectors. In case the data points have dimension lesser than three, the rest of x components are set to zero. Such an approach reduces the depth of the circuit by half. Further combinations of layers into a fewer rotations would be possible, but the nonlinearity inherent to subsequent rotations would be lost, and the circuit would not be performing well.
It is also possible to enlarge the dimensionality of the input space in the following way. Let us extend the definition of i-th layer to where each data point is divided into k vectors of dimension three. In general, each unitary U could absorb as many variables as freedom in a SU (2) unitary. Each set of variables act at a time, and all of them have been shown to the circuit after k iterations. Then, the layer structure follows. The complexity of the circuit only increases linearly with the size of the input space.

C. Measurement
The quantum circuit characterized by a series of processing angles {θ i } and weights {w i } delivers a final state |ψ , which needs to be measured. The results of each measurement are used to compute a χ 2 that quantifies the error made in the classification. The minimization of this quantity in terms of the classical parameters of the circuit can be organized using any preferred supervised machine learning technique.
The critical point in the quantum measurement is to find an optimal way to associate outputs from the observations to target classes. The fundamental guiding principle to be used is given by the idea of maximal orthogonality of outputs [14]. This is easily established for a dichotomic classification, where one of two classes A and B have to be assigned to the final measurement of the single qubit. In such a case it is possible to measure the output probabilities P (0) for |0 and P (1) for |1 . A given pattern could be classified into the A class if P (0) > P (1) and into B otherwise. We may refine this criterium by introducing a bias. That is, the pattern is classified as A if P (0) > λ, and as B otherwise. The λ is chosen so as to optimize the success of classification on a training set. Results are then checked on an independent validation set.
The assignment of classes to the output reading of a single qubit becomes an involved issue when many classes are present. For the sake of simplicity let us mention two examples for the case of classification to four distinct classes. One possible strategy consists on comparing the probability P (0) to four sectors with three thresholds: 0 ≤ λ 1 ≤ λ 2 ≤ λ 3 ≤ 1. Then, the value of P (0) will fall into one of them and a classification is issued. A second, more robust assignment is obtained by computing the overlap of the final state to one of the states of a label states-set. This states-set is to be chosen with maximal orthogonality among all of them. This second method needs from the maximally orthogonal points in the Bloch sphere. Figure 3 shows the particular cases that can be applied to a classification task of four and six classes. In general, a good measurement strategy may need some prior computational effort and refined tomography of the final state. Since we are proposing a single-qubit classifier, the tomography protocol will only require three measurements.
It is possible to make an interpretation of the singlequbit classifier in terms of geometry. The classifier opens a 2-dimensional Hilbert space, i.e. the Bloch sphere. As we code data and classification within the parameters defining rotations, this Hilbert space is enough to achieve classification. Any operation L(i) is a rotation on the surface of the Bloch sphere. With this point of view in mind, we can easily see that we can classify any point using only one unitary operation. We can transport any point to any other point on the Bloch sphere by nothing else than choosing the angles of rotation properly. However, this does not work for several data, as the op- Figure 3: Representation in the Bloch sphere of four and six maximally orthogonal points, corresponding to the vertices of a tetrahedron and an octahedron respectively. The singlequbit classifier will be trained to distribute the data points in one of these vertices, each one representing a class.
timal rotation for some data could be very inconvenient for some other.

A fidelity cost function
We propose a very simple cost function motivated by the geometrical interpretation introduced above. We want to force the quantum states |ψ( θ, w, x) to be as near as possible to one particular state on the Bloch sphere. The geometrical distance between the label state and the data state can be measured with the relative fidelity between the two states [15]. Thus, our aim is to maximize the average fidelity between the states at the end of the quantum circuit and the label states corresponding to their class. We define the following cost function that carries out this task, where |ψ s is the correct label state of the µ data point, which will correspond to one of the classes.

A weighted fidelity cost function
We shall next define a refined version of the previous fidelity cost function to be minimized. The set of maximally orthogonal states in the Bloch sphere, i.e. the label states, are written as |ψ c , where c is the class. Each of these label states represents one class for the classifier. Now, we will follow the lead usually taken in neural network classification.
Let us define the quantity where |ψ c is the label state of the class c and |ψ( θ, w, x) is the final state of the qubit at the end of the circuit.
This fidelity is to be compared with the expected fidelity of a successful classification, Y c ( x). For example, given a four-class classification and using the vertices of a tetrahedron as label states (as shown in Fig. 3), one expects Y s ( x) = 1, where s is the correct class, and Y r ( x) = 1/3 for the other r classes. In general, Y c ( x) can be written as a vector with one entry equal to 1, the one corresponding to the correct class, and the others containing the overlap between the correct class label state and the other label states.
With these definitions, we can construct a cost function which turns out to be inspired by the conventional cost function in artificial neural networks. By weighting the fidelities of the final state of the circuit with all label states, we define the weighted fidelity cost function as where M is the total number of training points, C is the total number of classes, x µ are the training points and α = (α 1 , · · · , α C ) are introduced as class weights to be optimized together with θ and w parameters. This weighted fidelity has more parameters than the fidelity cost function. These parameters are the weights for the fidelities.
The main difference between the weighted fidelity cost function of Eq. (9) and the fidelity cost function of Eq. (7) is how many overlaps do we need to compute. The χ 2 wf requires as many fidelities as classes every time we run the optimization subroutine, while the χ 2 f needs just one. This is not such a big difference for few classes and only one qubit. It is possible to measure any state with a full tomography process which, for one qubit, is achievable. However, for many different classes we expect that one measurement will be more efficient than many.
Besides the weighted fidelity cost function is costlier than the fidelity cost function, there is another qualitative difference between both. The fidelity cost function forces the parameters to reach the maximum in fidelities. As a way of speaking, this fidelity moves the qubit state to where it should be. The weighted fidelity forces the parameters to be close to a specified configuration of fidelities. It moves the qubit state to where it should be and moves it away from it should not. Therefore, we expect that the weighted fidelity will work better than the fidelity cost function.

III. UNIVERSALITY OF THE SINGLE-QUBIT CLASSIFIER
After analyzing several classification problems, we obtain evidences that the single-qubit classifier introduced above is able to classify any function. In this section, we provide the motivation for this statement based on the Universal Approximation Theorem (UAT) of artificial neural networks [11].

A. Universal Approximation Theorem
Theorem-Let I m = [0, 1] m be the m-dimensional unit cube and C(I m ) the space of continuous functions in I m . Let the function ϕ : R → R be a nonconstant, bounded and continuous function. Then, there exist an integer N such that for all x ∈ I m and > 0.
In artificial neural networks, ϕ is the activation function, w i are the weights for each neuron, b i are the biases and α i are the neuron weights that construct the output function. Thus, this theorem establishes that it is possible to reconstruct any continuous function with a single layer neural network of N neurons. The proof of this theorem for sigmoidal activation function can be found in Ref. [16]. This theorem was generalized for any nonconstant, bounded and continous activation function in Ref. [11]. Moreover, Ref. [11] presents the following corollary of this theorem: ϕ could be a nonconstant finite linear combination of periodic functions, in particular ϕ could be a nonconstant trigonometric polynomial.

B. Universal Quantum Circuit Approximation
The single-qubit classifier is divided into several layers which are general SU(2) rotational matrices. There exist many possible decompositions of a a SU(2) rotational matrix. In particular, we use Using the SU(2) group composition law, we can rewrite the above parametrization in a single exponential, with and where cos d = cos The single-qubit classifier codifies the data points into φ parameters of the U unitary gate. In particular, we can re-upload data together with the tunable parameters as defined in Eq. (5), i.e. Thus, Next, we apply the Baker-Campbell-Hausdorff (BCH) formula [17] to the above equation, Notice that the remaining BCH terms O corr are also proportional to Pauli matrices due to [σ i , σ j ] = 2i ijk σ k .
Each ω terms are trigonometric functions, unconstant, bounded and continuous. Then We still have to deal with the remaining terms O corr of the BCH expansion. Instead of applying such expansion, we can use again the SU(2) group composition law to obtain the analytical formula of U( x) = e i ξ( x)· σ , where ξ( x) will be an inextricably trigonometric function of x. The O corr terms are proportional to σ matrices, so O corr = ( x) · σ for some function ( x). Then, Thus, O corr terms can be absorbed in f ( x).
For each data point x, we obtain a final state that will contain these ξ( x) functions. With all training points, we construct a cost function that can include new parameters α c for each class if we use the weighted fidelity cost function of Eq. (9). The function obtained from the combination of ξ(x) and α c is expected to be complex enough to probably represent almost any continuous function. However, more parameters are necessary in order to map this argument with the UAT expression.
If we compare the parameters of the UAT with the single-qubit circuit parameters, the w i will correspond with the weights, the θ i with the biases b i , the number of layers N of the quantum classifier will correspond with the number of neurons in the hidden layer and ω functions with the activation functions ϕ.
We have provided an explanation about why is necessary to re-upload the data at each layer and why a single qubit could be a universal classifier. As has been stated before, an artificial neural network introduces the data points in each hidden neuron, weights them and adds some bias. Here we cannot just copy each data point because the non-cloning theorem, so we have to re-upload it at each layer.

IV. FROM SINGLE-TO MULTI-QUBIT QUANTUM CLASSIFIER
The single-qubit classifier can not carry any quantum advantage in front of classical classification techniques such artificial neural networks. In the previous sections, we have defined a quantum mechanical version of a neural network with a single hidden layer. In general, it is necessary a huge amount of hidden neurons to approximate a target function with a single layer. To circumvent this inconvenience, more hidden layers are introduced, leading eventually to the concept of deep neural networks.
By using the single-qubit classifier formalism that we have introduced in the previous sections, we propose its generalization to more qubits. The introduction of multiple qubits to this quantum classifier may improve the performance of it in a similar way as more hidden layers improves the classification task of an artificial neural network. With the introduction of entanglement between these qubits, we reduce the number of layers of our classifier as well as propose a quantum classification method that can achieve quantum advantage.

A. Measurement strategy and cost function for a multi-qubit classifier
With a single-qubit classifier, the measurement strategy consisting on comparing the final state of the circuit with a pre-defined target state was achievable. Experimentally, one needs to perform a quantum state tomography protocol of only three measurements. However, if more qubits are to be considered, tomography protocols become exponentially expensive in terms of number of measurements.
We propose two measurement strategies for a multiqubit classifier. The first one is the natural generalization of the single-qubit strategy, although it will become unrealizable for a large number of qubits. We compare the final state of the circuit with one of the states of the computational basis, one for each class. The second strategy consist on focusing in one qubit and depending on its state associate one or other class. This is similar to previous proposals of binary multi-qubit classifiers [10], although we add the possibility of multiclass classification by introducing several thresholds (see section II).
Another part that should be adapted is the definition of the cost function. In particular, we use different functions for each strategy explained above. Figure 4: Two-qubit quantum classifier circuit without entanglement (top circuit) and with entanglement (bottom circuit).
Here, each layer includes a rotation with data re-uploading in both qubits plus a CZ gate if there is entanglement. The exception is the last layer, which do not have any CZ gate associated. For a fixed number of layers, the number of parameters to be optimized doubles the ones needed for a single-qubit classifier.
For the first strategy, we use the fidelity cost function of Eq. (7). Its generalization to more qubits is straightforward. However, the orthogonal states used for a multi-qubit classifier are taken as the computational basis states. A more sophisticated set of states could be considered to improve the performance of this method.
For the second strategy, we use the weighted fidelity cost function. As stated above, we just focus on one qubit, thus where ρ q is the reduced density matrix of the qubit to be measured. Then, the weighted fidelity cost function can be adapted as where we average over all Q qubits that form the classifier. Eventually, we can just measure one of these qubits, reducing the number of parameters to be optimized.

B. Quantum circuits examples
The definition of a multi-qubit quantum classifier circuit could be as free as is the definition of a multi-layer neural network. In artificial neural networks, it is far from obvious which should be the number of hidden layers and neurons per layer to perform some task. In addition, it is, in general, problem-dependent. For a multiqubit quantum classifier there is an extra freedom in the circuit-design: how to introduce the entanglement. Figures 4 and 5 show the explicit circuits used in this work. For a two-qubit classifier without entanglement, and similarly for a four-qubit classifier, we identify each  (2) and (3)-(4) qubits and (2)- (3) and (1)-(4) qubits. The exception is in the last layer, which does not contain any CZ gate.
Last CZ gates will depend on the number of layers according to the alternation stated before. For a fixed number of layers, the number of parameters to be optimized quadruples the ones needed for a single-qubit classifier.
layer as parallel rotations on all qubits. We introduce the entanglement using CZ gates between each rotations that are absorbed in the definition of layer. For twoqubit classifier with entanglement, we apply a CZ gate after each rotation with the exception in the last layer. For a four-qubit classifier, two CZ gates are applied after each rotation alternatively between (1)- (2) and (3)-(4) qubits and (2)- (3) and (1)-(4) qubits.
The number of parameters needed to perform the optimization doubles the ones needed for a single-qubit classifier for the two-qubit classifier and quadruples for the four-qubit classifier. For N layers, the circuit depth is N for the non-entangling classifiers and 2N for the entangling classifiers.

V. MINIMIZATION METHODS
The practical training of a parametrized single-qubit or multi-qubit quantum classifier needs merging all the above structure with some machine learning algorithm to proceed with the minimization in the parameter space describing the circuit. This is often referred as a hybrid algorithm, where classical and quantum logic coexist and benefit from each other. To be precise, the set of {θ i } angles and {w i } weights, together with α q,l parameters if applicable, forms a space to be explored in search of a minimum χ 2 . This may be non-trivial and the ap-pearance of many false minima is likely. A bad classical minimizer can easily get trapped in those minima.
Our problem is reduced to minimize a function of many parameters. For a single-qubit classifier, the number of parameters is (3 + d)N where d is the dimension of the problem, i.e. the dimension of x, and N is the number of layers. Three of these parameters are the rotational angles and the other d correspond with the w i weight. If using the weighted fidelity cost function, we should add C extra parameters, one for each class.
In principle, one does not know how is the landscape of the cost function to be minimized. If the cost function were, for example, a really convex function, a downhill strategy would be likely to work properly. The pure downhill strategy is known as gradient descent. In machine learning, the method commonly used is a Stochastic Gradient Descent (SGD) [18].
There is another special method of minimization known as L-BFGS-B [19]. This method has been used in classical machine learning with very good results [20].
The results we present from now are starred by the L-BFGS-B algorithm, as we found it is accurate and relatively fast. We used open source software [21] as the core of the minimization with own made functions to minimize. The minimizer is taken as a black box whose parameters are set by default. As this is the first attempt of constructing a single-or multi-qubit classifier, further improvements can be done on the hyperparameters of minimization.
Nevertheless we have also tested a SGD algorithm for the fidelity cost function. This whole algorithm has been developed by us following the steps from [15]. The details can be read in App. A. In general, we found that L-BFGS-B algorithm is better than SGD. This is something already observed in classical neural networks. When the training set is small, it is often more convenient to use a L-BFGS-B strategy than a SGD. We were forced to use small training sets due to computational capabilities for our simulations. Numerical evidences on this arise when solving the problems we face for this single-and multiqubit classifiers with classical standard machine learning libraries [20]. This can be understood with a simple argument. Neural networks or our quantum classifier are supposed to have plenty of local minima. Neural networks have got huge products of non linear functions. The odds of having local minima are then large. In the quantum circuits side, there are nothing but trigonometric functions. In both cases, if there are a lot of training points it is more likely to find some of them capable of getting us out of local minima. If this is the case, SGD is more useful for being faster. On the contrary, when the training set is small, we have to pick an algorithm less sensitive to local minima, such as the L-BFGS-B.

VI. BENCHMARK OF A SINGLE-AND MULTI-QUBIT CLASSIFIER
We can now tackle some classification problems. We will prove that a single-qubit classifier can perform a multi-class classification for multi-dimensional data and that a multi-qubit classifier, in general, improves these results.
We construct several classifiers with different number of layers. We then train the circuits with a training set of data points to obtain the values of the free parameters {θ i } and {w i } for each layer and {α i } when applicable. We perform these calculations for cost functions defined in Eq. (9) and Eq. (7).
We run a single-, two-and four-qubit classifiers, with and without entanglement, using the two cost functions described above. We benchmark several classifiers formed by L = 1, 2, 3, 4, 5, 6, 8 and 10 layers.
In the following subsections, we describe the particular problems addressed with these single-and multi-qubit classifiers with data re-uploading. We choose four problem types: a simple binary classification, a classification of a figure with multiple patterns, a multi-dimensional classification and a non-convex figure.
The code used to define and benchmark the single-and multi-qubit quantum classifier is open and can be found in Ref. [22].

A. Simple example: classification of a circle
Let us start with a simple example. We create a random set of data on a plane with coordinates x = (x 1 , x 2 ) with x i ∈ [−1, 1]. Our goal is to classify these points according to x 2 1 + x 2 2 < r 2 , i.e. if they are inside or outside of a circle of radius r. The value of the radius is chosen in such a way that the areas inside and outside it are equal, that is, r = 2 π , so the probability of success if we label each data point randomly is 50%. We create a train dataset with 200 random entries. We then validate the single-qubit classifier against a test dataset with 4000 random points.
The results of this classification are written in Tab. I. With the weighted fidelity cost function, the single-qubit classifier achieves more than 90% of success with only two layers, that is, 12 parameters. The results are worse with the fidelity cost function. For a two-qubit and a fourqubit classifier, two layers are required to achieve 96% of success rate, that is, 22 parameters for the two-qubit and 42 for the four-qubit. The introduction of entanglement does not change the result in any case. The results show a saturation of the success rate. Considering more layers or more qubits does not change this success rate.
The characterization of a closed curved is a hard problem for an artificial neural network that work in a linear regime, although many different neurons, i.e. linear terms, can achieve a good approximation to any function.  Table I: Results of the single-and multi-qubit classifiers with data re-uploading for the circle problem. Numbers indicate the success rate, i.e. number of data points classified correctly over total number of points. Words "Ent." and "No Ent." refer to considering entanglement between qubits or not respectively. We have used the L-BFGS-B minimization method with the weighted fidelity and fidelity cost functions. For this problem, both cost functions lead to high success rates. The multi-qubit classifier increases this success rate but the introduction of entanglement does not affect it significantly.
On the contrary, the layers of a single-qubit classifier are rotational gates, which have an intrinsic non-linear behavior. In a sense, a circle becomes an easy function to classify as a linear function is for an artificial neural network. The circle classification is, in a sense, trivial for a quantum classifier. We need to run these classifiers with more complex figures or problems to really test their performance.
It is interesting to compare classifiers with different number of layers. Figure 6 shows the result of the classification for a single-qubit classifier of 1, 2, 3 and 10 layers. As with only one layer the best classification that can be achieved consist on dividing the plane in half, with two layers the classifier catches the circular shape. As we consider more layers, the single-qubit classifier readjust the circle to match the correct radius.

B. Classification of multiple patterns
We want to show now that the single-qubit classifier is able to solve multi-class problems. We divide a 2D plane into several regions and assign a label to each one. We propose the following division: three regions corresponding to three circular sectors and the intermediate space between them. We call this problem the 3-circles problem. This is a hardly non-linear problem and, consequently, difficult to solve for a classical neural network in terms of computational power. Table II shows the results for this four-class problem. For a single-qubit classifier, a maximum of 92% of success is achieved with 10 layers, i.e. 54 parameters. From these results, it seems that this problem also saturates around 91% of success. However, the introduction of more qubits  With one layer, the best that the classifier can do is to divide the plane in half. With two layers, it catches the circular shape which is readjusted as we consider more layers.
and entanglement makes possible this result with less parameters. For two qubits with entanglement, 4 layers are necessary to achieve the same success as with a singlequbit, i.e. 34 parameters. For four qubits without entanglement also requires 4 layers. Notice also that, although the number of parameters increase significantly with the number of qubits, some of the effective operations are performed in parallel.
There is an effect that arises from this more complex classification problem: local minima. Notice that the success rate can decrease when we add more layers into our quantum classifier.
As with the previous problem, it is interesting to observe the explicit results of different classifiers with different number of layers. Figure 7 shows the results for a two-qubit classifier with no entanglement for 1, 2, 3 and 4 layers. Even with only one layer, the classifier identifies the four regions, being the more complicated to describe the central one. As we consider more layers, the classifier performs better and adjust these four regions.

C. Classification in multiple dimensions
As explained in section II, there is no restriction in uploading multidimensional data. Actually, we can update up to three points per rotation since this is the degrees  Table II: Results of the single-and multi-qubit classifiers with data re-uploading for the 3-circles problem. Numbers indicate the success rate, i.e. number of data points classified correctly over total number of points. Words "Ent." and "No Ent." refer to considering entanglement between qubits or not respectively. We have used the L-BFGS-B minimization method with the weighted fidelity and fidelity cost functions. Weighted fidelity cost function presents better results than the fidelity cost function. The multi-qubit classifier reaches the 0.90 success rate with less number of layers than the singlequbit classifier. The introduction of entanglement slightly increases the success rate respect the non-entangled circuit.
of freedom of a SU(2) matrix. If the dimension of data is larger than that, we can just split the data vector into subsets and upload each one at a time, as described explicitly in Eq. (6). Therefore, there is no reason to limit the dimension of data to the numbers of degrees of freedom of a qubit. We can in principle upload any kind of data if we apply enough gates.
Following this idea we will now move to a more complicated classification using data with 4 coordinates. We use as a problem the four-dimensional hypersphere, i.e. classifying data points according to x 2 1 + x 2 2 + x 2 3 + x 2 4 < 2/π. Similarly with the previous problems, x i ∈ [−1, 1] and the radius has been chosen such that the volume of the hypersphere is half of the total volume. This time, we will take 1000 random points as the training set because the total volume increases.
Results are shown in Tab. III. With a single-qubit, it achieves the 97% of success with eight layers (82 parameters) using the weighted fidelity cost function. Results are better if we consider more qubits. For two qubits, the best result is 98% and it only requires three entangled layers (62 parameters). For four qubits, it achieves the 98% of success with two layers with entanglement, i.e. 82 parameters.

D. Classification of non-convex figures
As a final benchmark, we propose the classification of a non-convex pattern. In particular, we classify the points of an annulus with radius r 1 = 0.8 − 2/π and r 2 = √ 0.8. We fix three classes: points inside the small circle,    Table III: Results of the single-and multi-qubit classifiers with data re-uploading for the four-dimensional hypersphere problem. Numbers indicate the success rate, i.e. number of data points classified correctly over total number of points. Words "Ent." and "No Ent." refer to considering entanglement between qubits or not respectively. We have used the L-BFGS-B minimization method with the weighted fidelity and fidelity cost functions. The fidelity cost function gets stuck in some local minima for the multi-qubit classifiers. The results obtained with the weighted fidelity cost function are much better, reaching the 0.98 with only two layers for the four-qubit classifier. Here, the introduction of entanglement improves significantly the performance of the multi-qubit classifier.
points in the annulus and points outside the big circle.  Table IV: Results of the single-and multi-qubit classifiers with data re-uploading for the three-class annulus problem. Numbers indicate the success rate, i.e. number of data points classified correctly over total number of points. Words "Ent." and "No Ent." refer to considering entanglement between qubits or not respectively. We have used the L-BFGS-B minimization method with the weighted fidelity and fidelity cost functions. The weighted fidelity cost function presents better success rates than the fidelity cost function. The multi-qubit classifiers improves the results obtained with the single-qubit classifier but the using of entanglement does not introduce significant changes.
So, besides being a non-convex classification task, it is also a multi-class problem. A simpler example, with a binary classification, can be found in App. B.
The results are shown in Tab. IV. It achieves the 93% of success with a single-qubit classifier with 10 layers and a weighted fidelity cost function. With two qubits, it achieves better results, 94% with three layers. With four qubits, it reaches the 96% of success with only two layers with entanglement.
It is interesting to observe how the single-qubit classifier makes the effort to achieve the maximum possible results as we consider more and more layers. Figure 8 shows this evolution in terms of the number of layers for a single-qubit classifier trained with the weighted fidelity cost function. It requires four layers to learn that there are three concentric patterns and the addition of more layers adjust these three regions.

E. Comparison with classical classifiers
It is important to check if our proposal is in some sense able to compete with actual technology of supervised machine learning. To do so we have used the standard machine learning library scikit [20] and solved the same problems as we have solved with the quantum classifier. We have included the four problems presented in the main paper plus five extra problems analyzed in App. B. The aim of this classical benchmarking is not to make an extended review of what classical machine learning is capable to perform. The aim is to compare our simple quantum classifier to simple models such as narrow  (7) and Eq. (9) respectively. This table shows the best success rate, being 1 the perfect classification, obtained after running ten times the NN and SVC algorithms and the best results obtained with single-qubit classifiers up to 10 layers.
neural networks and simple support vector machines.
The technical details of the classical classification are the following: the neural network has got one hidden layer with 100 neurons, a ReLu activation function and the solver lbfgs by scikit. The support vector machine is the default sklearn.svm.SVC. Some changes in the initialization parameters were tested with no significant differences. Table V compares the best performance of a neural network, suport vector classifier (SVC), single-qubit classifier with fidelity cost function and single-qubit classifier with weighted fidelity cost function. In all problems, the performance of the single-qubit classifier is, at least, comparable with the classical methods. Some problems like 3-circles problem and binary annulus problem the results of the single-qubit classifier are better than with these methods.

VII. CONCLUSIONS
We have proposed a single-qubit classifier that is able to represent multidimensional complex figures. The core of this quantum classifier is the data re-uploading. This formalism allows to circumvent the limitations of the nocloning theorem in order to achieve a correct generalization of an artificial neural network with a single layer.
The structure of this classifier is the following. Data and processing parameters are uploaded multiple times with a single qubit rotation along the circuit. These processing parameters are different at each upload and should be optimized using a classical minimization algorithm. To do so, we have defined two cost functions: one inspired in the traditional neural networks cost functions (weighted fidelity cost function) and the other, simpler, consisting on the computation of the fidelity of the final state respect to a target state. These target states are defined to be maximally orthogonal between them. Then, the single-qubit classifier finds the optimal rotations to separate the data points into different regions of the Bloch sphere, each one corresponding with a class. The single-qubit classifier can be generalized to a larger number of qubits. This allows the introduction of entanglement between these qubits by adding two-qubit gates between each layer of rotations.
We have benchmarked several quantum classifiers of this kind, made of different number of layers, qubits and with and without entanglement. The patterns chosen to test these classifiers are the points inside and outside of a circle (simple example) and similarly for a fourdimensional hypersphere (multidimensional example); a two dimensional region composed by three circles of different size (multiple classes example); and the points outside and inside of an annulus (non-convex example). In all cases, the single-qubit classifier achieves more than 90% of success rate. The introduction of more qubits and entanglement increases this success and reduces the number of layers required. The weighted fidelity cost function turns out to be more convenient to achieve better results than the fidelity cost function. In all problems, the probability to get stuck in a local minima increases with the number of layers, an expected result from an optimization problem involving several parameters.
In summary, we have proposed a quantum classifier model that seems to be universal by exploiting the nonlinearities of the single-qubit rotational gates and by reuploading data several times.  Table VI: Results of the single-and multi-qubit classifiers with data re-uploading for the non-convex problem. Numbers indicate the success rate, i.e. number of data points classified correctly over total number of points. Words "Ent." and "No Ent." refer to considering entanglement between qubits or not respectively. We have used the L-BFGS-B minimization method with the weighted fidelity and fidelity cost functions. Both cost functions lead to higher success rates, although weighted fidelity cost function is better. It achieves the 0.98 success with two qubits, entanglement and four layers.

a. Non-convex problem
The non-convex problem is made for testing two mutually non-convex zones dividing a 2D area. The border of both zones lies on the function x 2 = −2x 1 +3/2 sin(πx 1 ). This border is chosen in a way that there is no area small enough as to leave it unclassified, forcing the classifier to catch these smaller zones.
Complete results can be read in Tab. VI. The weighted fidelity cost function gets the best performance, 98%, with 6 layers and 1 qubit, (32 parameters). Fidelity cost gets a result of 96% for the same conditions, while the best, 97%, is achieved for 2 entangled qubits with 8 layers (80 parameters). The final figure obtained after the classification can be seen in Fig. 9(a).
We can compare this result with the one obtained in Tab. V. Neural networks work really well as they can approximate our non convex function properly. However, SVC perform worse, as they find hard to deal with non convexity. In contrast with that, our quantum classifier is plastic enough to classify this data with no major difficulty.

b. Binary annulus
This a binary version of the annulus problem. The two classes are defined as being inside or outside the annulus with radii r 1 = 0.8 − 2/π and r 2 = √ 0.8. This geometry, as happens with the three-class annulus problem, is interesting because the classifier finds a way to connect areas of the problem which are disconnected. This involves a to and fro path for the parameters.
The fidelity cost function reaches the best result at  Table VII: Results of the single-and multi-qubit classifiers with data re-uploading for the binary annulus problem. Numbers indicate the success rate, i.e. number of data points classified correctly over total number of points. Words "Ent." and "No Ent." refer to considering entanglement between qubits or not respectively. We have used the L-BFGS-B minimization method with the weighted fidelity and fidelity cost functions. As happens in other problems, the results obtained with the weighted fidelity cost function are better than the ones obtained with the fidelity cost function. The multi-qubit classifiers and the introduction of entanglement increase the success rates. 94%, with 2 qubits with entanglement and 6 layers, that is 60 parameters. For the weighted fidelity we reach up to 97% with 2 qubits with no entanglement and 4 layers, 40 parameters. Results are written in Tab. VII and the best result is plotted in Fig. 9(b).
If we compare these results to the classical ones in Tab. V, we see again that the SVC method is way worse than the NN, which can be interpreted as the sign of non convexity this problem has.

c. Sphere
This quantum classifier is able to classify multidimensional data, as we have shown with the four-dimensional hypersphere. We also tested a three-dimensional figure, a sphere with radious r = √ 33/π. For this problem, fidelity cost function reaches its maximum, 93%, with a single-qubit classifier of 10 layers (60 parameters). The same success is obtained with a twoqubit entangled classifier and 6 layers (72 parameters). With the weighted fidelity, this success rate grows up to 96% for two-and four-qubit classifier of 2 layers (24 and 48 parameters respectively) with and without entanglement. All results are written in Tab. VIII.

d. Squares
This problem divides a 2D area in four quadrants with straight lines. This is one of the easiest problems for a neural network. By construction, neural networks can  Table VIII: Results of the single-and multi-qubit classifiers with data re-uploading for the three-dimensional sphere problem. Numbers indicate the success rate, i.e. number of data points classified correctly over total number of points. Words "Ent." and "No Ent." refer to considering entanglement between qubits or not respectively. We have used the L-BFGS-B minimization method with the weighted fidelity and fidelity cost functions. The weighted fidelity cost function is clearly better than the fidelity cost function. There are not significant differences between the two-qubit and the four-qubit classifiers. Both are better than the single-qubit classifier and the introduction of entanglement does not increase the success rates. establish separation between classes by using biases, and thus straight lines are immediate to understand. We construct this problem in order to see how a quantum classifier perform against a neural network in the latter's field.
Classical results are very good, up 98% and 96% for neural networks of 100 neurons and a single hidden layer and SVC respectively. However, the quantum classifier performs even better. The fidelity cost function reaches 99% of success in a two-qubit classifier without entanglement and 6 layers (60 parameters). Actually, any twoqubit result is comparable with the success rate of the classical models. Something similar can be found for the weighted fidelity. The maximum success, 96%, is obtained with a two-qubit entangled classifier with 4 layers (40 parameters). Results are written in Tab. IX and the best performance is plotted in Fig. 9(c).

e. Wavy lines
This problem is the four-class version of the non convex problem. Now the area is divided in four regions by two different functions. The borders' equations are x 2 = sin(πx 1 ) ± x 1 . The important feature of this problem is that there are some areas in the problem too small to be caught by the classifier.
As can be seen in Fig. 9(d), most of failed points are in these small non convex areas. The classifier would rather adjust the rest of the points instead tuning those zones and losing everything else. The results for this problem are not as good as for other problems, but we still get 94%  Table IX: Results of the single-and multi-qubit classifiers with re-uploading data for the four-classes squares problem. Numbers indicate the success rate, i.e. number of data points classified correctly over total number of points. Words "Ent." and "No Ent." refer to considering entanglement between qubits or not respectively. We have used the L-BFGS-B minimization method with the weighted fidelity and fidelity cost functions. In this problem, the fidelity cost function presents better results than the weighted fidelity cost function. It achieves the 0.99 success with the two-qubit classifier with six layers and no entanglement.  Table X: Results of the single-and multi-qubit classifiers with re-uploading data for the four-classes wavy lines problem. Numbers indicate the success rate, i.e. number of data points classified correctly over total number of points. Words "Ent." and "No Ent." refer to considering entanglement between qubits or not respectively. We have used the L-BFGS-B minimization method with the weighted fidelity and fidelity cost functions. Results with the weighted fidelity cost function are slightly better than the ones obtained with the fidelity cost function. The multi-qubit classifiers are vaguely better than the single-qubit classifiers. The introduction of entanglement does not change significantly the results.
for the fidelity cost function, two entangled qubits and 10 layers (200 parameters) and for the weighted fidelity, four entangled qubits and 4 layers (80 parameters).
It is remarkable to compare these results, written in Tab. X, with the ones obtained using classical models. The quantum classifier approximately equals the NN method for this problem and outperforms SVC, 94% against 95% (NN) and 82% (SVC).