# Experimental quantum pattern recognition in IBMQ and diamond NVs

Sreetama Das1,2, Jingfu Zhang3, Stefano Martina1,2, Dieter Suter3, Filippo
Caruso1,2,4 1Department of Physics and Astronomy, University of Florence, Via
Sansone 1, Sesto Fiorentino, I-50019, Italy  2European Laboratory for Non-
Linear Spectroscopy (LENS), University of Florence, Via Nello Carrara 1, Sesto
Fiorentino, I-50019, Italy  3Fakultaet Physik, Technische Universitaet
Dortmund, D-44221 Dortmund, Germany  4QSTAR and CNR-INO, Largo Enrico Fermi 2
- 50125 Firenze - Italy

###### Abstract

One of the most promising applications of quantum computing is the processing
of graphical data like images. Here, we investigate the possibility of
realizing a quantum pattern recognition protocol based on swap test, and use
the IBMQ noisy intermediate-scale quantum (NISQ) devices to verify the idea.
We find that with a two-qubit protocol, swap test can efficiently detect the
similarity between two patterns with good fidelity, though for three or more
qubits the noise in the real devices becomes detrimental. To mitigate this
noise effect, we resort to destructive swap test, which shows an improved
performance for three-qubit states. Due to limited cloud access to larger IBMQ
processors, we take a segment-wise approach to apply the destructive swap test
on higher dimensional images. In this case, we define an average overlap
measure which shows faithfulness to distinguish between two very different or
very similar patterns when simulated on real IBMQ processors. As test images,
we use binary images with simple patterns, greyscale MNIST numbers and MNIST
fashion images, as well as binary images of human blood vessel obtained from
magnetic resonance imaging (MRI). We also present an experimental set up for
applying destructive swap test using the nitrogen vacancy centre (NVs) in
diamond. Our experimental data show high fidelity for single qubit states.
Lastly, we propose a protocol inspired from quantum associative memory, which
works in an analogous way to supervised learning for performing quantum
pattern recognition using destructive swap test.

##  I Introduction

In the last few decades, the advancement in quantum information processing has
significantly impacted the fields of computation and communication
technologies. The superiority of a quantum protocol lies in the fact that it
can accomplish tasks either impossible by a classical protocol [1,
*densecoding], or in some cases it performs exponentially or polynomially
faster compared to its classical analogue, the most prominent examples being
Shor’s factorization algorithm [3] and Grover’s search algorithm [4]. These
traits of a quantum system, particularly the computational speed-up, has been
crucial in developing powerful algorithms for quantum simulation [5,
*simulation2, *simulation3, *simulation4, *simulation5, *simulation6,
*simulation7, *simulation8], Boson sampling [13, *bsampling2, *bsampling3,
*bsampling4, *bsampling5, *bsampling6], solving systems of linear equations
[19, *Cai_2013, *Pan_2014, *barz_2017, *zheng_2017], and many other
computational problems. Recently, the possibility to use quantum properties to
facilitate artificial intelligence and machine learning has been extensively
investigated [24, 25, 26, 27, *qmachine2, *qmachine3, *qmachine4, 31]. We are
living in the era of quantum supremacy [32, *china_supremacy1,
*china_supremacy2, *china_supremacy3]. It has been possible to build quantum
processors (processing units) with several tens of qubits, some of them being
accessible to users from anywhere in the world through cloud-based sharing
[36]. However, these machines are still extremely noisy and, for this reason,
they are called Noisy Intermediate-Scale Quantum (NISQ) devices [37].

This progress is staring to affect the field of image processing. Vision is
the most fundamental mechanism of obtaining information about a system. Thus,
image processing is a necessary task in a broad range of directions like
medical science, space science, automobile technologies etc. With the
advancement in quantum technologies, a growing interest has been directed
towards implementing quantum systems for improved image processing. Some
quantum image processing protocols have been proposed and tested, which show
polynomial and exponential speed up; an example is quantum edge detection [38,
39, 40, 41]. Another widely used image processing task is pattern recognition.
The application of the latter ranges from identifying a string of integers or
texts present in an 1D array, to recognizing 2D patterns such as faces of
people, handwritten digits, geometric shapes, and other tasks. In 2002,
Trugenberger introduced the idea of quantum associative memory, and put
forward a quantum pattern recognition protocol based on that [42]. Using
quantum Fourier transform, Schutzhold in 2003 devised another protocol for
pattern recognition which demonstrated exponential speed-up over its classical
analogue [43]. A number of follow-up works attempted to improve the above
protocols or presented similar algorithms inspired from them [44, 45, 46].
Except these, quantum pattern recognition protocols based on the framework of
classical Hopfield neural network [47], the hidden shift problem [48], pixel
gradient calculation [49], Grover’s algorithm [50, 51, 52] has been proposed.
Some of them adopted a quantum machine learning approach [25, 53,
*qmachinepattern2, *qmachinepattern3, *qmachinepattern4, 57]. However, when
tested on real quantum systems, the protocols are inevitably subject to noise,
which degrades their efficiency. Thus, one must learn how to control noise,
and counteract its effects.

In this work, we consider a quantum pattern recognition algorithm based on
swap test. The swap test is used to calculate the closeness between two
quantum states. In quantum image processing, the classical images are encoded
in quantum states, hence the swap test emerges as a very plausible approach to
find similarity between two quantum images. This has been previously mentioned
and briefly discussed in [39] and [40]. The question remains as what will be
the efficiency of this protocol in real quantum systems. This is motivation of
our work, where the real systems are the IBMQ devices [36]. We aim to identify
a pattern in the target image by comparing it with the patterns present in a
large set of reference images, and finding an exact match. We find that, for
systems as small as three qubits, and corresponding states which can be
prepared using a few Hadamard and controlled NOT gates, the performance of
swap test is low due to the strong presence of noise. To curb the effect of
noise, we try an alternate but equivalent circuit, often called as
‘destructive swap test’ in the past literature [58], in which the number of
necessary gates is reduced. By using this novel approach, we observe an
improved performance of the pattern recognition protocol for three-qubit
states in real IBMQ devices (see Section IV for more details). We then go on
to try the destructive swap test in these systems for higher dimensional
binary and greyscale images, including small-dimensional biomedical images
obtained in the lab with MRI. We also present an experimental setup and the
resulting data where destructive swap test is performed using diamond nitrogen
vacancy (NVs) centres. Our results suggest that destructive swap test can be a
potential alternative to achieve the goal of swap test, at a reduced level of
noise. Lastly, we propose a quantum protocol inspired from the quantum
associative memory, by which one can recognize a pattern from a large set of
reference patterns.

The paper is organized as follows. In Section II, we describe the encoding of
a classical image in a quantum state. In Section III, we discuss swap test and
its performance in real quantum computers. This leads the way to destructive
swap test and its improvements over swap test. In Section IV, we demonstrate
the performance of destructive swap test in real quantum systems, when
identifying similar geometric patterns encoded in binary images, as well as
binary images obtained from MRI of human blood vessel. We also present a short
analysis of how the success probability of the protocol changes with varying
noise in the real quantum processors. In Section V, we present similar results
for greyscale images. In Section VI we show the experimental result of
destructive swap test in diamond NVs. In Section VII, we propose a quantum
algorithm analogous to supervised learning, for using destructive swap test in
pattern recognition. Lastly, Section VIII contains the concluding remarks.

Figure 1: A schematic diagram of our pattern recognition protocol. In the
target image, one aims to detect the handwritten number “9”. There is a set of
reference images with handwritten digits from 0 to 9. The target image and an
arbitrary chosen reference image, in this case “2” for demonstration purpose,
is encoded as quantum states, passed as the inputs of a quantum protocol to
calculate the distance between them. The measurement result undergoes a
classical post-processing. The protocol is repeated for all the reference
images. The reference image with minimum distance to the target image is
assigned as the pattern to be detected.

Figure 2: The circuit diagram of Swap test for (a) single qubit states and (b)
three-qubit states. (c) The swap test circuit after transpilation in
$\mathrm{ibmq}\\_\mathrm{manila}$, for two single qubit states, both being
$|0\rangle$. The figure is exported from Qiskit.

