An Artificial Neuron Implemented on an Actual Quantum Processor

Artificial neural networks are the heart of machine learning algorithms and artificial intelligence protocols. Historically, the simplest implementation of an artificial neuron traces back to the classical Rosenblatt's `perceptron', but its long term practical applications may be hindered by the fast scaling up of computational complexity, especially relevant for the training of multilayered perceptron networks. Here we introduce a quantum information-based algorithm implementing the quantum computer version of a perceptron, which shows exponential advantage in encoding resources over alternative realizations. We experimentally test a few qubits version of this model on an actual small-scale quantum processor, which gives remarkably good answers against the expected results. We show that this quantum model of a perceptron can be used as an elementary nonlinear classifier of simple patterns, as a first step towards practical training of artificial quantum neural networks to be efficiently implemented on near-term quantum processing hardware.


INTRODUCTION
Artificial neural networks are a class of computational models that have proven to be highly successful at specific tasks like pattern recognition, image classification, and decision making [1]. They are essentially made of a set of nodes, or neurons, and the corresponding set of mutual connections, whose architecture is naturally inspired by neural nodes and synaptic connections in biological systems [1,2]. In practical applications, artificial neural networks are mostly run as classical algorithms on conventional computers, but considerable interest has also been devoted to physical neural networks, i.e. neural networks implemented on dedicated hardware [3][4][5].
Among the possible computing platforms, prospective quantum computers seem particularly well suited for implementing artificial neural networks [6]. In fact, the intrinsic property of Quantum Mechanics of representing and storing large complex valued vectors and matrices, as well as performing linear operations on such vectors, is believed to result in an exponential increase either in memory storage or processing power for neural networks directly implemented on quantum processors [7][8][9][10][11][12][13][14][15][16]. The simplest model of an artificial neuron, the so called "perceptron", was originally proposed by R. Rosenblatt in 1957 [17], and is schematically outlined in Fig. 1(a). A real valued vector, i, of dimension m represents the input, and it is combined with a real valued weight vector, w. The perceptron output is evaluated as a binary response function resulting from the inner product of the two vectors, with a threshold value deciding for the "yes/no" response. In the lowest level implementations, i and w are binary valued vectors themselves, as proposed by Mc-Culloch and Pitts in 1943 as a simple model of a neuron [2,18].
Perceptrons and McCulloch-Pitts neurons are limited in the operations that they can perform, but they are still at the basis of machine learning algorithms in more complex artificial neural networks in multilayered perceptron architectures. However, the computational complexity increases with increasing number of nodes and interlayer connectivity and it is not clear whether this could eventually call for a change in paradigm, although different strategies can be put forward to optimize the efficiency of classical algorithms [19]. In this respect, several proposals have been advanced in recent years to implement perceptrons on quantum computers. The most largely investigated concept is that of a "qubit neuron", in which each qubit (the computational unit in quantum computers) acts as an individual neuron within the network. Most of the research effort has been devoted to exploit the nonlinearity of the measurement process in order to implement the threshold function [8].
Here we introduce an alternative design that closely mimics a Rosenblatt perceptron on a quantum computer. First, the equivalent of m-dimensional classical input and weight vectors is encoded on the quantum hardware by using N qubits, where m = 2 N . On one hand, this evidently allows to exploit the exponential advantage of quantum information storage, as already pointed out [9,12]. On the other, we implement an original procedure to generate multipartite entangled states based on quantum information principles [20] that allows to crucially scale down the quantum computational resources to be employed. We experimentally show the effectiveness of such an approach by practically implementing a 2 qubits version of the algorithm on the IBM quantum processor available for cloud quantum computing. In this respect, the present work constitutes a key step towards the efficient use of prospective quantum processing de-arXiv:1811.02266v1 [quant-ph] 6 Nov 2018 Perceptron models. (a) Schematic outline of the classical perceptron as a model of artificial neuron: An input array i is processed with a weight vector w to produce a linear, binary valued output function. In its simplest realization, also the elements of i and w are binary valued, the perceptron acting as a binary (linear) classifier. (b) Scheme of the quantum algorithm for the implementation of the artificial neuron model on a quantum processor: From the system initialized in its idle configuration, the first two unitary operations prepare the input quantum state, |ψi , and implement the Uw transformation, respectively. The final outcome is then written on an ancilla qubit, which is eventually measured to evaluate the activation state of the perceptron.
vices for machine learning applications. Remarkably, we show that the quantum perceptron model can be used to sort out simple patterns, such as vertical or horizontal lines among all possible inputs. In order to show the potential of our proposed implementation of a quantum artificial neuron, we theoretically simulate a 4+1 qubits version using the IBM quantum simulator. We conclude the paper by discussing the usefulness of our algorithm as a quantum neuron in fully quantum neural networks.

