Neural Networks for Programming Quantum Annealers
Quantum machine learning has the potential to enable advances in artificial
intelligence, such as solving problems intractable on classical computers. Some
fundamental ideas behind quantum machine learning are similar to kernel methods
in classical machine learning. Both process information by mapping it into
high-dimensional vector spaces without explicitly calculating their numerical
values. We explore a setup for performing classification on labeled classical
datasets, consisting of a classical neural network connected to a quantum
annealer. The neural network programs the quantum annealer's controls and
thereby maps the annealer's initial states into new states in the Hilbert
space. The neural network's parameters are optimized to maximize the distance
of states corresponding to inputs from different classes and minimize the
distance between quantum states corresponding to the same class. Recent
literature showed that at least some of the "learning" is due to the quantum
annealer, connecting a small linear network to a quantum annealer and using it
to learn small and linearly inseparable datasets. In this study, we consider a
similar but not quite the same case, where a classical fully-fledged neural
network is connected with a small quantum annealer. In such a setting, the
fully-fledged classical neural-network already has built-in nonlinearity and
learning power, and can already handle the classification problem alone, we
want to see whether an additional quantum layer could boost its performance. We
simulate this system to learn several common datasets, including those for
image and sound recognition. We conclude that adding a small quantum annealer
does not provide a significant benefit over just using a regular (nonlinear)
classical neural network.
Samuel Bosch, Bobak Kiani, Rui Yang, Adrian Lupascu, Seth Lloyd
# Neural Networks for Programming Quantum Annealers

###### Abstract

Quantum machine learning is an emerging field of research at the intersection of quantum computing and machine learning. It has the potential to enable advances in artificial intelligence, such as solving problems intractable on classical computers. Some of the fundamental ideas behind quantum machine learning are very similar to kernel methods in classical machine learning. Both process information by mapping it into high-dimensional vector spaces without explicitly calculating their numerical values. Quantum annealers are mostly studied in the adiabatic regime, a computational model in which the quantum system remains in an instantaneous ground energy eigenstate of a time-dependent Hamiltonian. Our research focuses on the diabatic regime where the quantum state does not necessarily remain in the ground state during computation. Concretely, we explore a setup for performing classification on labeled classical datasets, consisting of a classical neural network connected to a quantum annealer. The neural network programs the quantum annealer's controls and thereby maps the annealer's initial states into new states in the Hilbert space. The neural network's parameters are optimized to maximize the distance of states corresponding to inputs from different classes and minimize the distance between quantum states corresponding to the same class. Recent literature showed that at least some of the "learning" is due to the quantum annealer, connecting a small linear network to a quantum annealer and using it to learn small and linearly inseparable datasets. In this study, we consider a similar but not quite the same case, where a classical fully-fledged neural network is connected with a small quantum annealer. In such a setting, the fully-fledged classical neural-network already has built-in nonlinearity and learning power, and can already handle the classification problem alone, we want to see whether an additional quantum layer could boost its performance. We simulate this system to learn several common datasets, including those for image and sound recognition. We conclude that adding a small quantum annealer does not provide a significant benefit over just using a regular (nonlinear) classical neural network.

## I Introduction:

Machine learning (ML) is among the most exciting prospective applications of quantum technologies. As kernel-based methods have become a pillar of modern ML applications, it is natural to explore their applications within ML applications using quantum computing. The fundamental idea of quantum computing is surprisingly similar to the principle behind kernel methods in ML. That is, to efficiently perform computation in an intractably large vector space. In the case of quantum computers, this vector space is a Hilbert space. Quantum algorithms aim to perform efficient computations in a Hilbert space that grows exponentially with the size of a quantum system. Efficient, in this context, means that the number of operations applied to the system grows at most polynomially with the size of the system.

There are different approaches to building physical quantum computers. The most well-known approaches are universal gate model quantum computers and quantum annealers. Universal gate model quantum computing (or general purpose quantum computing) is universal and flexible. However, building and maintaining the stability of physical qubits is hard. Quantum annealers are a less flexible paradigm of quantum computing but are easier to implement and realize than universal gate model quantum computers.

Quantum annealing started as a purely theoretical combinatorial optimization method [1]. It is mostly used for solving optimization problems formulated in terms of finding ground states of classical Ising spin Hamiltonians [2; 3]. More recently, though, it is also understood as a heuristic optimization method implemented in physical quantum annealing hardware [4]. A physical implementation of quantum annealing on quantum hardware might lead to speedups over algorithms running on classical hardware in some specific cases. The construction of commercial (non-universal) quantum annealing processors, such as by the Canadian quantum computing company D-Wave Systems [5; 6; 7; 8; 9; 10], was inspired by earlier theoretical proposals [11; 12].