##  II Encoding an image in a quantum state

The first task in quantum image processing is to encode the pixel positions
and corresponding pixel values of a classical image in a quantum state. A
number of encoding processes has been proposed to date, e.g. Flexible
Representation of Quantum Images (FRQI) [59] and Novel Enhanced Quantum
Representation (NEQR) [60]. In this work, we will use a different encoding
method first used by the authors in [39], which is often referred to as
Quantum Probability Image Encoding (QPIE).

We work with a 2D image of $N=P\times Q$ pixels, which is classically encoded
in a $P\times Q$ dimensional matrix $M$, the matrix element $M(i,j)$ denoting
the pixel value at position $(i,j)$. To encode this image in a quantum state,
we can use any $m$-qubit system, such that $2^{m}\geq N$. The Hilbert space
$\mathcal{H}_{2}$ of each qubit is spanned by the computational basis
$\\{|0\rangle,|1\rangle\\}$. From the $m$-qubit register, we choose $n$ qubits
such that $2^{n}=N$. We initialize them in the state
$|f\rangle=\sum_{i}c_{i}|i\rangle$ where the basis vectors $|i\rangle$ span
the $2^{n}$ dimensional Hilbert space $\mathcal{H}_{2}^{\otimes n}$, encoding
the positions of the pixels. The coefficients $c_{i}$ encode the corresponding
pixel values. The first $P$ elements of $|f\rangle$ encode the first column of
$M$, the next $P$ elements encode the second column, and so on. Thus, each
pixel position corresponds to a particular quantum state $|i\rangle$ of
$\mathcal{H}_{2}^{\otimes n}$, and its pixel value corresponds to the
coefficient $c_{i}$ in $|f\rangle$. Lastly, the state $|f\rangle$ must be
normalized.

Most generally, the images can have a color format e.g. RGB or sRGB, where the
pixel values can vary over a range. The images can also be greyscale, where
the varying pixel values denote different shades of grey. However, depending
on which type of information we want to acquire from the images, converting
them to binary images can be operationally advantageous for further image
processing tasks, e.g. edge detection. In a binary image, all the pixel values
are $0$ or $1$. The conversion can be achieved by choosing a suitable
threshold pixel value $p$ in between the minimum and maximum pixel values of
the color image. The pixel values equal or higher than the threshold are
converted to 1, those below the threshold are converted to 0. Depending on the
choice of $p$, the resulting images differ.

Now that we are able to encode the images, we proceed to apply a quantum
pattern recognition protocol in the next section. In classical image
processing, a brute-force method is to measure the pixel values of all the N
pixels. However, once encoded as an $n$-qubit quantum state, the number of
measurements necessary to obtain certain information about an image is
drastically reduced compared to the classical case. To define our pattern
recognition protocol, we assume that we have a target image with an unknown
pattern to be detected, and a large set of reference images with different
patterns which are known to us. The target pattern can be detected if it is
compared with each reference image and an exact match is found. In case an
exact match does not exist in the reference set, one can still look for the
closest match. Translated into the language of quantum physics, one needs to
calculate the closeness or distance between the quantum states representing
the images. A schematic diagram of the protocol is presented in Fig. 1. The
distance is determined by swap test, as we discuss in the next section.

##  III Swap test

Swap test is an widely used protocol for calculating the overlap between two
quantum states [61, 62, 63]. Specifically, if $|\psi\rangle$ and
$|\phi\rangle$ are two pure states, swap test can be used to calculate
$|\langle\psi|\phi\rangle|^{2}$, which is also a valid distance measure
between the two states, known as quantum Fidelity [64, 65]. The circuit of
swap test for single qubit states is shown in Fig. 2(a). It can be generalized
to $n$-qubit states by repeating the controlled-swap gate for all qubit pairs,
as shown in Fig. 2(b). Each of the states $|\psi\rangle$ and $|\phi\rangle$ is
encoded using three qubit quantum registers $Q_{1}$ and $Q_{2}$ respectively.
There is an auxiliary qubit $Q_{a}$ which is initialized in the computational
basis state $|0\rangle$. After initializing all the qubits, a Hadamard gate
$H$ is applied on $Q_{a}$, which transforms $|0\rangle$ to
$|+\rangle=\frac{1}{\sqrt{2}}(|0\rangle+|1\rangle)$. This qubit is then used
as the control qubit to apply the controlled swap operation between all
consecutive qubit pairs of $Q_{1}$ and $Q_{2}$. In the controlled swap
operation, if the control qubit is in state $|1\rangle$, the states of the two
target qubits are interchanged. If the control qubit is in state $|0\rangle$,
nothing changes. This is followed by another Hadamard operation on $Q_{a}$.
Lastly there is a classical register “cr” which registers the measurement
outcome on the auxiliary qubit. The outcome can be $``0"$ or $``1"$,
associated with the measurement basis states $|0\rangle$ and $|1\rangle$
respectively. The measurement is taken on a large number of identically
simulated circuits. If $|\psi\rangle=|\phi\rangle$, the measurements will
return “$0$” with probability $P(0)=1$. If they are orthogonal,
$P(0)=P(1)=\frac{1}{2}$. For all other cases, $P(0)$ varies between
$\frac{1}{2}$ and $1$. The fidelity between two states is then

$\mathcal{F}=|\langle\phi|\psi\rangle|^{2}=2P(0)-1,$ (1)

and the overlap $\mathcal{I}$ is

$\mathcal{I}=|\sqrt{\mathcal{F}}|.$ (2)

A higher value of $\mathcal{I}$ implies higher degree of similarity between
two states. Both $\mathcal{F}$ and $\mathcal{I}$ can be equivalently used to
measure the degree of similarity between two quantum states. In this work, for
most parts (except the diamond NVs), we stick to $\mathcal{I}$ since it is
more sensitive to small changes in $P(0)$.

We assume that for our pattern recognition protocol, both the target and
reference images have same dimension. The target image is encoded in a quantum
state, and passed as one of the inputs in the swap test circuit. On the other
hand, each of the reference images is encoded in a quantum state, and then
passed as the other input. If two patterns match exactly, one gets $``0"$ with
probability 1 in the measurement of the auxiliary qubit. Otherwise, one can
detect the closest pattern of the target image as the one with which it has
highest overlap.

Figure 3: The mean overlap $\mathcal{I}_{mean}$ between two identical states
encoded using $n$ qubits and the corresponding standard deviation $\sigma$ for
swap test. The data are obtained by performing 100 runs of the circuit in real
IBMQ processors.

Figure 4: The circuit diagram of destructive swap test for (a) single qubit
states and (b) three-qubit states. (c) The destructive swap test circuit after
transpilation in $\mathrm{ibmq}\\_\mathrm{manila}$, for two single qubit
states, both being $|0\rangle$. The figure is exported from Qiskit.