QUANTUM CIRCUIT MODELING OF A CLASSICAL PERCEPTRON
A scheme of the quantum algorithm proposed in this work is shown in Fig. 1(b). The input and weight vec-tors are limited to binary values, i j , w j ∈ {−1, 1}, as in McCulloch-Pitts neurons. Hence, a m-dimensional input vector is encoded using the m coefficients needed to define a general wavefunction |ψ i of N qubits. In practice, given arbitrary input ( i) and weight ( w) vectors with i j , w j ∈ {−1, 1}, we define the two quantum states The states |j ∈ {|00 . . . 00 , |00 . . . 01 , . . . , |11 . . . 11 } form the so called computational basis of the quantum processor, i.e. the basis in the Hilbert space of N qubits, corresponding to all possible states of the single qubits being either in |0 or |1 . As usual, these states are labeled with integers j ∈ {0, . . . , m − 1} arising from the decimal representation of the respective binary string. Evidently, if N qubits are used in the register, there are m = 2 N basis states labelled |j and, as outlined in Eq. (2), we can use factors ±1 to encode the mdimensional classical vectors into an uniformly weighted superposition of the full computational basis. The first step of the algorithm prepares the state |ψ i by encoding the input values in i. Assuming the qubits to be initialized in the state |00 . . . 00 ≡ |0 ⊗N , we perform a unitary transformation U i such that In principle, any m × m unitary matrix having i in the first column can be used to this purpose, and we will give explicit examples in the following. Notice that, in a more general scenario, the preparation of the input state starting from a blank register might be replaced by a direct call to a quantum memory [21] where |ψ i was previously stored. The second step computes the inner product between w and i using the quantum register. This task can be performed efficiently by defining a unitary transformation, U w , such that the weight quantum state is rotated as As before, any m × m unitary matrix having w T in the last row satisfies this condition. If we apply U w after U i , the overall N -qubits quantum state becomes Using Eq. (4), the scalar product between the two quantum states is and from the definitions in Eq. (2) it is easily seen that the scalar product of input and weight vectors is w · i = m ψ w |ψ i . Therefore, the desired result is contained, up to a normalization factor, in the coefficient c m−1 of the final state |φ i,w . In order to extract such an information, we propose to use an ancilla qubit (a) initially set in the state |0 . A multi-controlled NOT gate between the N encoding qubits and the target a leads to [22]: The nonlinearity required by the threshold function at the output of the perceptron is immediately obtained by performing a quantum measurement: indeed, by measuring the state of the ancilla qubit in the computational basis produces the output |1 a (i.e., an activated perceptron) with probability |c m−1 | 2 . As it will be shown in the following, this choice proves simultaneously very simple and effective in producing the correct result. However, it should be noticed that refined threshold functions can be applied once the inner product information is stored on the ancilla [23][24][25]. We also notice that both parallel and anti-parallel i-w vectors produce an activation of the perceptron, while orthogonal vectors always result in the ancilla being measured in the state |0 a . This is a direct consequence of the probability being a quadratic function, i.e. |c m−1 | 2 in the present case, at difference with classical perceptrons that can only be employed as linear classifiers in their simplest realizations. In fact, our quantum perceptron model can be efficiently used as a pattern classifier, as it will be shown below, since it allows to interpret a given pattern and its negative on equivalent footing. Formally, this intrinsic symmetry reflects the invariance of the encoding |ψ i and |ψ w states under addition of a global −1 factor.

