Quantum-enhanced barcode decoding and pattern recognition

Quantum hypothesis testing is one of the most fundamental problems in quantum information theory, with crucial implications in areas like quantum sensing, where it has been used to prove quantum advantage in a series of binary photonic protocols, e.g., for target detection or memory cell readout. In this work, we generalize this theoretical model to the multi-partite setting of barcode decoding and pattern recognition. We start by defining a digital image as an array or grid of pixels, each pixel corresponding to an ensemble of quantum channels. Specializing each pixel to a black and white alphabet, we naturally define an optical model of barcode. In this scenario, we show that the use of quantum entangled sources, combined with suitable measurements and data processing, greatly outperforms classical coherent-state strategies for the tasks of barcode data decoding and classification of black and white patterns. Moreover, introducing relevant bounds, we show that the problem of pattern recognition is significantly simpler than barcode decoding, as long as the minimum Hamming distance between images from different classes is large enough. Finally, we theoretically demonstrate the advantage of using quantum sensors for pattern recognition with the nearest neighbor classifier, a supervised learning algorithm, and numerically verify this prediction for handwritten digit classification.


I. INTRODUCTION
Quantum information science has undergone remarkable advances in the recent years, progressing in all its sub-fields of computing [1,2], communication [3] and sensing [4,5], both with discrete-and continuous-variable systems [6][7][8]. In this wide scenario, quantum sensing is arguably one of the most mature areas for near-term technological deployment. Its theoretical and experimental developments have been strongly based on quantum metrology [9,10] and quantum hypothesis testing [11][12][13][14]. Especially, the latter approach has allowed to show a quantum advantage over classical strategies in tasks of target detection [15,16] and data readout [17], modelled as binary problems of quantum channel discrimination.
The discrimination of quantum channels is an incredibly rich area of investigation [18,19], with unexplored consequences but also non-trivial difficulties. It represents a double optimization problem where both input states and output measurements need to be varied. Furthermore, in the bosonic setting, it has to be formulated as an energy-constrained problem, where the mean number of input photons is limited to some finite, small, value. In such a scenario, the central question is that of showing quantum advantage: Can truly-quantum states, e.g., entangled, lead to an advantage over classical, i.e. coherent, states? Addressing this question in the multiary case is difficult, since the theory is missing powerful tools that are instead available for the binary case.
In this work, we take a step forward by developing the theory of quantum hypothesis testing for the multi-ary setting of barcode decoding and pattern classification. We start from a general model of digital image, where each pixel is described by an ensemble of quantum channels defined over a finite alphabet. We specialize to the case where the single-pixel alphabet is binary, so that there are 2 n possible hypothesis or configurations for an n-pixel barcode. We then show how the use of quantum sources of light, based on entangled states, can clearly outperform classical strategies based on coherent states for the readout of the barcode configuration, i.e., the retrieval of its data. In particular, we derive an analytical condition for the maximum number of pixels or the minimum number of probings such that quantum advantage is obtained. This result holds not only for a uniform distribution of the possible configurations, but also when data is stored by the position of k white pixels among a grid of otherwise black pixels.
Besides data readout or barcode decoding, we consider the general problem of pattern recognition, where the task is to classify an image, e.g. a handwritten digit, without necessarily reconstructing it pixel by pixel. Here the image distribution is not uniform and generally unknown, and optimal classification has to be approximated via a collection of correctly classified examples, following supervised learning strategies [20]. We consider the ultimate limits of this procedure, where we may optimize over the optical circuit, measurements and subsequent classical post-processing algorithms. Introducing relevant bounds, we theoretically prove that this problem is significantly simpler than that of barcode decoding, as long as the minimum Hamming distance between images from different classes is large enough. Moreover, we show how clear quantum advantage can be obtained as a function of the number of training data. Finally, we consider a simplified scheme for recognizing black and white patterns, such as digital images of handwritten digits, by means local measurements followed by a classical nearest neighbor classifier. More specifically, we apply this classifier to the measurement outcomes that are obtained by either using entangled states or coherent states at the input of the grid of pixels. We are able to show a clear quantum advantage which holds even when we employ sub-optimal photon counting measurements for the quantum case, which are particularly relevant for nearterm experiments. The advantage becomes particularly evident at relatively small energies where a total of a few hundred of photons are irradiated over each pixel.
The paper is organized as follows. In Section II we discuss the problem of barcode decoding and show the possible advantage in using quantum detectors with entangled input states. In Section III we discuss the related problem of pattern recognition, showing a similar advantage. Discussions are drawn in Section IV.

II. BARCODE DECODING
A. Quantum mechanical model of a digital image A basic imaging system irradiates light over an array of pixels which can be read in transmission or in reflection. From the ratios between input and output intensities, the system generates a corresponding array of grey-levels that constitutes a monochromatic image. In a quantum mechanical setting, each pixel can therefore be modeled as a bosonic lossy channel E i whose transmissivity depends on the grey-level i. This lossy channel can be probed by an input state (with some limited energy) and a corresponding output measurement, generally described by positive-operator valued measure (POVM). Finally, the outcome is processed by a decision test that identifies the channel and, therefore, the grey-level i.
Let us formalize the problem in more mathematical detail, which can be seen as a multi-ary and multi-pixel generalization of the basic model of quantum reading [17]. Assume that each pixel is described by a channel ensemble {E i } spanned by the label 0 ≤ i ≤ C − 1, where C is the discrete number of grey-levels that can be assumed by the pixel. Let us define an image over n pixels as a sequence i := i 0 , · · · , i n−1 , together with an associated probability distribution π i , which is simply π i = C −n in the uniform case. The global channel describing the entire array of n pixels is the tensor product E n i := E i0 ⊗ · · · ⊗ E in−1 . Thus, an image can equivalently be represented by an ensemble of multi-channels {π i , E n i }. In order to read the image, let us assume that we have a generic 2n-mode stateρ at the input: n signal modes are sent through the pixels, while n idler modes are used to help the measurement. At the output, there is an en-semble of possible states {π i , ρ i } where ρ i := I n ⊗ E n i (ρ). In the case of a classical transmitter, the signal modes are prepared in coherent states while the idler modes are in vacuum states. In the case of a quantum transmitter, signal and idler modes are entangled pairwise. In particular, each signal-idler pair is described by a two-mode squeezed vacuum (TMSV) state.
In general, we probe the image i with identical inputs for M times, leading to the overall input statẽ ρ ⊗M and corresponding output ρ ⊗M i := [I n ⊗ E n i (ρ)] ⊗M . We measure this output with a collective POVM, where each measurement operator Π i represents the decision that the image is i . Because input states are energyconstrained, there will be readout errors described by the conditional probabilities (1) By including the priors {π i }, we may therefore define the success probability or, equivalently, the error probability Using Refs. [21,22] and the multiplicativity of the fidelity over tensor products, one finds that the minimum error probability (optimizd over POVMs) satisfies where is the fidelity between two generic single-probing multipixel output states, ρ i and ρ j . The inequalities in Eq. (3) bound the performances of a pretty good measurement [23][24][25] and have no explicit dependence on the dimension of the Hilbert space, so that they hold for bosonic states as long as these states are energyconstrained. Below, we build on these inequalities to derive our bounds for decoding barcodes.