In real quantum processors, the performance is unavoidably affected by noise.
The latter can appear due to decoherence, interaction among qubits, gate
fidelity, state preparation and measurements. The adverse effect of noise on
any protocol increases with increasing number of qubits and gates. In IBMQ,
each of the real quantum processors has a set of “basis gates” consisting of
some particular single qubit and two-qubit gates. When a circuit is simulated
using these, it typically needs to be“transpiled”, i.e. the action of all the
complex gates are obtained by using the basis gates. Thus in the actual
simulation, the number of gates are higher compared to what we add to the
circuit. This has been shown in Fig. 2(c) for single qubit states. For higher
dimensional states, performance of swap test invariably degrades. We
demonstrate this in Fig. 3 where we perform swap test for two states encoded
using one qubit, two qubits and three qubits respectively. For all three
cases, we take the two states to be same and calculate the overlap between
them. The states corresponding to these three cases are
$|\psi_{1}\rangle=\frac{1}{\sqrt{2}}\big{(}|0\rangle+|1\rangle\big{)}$,
$|\psi_{2}\rangle=\frac{1}{\sqrt{2}}\big{(}|00\rangle+|11\rangle\big{)}$, and
$|\psi_{3}\rangle=\frac{1}{\sqrt{2}}\big{(}|000\rangle+|111\rangle\big{)}$.
These states are typical exemplary states, and we prepare them by directly
adding Hadamard and controlled NOT (CNOT) gates to the circuit. The CNOT gate
has a control qubit and a target qubit, the state of the latter undergoes a
bit-flip operation (gate corresponding to pauli-x matrix $\sigma_{x}$) if the
control qubit is in state $|1\rangle$, otherwise nothing changes. The overlap
is calculated for 100 realizations of the identical circuit, and then the mean
overlap $\mathcal{I}_{mean}$ and the standard deviation $\sigma$ is
calculated. For this simulation, and for all the subsequent sections, we have
used the 5 and 7-qubit IBMQ systems which are-
$\mathrm{ibmq}\\_\mathrm{manila}$, $\mathrm{ibmq}\\_\mathrm{jakarta}$,
$\mathrm{ibm}\\_\mathrm{lagos}$, $\mathrm{ibm}\\_\mathrm{perth}$,
$\mathrm{ibmq}\\_\mathrm{casablanca}$ and $\mathrm{ibmq}\\_\mathrm{quito}$. We
see that for single qubit case, in spite of the presence of noise, the
performance of swap test is quite good. For two qubits, the noise becomes
significant, and for the three-qubit case the value of the overlap worsen. Due
to the cloud inaccessibility to higher dimensional systems, we could not check
the swap test for four qubit states. However the results are sufficient to
suggest that the swap test quickly loses its relevance for states having
dimension higher than 3, and this poses a primary challenge to utilize it for
pattern recognition in even fairly small images. Even in the NV setup, the
experimental results deviate because of imperfect realization of the pulse
sequences, as will be discussed in Section VI. However, the quantum simulators
do not suffer this problem. One can check that for two same images, the mean
inner product and standard deviation will always return values $1$ and $0$
respectively. This is because the IBMQ simulators are classical computers that
simulates the results of an ideal quantum evolution. Hence they can still be
used to check the performance of swap test irrespective of the dimension,
while being within their size limit, which is 32 qubits for the
$\mathrm{qasm}\\_\mathrm{simulator}$.

###  III.1 Destructive swap test

In [58], the authors showed that an equivalent circuit for swap test can be
built without using the auxiliary qubit, at the cost of measuring all the
qubits used to encode the states. The controlled swap gate used in the swap
test, is a three-qubit gate which can be realized by two CNOTs and one CCNOT
(controlled controlled NOT) gate. In the new circuit, all the controlled swap
gates are replaced by same number of two-qubit CNOT gates. Also, only one
Hadamarrd gate is required. Thus, compared to the original swap test, in this
case the number of gates in the transpiled circuit decreases significantly,
hence reducing the noise in the output. This protocol is referred to as
“destructive swap test”, because any superposition in the output is destroyed
on measuring all the qubits. Later in [66], the authors used machine learning
approach to find the optimized circuit for calculating overlap between two
states, and they rediscovered the destructive swap test as the optimum
algorithm. Their results, simulated using 5-qubit IBMQ and 19 qubit Rigetti’s
quantum computer, shows a huge improvement of destructive swap test over the
auxiliary qubit-assisted swap test, in terms of reducing the noise in the
output. The circuit for destructive swap test for single qubit states is shown
in Fig. 4(a). For $n$-qubit states, the gate sequence of (CNOT+Hadamard) is
applied to the $n$ pairs of qubits belonging to the two states, as shown in
Fig. 4(b). The circuit of Fig. 4(a) after transpilation is shown in Fig. 4(c),
which clearly uses a lot less number of gates compared to Fig. 2(c). For each
shot of circuit simulation, the classical bit string corresponding to
measurement outcomes from the qubits of $|\psi\rangle$ is denoted by
$O^{\psi}$, and that for $|\phi\rangle$ is denoted by $O^{\phi}$. Each of
$O^{\psi}$ and $O^{\phi}$ can have $2^{n}$ different possibilities. The joint
string $O^{\psi}O^{\phi}$ constitutes the measurement outcomes of the total
system, which has $2^{2n}$ possibilities. Each element $O^{\psi/\phi}_{i}$
$(i=1,2,...,n)$ is a bit, taking values either $``0"$ or $``1"$. Suppose
$O^{\psi}_{i}$ and $O^{\phi}_{i}$ are the $i^{\mathrm{th}}$ bits of the two
strings respectively. As shown in [58], an equivalent situation of obtaining
$``1"$ in the auxiliary qubit measurement in the standard swap test occurs
when $O^{\psi}$ and $O^{\phi}$ are such that
$\sum_{i}\mathrm{AND}(O^{\psi}_{i},O^{\phi}_{i})$ has odd parity. For all such
sequences $O^{\phi}$ and $O^{\psi}$, we take summation over the probabilities
$P(O^{\psi}O^{\phi})$ of the joint outcomes $O^{\psi}O^{\phi}$. A nonzero
value of this sum implies that $|\psi\rangle$ and $|\phi\rangle$ are not same.
For this reason, we call this sum as the “probability of failure”. By
subtracting it from unity, we get the “success probability” which we denote by
$P(0)$. A higher value of $P(0)$ implies higher overlap between two states.
When $|\psi\rangle$ and $|\phi\rangle$ are same, the success probability is 1.
The fidelity and the overlap can again be calculated using Eq. (1) and Eq.
(2).
Example: for two-qubit states, the probability of failure is obtained by
summing over the probabilities of outcomes 0101, 0111, 1010, 1011, 1101 and
1110. For each of them, the first two bits correspond to the measurement
outcome of qubits from one state, and the last two bits from the other state.
In ideal systems the swap test and destructive swap test will give same
success/failure probability to distinguish between two images. It’s not the
case for noisy systems.

Figure 5: Destructive swap test for pattern recognition in (a) two-qubit and
(b) three-qubit images. In each vertical panel, the image on the left is the
target image, and the one in the right is the reference image. The $y$-axis in
the left denotes the overlap and the one in the right denotes the standard
deviation corresponding to real quantum processors. The legendbox in (b)
applies to both the figures. The mean and standard deviation are calculated
over 100 runs of the circuit.  Figure 6: The destructive swap test applied to
compare the overlap between different geometric patterns in binary images.
Each image is $32\times 32$ pixels. The two images placed next to each other
in a vertical column are compared. In each column, the red square denotes the
ideal overlap, the blue cross denotes the overlap obtained from a quantum
simulator and the green triangle is the average overlap obtained from real
quantum processors by dividing the original image into $2\times 2$ segments.
The vertical axis is used to plot both the overlap for full images, and the
average overlap over the segments. Figure 7: The variation of the average
overlap $\mathcal{I}_{avg}$ with varying dimension of the blocks used to
divide the original $32\times 32$ images. The results are obtained by using
IBMQ simulator. Different markers and colors corresponds to comparison between
different pairs of geometric shapes as indicated in the legend.

##  IV Destructive swap test for pattern recognition

In this section, we present a comparative study between the swap test and
destructive swap test in real quantum processors as well as in the ideal
quantum simulators provided by IBMQ. We use binary images where the black
pixels compose a ‘pattern’ against the background of white pixels. Our goal is
to identify this pattern in a certain image. We start with small images with
$2\times 2$ and $2\times 4$ pixels, as shown in Fig. 5(a) and Fig. 5(b). The
black and white pixels correspond to pixel values “1” and “0” respectively.
The images are encoded using 2 and 3 qubits respectively. As shown in the
previous section, the swap test in these systems is highly noisy. We want to
check whether destructive swap test can reduce the effect of noise. For 100
simulations of the same circuit in real quantum processors, we calculate the
mean overlap $\mathcal{I}_{mean}$ and the standard deviation $\sigma$. For
comparison, we also show in Fig. 5(a) and Fig. 5(b) the theoretical value of
the overlap, and that obtained from IBMQ simulator. For the two-qubit images,
the result shows $7\%$ error to distinguish between same images, which is a
significant improvement over Fig. 3. For the three-qubit images, this error is
around $31\%$, which is still an improvement over the swap test. Also the
relative behaviour of $\mathcal{I}_{mean}$ for different reference images are
consistent with the actual overlap, and hence the destructive swap test can be
faithfully used for pattern recognition. This also demonstrates that, even
though the number of measurements increase, the noise in the output is much
less compared to swap test. However, the destructive swap test needs a more
complicated classical post-processing of the measurement outcomes. Thus, there
is a trade-off between swap test and destructive swap test in terms of
classical post processing, and number of quantum gates used in the circuit.
The reader may note that, even when comparing two same images, the
success/failure probability can vary little bit depending on the particular
quantum image states being considered. This is because the number of gates
used to prepare different initial states can be different, hence the effect of
noise can vary.