This work investigates a hybrid quantum-classical approach to performing classification tasks. The setup is illustrated and described in figures (1) and (2).In this study, we consider a classical fully-fledged neural network is connected with a small quantum annealer. In such a setting, the fully-fledged classical neural-network already has built-in nonlinearity and can already handle the classification problem alone, we want to see whether an additional quantum layer could boost its performance. Supervised training is performed on classical labeled datasets, such as MNIST and CIFAR, shown in figure (3a) and (4). The raw data is fed into a (classical) neural network. But instead of performing the entire learning procedure with
it (i.e., directly reading the outputs of the neural network for classification), we feed the neural network's output as the input to a quantum annealer. The quantum annealer interprets the neural network's output as the annealing schedule, as described in section (III). Once the quantum annealer in figures (1) and (2) outputs a final quantum state \(|\psi_{final}\rangle\), this is then used to calculate the loss function, which is then used to optimize the NN parameters via gradient descent. The complete training procedure is shown in figure (1).

## II Related Work

### Quantum Machine Learning

As quantum technologies continue to advance rapidly, it becomes increasingly important to understand which applications can benefit from the power of these devices. Over the past decades, ML on classical computers has made significant progress. Advanced ML and artificial intelligence (AI) tools have become openly available and easily accessible through libraries such as TensorFlow [13], Scikit-learn [14], and PyTorch [15] - to name a few. Together with increasing computing power, this resulted in revolutionizing applications such as text and image recognition, translation, and recently even the development of models for generating digital images from natural language descriptions - such as _DALL-E 2_[16]. Nevertheless, progress in applications such as self-driving cars [17] has been slower than many would have hoped, reminding us of the limitations of ML and AI. Therefore, if quantum computers could accelerate ML, the potential for impact would be significant.

Two major paths to the quantum enhancement of ML have been considered [18]. First, driven by quantum applications in optimization [19; 20; 21; 22; 23], the power of quantum computing could be used to help improve the learning process of existing classical models [24], or improve inference in graphical models [25]. This could result in better methods for finding optima in a training landscape or with fewer queries. However, in most general unstructured problems, the advantage of these algorithms compared to their classical counterparts may be limited to quadratic or small polynomial speedups [26; 27].

The second area of interest is the possibility of using quantum models to express functions that are inefficient to represent by classical computation [18]. Recent theoretical and experimental successes demonstrating quantum computations beyond classical tractability can be considered evidence that quantum computers can sample from probability distributions that are exponentially difficult to sample from classically [28; 29]. It is important to emphasize that these distributions have no known real-world applications. This is the type of advantage sought

Figure 1: _Training procedure._ Training the model works as follows. First, the neural network receives (classical) input data and feeds it to the quantum annealer, which outputs a state \(|\psi_{final}\rangle\) for each input. For details, see figure (2) and section III. In the above example, the inputs are 28 by 28 grayscale MNIST images, corresponding to hand-written digits from 0 to 9. Second, all the \(|\psi_{final}\rangle\) corresponding to the same class are grouped, and a density matrix is calculated for each class, as shown in the top right corner. Third, the Hilbert-Schmidt distance is calculated between all pairs of density matrices. Intuitively, this can be understood as the average distance between all the clusters of states on a Bloch sphere, as shown in a 1-qubit example in figure (3b). Forth, the loss function of the neural network is defined as the negative Hilbert-Schmidt distance and then used to perform gradient descent on the neural network’s parameters. These four steps are repeated until the loss function converges. Intuitively, the neural network is optimized in such a way that the output states \(|\psi_{final}\rangle\) cluster into groups located as far away from each other as possible, illustrated on the right side of figure (3b). Once the neural network is trained well, we can use it to perform classification on new input data because the input will be mapped into a quantum state close to its corresponding cluster.
in recent work on quantum neural networks (QNNs) [30; 31; 32], which seek to parameterize a distribution through a set of adjustable parameters. Nevertheless, it is well known that these QNNs come with a host of trainability issues that must be addressed before they are implemented in large-scale systems [33; 34; 35].

### Kernel methods

Some quantum algorithms, such as the quantum principal component analysis [36], and quantum support vector machines [21], have been inspired by classical machine learning algorithms. This field is generally known as _quantum machine learning (QML)_[37; 38]. Similar approaches have been used to create quantum algorithms inspired by classical neural networks.