B. Barcode discrimination
An important case of the general problem discussed in the previous section is barcode decoding, whose schematic setup is shown in Fig. 1. A barcode is either a one-dimensional (1D) or two-dimensional (2D) grid of pixels with two possible colors, black (B) or white (W). With a slight abuse of jargon, we call pixels the elements of the 1D or 2D grid that defines a barcode. In the 1D case (Fig. 1a), a pixel is a black or white vertical bar, while in the 2D case ( Fig. 1b) a pixel is an elementary square. It is worth noting that many of the conclusions drawn for barcode decoding can be extended to more general images. Indeed, a higher number of grey-levels Barcode decoding. Examples of 1D (a) and 2D (b) barcodes. (c) Schematic physical setup for decoding a 2D barcode with n = 5 × 5 pixels. A source shines light on the grid of pixels, each modeled by a quantum channel, which is either EB or EW depending on the pixel grey-level, black (B) or white (W). The reflected/scattered light is collected by a detector, which aims at recognizing all pixel values depending on the detected photons. In a quantum setup, the signal modes shined over the pixels are entangled with idler modes that are directly sent to the detector for a joint measurement. (d) General theoretical setup scheme for optimal barcode discrimination using entangled TMSV states, where the mixing optical circuit, the measurements and following classical post-processing must be optimized. (e,f) Special setup to claim quantum advantage: we compare independent entangled TMSV states on each pixel followed by independent local measurements (e) with classical coherent sources followed by global measurements. Quantum advantage is claimed whenever (e) beats (f).
C > 2 can always be formally mapped into a barcode. For instance, C = 256 corresponds to an 8-bit grey scale and each bit can be represented as a binary variable with two possible configurations (B or W, by convention). As such, images with C > 2 can be mapped into a "barcode" image with a higher number of pixels.
The general problem of barcode discrimination can be depicted as in Fig. 1c and 1d. According to our notation, each pixel of a barcode has two possible grey-levels i ∈ {B, W } and therefore corresponds to two possible quantum channels E B and E W . For barcode decoding, we assume that the pixels are independently probed, so that the input state takes the tensor-product formρ = ρ ⊗n 0 . Note that this assumption does not reduce the generality of our treatment. In fact, for the quantum source this leads to one of the best possible choices (tensor product of TMSV states). For the classical source, we know that independent and identical coherent states are able to saturate the lower bounds for general mixtures of multimode coherent states [19]. As for detection, the general scheme to correctly distinguish the various configurations consists in choosing a mixing optical circuit, followed by measurements and classical post-processing algorithms as in Fig. 1d. From an operational point of view, a suboptimal solution can be found for this problem by restricting to a cascade of beam splitters and phase shifter with tunable parameters, followed by independent measurements (e.g. homodyne or photodetection), similar to that of Ref. [18]; while for the classical post-processing we may employ statistical classification algorithms commonly employed in machine learning applications, e.g. based on neural networks [20]. The suboptimal solution is then numerically investigated by minimizing the parameters of the optical and neural networks in order to minimize p err . When photodetection measurements are employed, analytic gradients can be computed following Ref. [26] to speed-up the optimization algorithm. In this paper however we focus on the most general case and study the fundamental limits of barcode decoding and patter recognition, introducing different theoretical limits that any possible scheme must satisfy. Indeed, the physical optical circuit and measurements, and also the classical post-processing algorithm in Fig. 1d, can all be reabsorbed into an abstract POVM that must be optimized.
We start by considering the case where a barcode with n pixels is prepared in one of all possible 2 n patterns, each with equal prior. Then, we will consider the case where the patterns are restricted to specific configurations, where k white pixels are randomly positioned within a grid of otherwise black pixels.
Starting from the input stateρ = ρ ⊗n 0 , the possible states at the output of the barcode ρ i = I n ⊗ E i1 ⊗ · · · ⊗ E in (ρ), take the product form Correspondingly, the fidelities can be simplified as where ρ i = I ⊗ E i (ρ 0 ) for i ∈ {B, W } and hamming(i, j) is the Hamming distance between the two binary images i and j, namely the number of pixels in which the two images differ. Using the properties of the Hamming distance, in Appendix A we show that, for uniform a priory probabilities, the M -probing bounds (3) become where F max is the fidelity between any two (different) images with minimum Hamming distance [cf. Eq. (6)]. The minimum Hamming distance is achieved when the two images differ by a single pixel. Thus, we get F max = F (ρ B , ρ W ), namely the maximum fidelity between any two images is given by the fidelity between the states describing the grey-levels of a single pixel. Using the Bernoulli's inequality, we then simplify Eq. (7) as In Appendix B, we show that the upper bound can be achieved using local measurements, namely where each pixel is measured independently from the others and Π i = n−1 j=0 Π ij in Eq. (1), though each pixel and its respective idler may be measured together (see Fig. 1d). Once we restrict to local operations, the optimum is achieved by independent Helstrom measurements [27] and the upper bound in Eq. (8) follows from Fuchs-van de Graaf inequalities [28]. A sub-optimal local measurement is obtained by combining the signal and idler via a beam splitter followed by independent measurements [17]. Moreover, in the supplementary material we also discuss different inequalities on p err based on the multiple quantum Chernoff bound [29,30].
Two interesting observations can be made from the bounds (8). First, the upper bound for the error probability becomes small whenever nF M (ρ W , ρ B ) 1. This implies that, although the set of images (namely barcode configurations) grows exponentially with the number of pixels as 2 n , the required fidelities to accurately distinguish all configurations should decrease polynomially with 1/n. In particular, M = O(log n) copies are needed for correct discrimination. The second observation is that, due the factor 2 −n , the lower bound in Eq. (8) decreases exponentially with n. As we show in Appendix B, this factor disappears from the lower bound when local measurements are employed. It is known that, in general, optimum mixed state discrimination requires a joint measurement [31,32], yet in our setting optimal global measurements may in principle exponentially reduce the probability of error. Nonetheless, it is currently an open question to verify whether and exponentially decreasing error is achievable with optimal quantum measurements. In the next section we will claim quantum advantage whenever the upper bound on p err obtained with entangled states and local measurements is smaller than the lower bound on p err obtained with classical states and possibly global measurements, as schematically shown in Figs. 1d) 1e). Therefore, if the lower bound in (7) is loose, the regimes for quantum advantage are larger.
In the previous bounds we considered a uniform distribution of black an white pixels in the barcode. We may also consider a different encoding with a fixed number of white pixels, generalizing the results of Ref. [19]. The task is then to find the position of k white pixels in a barcode with n bars. The number of possible configurations is n k ≈ 2 nH(k/n) where H is the binary entropy function and the approximation holds when both n and k are large. Therefore, in that regime, the configuration space grows exponentially with n, as in the uniform case discussed above. In the asymptotic regime we obtain the following bounds while the exact expressions for finite M , n and k are discussed in Appendix C.