To perform destructive swap test for larger images, we need access to higher
dimensional real quantum processors. The largest system we have access to are
the 7 qubit IBMQ processors. A way out is to divide the original image into
smaller segments each of which can be encoded using the available few-qubit
systems. Then one can apply destructive swap test on the pair of segments
belonging to the same coordinates from the target and the reference image. In
case of binary images, there can exist segments on which all the pixels have
pixel values 0. Using our encoding method, we cannot encode these white blocks
as valid quantum states because $c_{i}=0$, $\forall i$. Hence, we run the
circuit only when both the blocks corresponding to target and reference image
have at least one pixel with non-zero pixel value. For each such pair of
blocks, we calculate the overlap. One drawback of this segment-wise approach
is that it does not anymore calculate the distance between the full quantum
states encoding the images. Also by taking this approach, we exclude those
cases when one among the pair of blocks is white and another has black pixels.
This exclusion induces error in the results.

In other words, a particular pattern can have same number of pixels in common
with two or more different patterns, e.g. in Fig. 6, the triangle has the same
pixels overlapping with the square, the circle, and with itself. Hence all
those reference patterns will correspond to exactly the same number of blocks
contributing to the overlap with the triangle. Thus to detect the closest
pattern, one should also take into account the white blocks which are not
common between the target and reference pattern. For this, we take summation
of all segment-wise overlaps, and divide it by
$\mathrm{max}\\{N_{1},N_{2}\\}$, where $N_{1}$ and $N_{2}$ are the number of
blocks having non-zero pixel values corresponding to the patterns in the
target and reference image respectively. We call this “average overlap”
$\mathcal{I}_{avg}$, and use this to capture the closeness between two
patterns. We show the results in Fig. 6, where we divide the original
$32\times 32$ pixels images containing simple geometric patterns into $2\times
2$ pixels segments, and apply destructive swap test on the $16\times 16$ pairs
of segments with same coordinates from the target and reference image. We also
have presented the actual value of the overlap between the full quantum image
states and those obtained from the quantum simulator. Clearly, the average
overlap is highest when the patterns from both the images match exactly.
Moreover, despite the noise, the comparative behaviour of $\mathcal{I}_{avg}$
is consistent with that of the actual overlap between the patterns. This
segmenting process indeed needs significantly higher number of measurements,
and computational time. However, as the computational power of quantum
computers improves more and more over the years, we will be able to select
bigger segments from original images, eventually being able to encode the
whole images using the available qubits. To check the validity of this
segmenting process for bigger than $2\times 2$ blocks, we increase the block
size step by step, and compare $\mathcal{I}_{avg}$ between the same pair of
patterns as in Fig. 6. Due to the size limitation of accessible real quantum
processors, we use IBMQ simulator to simulate the circuits, and the results
have been presented in Fig. 7. For every block size, the comparative behaviour
between different pairs of patterns remains consistent with the ideal
situation. There exist small anomalies, e.g. for the $\mathcal{I}_{avg}$ of
square-circle pair when the blocks are $8\times 8$ pixels. This may arise
because, as stated before, $I_{avg}$ is not entirely equivalent to the overlap
$\mathcal{I}$ between full quantum images. The results again indicate that the
destructive swap test is faithful for pattern recognition, and
$\mathcal{I}_{avg}$ can be used for large dimensional images with simple
binary patterns.

Figure 8: The behaviour of the overlap $\mathcal{I}$ between two identical
two-qubit image states, with varying depolarizing noise strength in the
circuit gates. The blue curve corresponds to the case when the noise in the
two CNOT gates is varied, keeping all the single qubit gates at very low
noise. The green one is for the case when the CNOT gate noise is low, but all
the single-qubit gate noise varies. The red curve is when all the gate noises
are varied together.

###  IV.1 Noise robustness

Due to the impossibility of completely removing the presence of noise, the
real IBMQ processors are subject to gate errors, state preparation and
measurement errors, and readout errors. The former is due to imperfect
implementation of a gate, and the later is due to imperfect measurement. As
all the IBMQ processors are calibrated on certain time intervals, the values
of these errors fluctuate. To understand the robustness of our results against
these fluctuating errors, it is important to check how the success probability
of destructive swap test changes with changing noise. Since we cannot manually
change the errors in IBMQ processors, we resort to the simulation using
“NoiseModel” class provided by IBMQ. The simulator copies the error values as
well as other system parameters like topology, coupling and basis gates of a
user-specified real quantum processor, so that the simulation result mimics
what is obtained from that real experiment. It is also possible to customize
the noise for all the basis gates, and then use the
‘$\mathrm{qasm}\\_\mathrm{simulator}$’ to simulate the result. For example,
one can choose among depolarizing noise, Pauli noise etc., vary the noise
strength, and select gates to which the noise is to be applied. With this
approach, we study three cases, i.e. (i) the single qubit gates are
significantly noisy, (ii) the two-qubit gates are significantly noisy, and
(iii) all the gates are equally noisy. In all three cases, we consider a
depolarizing noise. A quantum state $\rho$ subject to depolarizing noise
evolves to a mixture of itself and the maximally mixed state, i.e.
$\rho\rightarrow(1-p)\rho+p\frac{I}{4}$. Here $p$ is the noise strength which
satisfies the bound $0\leq p\leq 1+\frac{1}{d^{2}-1}$, $d$ being the dimension
of $\rho$, and $I$ is the identity operator. We vary $p$ from 0.05 to 1.05,
and calculate the overlap between two identical $2\times 2$ image by
destructive swap test. Our results are shown in Fig. 8. For this study, we
keep the readout error at the constant value of 0.01, which is of the same
order of magnitude as the typical readout errors in real quantum processors.
As we can see from the figure, the noise in single qubit gates is more
detrimental than the noise in two-qubit gates for destructive swap test. When
all the gates are noisy, then the circuit performance worsen, as expected. The
fluctuation reduces for higher values of $p$, but in that regime the value of
$\mathcal{I}$ is also small. However, for the IBMQ systems we have used, the
single-qubit gate errors are always well below 0.01, and the two-qubits gate
errors are below 0.1, which implies that $\mathcal{I}>0.55$ for two-qubit
states in this noise range. Since we use only depolarizing noise to model the
errors, the actual results from real quantum processors are not exactly same
as shown in Fig. 8. However, the noise simulation gives an idea about the
overall behaviour of the protocol with changing noise at different gates.

We also study the success probability by varying the readout error $r$. The
readout error is the fraction indicating the number of times a $``0"$ or
$``1"$ in the output is measured erroneously as $``1"$ or $``0"$. The result
is presented in Fig. 9. The gate errors corresponding to all the gates has
been kept at $10^{-3}$ which is of the same order of magnitude as the lowest
gate errors in real processors. Typically the readout error in these
processors are of the order of $10^{-2}$.

Figure 9: The behaviour of the overlap $\mathcal{I}$ between two identical
two-qubit states with varying readout error strength, when simulated using
destructive swap test.

###  IV.2 Feature recognition in MRI images