It has been shown that the mathematical frameworks of many quantum machine learning (QML) models are similar to _kernel methods_[39]. Quantum computers and kernel methods process information by mapping it into high (or infinite) dimensional vector spaces without explicitly calculating each element of this vector space explicitly. In this work, we will focus on QML in the context of learning classical data, even though QML can be applied to quantum data as well [40; 41]. To perform computation, data must be encoded into the quantum system's physical states, equivalent to a _feature map_[42; 43]. This map assigns quantum states to classical data, and the inner product of the encoded quantum states gives rise to a kernel [44; 45; 21; 43]. In classical kernel methods, we access the feature space through kernels or inner products of feature vectors. In quantum kernel methods, we also indirectly access the high-dimensional feature space through inner products of quantum states, which are facilitated by measurements. While the Hilbert space of quantum states may be vast, deterministic quantum models can still be trained and operated in a lower-dimensional subspace. Thus, we obtain the benefits of kernel methods without requiring direct access to the entire Hilbert space. The equivalence of QML and kernel methods resulted in research on kernelized ML models [46], quantum generative models [47], as well as understanding the difference between the complexities of quantum and classical ML algorithms [48; 43; 18] - to mention a few examples.

The connection between kernel and quantum learning methods arises from the classical data encoding process (quantum embedding), which determines the kernel. Although the quantum kernel has the potential to access an extremely high-dimensional Hilbert space, quantum learning model training actually occurs in a lower-dimensional subspace. This contrasts with variational models, where optimizing a significant number of classical parameters and finding a suitable circuit ansatz are necessary. The ansatz's parameters also require optimization. It's important to note that quantum learning models, including quantum neural networks (QNNs), do not always require exponentially many parameters to achieve effective results.

It is important to consider the limitations of kernel methods, as highlighted by Kubler et al.[49]. The authors suggest that quantum machine learning models can only offer speed-ups if we manage to encode knowledge about the problem at hand into quantum circuits, while encoding the same bias into a classical model would be hard. They argue that this situation may plausibly occur when learning on data generated by a quantum process, but it seems more challenging for classical datasets [49]. Furthermore, the authors show that finding suitable quantum kernels is not easy because the kernel evaluation might require exponentially many measurements, which could limit the practicality of quantum kernel methods in some cases [49]. Despite the potential benefits of quantum kernel methods, these limitations should be taken into account when considering their use in quantum machine learning.

### Quantum Annealing

An in-depth explanation can be found in Albash _et al._, 2018 [1], but for our purposes, it suffices to define adiabatic quantum annealing as a computational model in which the system remains in an instantaneous ground state of a time-dependent Hamiltonian \(H(t)\)[3]. For example, define

\[H(t)=A(t)H_{X}+B(t)H_{Z} \tag{1}\]

where \(H_{X}=-\sum_{i}\sigma_{X}^{(i)}\) denotes the Pauli \(\sigma_{x}\) matrices acting on the \(i\)-th qubit and \(H_{Z}\) is a Hamiltonian that is diagonal in the computational basis of eigenstates of tensor products of \(\sigma_{Z}^{(i)}.A(t)\) and \(B(t)\) are the time-dependent transverse and longitudinal coupling strengths. \(H_{Z}\) is the problem Hamiltonian, and its ground states encode the solution to a computational problem. In the case of standard quantum annealing, we start with \(A(t=0)=A_{0}\) and then monotonically decrease this to \(A(t=T)=0\) during a time interval \([0,T]\). During the same time period, \(B(t)\), which is the control of our problem Hamiltonian, \(H_{Z}\), is monotonically increased from \(B(t=0)=0\) to \(B(t=T)=B_{0}\). The core assumption here is that this transition happens slowly enough so that the system (which started in the ground state of \(H_{X}\)) remains in the ground state of \(H(t)\) until it eventually ends up in the ground state of \(H_{Z}\) at time \(t=T\). This gives us access to the solution to our computational problem. In a closed system, the time evolution of the entire system can be described by

\[\left|\psi_{final}\right\rangle=\Big{(}\int_{0}^{T}e^{-\frac{i\pi}{H}H(t)}dt \Big{)}\left|\psi_{initial}\right\rangle \tag{2}\]

In this work, we are not just focused on the adiabatic limit of quantum annealing (where the system always remains in the ground state of \(H(t)\)) but also in the
diabatic setting. Here, diabatic transitions from and to low-energy excited states are permitted. The term _diabatic quantum annealing_ first appeared in _Muthukrishnan et al., 2016_[50], although the same concept appeared in earlier literature as _nonadiabatic quantum annealing_[51], and later also as _pulsed quantum annealing_[52].

With this in mind, we can now define _diabatic quantum computing_. To do so, we relax the condition that the system must always remain in a single instantaneous eigenstate of \(H(t)\). Instead, diabatic quantum computing and annealing are computational models (universal and for optimization, respectively) in which the system remains in a subspace spanned by the eigenstates of \(H(t)\) at all times.

The instantaneous computational eigenstate in quantum annealing and adiabatic quantum computing is usually taken to be the ground state of \(H(t)\). Therefore, the energy band in diabatic quantum computing is usually taken to be the low-energy subspace of \(H(t)\), even though, by definition, it could be any part of the energy spectrum.