C. Quantum enhancement
We now discuss the regime where we get an advantage from using entangled photons as input. We compare the case where each input ρ 0 is a TMSV state |Φ N S with N S average photons and the case where the input is a coherent state with the same number of signal photons √ N S ⊗|0 (where the vacuum state means that no idler is used). Note that one can replace the vacuum idler with an arbitrary state, such as a strong local oscillator in a coherent state, however that will not give a better performance when the optimum measurement is considered. Assuming M probings of the barcode, we have a total of N tot = M N S mean photons irradiated over each pixel. According to the analysis from the previous section, provable quantum advantage can be achieved whenever the upper bound from Ineqs. (8), obtained with TMSV input states, is less than the lower bound obtained with coherent state inputs. Since the upper bound in (8) is obtained with local measurements, what we call "provable advantage" means that possibly non-optimal local measurement strategies with entangled inputs beat any strategy with coherent states, even when the latter is enhanced by complex global measurements. Provable quantum advantage may be more difficult for larger n, given the exponentially decreasing factor in the lower bound of Eq. (8), but here we show that it can be achieved for every number of pixels n with suitably large number of probings M .
Using the formula for the fidelity between two generally-mixed Gaussian states [33,34], for TMSV states at the input, we compute (see Appendix D) where the index q stands for quantum and For a coherent-state input, we instead have By comparing Eqs. (10) and (12) we see that, for fixed M , the fidelity between coherent states displays an exponential decay as a function of N S , while for quantum states we see a polynomial decay in N S . Nonetheless, for large M and small N S , the inequality in Eq. (10) becomes tight and, since ∆ q ≥ ∆ c , in that limit we find that quantum light always provides an advantage for discrimination, irrespective of the values of η W and η B . The limits of small N S and large M are widely employed to show quantum advantage and can be realized experimentally with little imperfections [35]. Therefore, from now on we will focus on such limits, M → ∞ and N S → 0, while keeping fixed the total mean number of photons M N S irradiated over each pixel.
To properly demonstrate the advantage, we need to show that the upper bound on the probability of error using quantum light is smaller than the lower bound on the probability of error using coherent states. From Ineqs. (8), we see that this happens when F 2M c ≥ 2 n F M q . Setting n = νM N S , the previous inequality implies that quantum advantage is obtained for which is a barcode multi-pixel generalization of the "threshold energy" theorem proven in the context of single-cell quantum reading [17]. According to Eq. (13), whenever the number n of pixels is smaller than a certain threshold, entangled light always provides an advantage in the discrimination of barcode configurations (barcode decoding) with respect to the best classical strategy with the same signal energy, even when the latter uses possibly complex global measurements. The behaviour of ν th as a function of η W and η B is numerically shown in Fig. 2.
Quantum advantage can also be proven when we consider a prior distribution for the barcode configurations that is non-uniform, more precisely for the case where the number k of white pixels is fixed. Using Ineqs. (9), we find that there is a provable quantum advantage when F 4M c ≥ 2 nH(k/n)+1 F 2M q , namely when nH(k/n) + 1 ≤ 2ν th M N S . Therefore, as in the previous case, quantum advantage may be observed when the number of pixels is sufficiently small or the number of probes M is sufficiently large, as long as ν th ≥ 0.
It is currently an open question to prove whether or not the lower bound in (8) can be achieved when classical light is employed. Nonetheless, our analysis shows that even assuming that such bound can be achieved with classical inputs, a strategy based on entangled light and the much simpler local measurements can beat any approach based on coherent states. On the other hand, if only local measurements can be performed, then the factor 2 −n in the lower bound (8) disappears (see Appendix B). This corresponds to the case ν = 0. Therefore, in that case, whenever ν th > 0, namely when η W > 1 − η B , quantum light provides an advantage for decoding uniformlydistributed barcodes, irrespective of n.