To consider a more practical application e.g. in biomedicine, we repeat the
destructive swap test to detect a particular feature in an image of human
blood vessel obtained from MRI in our lab. The original images are colored
images. We choose a threshold value to binarize the image so as to reveal all
the details of the vessel against the background of Formaldehyde. In this
particular case, we want for instance, to identify a cavity present in the
tissue of the smaller vessel in the left of the image, see Fig. 10(a). To do
so, we compare different sections of that blood vessel with a sample image of
a cavity. The later is extracted from another MRI image of human blood vessel.
In Fig. 10(a), we have highlighted a few of the sections of the blood vessel
which are compared with the reference cavity in Fig. 10(b). We select $2\times
2$ blocks from each image, belonging to the same coordinates, and calculate
$\mathcal{I}_{avg}$. In Fig. 10(c), we present the comparison of
$\mathcal{I}_{avg}$ with the theoretical overlap and that obtained from
quantum simulator. In this case as well, $\mathcal{I}_{avg}$ has highest value
when the target and reference cavities match very closely, proving again the
utility of destructive swap test, as well as the average overlap measure
defined by us. This also opens up the possibility of pattern recognition in
medical images using destructive swap test.

Figure 10: Destructive swap test performed in real quantum processors to
detect a cavity in the MRI image of human blood vessel. (a) (In the left) The
full image after conversion from colored to binary. (In the right) A zoomed-in
segment of the smaller vessel containing the cavity to be identified. The five
rectangular areas with red outline is compared with the reference cavity. (b)
The reference cavity, obtained from another similar MRI image. (c) The
theoretical overlap $\mathcal{I}$, the overlap from quantum simulator, and the
average overlap $\mathcal{I}_{avg}$ obtained by comparing (b) with the six
segments in (a).

Figure 11: Comparison between the actual overlap $\mathcal{I}$ between two
quantum images, the overlap obtained from a quantum simulator, and the average
overlap $\mathcal{I}_{avg}$ obtained from real IBMQ processors. The plots are
for (q) MNIST numbers and (b) MNIST Fashion images. Two images along a
vertical column are compared.

##  V Pattern recognition in greyscale images

While binary images are the simplest image prototypes, in practice the images
acquired for quantum image processing tasks are mostly greyscale or with an
RGB color profile. Hence it is important to investigate whether the
destructive swap test can efficiently identify patterns in greyscale/RGB
images. Irrespective of the pixel values, we can encode these images in a
quantum state using QPIE method, and then apply the destructive swap test to
measure the overlap between them. First, we use MNIST images as the prototype
for greyscale images. MNIST images is a large set of images, frequently used
in machine learning and pattern recognition algorithms [67]. Each image is
$28\times 28$ pixels, containing a handwritten digit between 0 and 9. The
dimension of these images is not an integer power of 2, hence they cannot be
encoded using QPIE method. To tackle this, we add rows and columns all having
black pixels to the original images, to increase the dimension to $32\times
32$ pixels, which can be encoded using 10 qubits. As our target image, we pick
a particular image containing “0” as the pattern, and compare it with a set of
other images with different numbers. We simulate the circuit in IBMQ simulator
to obtain the overlap $\mathcal{I}$ between full quantum images. Then we
divide them into $2\times 2$ segments to calculate $\mathcal{I}_{avg}$ from
real quantum processors. The results have been presented in Fig. 11(a), which
shows that the behaviour of $\mathcal{I}_{avg}$ for different reference images
is consistent with the theoretical overlap or the simulated one. It suggests
that the destructive swap test can identify images with similar greyscale
patterns by picking the images with highest $\mathcal{I}$ or
$\mathcal{I}_{avg}$. For example, the overlap of the target image with the
reference image containing “6”, is close to the overlap with reference images
containing “0”. This is expected because the images are handwritten and in
some cases “6” can resemble the circular nature in “0”. Of course, if the
reference images are enough noisy, the destructive swap test results can
indicate a wrong digit for the target image.

We also simulate the same circuit for MNIST fashion images. The result is
presented in Fig. 11(b). In this case, $\mathcal{I}_{avg}$ is not as efficient
as for MNIST numbers. Though the reference images with comparatively higher
$\mathcal{I}_{avg}$ matches well with those having highest overlap, choosing
one particular closest pattern based on $\mathcal{I}_{avg}$ may not exactly
match with the actual closest pattern. This is also due to the higher
complexity of the images, as it is clear from the pictures that the pixels in
these images encode more shades of grey compared to MNIST numbers. However,
the $\mathcal{I}_{avg}$ in this case can still be used to distinguish between
widely different categories of the fashion images, e.g. shirts and dresses.

##  VI Experimental demonstration of destructive swap test in diamond NVs

Figure 12: Experiment scheme to demonstrate the destructive swap test in NVs.
(a) Structure of the NV center with a coupled 13C spin. (b) Quantum circuit
with the steps of the state preparation and destructive swap test, indicated
by the green dotted boxes. The operation $\theta_{\beta}$ denotes an operation
as $\theta_{\beta}=e^{\mp i\theta I_{y}}$, corresponding $\beta=\pi/2$ and
$\beta=3\pi/2$, respectively. The observable
$\mathcal{F}=|\langle\phi|\psi\rangle|^{2}$ is the population of the electron
state $|0\rangle$. (c) The microwave (MW) pulse sequence for implementing the
circuit in (b). The dashed lines indicate the correspondence between the
operations in the circuit (b) and pulse sequence (c), where the first MW pulse
is for $\theta_{\beta}$, and the other three MW pulses are for the two
Hadamard gates sandwiched by the CNOT gate, and the laser pulse detects
$\mathcal{F}$. The Rabi frequency of the MW pulses is 2 MHz. The pulse
durations are $t_{1}=0.206$, $t_{2}=0.122$, $t_{3}=0.182$ $\mu$s, the pulse
phases are $\phi_{1}=317^{\circ}$, $\phi_{2}=273^{\circ}$,
$\phi_{3}=90^{\circ}$, and delays $\tau_{0}=4.336$, $\tau_{1}=3.478$,
$\tau_{2}=2.368$, $\tau_{4}=4.988$ $\mu$s.  Figure 13: Experiment results for
$\mathcal{F}$ vs $\theta_{\beta}$ to demonstrate the swap test in NVs, where
the flip angles and the phases in operation $\theta_{\beta}$ are indicated as
the horizontal axis and in the panels. The vertical dashed lines indicate the
angles corresponding the maximums fidelity in fit.

The IBMQ processors are based on superconducting qubit technology. To test the
efficiency of destructive swap test in a different quantum system, we use two
qubits in diamond NVs [68, 69] to demonstrate the performance of destructive
swap test. The experiment scheme is shown in Fig. 12. The demonstration starts
with the pure state $|00\rangle$, which is prepared by the schemes proposed in
the previous works [70, 71, 72, 73]. In Fig. 12 (a), we show the structure of
the NV center with a coupled 13C spin. Here we choose the electron spin in
states with $m_{S}=0$ and $m_{S}=-1$ as qubit 1, and 13C spin as qubit 2,
where $m_{S}$ denotes quantum number for the electron spin. Fig. 12 (b) shows
the quantum circuit to demonstrate the destructive swap test.

We choose $|\phi\rangle=\frac{1}{\sqrt{2}}(|0\rangle+|1\rangle)$, generated by
applying a Hadamard gate $H$ to state $|0\rangle$. We use the destructive swap
test to measure the fidelity between state $|\phi\rangle$ and various states
$|\psi\rangle$, which is generated by applying an operation
$\theta_{\beta}=e^{\mp i\theta I_{y}}$ to state $|0\rangle$, where
$\beta=\pi/2$ or $\beta=3\pi/2$, respectively, and $I_{y}$ denotes $y$
component of the spin $1/2$ operator. The fidelity $\mathcal{F}$ is the
population of the electron spin in state $|0\rangle$. The theoretic
$\mathcal{F}$ is calculated as

$\mathcal{F}_{th}=\frac{1}{2}(1\pm\sin\theta)$ (3)

with maximums at $\theta_{opt}=\pi/2$ or $3\pi/2$, for $\beta=\pi/2$ or
$\beta=3\pi/2$, respectively. In Fig. 12 (c), we show the microwave (MW) pulse
sequence for implementing the circuit in (b). The first pulse is for the
operation $\theta_{\beta}$, and the other three MW pulses are for the two
Hadamard gates sandwiched by the CNOT gate. The laser pulse detects the
observable $\mathcal{F}$.