IMPLEMENTATION OF THE UNITARY TRANSFORMATIONS
One of the most critical tasks to be practically solved when implementing a quantum neural network model is the efficient implementation of unitary transformations. In machine learning applications, this might eventually discriminate between algorithms that show truly quantum advantage over their classical counterparts [12].
Here we discuss an original strategy for practically implementing the preparation of the input state |ψ i and the unitary transformation U w on a quantum hardware. In particular, we will first outline the most straightforward algorithm one might think of employing, i.e. the "brute force" application of successive sign flip blocks. Then, we will show an alternative and more effective approach based on the generation of hypergraph states. In the next Section we will see that only the latter allows to practically implement this quantum perceptron model on a real quantum device.
So, as a first step we define a sign flip block, SF N,j , as the unitary transformation acting on the computational basis of N qubits in the following way: For any N, m = 2 N , a controlled Z operation between N qubits (C N Z) is a well known quantum gate [22] realizing SF N,m−1 , while a single qubit Z gate acts as SF 1,1 . We can therefore implement in practice the whole family of sign-flip blocks for N qubits by using C N Z gates in combination with single qubit NOT gates (i.e. single bit flip operations): where In the expression above, NOT l means that the bit flip is applied to the l-th qubit and j l = 0(1) if the l-th qubit is in state |0 (|1 ) in the computational basis state |j . Alternatively, the same result can also be obtained by using an extra ancillary qubit and multi-controlled NOT gates (C N NOT), i.e. bit flip operations conditioned on the state of some control qubits. We explicitly point out that, as it is easily understood from the definition in Eq. (8), any SF N,j is the inverse of itself. Then, the full sequence to implement U i can be summarized as follows: starting from the initialized register |0 ⊗N , parallel Hadamard (H) gates are applied to create an equal superposition of all the elements of the computational basis: where we remind that [22] Then, the SF N,j blocks are applied one by one whenever there is a −1 factor in front of |j , in the representation of the target |ψ i . Notice that any SF N,j only affects a single element of the computational basis while leaving all others unchanged. Moreover, all SF N,j blocks commute with each other, so they can actually be performed in any order. As already anticipated, the whole problem is symmetric under the addition of a global −1 factor (i.e. |ψ i and −|ψ i are fully equivalent). Hence, there can be only at most m/2 = 2 N −1 independent −1 factors, and 2 N −1 sign flip blocks are needed in the worst case. A similar strategy can also be applied to implement the other unitary operation in the quantum perceptron algorithm, U w . Indeed, applying first the SF N,j blocks that would be needed to flip all the −1 signs in front of the computational basis elements in the associated |ψ w leads to the balanced superposition |ψ w → |ψ 0 . This quantum state can then be brought into the desired |11 . . . 11 ≡ |1 ⊗N state by applying parallel Hadamard and NOT gates: Evidently, the above strategy is exponentially expensive in terms of circuit depth as a function of the number of qubits, and requires an exponential number of Ncontrolled quantum gates.
On the other hand, a more efficient strategy can be given after realizing that the class of possible input-and weight-encoding states, Eq. (2), coincides with the set of the so called hypergraph states. The latter are ubiquitous ingredients of many renown quantum algorithms, and have been extensively studied and theoretically characterized [20,26]. In particular, hypergraph states can be mapped into the vertices and hyper-edges of generalized graphs, and can be prepared by using single qubit and (multi)-controlled Z gates, with at most a single Ncontrolled C N Z and with the possibility of performing many p-controlled C p Z gates (involving only p qubits, with p < N ) in parallel. After an initial H ⊗N gate (see Eq. (11)), the algorithm takes a series of iterative steps [20] that are described below. In the following, we will refer to this portion of the algorithm to generate hypergraph states as the "hypergraph states generation subroutine" (HSGS). First, we check whether there is any component with only one qubit in state |1 (i.e. of the form |0 . . . 010 . . . 0 ) requiring a −1 factor, in the representation of |ψ i on the computational basis. If so, the corresponding single qubit Z gate is applied by targeting the only qubit in state |1 . Notice that this might introduce additional −1 factors in front of states with more than one qubit in state |1 . Then, for p = 2, . . . , N , we consider the components of the computational basis with exactly p qubits in state |1 . For each of them, an additional −1 sign is introduced in front of its current amplitude (if it is needed and it was not previously introduced) by applying the corresponding C p Z between the p qubits in state |1 . Similarly, if an unwanted sign is already present due to a previous step, this can be easily removed by applying the same C p Z. Since C p Z acts non trivially only on the manifold with p or more qubits being in state |1 , the signs of all the elements with a lower number of |1 components are left unchanged. As a consequence, when p = N all the signs are the desired ones. As in the previous case, U w can be obtained by slightly modifying the sequence of gates that would be used to generate |ψ w . Indeed, one can start by first performing the HSGS tailored according to the ±1 factors in |ψ w . Since all the gates involved in HSGS are the inverse of themselves and commute with each other, this step is equivalent to the unitary transformation bringing |ψ w back to the equally balanced superposition of the computational basis states |ψ 0 . The desired transformation U w is finally completed by adding parallel H ⊗N and NOT ⊗N gates (see Eq. (13)). An example of the full sequence for a specific N = 4 case is shown, e.g., in Fig. 2. Notice that our optimized algorithm involving hypergraph states successfully reduces the required quantum resources with respect to a brute force approach, even if it still involves an exponential cost in terms of circuit depth or clock cycles on the quantum processor in the worst case. Before proceeding, it is probably worth pointing out the role of U w in this algorithm, which is essentially to cancel some of the transformations performed to prepare |ψ i , or even all of them if the condition i = w is satisfied. Further optimization of the algorithm, lying beyond the scope of the present work, might therefore be pursued at the compiling stage. However, notice that the input and weight vectors can, in practical applications, remain unknown or hidden until runtime.