A. Statistical pattern classification
We now focus on the problem of pattern recognition. Consider the problem of recognizing handwritten digits as shown in Fig. 3a, whose images have been adapted from the MNIST dataset [36]. Each image depicts a single handwritten digit and the task is to extract from the image the corresponding number 0-9. From an algorithmic perspective, this task is more complex than the mere decision of whether a pixel is black or white but, from a physical point of view, this problem is actually simpler as errors are tolerated. Indeed, a human is able to instantly recognize all the numbers in Fig. 3a even when some of the pixels are randomly flipped. Therefore, for reliable pattern recognition, it is not necessary to perfectly reconstruct the entire image. Compared to the barcode configurations of Fig. 1, where each pixel provides important information, here the goal is to recognize a global property that is robust against individual pixel errors, which means that entirely different strategies are possible.
In statistical learning theory [37], different learning tasks, such as image classification, can be modeled using probabilities. We consider the abstract space of all possible images and define the probability π i of getting the image i -this is unknown and generally not uniform. Image classification is a rule that attaches a certain label c, or class, to a given image i. If this rule is deterministic, then it can be modeled via a function c = f (i) but, more generally, the strategy is stochastic: given a certain image, the rule predicts different possible classes c with a probability distribution P (c|i). Let us consider a pair (c, i) and assume that, given our data, we have built a classifierc(i) that assigns a certain classc(i) to the image i. The error in our classification can be described by a loss matrix with elements L cc that models the error of misclassification. The common choice is the 0-1 loss with L cc = 0 and L cc = 1 forc = c. By using the conditioning P (c, i) = P (c|i)π i = P (i|c)P (c), the expected classification error can be written as For known P (c, i) the optimal classifier is then the one minimizing the expected classification error,c B (i) = argmax c P (c|i), which is called Bayes classifier, while the resulting error from (14), is called Bayes rate. The Bayes rate represents the theoretical minimum error that can be expected with the optimal classifier. We now study the error of pattern classification when images are noisy, for instance due to an imperfect detection. The setup is the same of Fig. 1, where light, either quantum or classical, is used to illuminate the pattern (e.g. a handwritten digit as in Fig. 3a) and, from the detected output, the task is to find the correct class (e.g. a number between 0-9). For this purpose, we introduce the minimum error as a generalization of Eqs. (14) and (1) where the operators {Π c } define a POVM whose measurement outcome c predicts the class of the image i encoded into the quantum state ρ i . For a two-class decision problem, the optimal POVM can be explicitly found by Helstrom theorem [27]. When the number of classes is larger, a "pretty good" approximation to the optimal POVM can be obtained with pretty good measurements, so that we may derive bounds similar to (3), generalizing [21,22,38] (see Appendix E for details). (16) where K is such that K −1 is the minimum non-zero value of P (c, i)P (c , i ), which is independent of M , ρ W and ρ B , and we have defined where P cc (h) is the probability that two images from different classes c and c have Hamming distance h. For large M , the term with minimum Hamming distance dominates and we may write where h min is the minimum Hamming distance between two images from different classes. The Ineqs. (16) and the expansion (18) represent the most important results of this section, generalizing Ineqs. (8) and (9) to the problem of pattern recognition. By comparing those bounds, we find that quantum-enhanced pattern recognition is significantly simpler than barcode discrimination when h min > 1, as the error decreases with the faster rate (18).
The error E Q is a quantum generalization of Bayes rate, and quantifies the theoretical optimal performance of the classification rule. However, alike the Bayes rate, it is difficult to compute since the distribution P (c, i) is typically unknown, and no closed-form solutions to (15) exist beyond the two-class case. To solve these issues, in the next section we propose a supervised learning approach where an optimal classification measurement is estimated from a collection of correctly classified data.

B. Supervised quantum pattern recognition
In data driven approaches the task is to approximate the optimal classifier via a collection of already classified examples (c T k , i T k ). The set T = {(c T k , i T k ) for k = 1, . . . , T } is called training set and T is its cardinality. In the framework of statistical learning theory, we can treat the elements of this set as samples from the abstract and unknown joint probability distribution P (c, i) introduced above. Then, in the limit of large T we may approximate the averages with respect to P (c, i) with empirical averages over the training set. This allows us to explicitly compute the classification error (15) and the theoretical bounds (16). Therefore we define an empirical learning method, also called "training", as an optimization of the POVM {Π c } to correctly classify, as much as possible, the known samples from the training set T training : min From an operational point of view, a suboptimal solution to optimal detection {Π c } can be found for instance as shown Fig. 1d and discussed in section II, by optimizing over the available optical circuit, measurement schemes and classical post-processing. Here on the other hand we study the ultimate theoretical limits that any classification task must satisfy, studying the minimum training error E Q T via bounds like (16), while the ability to classify unseen data will be discussed in the next section. Indeed, upper and lower bounds on E Q T can be obtained (see Appendix E) as an average fidelity between states ρ i T k and ρ i T k whose images from the training set have different classes, c T k = c T k . Thanks to Eq. (6) we finally get where we have defined It is simple to show that B T [F ] is a particular case of B[F ] from Eq. (17) in which averages over the abstract distribution are substituted with averages over the empirical distribution. As such, we may rewrite B T as in Eq. (17) and obtain the large-M scaling (18). As a relevant example, we consider the problem of handwritten digit classification with the MNIST dataset [36]. The MNIST dataset is composed of a training set of 60000 images and corresponding classes, and a testing set of 10000 images and corresponding classes. Each original image is in grey scale and has n = 28×28 pixels. For simplicity we first map each pixel to either black or white, depending on the closest grey-level. In this way, every image can be seen as a 2D barcode. For the MNIST dataset we see from Fig. 3b) that the probability P cc (h) that two images from different classes have Hamming distance h resembles a Gaussian distribution with mean µ cc and standard deviation σ cc , and minimum non-zero value h min cc . Using this approximation, we find in Appendix E analytical approximations for B T [F ], recovering the scaling (18), where h min = min c =c h min cc . For the MNIST dataset, we find h min = 25. Therefore, from (20) we may get an error that decays as E Q T ≈ F (ρ B , ρ W ) αM hmin , independently on the number of pixels n and with 1 ≤ α ≤ 2. Moreover, thanks to Ineqs. (20) we may define a guaranteed quantum advantage when the upper bound obtained with entangled states is smaller than the lower bound obtained with classical data, namely when 2T F M hmin Since the training set is normally very large, we may set 2T = 2 νM hminN S for some ν and the above inequality becomes equivalent to (13), in the limit M → ∞ and N S → 0. Therefore, we may repeat the same analysis of Sec. II C: whenever ν th > 0 (see Fig. 2), quantum advantage can be proven for training sets whose dimension is bounded as 2T ≤ 2 ν th M N S hmin . In other terms, setting N tot = M N S we find a simple relation between the number of photons to show quantum advantage and the dimension of the training set as In the above expression the first inequality holds in general, while the approximated numerical value is for the MNIST dataset, where h min = 25 and T = 6×10 4 .
To conclude this section we note that unlike (7), the upper bound in (20) is achieved with global measurements, so a strategy like the one in Fig. 1f may be needed to achieve such classification accuracy. Bounds with local measurement errors are discussed in the next section, where each pixel is detected independently.