It is important to point out that in diabatic quantum computing, the final state reached in equation (2) doesn't have to be the ground state of \(H(t)\). Diabatic quantum annealing dynamics are generally non-local because the unitary term in equation (2) cannot be written as a tensor product of locally acting unitaries. This is due to the non-commutativity of the terms in equation (1). The standard method for digitalizing this non-local unitary on a gate-based device required a very large number of gates [53], meaning that diabatic quantum annealing hardware can be used to run algorithms distinct from those being implemented on gate-based devices.

## III Setup and Simulations

To illustrate the idea behind the training procedure, we present a simplified example, illustrated in figure (3). We use a subset of the MNIST database of handwritten digits, containing only 0s and 1s - shown in figure (3a). And we use our training setup from figure (1) with a small NN to train our model in figure (2). For simplicity, we use \(n=1\) qubits, so we can visualize all states on Bloch spheres. The NN is randomly initialized, so after passing the input data through the small NN and then inputting the NN's output into the schedule parameters of the quantum annealer to evolve its initial state into a final state, we will end up with a cluster of randomly mixed \(\psi_{output}\) states. This pre-training stage is illustrated on the left Bloch sphere in figure (3b). The loss function,

Figure 2: Hybrid classical neural network/quantum annealer setup. The setup works as follows: the neural network receives classical data as input and forward-passes the information through its layers. In the above case, it’s a 28 by 28 grayscale MNIST image, and the neural network has only one hidden layer with 120 neurons. The outputs of the neural network, \(f_{ik}\), are the annealing schedule for the quantum annealer. The quantum annealer starts with state \(\ket{0,...,0}\) and outputs state \(\ket{\psi_{final}}\), which is defined above. The value of \(i\) corresponds to the different Hamiltonians which the quantum annealer can apply (see the beginning of section III), and the value of \(k\) corresponds to the discretized time instance of the annealing schedule. The output state \(\ket{\psi_{final}}\) can then be used for training the model, as shown in figure (1), as well as performing classification tasks.
which is the negative average Hilbert-Schmidt distance, defined in equation (6), is close to zero. Next, we start training the NN by minimizing the loss function (or maximizing the Hilbert Schmidt distance between states corresponding to different classes), until we eventually end up with a trained NN. Now, if we pass the same (or new) images of 0s and 1s through the trained NN and then pass the NN's output to the quantum annealer to get evolved final states, we end up with states as shown on the right of figure (3b). Here, we can clearly see that the input data was mapped into two distinct clusters, corresponding to 0s and 1s, respectively.

The hardware we simulated is able to apply the following operators on the state inside the quantum computers:

* \(\sigma_{x}\) operation on individual qubits: \(\begin{pmatrix}0&1\\ 1&0\end{pmatrix}\)
* \(\sigma_{z}\) operation on individual qubits: \(\begin{pmatrix}1&0\\ 0&-1\end{pmatrix}\)
* \(\sigma_{z}\otimes\sigma_{z}\) on each pair of qubits

The hardware has the ability to apply any linear combination of these operators at a given time and can vary their individual intensities over time. In total, for an \(n\)-qubit quantum system, there are \(m=n+n+\frac{n(n-1)}{2}=\frac{n}{2}(n+3)\) Hamiltonians, and therefore also \(m\) parameters which control the system at any instance of time.

Our goal is to create a hybrid NN, which consists of a classical NN and a quantum diabatic annealer. The Hamiltonian at any time instance can be described as a linear combination of the form:

\[H(t)=\sum_{i=1}^{m}f_{i}(t)H_{i} \tag{3}\]

where \(H_{i}\) for \(i\in\{1,...,n\}\) refers to single \(\sigma_{x}\) gates acting on the \(i^{th}\) qubit. \(H_{i}\) for to single \(\sigma_{z}\) gates acting on the \((i-n)^{th}\) qubit. \(H_{i}\) for \(i\in\{2n+1,...,m\}\) refers to double \(\sigma_{z}\otimes\sigma_{z}\) gates acting on all pairs of \((i,j)\in\{1,...,n\}\). The functions \(f_{i}(t)\) (or \(f_{i\mathbf{k}}\) in the discretized version from figure 2) define "how much" of the Hamiltonian \(H_{i}\) is applied at the time instance \(t\). Here \(t\in[0,T]\), meaning that the Hamiltonians are applied within a fixed time period \(T\).

The goal of this simulation is to find the right weights and biases of the classical NN which, after classical input data is forward passed through it, outputs the optimal \(f_{i}(t)\) functions which map the initial quantum state \(|\psi_{init}\rangle=|0...0\rangle\) to _maximally_ distant final quantum states \(|\psi_{final}\rangle\) for input data corresponding to distinct classes. At the same time, for input data corresponding to the same class, it should map the initial quantum state \(|\psi_{init}\rangle\) to _minimally_ distant final quantum states \(|\psi_{final}^{(k)}\rangle\). Here \(k\) is simply the label of a class for classification purposes. In other words, \(|\psi_{final}^{(k)}\rangle\) states form clusters, as shown in a \(n=1\) qubit example with two classes in figure (3).