NUMERICAL RESULTS AND QUANTUM SIMULATIONS
We implemented the algorithm for a single quantum perceptron both on classical simulators working out the matrix algebra of the circuit and on cloud-based quantum simulators, specifically the IBM Quantum Experience real backends [27], using the Qiskit Python develop-ment kit [28]. Due to the constraints imposed by the actual IBM hardware in terms of connectivity between the different qubits, we limited the real quantum simulation to the N = 2 case. Nevertheless, even this small-scale example is already sufficient to show all the distinctive features of our proposed set up, such as the exponential growth of the analyzable problems dimension, as well as the pattern recognition potential. In general, as already mentioned, in this encoding scheme N qubits can store and process 2 N -dimensional input and weight vectors, and thus 2 2 N different input patterns can be analyzed against the same number of the different w that are possible. Moreover, all binary inputs and weights can easily be converted into black and white patterns, thus providing a visual interpretation of the activity of the artificial neuron.
Going back to the case study with N = 2, 2 2 = 4 binary images can be managed, and thus 2 2 2 = 16 different patterns could be analyzed. The conversion between i or w and 2 × 2 pixels visual patterns is done as follows. As depicted in Fig. 3a, we label each image ordering the pixels left to right, top to bottom, and assigning a value n j = 0(1) to a white (black) pixel. The corresponding input or weight vector is then built by setting i j = (−1) nj (or w j = (−1) nj ). We can also univocally assign an integer label k i (or k w ) to any pattern by converting the binary string n 0 n 1 n 2 n 3 to its corresponding decimal number representation. Under this encoding scheme, e.g., numbers 3 and 12 are used to label patterns with horizontal lines, while 5 and 10 denote patterns with vertical lines, and 6 and 9 are used to label images with checkerboard-like pattern. An example of the sequence of operations performed on the IBM quantum computer using hypergraph states is shown in Fig. 3c for i corresponding to the index k i = 11, and w corresponding to k w = 7.
The Hilbert space of 2 qubits is relatively small, with a total of 16 possible values for i and w. Hence, the quantum perceptron model could be experimentally tested on the IBM quantum computer for all possible combinations of input and weights. The results of these experiments, and the comparison with classical numerical simulations, are shown in Fig. 3d-f. First, we plot the ideal outcome of the quantum perceptron algorithm in Fig. 3d, where both the global −1 factor and the input-weight symmetries are immediately evident. In particular, for any given weight vector w, the perceptron is able to single out from the 16 possible input patterns only i = w and its negative (with output |c m−1 | 2 = 1, i.e. the perfect activation of the neuron), while all other inputs give outputs smaller than 0.25. If the inputs and weights are translated into 2 × 2 black and white pixel grids, it is not difficult to see that a single quantum perceptron can be used to recognize, e.g., vertical lines, horizontal lines, or checkerboard patterns.
The actual experimental results are then shown in Fig. 3e-f, where the same algorithm is run on the IBM Q 5 "Tenerife" quantum processor [29]. First, we show in panel 3e the results of the first, non-optimized approach introduced in the previous Section, which makes direct use of sign flip blocks. We deliberately did not take into account the global sign symmetry, thus treating any |ψ i and −|ψ i as distinct input quantum states and using up to 2 N sign flip blocks. We notice that even in such an elementary example the algorithm performs worse and worse with increasing number of blocks. Notice, however, that despite the quantitative inaccuracy of the quantum simulated outputs, the underlying structure of the output is already quite clear. On the other hand, a remarkably better accuracy, also on the quantitative side and with small errors, is obtained when using the algorithm based on the hypergraph states formalism, whose experimental results are shown in panel 3f and represent the main result of this work. In this case, the global phase symmetry is naturally embedded in the algorithm itself, and the results show symmetric performances all over the range of possible inputs and weights. All combinations of i and w yield results either larger than 0.75 or smaller than 0.3, in very good quantitative agreement with the expected results plotted in panel 3d. As a technical warning, we finally notice that in all of the three cases shown in panels d-f of Fig. 3, the C p Z operations were obtained by adding single qubit Hadamard gates on the target qubit before and after the corresponding C p NOT gate. For p = 1 this is a CNOT gate, which is natively implemented on the IBM quantum hardware, while the case p = 2 is known as the Toffoli gate, for which a standard decomposition into 6 CNOTs and single qubit rotations is known [22]. Finally, in the spirit of showing the potential scalability and usefulness of this quantum perceptron model for classification purposes, we have applied the algorithm to the N = 4 qubits case by using the circuit simulator feature available in Qiskit [30]. Now, there are a total 2 32 possible combinations of i and w vectors, far too many to explore the whole combinatorial space as previously done for the 2 qubits in Fig. 3. To explicitly show a few examples, we have chosen a single weight vector corresponding to a simple cross-shaped pattern when represented as a 4×4 pixels image (encoded along the same lines of the N = 2 case, see first panel in Fig. 3), and weighted it against several possible choices of input vectors. Some results are reported in Fig. 4 for a selected choice of input vectors, where the artificial neuron output is computed both with standard linear algebra and simulated with a quantum circuit on a virtual quantum simulator run on a classical computer. Evidently, there is an overall excellent agreement when comparing the two values for each pattern, within statistical inaccuracy due to the finite number (n shots = 8192) of repetitions imposed on the quantum sequence used to estimate the probability |c m−1 | 2 . The perceptron is able to discriminate the weight pattern (and its negative) giving an output larger than 0.5 for all images that differ from the weight or its negative by 2 bits or less.