C. Independent on-pixel measurements
In the previous section we have studied the ultimate physical limits for pattern recognition by optimizing over all the elements of the optical apparatus, namely the optical circuit, the measurements and the classical postprocessing routines (Fig. 1c). Together these can all be described as an abstract global POVM, as in Eq. (15). Here we consider a simplified setup, similar to that of Fig. 1c but without the optical circuit and with local measurements Π i = N j=1 Π ij . Here a noisy image is reconstructed first, and then a classical algorithm is used to classify it. As before, we call i the real physical configuration of the n pixels, each either black or white i j = {B, W }, andĩ the binary variables corresponding to the reconstructed image, read by the sensors. Using M copies to perform the detection, all possible reconstructed images can appear with probability p read (ĩ|i) as in Eq. (1). Considering also the classical classification routine, the local setup consists in choosing a nonoptimal POVM in Eqs. (15) or (19) as where A(c|i) is any reliable (possibly non-linear) machine learning algorithm that can classify the reconstructed images. The above equation defines a POVM as long as c A(c|i) = 1 for all i, which is an obvious requirement since every image must be in at least one class.
The classical algorithm must be noise resilient, because some pixels might not be properly reconstructed, see e.g. Fig. 3a. Noise naturally occurs in readouts that are made in reflection where the light is diffused back to the receiver. Classification in the presence of different forms of noise has a large literature in machine learning [39]. Here, we assume that our training set is composed of noiseless images that are correctly classified, namely that c T k is the true class of i T k . Although not explicitly discussed here, it is possible to extend our analysis to noisy training sets via the method of importance reweighting [40][41][42].
As for the classical algorithm in Eq. (23), there are different strategies to define a classifier given the training set, all with different performances and ranges of applicability [37]. Here we focus on the nearest neighbor classifier [43], defined as where D(i, i ) is a suitable distance between two images. In other terms, classification of an unknown image i is done by selecting the class c T kmin of the image from the training set that is closest to i, according to distance D. The corresponding algorithm in (23) is A(c|i) = δ c,c T NN (i) . More advanced neural-network based algorithms will be considered in another paper [44].
In spite of being very simple, the nearest neighbor classifier has many desirable features. Indeed, under mild conditions, it has been proven [43] that, for T → ∞, the classification error using the nearest neighbor classifier is at most twice the Bayes rate, irrespective of the number of classes. More details are shown in the Supplemementary material, where we study the performance of this classifier for finite T , i.e., for finite training sets. Another feature is the ability to choose the most appropriate distance D. Here we choose the Hamming distance, which allows us to exploit many results from previous sections.
In this section we consider quantum sources and sensors, but classical algorithms for nearest neighbor classification. Quantum computers can perform nearest neighbor classification quicker than any classical counterpart [45], but how to mix those quantum algorithms with optical detection schemes is still an open problem.
Inserting Eq. (23) into (15) and employing the nearest neighbor classifier we get To understand this error, suppose that the pixel error probability p is independent on whether the pixel is black or white. In this case, the probability that the reconstructed imageĩ differs from the true image Classification error when each pixel is probed using either coherent inputs or entangled TMSV states. The plot is generated by combining the error coming from the single pixel error probability (see Appendix B) with the classification error from (a). We focus on the limit M → ∞, NS → 0 while keeping fixed the total mean number of photons M NS irradiated over each pixel. The colored areas represent the region between the upper and lower bounds assuming quantum (blue) or classical (red) sources combined with optimal local measurements. These bounds depend on the quantum and classical fidelities from Eqs. (10) and (12). The cyan and orange lines represents the performance with quantum light (cyan) or classical coherent states (orange) using (non-optimal) photodetection measurements. We set ηB = 0.9 and ηW = 0.95.
i in k = hamming(i,ĩ) pixels is a binomial distribution ∝ p k (1 − p) n−k , with mean np. Thanks to the analysis shown in Fig. 3b we know that, on average, as long as the number of wrongly detected pixels is smaller than the typical separation in Hamming distance between different classes, the nearest neighbour classifier should provide the correct result. For the transformed MNIST dataset, n = 28×28 and the typical number of flips between different classes is ≈ 160 (see Fig. 3b), so a pixel error probability up to p 160/784 20% should be tolerated by the algorithm.
In Fig. 4 we study the robustness of the nearest neighbor classifier via a numerical analysis with the trans-formed MNIST dataset, where each image is transformed into a 2D barcode as described in Sec. III B. We use such transformed training set to build a nearest neighbor classifier, and then estimate the error (25) as an average over the testing set, namely as N wrong /10000 where N wrong is the number of times that in the 10000 entries of the testing set, the predicted digit is different from the true one. Since the images from the testing set are samples from the abstract and unknown probability P (c, i) in the limit of infinitely large testing sets such estimate converges to E NN T from Eq. (25). Moreover, since the images from the testing set are different from the ones in the training set, this error contains two terms: an error due to imperfect detection and an generalization error, since we are classifying previously unseen data.
In Fig. 4a we study the classification error as a function of the probability p of wrong pixel detection. As we see, even for noiseless images, namely when p = 0, the classification error is still non-zero, as the nearest neighbor classifier may provide wrong outcomes. Nonetheless, as predicted, Fig. 4a shows that the nearest neighbor classifier is remarkably robust against relatively high pixel error probabilities p.
In Fig. 4b we combine the bound on the pixel error probability (see Eq. (B5), for a single pixel n = 1) with the theoretical curve that predicts the classification error from the pixel error probability in Fig. 4a. The bounds on the pixel error probabilities are obtained from the fidelities, Eqs. (10) and (12), which consider either coherent states or entangled TMSV states with the same average number of photons M N S . The results from Fig. 4b show that the classification error when we use quantum light is lower than the corresponding classical value. These results are basesd on the assumption that the detector performs the optimal Helstrom measurement, which may be complex to implement experimentally. Therefore, in Fig. 4b, we also consider the simpler photodetection measurement, where the POVM in Eq. (1) is a projection onto the Fock basis. The resulting pixel error probabilities with both coherent states and TMSV inputs are studied in the Supplementary Material, adapting the analysis from Ref. [46]. We see that even for this nonoptimal measurement, entangled inputs always provide an advantage against purely classical coherent states for all possible values of M N S . This advantage can be experimentally observed via a setup like that of Ref. [46].