The experiment results are shown in Fig. 13, where figures (a-b) correspond to
$\beta=\pi/2$ and $3\pi/2$, respectively. The experiment data $\mathcal{F}$
can be fitted by the theory $\mathcal{F}_{th}$ as

$\mathcal{F}=a+b\mathcal{F}_{th}$ (4)

where parameters $a$ and $b$ are obtained in fit as $a=0.04$, $b=0.89$ in Fig.
13 (a), and $a=0.10$, $b=0.83$ in Fig. 13 (b). The deviation between
experiment and theory can be mainly attributed to the theoretical imperfection
of the pulse sequence with theory fidelity $0.9$ in the optimizing the pulse
parameters, dephasing effects of the electron spin since the total pulse
duration is up to 16.3 $\mu$s and is comparable to $T_{2}^{*}\approx 35$
$\mu$s and the statistics of the photon detection.

Figure 14: The quantum circuit of supervised learning algorithm based on
destructive swap test, to detect the closest pattern to a given pattern.

##  VII Supervised learning with destructive swap test

In classical computers, information is stored in a particular memory address
of the RAM. These computers recognize a given input by knowing its exact
location in the memory. The term associative memory is used to describe
instances when an object is recognized not by accessing its location in the
memory, but by associating the partial knowledge about it with the already
stored information in the memory. This is similar to the functioning of human
brain, e.g. while solving a crossword puzzle. A computational application of
associative memory is artificial neural networks [74]. Associative memory is
advantageous over RAM while solving complex problems, but on the other hand
requires huge capacity to store information for an efficient performance. In
[42], C. A. Trugenberger introduced the idea of quantum associative memory to
be used for quantum pattern recognition. Besides exploiting the quantum speed-
up, the protocols based on quantum associative memory can overcome the
limitation of short storage capacity in classical systems. Inspired by [42], a
number of previous works have proposed quantum pattern recognition protocols
which work in a similar way to classical supervised learning. In [25], the
authors proposed a machine learning protocol for assigning a particular class
to a vector, by optimizing the mean distance between the target and reference
vectors. In [44], the authors propose a similar protocol for pattern
recognition, by taking the $k$-nearest neighbour approach to optimize the
distance between target and reference states. In this section, we devise a
quantum machine learning protocol for pattern recognition, which uses
destructive swap test. The corresponding circuit for a three-qubit state is
shown in Fig. 14. The target state $|\psi\rangle$ has been encoded using three
quantum registers, which are represented by the black horizontal lines in the
figure. Let us assume that there are $d$ reference states $\phi_{i}$
$(i=1,2,...,d)$, each having the same dimension as $|\psi\rangle$, from which
we have to detect the closest pattern to $|\psi\rangle$. The three quantum
registers which can be used to encode these states are denoted by the blue
horizontal lines in the figure. We take a $d$ dimensional quantum system
(qudit), the basis vectors of which can be associated with the $d$ reference
states. In Fig. 14, the qudit is represented as the red horizontal line. Now
we prepare the following superposition,

$|\Phi\rangle=\frac{1}{N^{\prime}}\sum_{i}|\phi_{i}\rangle|q_{i}\rangle,$ (5)

where $q_{i}$ $(i=0,1,...,d-1)$ is the $i^{\mathrm{th}}$ basis vector in the
Hilbert space $\mathcal{H}^{d}$ of the qudit, and $N^{\prime}$ is the
normalization constant. The blue and the red quantum registers are initialized
in the joint state $|\Phi\rangle$. There is an auxiliary qubit which is
initialized in the state $|0\rangle$, represented by the green horizontal line
in Fig. 14. Thus the initial state of the total system is,

$|\Psi_{0}\rangle=\frac{1}{N^{\prime}}|\psi\rangle\otimes\sum_{i}|\phi_{i}\rangle|q_{i}\rangle\otimes|0\rangle.$
(6)

Now we apply the gates in accordance to the destructive swap test, i.e. CNOT
gates on each pair of qubits from target and reference states, followed by
Hadamard on the qubits of the target state. After this, the total state is,

$\displaystyle|\Psi_{1}\rangle=\frac{1}{N^{\prime}}\sum\limits_{i}(C^{i}_{1}|000000\rangle+C^{i}_{2}|000001\rangle+...$
$\displaystyle+C^{i}_{64}|111111\rangle)\otimes|q_{i}\rangle\otimes|0\rangle.$
(7)

Figure 15: The supervised learning protocol based on destructive swap test
performed to detect the closest pattern of a two-qubit target image from a set
of four reference images, also shown in Fig. 5. The horizontal axis shows the
classical bits corresponding to the measurement outcomes from the joint system
composed of the qudit (in this case four dimensional) and the auxiliary qubit.
The vertical axis denotes the corresponding probabilities. The success
probability corresponding to the basis $|110\rangle$ is the highest, which
corresponds to the case of equal target and reference images.

Here $C_{j}^{i}$ $(j=1,1,...,64)$ are the coefficients of the vector in the
joint Hilbert space $\mathcal{H}^{6}$ of target and reference states
associated with $|q_{i}\rangle$. We remind that the basis vectors in this
space for which the pairwise AND of the bits have odd parity, contributes to
the failure probability. To differentiate between these basis vectors and the
rest, we apply CCNOT gates such that each pair of the target and reference
state qubit acts as the control qubits, and the auxiliary qubit flips its
state when both of the former are in state $|1\rangle$. Thus, the additional
qubit keeps a count of the parity. If the basis vector has odd parity, the
auxiliary qubit has final state $|1\rangle$. In case of even parity, the qubit
state remains $|0\rangle$. The total state after applying the CCNOT gate can
be written as,

$\displaystyle|\Psi_{2}\rangle=\frac{1}{N^{\prime}}\sum\limits_{i}\big{[}\big{(}C^{i}_{1}|000000\rangle+C^{i}_{1}|000001\rangle+..\big{)}\otimes|q_{i}\rangle\otimes|0\rangle$
$\displaystyle+\big{(}C^{i}_{16}|001111\rangle+C^{i}_{19}|010010\rangle+...\big{)}\otimes|q_{i}\rangle\otimes|1\rangle\big{]}$
(8)

Thus, the qudit keeps the memory of the reference images, whereas the
auxiliary qubits keeps record of the basis vectors contributing to success and
failure probabilities. Now, repeated joint measurement on the qudit and the
auxiliary qubit can reveal the success and failure probabilities corresponding
to each reference image. The one having the largest success probability is
closest to the target image. In Fig. 15, we show the measurement outcomes as a
histogram when a two-qubit target image is identified by comparing it with
four reference images. For this task, we use the same images as in the first
four columns of Fig. 5. We denote the target image as $|S_{1}\rangle$, and the
set of reference patters as
$\\{|S_{1}\rangle,|S_{2}\rangle,|S_{3}\rangle,|S_{4}\rangle\\}$. To label the
reference states, we use the basis states
$\\{|00\rangle,|01\rangle,|10\rangle,|11\rangle\\}$ of a two-qubit system, and
prepare the following superposition,

$|\Phi\rangle=\frac{1}{N^{\prime}}\big{(}|S_{1}\rangle|11\rangle+|S_{2}\rangle|01\rangle+|S_{3}\rangle|10\rangle+|S_{4}\rangle|00\rangle\big{)}$
(9)

Since the target image is $|S_{1}\rangle$, we expect that at the end of the
protocol described above, the joint measurement on the two-qubit system and
the auxiliary qubit will give highest probability corresponding to the state
$|110\rangle$. Here the first two bits correspond to the two-qubit system,
whereas the last bit corresponds to the auxiliary qubit. The height of the bar
plots in Fig. 15 are consistent with the expectation. The circuit in this case
has been simulated using a 7 qubit IBMQ simulator.

##  VIII Conclusion