CONCLUSIONS AND DISCUSSION
In summary, we have proposed a model for perceptrons to be directly implemented on near-term quantum processing devices, and we have experimentally tested it on a 5-qubits IBM quantum computer based on superconducting technology. Our algorithm presents an exponential advantage over classical perceptron models, as we have explicitly shown by representing and classifying 4 bits strings using 2 qubits, and 16 bits strings using only 4 qubits.
The problem of exponential advantage requires a separate discussion. In principle, generic quantum states or unitary transformations require an exponentially large number of elementary gates to be implemented, and this could somehow hinder the effective advantages brought by quantum computers for machine learning applications. This currently represents a general problem of most quantum machine learning algorithms. Moreover, with increasing N , severe issues can arise from the practical necessity to decompose multiply controlled operations by only using single-and two-qubit gates [31,32]. However, this limitation strictly depends on the effective constraints imposed by the given quantum processor and on the required degree of accuracy. In fact, it has been shown that several classes of quantum states can be approximated efficiently with arbitrary precision, with oracle based approaches [33][34][35] or by using a number of multi-controlled rotations that is linear with the number of qubits [36]. Using these results, it might then be possible to design a version of our proposed quantum perceptron algorithm working with approximated encoding quantum states instead of exact ones, which would have the potential to scale exponentially better than any classical algorithm implementing a perceptron model. In this respect, it is also worth pointing out that our procedure is fully general and could be implemented and run on any platform capable of performing universal quantum computation. While we have employed a quantum hardware that is based on superconducting technology and qubits, a very promising alternative is the trappedion based quantum computer [37], in which multi-qubit entangling gates might be readily available [38,39].
As a further strategy for future developments, we notice that in the present work we restricted the whole analysis to binary inputs and weight vectors (the so called "McCollough-Pitts" neuron model), mainly for clarity and simplicity of implementation. A possible improvement for the algorithm presented is obviously to encode continuously valued vectors (equivalent to grey scale images). This could be achieved by using continuously valued phase factors in |ψ i and |ψ w [9]. Finally, a potentially very exciting continuation of this work would be to connect multiple layers of our quantum perceptrons to build a feedforward deep neural network, which could be fully run on dedicated quantum hardware. In such a network, each neuron could use two ancilla qubits, one to be measured to introduce the nonlinearity as done in this work, while the second would be used to propagate the information from each neuron to the successive layer in the network in a fully quantum coherent way. As such, our work thus constitute a concrete first step towards an actual application of near-term (i.e., with few tens of non-error corrected qubits) quantum processors to be employed as fast and efficient trained artificial quantum neural networks.

AKNOWLEDGEMENTS
We acknowledge the University of Pavia Blue Sky Research project number BSR1732907. This research was also supported by the Italian Ministry of Education, University and Research (MIUR): "Dipartimenti di Eccellenza Program (2018-2022)", Department of Physics, University of Pavia. We acknowledge use of the IBM Quantum Experience for this work. The views expressed are those of the authors and do not reflect the official policy or position of IBM company or the IBM-Q team.