IV. DISCUSSION
In this work, we have investigated multi-pixel problems of quantum channel discrimination, namely the identification of barcode configurations (equivalent to readout of the stored data) and the classification of black and white patterns, e.g. given by noisy digital images of handwritten digits. In both cases, we have shown that the use of quantum light based on entangled states clearly outperforms classical strategies based on coherent states.
For both quantum-enhanced barcode decoding and pattern recognition, we have analytically studied, via bounds, the physical limits to the classification error that we may get by optimizing over all optical elements, measurements and classical post-processing. This allows us to to derive explicit analytical conditions for the quantum advantage to hold. Moreover, the analysis of our bounds allows us to rigorously prove that quantum-enhanced pattern recognition can vastly reduce the classification error with respect to the mere independent measurement of each pixel.
Nonetheless, being easier from the experimental point of view, we have also considered a simplified setup where all pixels are probed independently and, for the problem of pattern recognition, we found that photon counting measurements are sufficient to show quantum advantage, paving the way for an experimental demonstration with state of the art quantum technology. Consider a barcode with n pixels or bars, where each bar can assume two possible values (black or white) as in Fig. 1. There are in total 2 n possible configurations and the discriminator must be able to correctly identify each code. Using uniform a priori probabilities π i = 2 −n in (3) we get For some specific choices of the input, e.g. for coherent states or TMSV states, the states take the product form (5) and the fidelities can be written as (6), where hamming(i, j) is the Hamming distance between the two images. In oder to find computable bounds for p err we study then the following quantity We find a closed form for D n (f ) by recursion. We may write i = {i 1 , i } where i has n − 1 components and similarly for j. Then in (A3) we may separately consider all four possible values of i 1 and j 1 , noting that when i 1 = j 1 we may also have i = j . Therefore we get where each term in the sum corresponds to (i 1 , j 1 ) = {(0, 0), (1, 1), (1, 0), (0, 1)}. The solution to the above recursion is from which we get the following inequalities where in the last line we use the inequality (1+x) r ≤ e rx . A small error p err ≤ is then obtained if we use M copies with Finally we study the asymptotic performance for M → ∞. From the definition of the state (5) we may write (A11) and taking the limit in Eqs.(A8)-(A9) we get which is valid for large M .

Appendix B: Local measurements
When local measurements are employed together with product states as in (5), then the success probability can be simplified as the probability of independently discriminating each pixel, namely where p local succ is the success probability of discriminating each image (2) using local measurements only and p pixel succ is the success probability of detecting the grey-level of a single pixel. For equal a priory probabilities, the success probability can be written as p pixel and, thanks to the Helstrom theorem [27,47], minimum error is obtained when Π B and Π W are, respectively, the projectors onto the positive and negative subspace of ρ B − ρ W . Therefore, with optimal Helstrom measurements the success probability is given by p pixel succ = 1/2 + 1/4 ρ W − ρ B 1 . Using the Fuchs-van de Graaf inequalities [28], and the fact that From the above inequalities, we may get a bound on the error probability p local err = 1 − p local succ using local measurements and M copies. The result is (B5) Performing the asymptotic analysis, for large M we find which results in the same decaying rate of Eq. (A12). Therefore, for small n (and large M ), the use of global measurements does not increase our ability to distinguish the product states (5). However, for large n the factor 2 −n−1 in (A12) shows that non-local quantum measurements might provide an important advantage. We now show that the upper bound from Eq. (B5) is tighter than that of Eq. (A9), namely that Indeed, for any 0 ≤ f ≤ 1 we find given that all terms in the sum are positive. Substituting f = F M max in the above equation we get (B7). The upper bound from (B5) is always tighter than (A9) and we may combine the two bounds (A8) and (B5) as in Eq. (7). Finally, using the Bernoulli's inequality, (1+x) n ≥ 1+nx when x ≥ −1, we find Eq. (8), which is valid for any n and M . The above bounds coincide with what we get from the asymptotic analysis, Eqs. (A12) and (B6), showing that the Bernoulli's inequality is tight in that regime.
Appendix C: Non-uniform a priori probabilities Here we consider a different problem where the set of images or configurations is restricted to have only k white pixels. We may also call this problem k channel position finding, k-CPF, being a generalization of the idea of CPF introduced in Ref. [19]. Namely, we know that there will be exactly k target channels (white pixels), but we do not know their positions. There are n choose k configurations in this set. The upper and lower bounds in Eqs. (A1) and (A2) can be solved as follows.
Similar to Eq. (A3), we can define where the summation is over configurations i = j with k target channels, and we can express Eqs. (A1) and (A2) as Our task reduces to solving the summation in Eq. (C1).
To begin with, we consider the simple case of k = 2, as the case of k = 1 is solved in Ref. [19]. For the case of 2-CPF, we will have two kinds of terms in the summation of Eq. (C1), one with Hamming distance 4 (corresponding to patterns with no target channels overlapping), and one with Hamming distance 2 (corresponding to patterns with one target channel overlapping), so that In general, for k-CPF with n pixels, we have n k configurations of patterns. Therefore, Eq. (C1) is a summation of n k n k − 1 terms. There are terms with Hamming distance of from 2 to 2k. By counting the number of terms with an identical hamming distance, we can compute where 2 F 1 is the standard hypergeometric function.
Therefore we can solve the function D k n as and then evaluate the bounds through Ineqs. (C2) and (C3). For large M we may expand D k n as and for large n and k we may write n k ≈ 2 nH(k/n) , where H(p) = −p log 2 (p) − (1 − p) log 2 (1 − p) is the binary entropy function. Employing these approximations in Eqs. (C2)-(C3) we find Eq. (9).