Image processing is indispensable in a plethora of everyday applications. Some
quantum image processing algorithms have been studied in theory, which show
polynomial and exponential speed-up over their classical analogues. There
exists a number of quantum image encoding methods, one of which (QPIE) encodes
the pixel positions and pixel values as the basis vectors and corresponding
amplitudes of a quantum state. This naturally implies that swap test, which
calculates the closeness between two quantum states, is a plausible tool to
identify similar patterns in quantum images. In this paper, we investigated
the efficiency of swap test for this task in real quantum processors. Our
results showed that for the typical values of the gate errors present in IBMQ
quantum machines, the output of swap test becomes completely noisy
corresponding to three or more qubits. For lower dimensional states, it can
still faithfully identify the pattern closest to a given pattern. To mitigate
the effect of noise, we propose to exploit the destructive swap test, which
showed considerable improvement for the three-qubit states. With access to
larger quantum processors, it will be interesting to see whether the
destructive swap test still remains successful against the noise for higher
dimensional states. Considering the fact that a simple circuit such as swap
test becomes completely noisy for three qubits, it is questionable how much
practically useful the larger IBMQ processors will be for moderately complex
algorithms. A scaling analysis with respect to dimension of the image states
can be performed to investigate this question. To apply destructive swap test
to larger images, we divided them into smaller segments which can be encoded
using the 5 or 7 qubit quantum devices. The segment-wise overlaps were
aggregated by defining an average overlap, which though not being equivalent
to the actual distance between full quantum image states, remained consistent
while distinguishing between two very similar or very different ones. The
above findings remain true for both binary and greyscale images. We tested the
destructive swap test for identifying a cavity in the binary image of human
blood-vessel obtained by MRI, which again showed consistency, thus implying
possible applications of this protocol in biomedical fields. As observed from
the results involving simple and complex binary patterns, and greyscale MNIST
images, the efficiency of average overlap may diminish with increasing range
of pixel values and the complexity of the pattern. However, if it is possible
to encode the full quantum states using the real IBMQ processors with suitably
controlled noise, the destructive swap test is without any doubt a potentially
useful tool for pattern recognition, as clear from our results in this work.
Besides IBMQ devices, we also used the nitrogen vacancy centre in diamond to
exhibit the destructive swap test for single qubit states, which shows good
agreement with theoretical results. A future aim will be to find a suitable
function of the segment-wise overlaps, which is equivalent to the distance
between the full images. Also an important objective will be to find whether
the machine learning tools can be used to counteract the noise in the outputs.
We believe that the destructive swap test based protocol can be used for
pattern recognition in all the relevant fields and for quantum machine
learning algorithms.

###### Acknowledgements.

The work was financially supported by the European Union’s Horizon 2020
research and innovation programme under FET-OPEN Grant Agreement No. 828946
(PATHOS). We acknowledge the use of IBM Quantum services. The views expressed
are those of the authors, and do not reflect the official policy or position
of IBM or the IBM Quantum team.