Let us explain the details of the whole setup, shown in figure 2, starting with the classical NN on the left. As aforementioned, the input to the NN can be any type of labeled classical dataset (not restricted to images). We used different types of NNs, depending on how complex a given dataset is. For MNIST, shown in figure (4), a simple NN with one hidden layer with 120 neurons was sufficient. More complex datasets, such as CIFAR [54], also shown in figure (4), required convolutional neural networks (CNNs) with several hidden layers. It is common practice in the ML community to normalize all the input data \(D\), so that \(max(D)=1\), \(min(D)=-1\), and \(mean(D)=0\). The weights and biases of the NN are initialized randomly.

For example, in the case of MNIST (as shown in figure 2.), using tanh activation functions for connecting the input layer with the hidden layer, followed by \(Sigmoid\) activation functions connecting the hidden layer with the output layer worked well. Once the input data has been passed through the randomly initialized NN,

Figure 3: A simplified example of training our hybrid neural network/quantum annealer from figure (2) through the training procedure shown in figure (1).
we receive the annealing schedule, which is the input to the quantum annealer shown in figure (2). As the output of the NN is supposed to describe the annealing schedules \(f_{i}(t)\), we have to restrict \(f_{i}(t)\) to a set of discrete values, as opposed to continuously changing functions. Therefore, we have to choose a value for the total number of discrete "steps" that each of the functions \(f_{i}(t)\) can take. Hence, the actual output of the NN isn't continuous functions \(f_{i}(t)\), but rather discrete values \(f_{ik}\), as shown in figure (2). The total size of the NN's output layer is the number of discretized steps multiplied by the number of control Hamiltonians:

\[\text{NN output size = }steps\ \times\ m\text{=}steps\ \times\ \tfrac{n}{2}(n+3)\]

Next, let us talk about the quantum annealer, shown in the right half of figure 2. The quantum annealer is initialized with the standard \(\ket{\psi_{input}}=\ket{0,...,0}\) quantum state (which is the ground state of a pure longitudinal Hamiltonian without interactions), and then evolves this state using the Hamiltonian \(H(t)\) described in equation (3). Given that the Hamiltonian \(H(t)\) in our discretized model changes only every \(\Delta t=\frac{T}{steps}\), the change of the quantum state inside the quantum annealer between each discretized time instance can be described by:

\[\ket{\psi(t_{k+1})}=e^{\frac{-i\Delta t}{\hbar}H(t_{k})}\ket{\psi(t_{k})} \tag{4}\]

where \(t_{k}=k\Delta t\) and \(H(t)=\sum_{i=1}^{m}f_{i}(t)H_{i}\).

The final quantum state is:

\[\ket{\psi_{final}}=\prod_{t(i=0)=0}^{t(i=N)=T}e^{-\frac{i\Delta t}{\hbar}\sum _{i=1}^{m}f_{ik}H_{i}}\ket{0,...,0} \tag{5}\]

where \(f_{ik}=f_{i}(t_{k})\). Therefore, given all parameters of the classical NN, any input to the entire setup in figure (2) is mapped to a particular quantum state.

### Training procedure

In the previous section, we described how a classical input state (for example, a handwritten digit) can be mapped into a quantum state through the setup shown in figure (2). In this section, we will explain how this setup can be used for classification tasks. A key element of every ML application is a training procedure, which uses a training dataset. The whole training procedure is illustrated in figure (1).

The first part of the training procedure is just repeating the steps described in section III. We take the whole dataset of, in this illustration, MNIST 28 by 28 images, pass them through the NN, and then use the outputs of the NN as annealing schedules to create a set of output states \(\ket{\psi_{final}}\). As a next step, we create a set of mixed-density matrices for every class in the dataset. For a standard MNIST dataset, there are \(K=10\) classes. One for each digit. The density matrix corresponding to class \(j\) is defined as \(\rho_{j}=\sum_{i\in\{\text{input}_{i}=j\}}\ket{\psi_{final}}\bra{\psi_{final}}\). The goal of the training procedure is to make these density matrices as distinct as possible. We used the Hilbert-Schmidt distance as a metric to compare two density matrices. The Hilbert-Schmidt distance is defined as:

\[D_{HS}(\rho,\sigma)=Tr\big{[}(\rho-\sigma)^{2}\big{]}=||\rho-\sigma||_{2}^{2} \tag{6}\]

We could have also used the standard trace distance, defined as \(D(\rho,\sigma)=\frac{1}{2}Tr\big{[}\rho-\sigma\big{]}=\frac{1}{2}||\rho- \sigma||_{1}\). We decided not to use it, as the trace distance is more difficult to compute than the Hilbert-Schmidt distance, as it involves the diagonalization of \(\rho-\sigma\)[55].