Appendix D: Quantum and classical fidelities
In the case of a quantum source, the input state is a two-mode Gaussian state, described by the quadrature operators Q = (x 1 , p 1 , x 2 , q 2 ). A TMSV state Φ N S has zero first moments and covariance matrix (CM) V jk = {Q j , Q k } /2 given by where I is the 2x2 identity matrix and Z is the Pauli Z operator. In the above expression the variance of the vacuum noise is 1/2, and N S is the mean number of thermal photons in each mode. If we now apply I ⊗ E η to the TMSV state, we get a Gaussian output state with CM The fidelity F (ρ W , ρ B ) can be computed using the formulae from Refs. [33,34], and depends on the invariants where Ω = (iY ) ⊕2 and Y is the Pauli Y operator. In terms of the above quantities the fidelity can be written as where in the second line we simplify the first expression, derived in [33,34], by explicitly evaluating the square root. Inserting the values from Eqs. (D4)-(D6) we get the result shown in Eq. (10). The tightness of the inequality in Eq. (10) can be proven by setting N tot = M N S and using e x = lim M →∞ (1 + Now let us compute the output fidelity corresponding to an input coherent state D( √ N s ) |0 , where D is the displacement operator. The action of the channel with transmissivity η is described by the Heisenberg evolution where b describes the photons in the (vacuum) bath. After the application of the channel we get a new coherent state D( √ ηN S ) |0 , so the fidelity is which is the result shown in Eq. (12).

Appendix E: Quantum pattern recognition with pretty-good measurements
A pretty good solution to the optimization problem (15) can be obtained with pretty good measurements [23][24][25] . Using these measurements, we may find upper and lower bounds [21,22] similar to (3). The lower bound can be simplified thanks to the concavity of F 2 [48], so as to get while the same simplification cannot be obtained for the upper bound. As a consequence, the upper bound cannot be directly computed, as ρ M c is not a quantum Gassian state. In order to introduce a computable upper bound we prove the following lemma, generalizing methods from [21,38].
Lemma: Let us fix a function f . Then using pretty good measurements we can derive the following bound for the probability of error Proof: Let us write σ x = p x ρ x = k λ xk |ψ xk ψ xk |, where λ xk and |ψ xk form the eigen-decomposition of σ x . We also set Π y = σ −1/2 σ y σ −1/2 , σ = x σ x , and define the Gram matrix G xy kl = λ xk λ yl ψ xk | ψ yl . Then the following identities hold (see [38] for a proof): where A 2 2 = Tr A † A , A 1 = Tr √ A † A and G xy is a matrix with elements G xy kl . Moreover, √ G xy 2 2 ≤ G xy 1 from lemma 4 in [21]. Therefore, which produces (E5) via (E7).
Thanks to the above lemma, we may now derive a simpler upper bound than (E2). Indeed, we may rewrite (15) as in (E4) by setting f (c, i) = c, calling ρ c,i := ρ i and Π c := i Π c ,i and defining multi-indices x = (c, i) and y = (c , i ). Then from the above lemma we get Now we show how to get Ineqs. (16). Indeed, via (E3) and (6) we may write Similarly, we may rewrite the upper bound (E8) as where K −1 is the minimum non-zero value of P (c, i)P (c , i ). Therefore, as long as P cc (h) is zero for h < h min cc in the limit of large M we get up to a constant C.
We now focus on the bounds in Eq. (20), which follow by approximating P (c, i) via the training distribution and noting that, in (E8), we may use δ ij + δ kl ≤ δ ij + δ kl . Alternatively, we may employ (E12) and note that K = T for the distribution (E13).
As for the bounds (20), let us study the function defined in Eq. (21), which can be rewritten as The probability P T 01 (h) is numerically studied in Fig. 3b for the MNIST dataset, where we see that P T 01 (h) closely matches a normal distribution. Therefore, approximating P T cc (h) as a normal distribution with mean µ cc and standard deviation σ cc we may write where p µ,σ (h) is the probability density function of a normal distribution with mean µ and standard deviation σ, w cc := σ 2 cc log(F ) + µ cc − h 0 cc and h 0 cc is the minimum value of Hamming distance in the empirical distribution. When µ σ we find B T cc F µ cc . On the other hand, for F → 0 we find This leads to the asymptotic decay rate B cc [F M ] ∝ F M h 0 cc for large M , up to constants and logarithmic corrections. Using the latter asymptotic decay expression in Eq. (E15), we find that, for large M , only the classes with smallest minimum Hamming distance h 0 cc survive. Moreover, we assume that the ratio T c /T does not scale with M , e.g. for digit reconstruction we assume that the number of 4s and 9s are basically constant if we increase the number of images. As such we may write Here we show that, in the uniform case, we may also employ the multiple quantum Chernoff bound [29,30]. Combining this with known inequalities [49], we find where F max := max i =j F i:j , and the approximations are valid in the large-M limit. The above inequality becomes exact for M → ∞, while (3) is valid for any M . Following [29,30] for i.i.d. hypotheses, we may also consider the following quantum Chernoff bound where and which can be computed for any Gaussian state [49]. Using known inequalities [28,49] we may write where From the above we finally get the following inequalities where in the last inequality we use 1 − √ 1 − x ≥ x/2 for 0 ≤ x ≤ 1, which is tight for x 0. In the large-M limit we get the inequalities (S1). Nonetheless, the exact computation of Q via (S4) may provide a tighter inequality via (S2).
Moreover, from the definition of the states (5), and from (S5) we get and accordingly, since Q ≤ 1, we find (S12) Together with (S2), this gives computable upper (and possibly lower) bounds on the error rate. Similarly, we may write (S13) so we may study the quantum Chernoff bound via (S9) and (S10).
An interesting comparison is between the asymptotic performance given by Eq. (S10), and the explicit results that we may get from from Eq. (A12). Indeed, for large- which is independent on n, as it is Eq. (S10).

Photodetection
We study the performance of barcode decoding and pattern recognition using photodetection. Photodetection is a local measurement, where each pixel is probed independently. As such, this strategy cannot achieve the lower bound in Eq. (8), but it is nonetheless interesting because it can be implemented experimentally with current technology. According to Ref. [46], the pixel error probability for a coherent-state input is given by where n th = N S (η W − η B )/ log(η W /η B ), while γ(η) := Γ( n th + 1 , N S η) and Γ(x, y) is the incomplete Gamma function. For a TMSV with mean photon number N S we may write |TMSV = n c Ns (n) |n, n with c N = N n S (1+N S ) n+1 . After the first mode of the TMSV state is transmitted through a channel with transmissivity η, the resulting photon number distribution is P (n 1 , n 2 |η) = P 0 (n 2 )B(n 2 , n 1 |η) when n 2 ≥ n 1 , 0 when n 2 < n 1 , (S16) where B(n 2 , n 1 |η) = n2 n1 η n1 (1 − η) n2−n1 and P 0 (n 2 ) = c 2 N S (n 2 ) is the initial distribution. The success probability of distinguishing the two channels with transmissivity η B and η W is then p pixel succ,TMSV = 1 2 ∞ n2=0 n th 2 (n1) n1=0 P (n 1 , n 2 |η B )+ (S17) where n th 2 (n 2 ) = cn 2 and (S18) For M probings, one may substitute the initial distribution in Eq. (S16) with the Poisson distribution P 0 (n 2 ) = e −λ λ n2 /n 2 ! with parameter λ ≈ M N S [46]. For large average photon number, namely for large λ, the sum in Eq. (S17) is hard to evaluate. Nonetheless, we may approximate the Poisson distribution P 0 (n 2 ) with a normal distribution n 2 ∼ N (λ, λ), where N (µ, σ 2 ) is the normal distribution with mean µ and variance σ 2 . Similarly, we may approximate the binomial distribution in (S16) as n 1 ∼ N (n 2 η, n 2 η(1 − η)). Introducing the quantity g(λ, η) = ∞ 0 dn 2 cn2 0 dn 1 f λ,λ (n 2 )f n2η,n2η(1−η) (n 1 ) , (S19) where f µ,σ 2 (x) is the probability density function of N (µ, σ 2 ), and approximating the sum with an integral in (S17), we then get where T is the size of the training set. Under mild conditions, it has been proven [43] that in the limit T → ∞, the expected classification error E NN = lim T →∞ E NN (T ) satisfies where E B is the Bayes rate and K is the number of classes. Therefore, the expected error from the nearest neighbor classifier is at most twice the Bayes rate, irrespective of the number of classes.
To study the error for finite T in (S22) we first note that even the training set is made by samples, so the predicted nearest neighbour classifierc is a random variable that depends on the training set T . (Note that we have removed the subscript NN fromc to simplify the notation.) Therefore, we may rewrite Eq. (S22) as (S24) We know from Eq. (24) thatc is equal to one element of the training set. Let us callĩ all possible images that have classc. Then by the law of total probability In the above equation, we assume that (c, i) are sampled from the unknown distribution P (c, i) that describes all possible images and their true label. As in the previous section, we assume that the training set is made by samples from P (c, i). Then, Eq. (S27) can be interpreted as follows: we sample a new physical image i and the corresponding true label c, which is unknown to us. This physical image is measured by a sensor and we get a reconstructed image i with probability (1). Then we apply the nearest neighbor classifier to find the closest imagẽ i to i from the training set, and get its corresponding labelc. A loss matrix L c,c is the used to weigh the error whenc = c. Thanks to the above definition, the optimal measurement in (1) is then the one minimizing the expected classification error Employing (S25) and taking expectation values with respect to the training set we find If a given image belongs to a single class, as it is the case with the nearest neighbor classifier, we may write P (c|i) = δ c,f (i) for a certain classifier function f , and accordingly c P (c|i)P (c|j) = δ f (i),f (j) .
so that we may write ∆(i,ĩ)P NN (ĩ|i , T )p read (i |i)π i , (S30) For the nearest neighbor classifier, f is the function that associates to an image from either the training or testing set the corresponding class. For instance, in Eq. (S30) the image i is from the testing set, say with class c, and the imageĩ is the nearest neighbor to the noisy reconstructed image, and accordinglyĩ is from the training set. Calling c the corresponding class from the training set, ∆(i,ĩ) = δ c,c . Moreover, in the previous section we have seen that, when T is much bigger than the dimension of the image space (T 2 N in this case), we may write P NN (j|i) = δ i,j and we finally get (1 − δ f (i),f (i ) )p read (i |i) ≤ p err .
(S31) Therefore, in the limit T → ∞ the classification error is smaller than the error in the state discrimination (2).

Finite sample-error in the nearest neighbor classifier
Here we explictly show that P NN (ĩ|i, T ) → δ i,ĩ in the limit T → ∞. To prove this, we study the statis-tics of d k = dist(i T k , i) and define d min = min k d k , where we employ the Hamming distance. If the samples i k are independent and identically distributed we get P T (d min ≤D) ≡ E T P (d min ≤D|i, T ) and P T (d min ≤D|i, T ) = 1 − P T (d 1 >D, . . . , d T >D|i) where is the probability that a new image i has at most distance D from the given image i. (S35) From the above equation and from (S32), it is clear that, as long as P (d=0|i) > 0, for T → ∞ we find In particular, if the set of images is finite and of dimension N , then P (d=0|i) ≈ N −1 and a training set with T N is required to approximate the limit (S36). For any i, the solution of d min = 0 is unique and, therefore, we have that i T k = i for some k. We may get the above result more explicitly by defining an order between images so that With the above definitions, by calling P NN (ĩ|i) = E T P NN (ĩ|i, T ), we get P NN (ĩ|i) := P T (j iĩ |i) − P T (j ≺ iĩ |i) , (S40) and, in particular, forĩ = i we find