## References

  * Bennett  _et al._ [1993] C. H. Bennett, G. Brassard, C. Crépeau, R. Jozsa, A. Peres, and W. K. Wootters, Phys. Rev. Lett. 70, 1895 (1993).
  * Bennett and Wiesner [1992] C. H. Bennett and S. J. Wiesner, Phys. Rev. Lett. 69, 2881 (1992).
  * Shor [1997] P. W. Shor, SIAM Journal on Computing 26, 1484 (1997).
  * Grover [1997] L. K. Grover, Phys. Rev. Lett. 79, 325 (1997).
  * Lloyd [1996] S. Lloyd, Science 273, 1073 (1996).
  * Peng  _et al._ [2009] X. Peng, J. Zhang, J. Du, and D. Suter, Phys. Rev. Lett. 103, 140501 (2009).
  * Peng and Suter [2010] X.-h. Peng and D. Suter, Frontiers of Physics in China 5, 1 (2010).
  * Álvarez and Suter [2010] G. A. Álvarez and D. Suter, Phys. Rev. Lett. 104, 230403 (2010).
  * Peng  _et al._ [2014] X. Peng, Z. Luo, W. Zheng, S. Kou, D. Suter, and J. Du, Phys. Rev. Lett. 113, 080404 (2014).
  * Álvarez  _et al._ [2015] G. A. Álvarez, D. Suter, and R. Kaiser, Science 349, 846 (2015), https://www.science.org/doi/pdf/10.1126/science.1261160 .
  * Chen  _et al._ [2016] M.-C. Chen, D. Wu, Z.-E. Su, X.-D. Cai, X.-L. Wang, T. Yang, L. Li, N.-L. Liu, C.-Y. Lu, and J.-W. Pan, Phys. Rev. Lett. 116, 070502 (2016).
  * Li  _et al._ [2017] J. Li, R. Fan, H. Wang, B. Ye, B. Zeng, H. Zhai, X. Peng, and J. Du, Phys. Rev. X 7, 031011 (2017).
  * Aaronson and Arkhipov [2011] S. Aaronson and A. Arkhipov, in  _Proceedings of the Forty-Third Annual ACM Symposium on Theory of Computing_, STOC ’11 (Association for Computing Machinery, New York, NY, USA, 2011) p. 333–342.
  * Broome  _et al._ [2013] M. A. Broome, A. Fedrizzi, S. Rahimi-Keshari, J. Dove, S. Aaronson, T. C. Ralph, and A. G. White, Science 339, 794 (2013), https://www.science.org/doi/pdf/10.1126/science.1231440 .
  * Spring  _et al._ [2013] J. B. Spring, B. J. Metcalf, P. C. Humphreys, W. S. Kolthammer, X.-M. Jin, M. Barbieri, A. Datta, N. Thomas-Peter, N. K. Langford, D. Kundys, J. C. Gates, B. J. Smith, P. G. R. Smith, and I. A. Walmsley, Science 339, 798 (2013), https://www.science.org/doi/pdf/10.1126/science.1231692 .
  * Tillmann  _et al._ [2013] M. Tillmann, B. Dakić, R. Heilmann, S. Nolte, A. Szameit, and P. Walther, Nature Photonics 7, 540 (2013).
  * Crespi  _et al._ [2013] A. Crespi, R. Osellame, R. Ramponi, D. J. Brod, E. F. Galvão, N. Spagnolo, C. Vitelli, E. Maiorino, P. Mataloni, and F. Sciarrino, Nature Photonics 7, 545 (2013).
  * Wang  _et al._ [2017] H. Wang, Y. He, Y.-H. Li, Z.-E. Su, B. Li, H.-L. Huang, X. Ding, M.-C. Chen, C. Liu, J. Qin, J.-P. Li, Y.-M. He, C. Schneider, M. Kamp, C.-Z. Peng, S. Höfling, C.-Y. Lu, and J.-W. Pan, Nature Photonics 11, 361 (2017).
  * Harrow  _et al._ [2009] A. W. Harrow, A. Hassidim, and S. Lloyd, Phys. Rev. Lett. 103, 150502 (2009).
  * Cai  _et al._ [2013] X.-D. Cai, C. Weedbrook, Z.-E. Su, M.-C. Chen, M. Gu, M.-J. Zhu, L. Li, N.-L. Liu, C.-Y. Lu, and J.-W. Pan, Phys. Rev. Lett. 110, 230501 (2013).
  * Pan  _et al._ [2014] J. Pan, Y. Cao, X. Yao, Z. Li, C. Ju, H. Chen, X. Peng, S. Kais, and J. Du, Phys. Rev. A 89, 022313 (2014).
  * Barz  _et al._ [2017] S. Barz, I. Kassal, M. Ringbauer, Y. O. Lipp, B. Dakić, A. Aspuru-Guzik, and P. Walther, Scientific reports 7, 42653 (2017).
  * Zheng  _et al._ [2017] Y. Zheng, C. Song, M.-C. Chen, B. Xia, W. Liu, Q. Guo, L. Zhang, D. Xu, H. Deng, K. Huang, Y. Wu, Z. Yan, D. Zheng, L. Lu, J.-W. Pan, H. Wang, C.-Y. Lu, and X. Zhu, Phys. Rev. Lett. 118, 210504 (2017).
  * Manzano  _et al._ [2009] D. Manzano, M. Pawłowski, and Č. Brukner, New Journal of Physics 11, 113018 (2009).
  * Lloyd  _et al._ [2013] S. Lloyd, M. Mohseni, and P. Rebentrost, “Quantum algorithms for supervised and unsupervised machine learning,” (2013), arXiv:1307.0411 [quant-ph] .
  * Rebentrost  _et al._ [2014] P. Rebentrost, M. Mohseni, and S. Lloyd, Phys. Rev. Lett. 113, 130503 (2014).
  * Cai  _et al._ [2015] X.-D. Cai, D. Wu, Z.-E. Su, M.-C. Chen, X.-L. Wang, L. Li, N.-L. Liu, C.-Y. Lu, and J.-W. Pan, Phys. Rev. Lett. 114, 110504 (2015).
  * Li  _et al._ [2015] Z. Li, X. Liu, N. Xu, and J. Du, Phys. Rev. Lett. 114, 140504 (2015).
  * Ristè  _et al._ [2017] D. Ristè, M. P. da Silva, C. A. Ryan, A. W. Cross, A. D. Córcoles, J. A. Smolin, J. M. Gambetta, J. M. Chow, and B. R. Johnson, npj Quantum Information 3, 16 (2017).
  * Dunjko  _et al._ [2016] V. Dunjko, J. M. Taylor, and H. J. Briegel, Phys. Rev. Lett. 117, 130501 (2016).
  * Buffoni and Caruso [2020] L. Buffoni and F. Caruso, EPL 132, 60004 (2020).
  * Arute et al. [2019] F. Arute et al., Nature 574, 505 (2019).
  * et al. [2020] H.-S. Z. et al., Science 370, 1460 (2020).
  * Zhong et al. [2021] H.-S. Zhong et al., Phys. Rev. Lett. 127, 180502 (2021).
  * Wu et al. [2021] Y. Wu et al., Phys. Rev. Lett. 127, 180501 (2021).
  * [36] https://www.ibm.com/quantum-computing/.
  * Preskill [2018] J. Preskill, Quantum 2, 79 (2018).
  * Zhang  _et al._ [2015a] Y. Zhang, K. Lu, and Y. Gao, Science China Information Sciences 58, 1 (2015a).
  * Yao  _et al._ [2017] X.-W. Yao, H. Wang, Z. Liao, M.-C. Chen, J. Pan, J. Li, K. Zhang, X. Lin, Z. Wang, Z. Luo, W. Zheng, J. Li, M. Zhao, X. Peng, and D. Suter, Phys. Rev. X 7, 031041 (2017).
  * Cavalieri and Maio [2020] G. Cavalieri and D. Maio, “A quantum edge detection algorithm,” (2020), arXiv:2012.11036 [quant-ph] .
  * Xu  _et al._ [2020] P. Xu, Z. He, T. Qiu, and H. Ma, Opt. Express 28, 12508 (2020).
  * Trugenberger [2002] C. A. Trugenberger, Quantum Information Processing 1, 471 (2002).
  * Schützhold [2003] R. Schützhold, Phys. Rev. A 67, 062311 (2003).
  * Pham and Park [2014] D. Pham and S. Park,  _PRICAI 2014: Trends in Artificial Intelligence: 13th Pacific Rim International Conference on Artificial Intelligence, PRICAI 2014, Gold Coast, QLD, Australia, December 1-5, 2014, Proceedings_, Lecture Notes in Computer Science (Springer International Publishing, 2014).
  * Prousalis and Konofaos [2019] K. Prousalis and N. Konofaos, Scientific Reports 9, 7226 (2019).
  * Banchi  _et al._ [2020] L. Banchi, Q. Zhuang, and S. Pirandola, Phys. Rev. Applied 14, 064026 (2020).
  * Neigovzen  _et al._ [2009] R. Neigovzen, J. L. Neves, R. Sollacher, and S. J. Glaser, Phys. Rev. A 79, 042321 (2009).
  * Montanaro [2015] A. Montanaro, “Quantum pattern matching fast on average,” (2015), arXiv:1408.1816 [quant-ph] .
  * Zhang  _et al._ [2015b] Y. Zhang, K. Lu, K. Xu, Y. Gao, and R. C. Wilson, Quantum Information Processing 14, 1573 (2015b).
  * Jiang  _et al._ [2016] N. Jiang, Y. Dang, and J. Wang, Quantum Information Processing 15, 3543 (2016).
  * Soni and Rasool [2020] K. K. Soni and A. Rasool, Procedia Computer Science 167, 1991 (2020), international Conference on Computational Intelligence and Data Science.
  * Tezuka  _et al._ [2022] H. Tezuka, K. Nakaji, T. Satoh, and N. Yamamoto, Phys. Rev. A 105, 032440 (2022).
  * Kapoor  _et al._ [2016] A. Kapoor, N. Wiebe, and K. Svore, in  _Advances in Neural Information Processing Systems_, Vol. 29, edited by D. Lee, M. Sugiyama, U. Luxburg, I. Guyon, and R. Garnett (Curran Associates, Inc., 2016).
  * Benedetti  _et al._ [2017] M. Benedetti, J. Realpe-Gómez, R. Biswas, and A. Perdomo-Ortiz, Phys. Rev. X 7, 041052 (2017).
  * Denchev  _et al._ [2012] V. S. Denchev, N. Ding, S. V. N. Vishwanathan, and H. Neven, in  _ICML_ (2012).
  * Schuld  _et al._ [2016] M. Schuld, I. Sinayskiy, and F. Petruccione, Phys. Rev. A 94, 022342 (2016).
  * Schuld  _et al._ [2015] M. Schuld, I. Sinayskiy, and F. Petruccione, Contemporary Physics 56, 172 (2015).
  * Garcia-Escartin and Chamorro-Posada [2013] J. C. Garcia-Escartin and P. Chamorro-Posada, Phys. Rev. A 87, 052330 (2013).
  * Le  _et al._ [2011] P. Q. Le, F. Dong, and K. Hirota, Quantum Information Processing 10, 63 (2011).
  * Zhang  _et al._ [2013] Y. Zhang, K. Lu, Y. Gao, and M. Wang, Quantum Information Processing 12, 2833 (2013).
  * Buhrman  _et al._ [2001] H. Buhrman, R. Cleve, J. Watrous, and R. de Wolf, Phys. Rev. Lett. 87, 167902 (2001).
  * Gottesman and Chuang [2001] D. Gottesman and I. Chuang, “Quantum digital signatures,” (2001), arXiv:quant-ph/0105032 .
  * Kang  _et al._ [2019] M.-S. Kang, J. Heo, S.-G. Choi, S. Moon, and S.-W. Han, Scientific Reports 9, 6167 (2019).
  * Jozsa [1994] R. Jozsa, Journal of Modern Optics 41, 2315 (1994).
  * Schumacher [1995] B. Schumacher, Phys. Rev. A 51, 2738 (1995).
  * Cincio  _et al._ [2018] L. Cincio, Y. Subaşı, A. T. Sornborger, and P. J. Coles,  20, 113022 (2018).
  * Deng [2012] L. Deng, IEEE Signal Processing Magazine 29, 141 (2012).
  * Wrachtrup and Jelezko [2006] J. Wrachtrup and F. Jelezko, J. Phys.: Condens. Matter 18, S807 (2006).
  * Suter and Jelezko [2017] D. Suter and F. Jelezko, Progress in Nuclear Magnetic Resonance Spectroscopy 98-99, 50 (2017).
  * Zhang  _et al._ [2019] J. Zhang, S. S. Hegde, and D. Suter, Phys. Rev. Applied 12, 064047 (2019).
  * Zhang  _et al._ [2020] J. Zhang, S. S. Hegde, and D. Suter, Phys. Rev. Lett. 125, 030501 (2020).
  * Hegde  _et al._ [2020] S. S. Hegde, J. Zhang, and D. Suter, Phys. Rev. Lett. 124, 220501 (2020).
  * Zhang  _et al._ [2021] J. Zhang, S. S. Hegde, and D. Suter, arXiv:2108.13738 [quant-ph] (2021).
  * Müller  _et al._ [2012] B. Müller, J. Reinhardt, and M. Strickland,  _Neural Networks: An Introduction_, Physics of Neural Networks (Springer Berlin Heidelberg, 2012).