Even though a mixed-density matrix cannot be shown on a Bloch sphere, such as in figure (3b), we can still imagine the training procedure to be somewhat similar. Our goal is to maximize the distance between states corresponding to different classes while keeping the distance between states corresponding to the same class as small as possible. Therefore, we define the loss function of the NN as minus the average Hilbert-Schmidt distance between all pairs of density matrices \(\rho_{j}\). Having a loss function allows us to use gradient descent (or another minimization algorithm) on all the parameters of the NN. This gradient-update procedure now needs to be repeated until the loss function converges to a minimum (=maximum average distance).

### Computational methods and errors

In setting up the hybrid NN-QA model in this study, the choice was made to work with the largest number of qubits possible, as determined by practical memory and computation time limits on a conventional computer. The main bottleneck for the runtime was calculating the matrix exponentiations. The main bottleneck for memory consumption was performing the backpropagation (gradient calculation) step during the NN training procedure. Also, before even looking into the results of our simulations, it is essential to determine the magnitudes of the error rates of our approximation methods and whether or not they accurately simulate the quantum annealer. All numerical methods used are already well-established, including the matrix exponentiation approximation method needed for simulating equation (4). This method is based on the SSA approximation [56; 57], and it is one of the fastest and most accurate methods for general, non-sparse matrix exponentiation. Nevertheless, the computational resources needed for this matrix exponentiation approximation scales roughly as \(\mathcal{O}(2^{n})^{3}\). Therefore, given the large number of matrix exponentiations used in our simulations, we had to implement the Suzuki-Trotter approximation, explained in more detail in appendix B. The Suzuki-Trotter approximation
method can be made arbitrarily accurate by adjusting its parameters, resulting in a trade-off between accuracy and the computational resources needed. A more detailed investigation of this method can be found in appendix B.

## IV Results

In this section we discuss the datasets used, the classification accuracies achieved with them, as well as the overall improvement through the quantum annealer.

### Datasets and learning models

In this section, we analyze the classification accuracies of four different setups on four different datasets. The datasets listed in table 1 are MNIST, CIFAR, ISOLET, and UCIHAR:

* **MNIST** consists of 28 by 28 grayscale images of handwritten digits from 0 to 9, shown in figure (4). As of writing, the highest classification accuracy is 99.91% achieved by using a majority vote between several convolutional neural networks [58].
* **CIFAR** consists of 32 by 32 color images of 10 different objects, shown in figure (4). As of writing, the highest classification accuracy achieved is 99.5% by using transformer models, shaking up the long "supremacy" of CNNs [59].
* **ISOLET** consists of human voice recordings pronouncing the letters of the English alphabet, hence 26 different classes
* Lastly, **UCIHAR** consists of acceleration and velocity data from a smartphone's gyroscope, as well as other motion, time, and frequency variables. The 12 labeled classes include activities such as walking upstairs, sitting, standing, etc.

Even though the use of CNNs and transformer models can accomplish remarkable accuracies, we decided not to use such complex models. If state-of-the-art models were used, most of the learning would happen in the classical part of the model, leaving little room for improvement by the quantum annealer. Second, simulating a complex state-of-the-art model connected to a quantum annealer would be computationally infeasible, especially given the exponential growth of the quantum annealer simulation with the number of qubits.

Not all datasets were equally easy to learn, and each required tuning of the network architecture. Here, we either used a simple neural network with one hidden layer or a more complex convolutional neural network. We ran both of these networks in isolation and contrasted this with the setting where they were connected to quantum annealers. The four different setups used to learn the aforementioned datasets are:

* **NN**: This is a very simple classical neural network consisting of an input layer with one neuron for each input feature, one hidden layer with 120 neurons, and one output layer with one neuron for each class. The output is, therefore, \(K\) real numbers between 0 and 1, indicating how similar the input is to each class. Training is done by classical loss function minimization.
* **NN + Annealer**: This is a very simple classical neural network consisting of an input layer with one neuron for each input feature, one hidden layer with 120 neurons, and one output layer with one neuron for each control parameter of the quantum annealer. The outputs are the parameters \(f_{ik}\) controlling the quantum annealer, as shown in figure (2). The resulting quantum states are then used to train the neural network, as illustrated in figure (1).
* **CNN**: This is a small classical convolutional neural network consisting of two 2D convolutions. The first convolution has three input channels, six output channels, and a kernel size of five, so it has \((3\times 5\times 5+1)*6=456\) parameters. The second convolution has six input channels, 16 output channels, and a kernel size of five, so it has \((6*5*5+1)*16=2416\) parameters. An input layer with one neuron for each input feature, two hidden layers with 120 and 84 neurons, respectively, and an output layer with one neuron for each class. The output is, therefore, \(K\) real numbers between 0 and 1, as shown in figure (5). Training is, again, done by classical loss function minimization.
* **CNN + Annealer**: This is a small classical convolutional neural network consisting of two 2D convolutions. The first convolution has three input channels, six output channels, and a kernel size of five, so it has \((3*5*5+1)*6=456\) parameters. The second convolution has six input channels, 16 output channels, and a kernel size of five, so it has \((6*5*5+1)*16=2416\) parameters. An input layer with one neuron for each input feature, two hidden layers with 120 and 84 neurons, respectively, and one output layer with one neuron for each control parameter of the quantum annealer. The outputs, again, are the parameters \(f_{ik}\) controlling the quantum annealer, as shown in figure (2). The resulting

\begin{table}
\begin{tabular}{c c c c c c} \hline \hline  & **Data** & **Train** & **Test** & **Description** & Source \\ \hline
**MNIST** & 784 & 10 & 11.1318/0.00 & 0.000 & Image recognition of handwritten digits (fig. 4) & [90] \\
**CIFAR** & 3072 & 10 & 15.681/0.00 & 0.000 & Image recognition of different objects (fig. 4) & [54] \\
**ISOLET** & 671 & 672 & 15.091/0.6 & 6.238 & 1.550 & Included letter speech recognition & [61] \\
**UCIHAR** & 561 & 12 & 1001/0.6 & 6.233 & 1.554 & Human activity recognition with smartphones & [62] \\ \hline \hline \end{tabular}
\end{table}
Table 1: Datasets (\(n\): # of features, \(k\): # of classes).
quantum states are then used to train the neural network, as illustrated in figure (1).

### Is there any advantage in using a quantum annealer?

The results of our simulation experiments can be found in table 2. We performed 32 different experiments, with 8 for each dataset. Firstly, it is important to note that without training, the classification accuracy of our NN and CNN was always around \(\frac{1}{K}\), which is equivalent to random guessing. This is no surprise, given that the network cannot know which output neuron corresponds to which class in our prediction model. At the same time, when we connect the setup to an annealer, the classification accuracy is always better than \(\frac{1}{K}\). In the case of MNIST, it is around 59%; for CIFAR, it is 12%; for ISOLET, it is 44%; and for UCIHAR, it is 44%. This is because the output vectors \(|\psi_{final}\rangle\) are mapped to classes based on how close they are in the Hilbert space. Even with a neural network that is completely untrained, it is possible to achieve classification accuracies better than random choice. Nevertheless, this is not a property unique to quantum annealers but rather a consequence of the way in which classification is performed. To confirm this, we created a classical model which would average all images corresponding to a given class and then perform classification by comparing images to the \(K\) different averages. For MNIST, the accuracy of this trivial model was around 63% and for CIFAR around 13%, for ISOLET around 47%, and for UCIHAR also around 47%, with error margins of less than 1%. Therefore, quantum annealers provide no advantage over classical models without performing training.

Next, let us have a closer look at what happens after the training procedure, as shown in figure (1). The results are reported in table (2). We can see that training a (C)NN + Annealer model never results in better classification accuracies as compared to a classical (C)NN model. There are multiple possible explanations for this negative result:

1. The annealers which we simulate may not be large enough. We could only consistently simulate systems with up to \(n=10\) qubits. It is possible that with a significantly larger number of qubits an advantage is gained from using a quantum annealer
2. It could be that we were using the wrong datasets. There is no apparent reason why, for example, image classification should benefit from a quantum annealer. All our datasets work really well with classical machine learning models, which is why they are so commonly used in research. Other datasets containing data about quantum systems might benefit from adding a quantum annealer to a neural network
3. Lastly, it could be that there is just no benefit from using our system from figure (2). This would mean

\begin{table}
\begin{tabular}{c c c c c c c c c c} \hline \hline
**Architecture** & **Training** & \multicolumn{2}{c}{**MNIST 10**} & \multicolumn{2}{c}{**CIFAR 10**} & \multicolumn{2}{c}{**ISOLET 26**} & \multicolumn{2}{c}{**UCIHAR 12**} \\  & & Accuracy & Params & Accuracy & Params & Accuracy & Params & Accuracy & Params \\ \hline
**NN** & No & \((10.0\pm 0.2)\%\) & \(97,346\) & \((10.0\pm 0.2)\%\) & \(371,906\) & \((3.8\pm 0.2)\%\) & \(77,306\) & \((8.3\pm 0.5)\%\) & \(70,586\) \\
**NN** & Yes & \((88.2\pm 0.3)\%\) & \(97,346\) & \((44.1\pm 0.4)\%\) & \(371,906\) & \((86.2\pm 0.3)\%\) & \(77,306\) & \((87.2\pm 0.2)\%\) & \(70,586\) \\
**NN + Annealer** & No & \((59\pm 1)\%\) & \(133,525\) & \((12\pm 2)\%\) & \(408,085\) & \((43.9\pm 0.4)\%\) & \(113,485\) & \((44.2\pm 0.3)\%\) & \(106,765\) \\
**NN + Annealer** & Yes & \((86\pm 1)\%\) & \(133,525\) & \((13\pm 2)\%\) & \(408,085\) & \((85.5\pm 0.4)\%\) & \(113,485\) & \((85.9\pm 0.4)\%\) & \(106,765\) \\
**CNN** & No & \((10.0\pm 0.2)\%\) & \(45,786\) & \((10.0\pm 0.2)\%\) & \(63,366\) & \((3.9\pm 0.1)\%\) & \(63,366\) & \((8.8\pm 0.5)\%\) & \(63,366\) \\
**CNN** & Yes & \((95.0\pm 0.3)\%\) & \(45,786\) & \((49.9\pm 0.2)\%\) & \(63,366\) & \((93.4\pm 0.2)\%\) & \(63,366\) & \((94.2\pm 0.3)\%\) & \(63,366\) \\
**CNN + Annealer** & No & \((53\pm 1)\%\) & \(88,781\) & \((18.1\pm 0.5)\%\) & \(88,781\) & \((42\pm 1)\%\) & \(88,781\) & \((44\pm 1)\%\) & \(88,781\) \\
**CNN + Annealer** & Yes & \((91\pm 2)\%\) & \(88,781\) & \((18\pm 1)\%\) & \(88,781\) & \((90\pm 2)\%\) & \(88,781\) & \((92\pm 1)\%\) & \(88,781\) \\ \hline \hline \end{tabular}
\end{table}
Table 2: Classification accuracies and numbers of trainable parameters. This is for n=10 qubits, steps=10, TN=50. These results are discussed in section (IV.2). The reason why our (C)NN’s do not have the same number of parameters as the (C)NN’s + Annealer’s is that the output layer is of different sizes. The (C)NN has \(K\) output features (one for every class), while the (C)NN+Annealer has one output for every parameter of the annealing schedule.

Figure 4: a) MNIST dataset from [60]. It consists of 28 by 28 grayscale images (784 numbers each between 0 and 127). The full training dataset contains 60,000 images and the testing dataset 10,000 images. b) CIFAR dataset from [54]. It consists of 32 by 32 color images (1024 triples of numbers, each between 0 and 127). The full training dataset contains 50,000 images, and the testing dataset 10,000 images.
that there exists no quantum advantage from connecting neural networks to quantum annealers and using them to perform classical classification.

Simulating a system with more qubits might be very difficult, so it is unlikely that significant progress can be made in this direction. Therefore, we suggest future investigations focusing on applying our system to learning inherently different datasets. An example of these could be quantum datasets, such as quantum state tomography and quantum error correction.[63]

## V Conclusion

We explore a setup for performing classification on labeled classical datasets consisting of a classical neural network connected to a quantum annealer. Quantum annealers are mostly studied in the adiabatic regime, a computational model in which the quantum system remains in an instantaneous eigenstate of a time-dependent Hamiltonian. However, in our research, we focus on the diabatic regime where the quantum state doesn't always have to remain in the ground state. The neural network programs the quantum annealer's controls and thereby maps the annealer's initial states into new states in the Hilbert space. The neural network's parameters are optimized to maximize the distance of states corresponding to inputs from different classes and minimize the distance between quantum states corresponding to the same class. Recent literature [64] demonstrates that at least some of the "learning" is due to the quantum annealer in our setup. This is due to the fact that the quantum annealer introduces a non-linearity in the network. No matter how large, neural networks can only be more powerful than linear classifiers if non-linearities are introduced between layers. In [64], the authors classified a linearly inseparable dataset by using only a linear layer + the quantum annealing setup, explicitly showing that the learning is due to the non-linearity introduced by the quantum annealer. Also, our setup can perform classification with fewer parameters for training and inference. In this study, we consider a similar but not quite the same case, where a classical fully-fledged neural network is connected with a small quantum annealer (of course, adding back the full classical nn will compromise the advantage in the number of parameters). In such a setting, the fully-fledged classical neural-network already has built-in nonlinearity and can already handle the classification problem alone, we want to see whether an additional quantum layer could boost its performance. However, as of writing, we didn't find sufficient evidence demonstrating any advantage over just using classical neural networks. This could be due to our inability to simulate large quantum annealers effectively, our datasets, or there might be no real advantage to using our setup at all.

**ACKNOWLEDGMENTS**

This publication is the result of research funded by the Defense Advanced Research Projects Agency (DARPA) under agreement No.HR00112109969.
