Quantum HyperNetworks: Training Binary Neural Networks in Quantum
  Superposition
Binary neural networks, i.e., neural networks whose parameters and
activations are constrained to only two possible values, offer a compelling
avenue for the deployment of deep learning models on energy- and memory-limited
devices. However, their training, architectural design, and hyperparameter
tuning remain challenging as these involve multiple computationally expensive
combinatorial optimization problems. Here we introduce quantum hypernetworks as
a mechanism to train binary neural networks on quantum computers, which unify
the search over parameters, hyperparameters, and architectures in a single
optimization loop. Through classical simulations, we demonstrate that of our
approach effectively finds optimal parameters, hyperparameters and
architectural choices with high probability on classification problems
including a two-dimensional Gaussian dataset and a scaled-down version of the
MNIST handwritten digits. We represent our quantum hypernetworks as variational
quantum circuits, and find that an optimal circuit depth maximizes the
probability of finding performant binary neural networks. Our unified approach
provides an immense scope for other applications in the field of machine
learning.
Juan Carrasquilla, Mohamed Hibat-Allah, Estelle Inack, Alireza Makhzani, Kirill Neklyudov, Graham W. Taylor, Giacomo Torlai
# Quantum HyperNetworks: Training Binary Neural Networks in Quantum Superposition

###### Abstract

Binary neural networks, i.e., neural networks whose parameters and activations are constrained to only two possible values, offer a compelling avenue for the deployment of deep learning models on energy- and memory-limited devices. However, their training, architectural design, and hyperparameter tuning remain challenging as these involve multiple computationally expensive combinatorial optimization problems. Here we introduce quantum hypernetworks as a mechanism to train binary neural networks on quantum computers, which unify the search over parameters, hyperparameters, and architectures in a single optimization loop. Through classical simulations, we demonstrate that of our approach effectively finds optimal parameters, hyperparameters and architectural choices with high probability on classification problems including a two-dimensional Gaussian dataset and a scaled-down version of the MNIST handwritten digits. We represent our quantum hypernetworks as variational quantum circuits, and find that an optimal circuit depth maximizes the probability of finding performant binary neural networks. Our unified approach provides an immense scope for other applications in the field of machine learning.

+
Footnote †: Work done before joining AWS.

+
Footnote †: Work done before joining AWS.

## I Introduction

The availability of high quality data sources along with algorithmic and hardware advances for training neural networks have paved the way for a new generation of large models displaying unprecedented accuracy across a wide array of technologically and scientifically relevant tasks. These advances crucially depend on the availability of specialized computational resources such as graphics and tensor processing units, which demand a high electricity consumption. In particular, a set of key but computationally expensive elements in the modern machine learning (ML) workflow include hyperparameter optimization and neural architecture search. Traditionally, these operate via an outer optimization loop which searches through the hyperparameter and architectural state spaces guided by the model's performance on a validation set, and an inner optimization which adjusts the parameter of the neural network on a training set. Such a nested optimization process remains the most computationally demanding task in the modern ML workflow and entails an unsustainable carbon footprint, which calls for computationally efficient hardware and algorithms to train and search for neural architectures [1].

Neural networks with binary parameters and activations (BiNNs) partially alleviate these issues as they are computationally efficient, hardware-friendly, and energy efficient. Beyond a direct 32-fold reduction of the memory footprint with respect to a full-precision neural network, BiNNs can exploit specialized hardware implementations that simultaneously increase computational speed [2] and improve their energy efficiency [3]. Another benefit of very low-precision neural networks is their improved robustness against adversarial attacks while matching the performance of full-precision models in the worst cases [4]. While in principle it is possible to binarize trained continuous-variable neural networks, such a procedure typically leads to significant accuracy losses, which makes it preferable to directly learn their binary parameters.

The ML community has developed approaches to the use of BiNNs which bypass the infeasible discrete optimization of their training through a re-framing of the problem in the conventional domain of gradient descent algorithms. These include post-quantization of conventionally trained neural networks, as well as deterministic and stochastic relaxations of the original problem both for parameter tuning [5; 6; 7; 8] and architecture search [9]. In spite of these advances, the combined optimization of a BiNN's parameters and their associated hyperparameter and architecture searches remain computationally demanding as these involve solving multiple nested combinatorial optimization problems or their associated relaxations.

Quantum computing, which aims at exploiting quantum interference and entanglement to enable the solution
to a wide array of classically intractable computations, provides an alternative approach to the training of neural networks [10; 11; 12; 13; 14; 15; 16; 17; 18; 19; 20]. In particular, variational quantum algorithms (VQAs) have emerged as a potential strategy to obtain quantum computational advantage on near-term quantum devices [21; 22]. These algorithms employ parameterized quantum circuits that can adapt to current experimental constraints such as the limited number and connectivity of the qubits, gate infidelities, and coherent and incoherent errors that limit the accuracy of practically realizable quantum circuits [21; 22].

Here we promote hypernetworks-networks that generate the weights of another network [23]-to quantum hypernetworks, i.e., quantum states that generate the weights of a neural network. Quantum hypernetworks offer an alternative approach to the training of BiNNs through a unification of the parameter, hyperparameter, and architecture searches in a single optimization loop. A quantum hypernetwork, here implemented through a parameterized quantum circuit of variable depth, is trained to search over an augmented space comprising the parameters of the neural network, its hyperparameters, and any desired architectural choices with an eye on improving the overall efficiency of the BiNN workflow. Through classical simulations, we show that quantum hypernetworks with short depth and limited connectivity can jointly optimize BiNNs' hyperparameters, architectural choices, and parameters for toy classification problems including a two-dimensional Gaussian dataset and a scaled-down version of the MNIST handwritten digits. We find that the probability of finding performant BiNNs is maximized at a specific circuit depth, which suggests that an optimal use of entanglement and quantum effects decrease the probability that the optimization finds poor local minima.

Through a Fourier analysis, we reveal that the objective functions used to train the BiNNs are predominantly local. This observation, together with our numerical experiments, suggests that quantum hypernetworks built from local low-depth circuits with limited connectivity, all of which are common features to most currently available quantum computers, can be effective at training BiNNs. Our analysis indicates that the locality of the objective function may not induce tractability problems related to the presence of barren plateaus which interfere with the accurate estimation of the gradients used during the optimization of the circuits.

## II Results

### Variational Quantum HyperNetworks

To encode the problem in a form suitable to optimization by a quantum computer, we consider quantum states composed of \(N\) qubits written in the computational basis corresponding to the eigenstates of tensor products of the Pauli operator \(\hat{\sigma}_{i}^{z}\) acting on qubits \(i\), namely

\[|\Psi\rangle=\sum_{\sigma_{1},\ldots,\sigma_{N}}\Psi(\sigma_{1},\ldots,\sigma_ {N})|\sigma_{1},\ldots,\sigma_{N}\rangle, \tag{1}\]

where \(\hat{\sigma}_{i}^{z}|\sigma_{1},\ldots,\sigma_{i},\ldots,\sigma_{N}\rangle=(2 \sigma_{i}-1)|\sigma_{1},\ldots,\sigma_{i},\ldots,\sigma_{N}\rangle\), and \(\sigma_{i}\in\{0,1\}\).

A quantum hypernetwork is a quantum state \(|\Psi\rangle\) where each basis element \(|\mathbf{\sigma}\rangle=|\sigma_{1},\ldots,\sigma_{N}\rangle\) is associated with a specific configuration of an augmented model comprising the parameters of a BiNN, its hyperparameters, and any desired architectural choices to be encoded in the quantum hypernetwork. As quantum superposition is the feature of a quantum system whereby it exists in several separate states, i.e., all the different BiNNs encoded in Eq. 1, our approach can be understood as training BiNNs in quantum superposition. In Fig. 1(a) we represent a quantum hypernetwork encoding a small binary linear feed-forward network with a two-dimensional input and one-dimensional output. The BiNN is characterized by 2 weights (qubits \(\sigma_{1}\) and \(\sigma_{2}\)), a bias (qubit \(\sigma_{3}\)), and an activation function. To encode architectural choices, e.g., the selection of activation function from two possibilities \(f_{1}\) or \(f_{2}\), we make the activation function qubit dependent (qubit \(\sigma_{4}\) in Fig. 1(a-b)), i.e., \(f(x)\to f(x,\sigma)\), where, e.g.,

\[f(\mathbf{x};\sigma)=\begin{cases}f_{1}(\mathbf{x})&\text{if}\ \sigma=0\\ f_{2}(\mathbf{x})&\text{if}\ \sigma=1.\end{cases}\]

As explored below, other architectural choices and hyperparameters can be similarly encoded through the use of additional qubits.

A design principle for a quantum algorithm aiming at training classical neural networks may consist of the preparation of a quantum state \(|\Psi\rangle\) (i.e. the hypernetwork) that assigns high amplitudes \(\Psi(\sigma_{1},\ldots,\sigma_{N})\) to basis states \(|\sigma_{1},\ldots,\sigma_{N}\rangle\) encoding neural networks with a low cost function \(C\) quantifying their performance

\[C\left(\mathbf{w}\right)=\frac{1}{N_{t}}\sum_{i=1}^{N_{s}}\mathcal{L}\left(\text{ NN}(\mathbf{x}_{i};\{\mathbf{w}\}),\mathbf{y}_{i}\right). \tag{2}\]

Here \(N_{s}\) is the size of the training dataset composed of input \(x_{i}\) and output \(y_{i}\) variables, \(\mathcal{L}\) is a loss function, and \(\text{NN}(\mathbf{x}_{i};\mathbf{w})\) represents an augmented neural network model. The augmented model parameters \(\mathbf{w}=\{w_{1},\ldots,w_{N}\}\), include the neural network weights, biases, hyperparameters, and architectural choices. The cost function corresponds to an \(N\)-bit real Boolean function \(C:\{0,1\}^{N}\rightarrow\mathbb{R}\), which the quantum algorithm aims to minimize. The weights and biases take the values \(2\sigma_{i}-1\in\{-1,1\}\).

The simplest and currently most experimentally friendly approach to carry out this optimization using quantum resources is through a VQA. VQA employs a classical optimizer acting on a parameterized quantum circuit, with the purpose of finding solutions to a problem encoded in an objective function, which in our setting
corresponds to \(C\left(\mathbf{w}\right)\). A key element to a VQA is the encoding of the objective function, achieved by promoting Eq. (2) to a quantum operator. A natural choice is to promote the parameters of the BiNN to a set of Pauli matrices \(\mathbf{w}\rightarrow\mathbf{\hat{\sigma}_{z}}=(\hat{\sigma}_{1}^{z},\hat{\sigma}_{2}^{z},\ldots,\hat{\sigma}_{N}^{z})\), which, in turn, promotes the objective function \(C\left(\mathbf{w}\right)\) to an operator \(\hat{C}\). Here \(\hat{\sigma}_{i}^{z}\) is the Pauli matrix \(\begin{pmatrix}1&0\\ 0&-1\end{pmatrix}\) acting on qubit \(i\), the diagonal cost operator

\[\hat{C}=\begin{pmatrix}C(\mathbf{w}_{1})&0&\cdots&0\\ 0&C(\mathbf{w}_{2})&\cdots&0\\ \vdots&\vdots&\ddots&\vdots\\ 0&0&\cdots&C(\mathbf{w}_{2^{N}})\end{pmatrix}, \tag{3}\]

and \(\mathbf{w}_{1},\ldots,\mathbf{w}_{2^{N}}\) are all the \(2^{N}\) possible BiNN. This encoding is flexible and other operator choices, including off-diagonal operators, are possible.

We construct a quantum hypernetwork \(\ket{\Psi}\) through a parameterized quantum circuit \(U(\mathbf{\theta})\) with continuous parameters \(\mathbf{\theta}\) such that \(\ket{\Psi}\rightarrow\ket{\Psi_{\mathbf{\theta}}}=U(\mathbf{\theta})\ket{0}^{ \mathbf{\bigotimes}\,n}\). We aim at finding solutions to the training of the BiNN solving for

\[\mathbf{\theta}^{*}=\arg\min_{\mathbf{\theta}}\ E\left(\mathbf{\theta}\right), \tag{4}\]

where \(E\left(\mathbf{\theta}\right)=\bra{\Psi_{\mathbf{\theta}}}\hat{C}\ket{\Psi_{\mathbf{ \theta}}}\). From an ML perspective, this approach can be understood as a stochastic relaxation of the discrete optimization problem. That is, instead of directly searching for the optimal binary parameters, we introduce a joint distribution over the parameters and architectural choices encoded by the quantum state \(\ket{\Psi_{\mathbf{\theta}}}\). Measuring the quantum state (see Fig. 1(b)) produces trial binary parameters and architectural choices and gives access to estimates of the learning objective \(E(\mathbf{\theta})\).

We express \(U(\mathbf{\theta})\) as the product of \(L\) unitary blocks of the form \(U(\mathbf{\theta})=U_{L}\left(\mathbf{\theta}_{L}\right)\cdots U_{1}\left(\mathbf{\theta}_ {1}\right)\). We restrict ourselves to one of the simplest and most widely available circuits in current quantum computing platforms, namely those implementable in quantum devices with a linear connectivity:

\[U_{k}\left(\mathbf{\theta}_{k}\right) =\prod_{m=1+k\text{ mod }2,\text{ step }2}^{N-2+k\text{ mod }2}\text{ CX}(m,m+1) \tag{5}\] \[\prod_{j=1}^{N}\text{RY}(j,\theta_{y,j,k})\text{RZ}(j,\theta_{z, j,k}).\]

Here \(\text{CX}(m,j)\) denotes a control-X gate acting on the control \(m\) and target \(j\) qubits. The parameterized single-qubit unitaries \(\text{RY}(j,\theta_{y,j,k})\) and \(\text{RZ}(j,\theta_{z,j,k})\) at block \(k\) are given by \(e^{i\theta_{y,j,k}\theta_{j}^{y}}\) and \(e^{i\theta_{z,j,k}\theta_{j}^{z}}\), respectively. The symbol \(i\) is the imaginary unit. The parameters of the circuit are \(\mathbf{\theta}=\{\theta_{\alpha,j,k}\}\), where \(\alpha=y,z\), \(j=1,\ldots,N\), and \(k=1,\ldots,L\). We illustrate a quantum circuit with \(L=2\) and \(N=4\) in Fig. 1(b), where the green boxes synthesize the combined effect of \(\text{RY}(j,\theta_{y,j,k})\) and \(\text{RZ}(j,\theta_{z,j,k})\). In our experiments, we consider even \(L=2\times N_{\text{layer}}\) and define a layer (see encircled blocks in Fig. 1(b)) as 2 unitary blocks, so that the circuit in Fig. 1(b) contains \(N_{\text{layer}}=1\) layers. In addition, we also consider one of the simplest possible quantum states, namely an entanglement-free product state ansatz, where \(U(\mathbf{\theta})_{\text{prod.}}=\prod_{j=1}^{N}\text{RY}(j,\theta_{y,j,1})\text{ RZ}(j,\theta_{z,j,1})\). The latter have been shown effective at solving quadratic unconstrained binary optimization problems [24; 25].

### Optimization

We optimize the Eq. (4) via a gradient-based method where \(E\left(\mathbf{\theta}\right)\) and its gradient \(\nabla_{\mathbf{\theta}}E\left(\mathbf{\theta}\right)\) are evaluated through measuring the quantum hypernetwork \(\ket{\Psi_{\mathbf{\theta}}}\) followed by a classical optimizer that iteratively updates its parameters. At the end of the optimization, we expect that \(\ket{\Psi_{\mathbf{\theta}}}\) assigns high amplitudes to BiNNs with low cost function, i.e., good architectural choices, parameters and hyperparameters.

Figure 1: **Quantum HyperNetworks** (a) The different BiNN’s configurations can be encoded in the computational basis \(\mathbf{\sigma}\) of a quantum state \(\ket{\Psi}\), which is defines a quantum hypernetwork. (b) The quantum hypernetwork can be constructed via a parameterized quantum circuit which upon measuring produces BiNN configurations. Different qubits \(\sigma_{i}\) are interpreted as parameters, hyperparameters and architectural choices of the BiNN.
In an experimental setting, the estimation of the gradients \(\nabla_{\mathbf{\theta}}E\left(\mathbf{\theta}\right)\) makes use of the parameter-shift rule [26, 27].

It follows that the entries of the gradient are given by

\[\frac{\partial E\left(\mathbf{\theta}\right)}{\partial\theta_{\alpha,j,k}}=\frac{1} {2}\left[E(\mathbf{\theta}_{\alpha,j,k}^{+})-E(\mathbf{\theta}_{\alpha,j,k}^{-}) \right], \tag{6}\]

where the elements of the shifted parameter vector \(\mathbf{\theta}_{\alpha jk}^{\pm}\) are such that \(\theta_{\beta,m,l}^{\pm}=\theta_{\beta,m,l}\pm\frac{\pi}{2}\delta_{\alpha, \beta}\delta_{m,j}\delta_{k,l}\). Thus, the calculation of the gradient corresponds to the evaluation of a shifted version of the objective function \(E(\mathbf{\theta})\), which can be estimated by preparing and measuring the same quantum circuit used to compute the original objective with shifted circuit parameters.

In a quantum experiment, functions of the form \(E(\mathbf{\theta})\) are estimated via averages over the measurement outcomes of projective measurements, e.g.,

\[E\left(\mathbf{\theta}\right) =\langle\Psi_{\mathbf{\theta}}|\hat{C}|\Psi_{\mathbf{\theta}}\rangle \tag{7}\] \[=\sum_{\sigma_{1},\sigma_{2},\ldots,\sigma_{N}}|\Psi_{\mathbf{ \theta}}(\sigma_{1},\sigma_{2},\ldots,\sigma_{N})|^{2}C(\sigma_{1},\sigma_{2 },\ldots,\sigma_{N})\] \[=\mathbb{E}_{\mathbf{\sigma}\sim|\Psi_{\mathbf{\theta}}|^{2}}\left[C( \mathbf{\sigma})\right]\approx\frac{1}{N_{qc}}\sum_{i=1}^{N_{qc}}C(\mathbf{\sigma}_{i}),\]

where \(N_{qc}\) configurations \(\mathbf{\sigma}_{i}\) are distributed according to \(|\Psi_{\mathbf{\theta}}|^{2}\). The estimate of \(E(\mathbf{\theta})\approx\frac{1}{N_{qc}}\sum_{i=1}^{N_{qc}}C(\mathbf{\sigma}_{i})\) is evaluated classically by computing \(C(\mathbf{\sigma})\) on the BiNNs \(\mathbf{\sigma}\sim|\Psi_{\mathbf{\theta}}|^{2}\) sampled by the quantum computer.

In contrast, we use classical simulations based on tensor networks (TN) [28] implemented through the PastaQ.jl package [29]. The TN techniques allow for the exact evaluation of expectations and their gradients through automatic differentiation (AD) provided by the package Zygote.jl [30]. To optimize \(E(\mathbf{\theta})\) we use the limited-memory Broyden-Fletcher-Goldfarb-Shanno (LBFGS) algorithm [31].

### Gaussian dataset with a choice of activation

We first consider the training of a small BiNN binary classifier with a two-dimensional input, a three-dimensional hidden layer, and a single output depicted in Fig. 2(a). We would like to simultaneously train the parameters, as well as an architectural choice, here the selection of activation function \(f\), which in our example can be a sigmoid or a rectified linear unit (ReLU):

\[f(\mathbf{x};\sigma)=\begin{cases}S(\mathbf{x})&\text{if}\ \sigma=0\\ \text{ReLU}(\mathbf{x})&\text{if}\ \sigma=1.\end{cases}\]

Here \(S(\mathbf{x})=1/(1+e^{-\mathbf{x}})\) and \(\text{ReLU}(\mathbf{x})=\max(\mathbf{x},0)\) are applied element-wise on the components of the arrays \(\mathbf{x}\). The activation function in the output layer is \(f_{\text{out}}(\mathbf{x})=S(\mathbf{x})\).

We train the BiNN on a toy dataset drawn from a two-dimensional mixture of 4 Gaussian distributions shown in Fig. 2(b). The samples are drawn from the red (squares) Gaussian with probability \(1/2\) and from each of the blue (circles) Gaussians with probability \(1/6\). Each data point is labeled according to whether it was drawn from the red or blue Gaussians, and we aim to train the BiNNs to classify any point in the plane accordingly.

The BiNN is characterized by 13 binary parameters and a binary variable \(\sigma_{14}\) codifying the architectural choice of activation function, i.e. \(N=14\) variables. For small BiNNs, a training dataset, and an objective function \(C\left(\mathbf{w}\right)\), it is possible to compute the optimal BiNN configuration by enumerating all the \(2^{N}\) BiNNs and choosing the one with the smallest \(C\left(\mathbf{w}\right)\). In our example, the best configuration yields the decision boundary shown in Fig. 2(b), where the optimal BiNN classifies points in the green region as coming from the red Gaussian and points in the orange region as coming from the blue Gaussians. The optimal choice of activation function is the ReLU. Now we explore solving the problem via quantum optimization. We consider the circuit ansatz shown in Fig. 1 with varying number of layers \(N_{\text{layer}}=1,2,3,4\), as well as a product state ansatz. We randomly and independently initialize all the parameters of the circuits from a uniform distribu

Figure 2: **BiNNs applied to a Gaussian dataset.** (a) A BiNN with two dimensional input, a three dimensional hidden layer, and one output. (b) The decision boundary drawn by our BiNN after training on a two-dimensional mixture of 4 Gaussian distributions with two labels. (c) A kernel density estimation (KDE) of the probability that a quantum circuit (product state and with different number of layers) achieves an average cost \(E(\theta)\). The bottom row of this panel corresponds to the density of configurations with a cost \(C(\mathbf{w})\) after filtering for low-cost configurations. (d) The probability of finding the lowest objective \(C(\mathbf{w^{\star}})\) within \(\epsilon=0.03\) for the different quantum circuits.
tion \(\theta_{\alpha,i,k}\sim U(0,2\pi)\). We first note that all the circuit ansatze have sufficient expressive power to represent the optimal solution, which is simply the product state. In our numerical experiments, we find that all of our ansatze can find the optimal solution, including the product state ansatz, with varying degree of success. The success rate of the optimization depends on the interplay between the initialization of the circuit parameters and the depth of the circuit. To understand the typical behaviour of the optimization procedure and to shed light onto the role of the circuit depth, we perform the circuit optimization for a number \(N_{\mathrm{optim}}=200\) of independent initializations.

In Fig. 2(c) we summarize the results of these optimizations through a kernel density estimation (KDE) of the probability density function that the optimization finds an average objective \(E(\mathbf{\theta})\) for different circuit depths. In addition, through full enumeration, we compute a KDE of the 200 top performing BiNN with the lowest \(C(\mathbf{w})\) (the bottom row of Fig. 2(c)). This can be interpreted as the density of configurations at a particular "\(E\) level" that a BiNN can take, and is analogous to the density of states in condensed matter physics. Since we only take the 200 lowest objective function BiNNs, this means that the probability assigned by the KDE to each value \(C(\mathbf{w})\) is significantly overestimated.

We observe that most solutions found by all circuits considered here are concentrated near the optimal configuration of weights and hyperparameters \(\mathbf{w}^{*}\), for which \(C(\mathbf{w}^{*})\approx 0.008\) (see the encircled densities in Fig. 2(c)). This is in spite of the fact that the density of solutions with low \(C\) is significantly small, which indicates that the quantum optimization is effective. However, the frequency with which solutions with low objective function are found varies as a function of the circuit depth. To probe this behaviour, we estimate the probability that a certain circuit depth finds solutions with precision \(E(\mathbf{\theta}-C(\mathbf{w}^{*})<\epsilon)\) by counting the solutions found by the VQA meeting the precision condition. This is shown in Fig. 2(d). As noted earlier, even a product state circuit finds accurate solutions. A circuit with 1 layer (see Fig. 1) doubles the number of variational parameters and decreases the probability to find accurate solutions which indicates that the optimization of the variational parameters \(\mathbf{\theta}\) is more prone to getting stuck in local minima than a product state circuit. Upon increasing the depth, we note that for 2 and 3 layers, the probability to find accurate solutions reaches a maximum but eventually decreases for 4 layers. Circuits with layers composed of entangling gates and multiple (optimally for \(N_{\mathrm{layer}}=3,4\)) layers of parameterized single-qubit gates provide an advantage as these enhance the success of finding good solutions with respect to a product state.

### Gaussian dataset with a choice of activation and dimension of hidden layer

Next we consider the simultaneous optimization of the BiNN's parameters, a hyperparameter (hidden layer dimension \(N_{hid}\)) and the architectural choice non-linearity. We encode the choice of \(N_{hid}\in\{2,3\}\) through an additional qubit \(\sigma_{N_{hid}}\). A wider set of choices of \(N_{hid}\) is possible through the use of more qubits. We encode these choices through a single function \(\mathrm{NN}(\mathbf{x}_{i};\mathbf{w})\) that evaluates the BiNN's output as a function of weights and biases, and the choices of non-linearity and \(N_{hid}\). The choice of qubit assignment of the BiNN's parameters and nonlinearity are presented in Fig. 3(a), where the qubits encircled in blue are left unused in the evaluation of the BiNN output for \(N_{hid}=2\) but are used for \(N_{hid}=3\).

The results of the optimization procedure are displayed in Fig. 3(b-c), which display a behaviour similar to the experiments in Fig. 2(c-d). While the optimization is successful, the probability of finding low-energy solutions is reduced with respect to the original optimization task in Fig. 2. As noted in Fig. 2, while even a product state circuit finds accurate solutions with high probability, there exists an optimal circuit depth that significantly enhances the probability of a finding the optimal solution, eventually decreasing upon further increasing depth. This effect is due to the optimization becoming

Figure 3: **BiNNs with two layers with width and nonlinearity hyperparameters on the Gaussian toy dataset.** (a) An illustration of the weights, biases, hyperparameters within a flattened list for two different numbers of hidden neurons \(N_{hid}=2,3\). Blue color means that the corresponding parameter is not used. (b) Similarly to Fig. 2(c), we show the KDE for different quantum circuits’ objectives in the top five rows, as well as the density of configurations in the bottom row. (c) In a similar fashion to Fig. 2(d), we show the probability of success within a threshold \(\epsilon=0.03\) for each quantum circuit.
more prone to finding local minima and not to the ansatz' expressive power, as deeper circuits are more expressive than shallower ones.

### Scaled-down MNIST

Finally, to investigate the performance of quantum optimization for a representative dataset, we consider training a simple logistic regression model with binary parameters and a cross-entropy loss, as shown in Fig. 4(a). The training data corresponds to a subset of MNIST images of zeros and ones scaled down to \(L\times L=4\times 4\) pixels. We explore solving the training problem via quantum optimization with the circuit depths \(N_{\text{layer}}=1,2,3\) as well as with a product state circuit. As in our previous example, we run the optimization for \(N_{\text{optim}}=200\) independent initializations. The results are shown in Fig. 4(b).

While optimization via a product state ansatz attains optimal solutions with nearly 60% success rate, the rate is enhanced for circuits with an optimal number of entangling layers, which display a 90% chance of success for \(N_{\text{layer}}=2,3\). This backs up our previous observation that entanglement plays an important role in the optimization procedure. As seen in Fig. 4(b-c) our circuits enhance the probability of finding the optimal solution going beyond simply increasing of the expressive power of the circuit ansatz.

### Fourier analysis of \(C\)

In spite of the similarities between the MNIST and Gaussian mixture examples in terms of problem size \(N\) and task, we note that the probability of finding solutions with low cost function is higher for the MNIST task. To shed light onto the origin of these differences in optimization performance, we examine the structure of the objective functions \(C\) through a Fourier analysis.

As pointed out by Torta _et al._ [19], due to the non-linearities of the BiNNs and the loss function \(\mathcal{L}\), the objective function \(C\) and its quantum extension \(\hat{C}\) may contain highly non-local, all-to-all multi-variable interactions. Beyond understanding the differences in optimization performances across different tasks, the locality of \(C\) plays an important role in the optimization of the circuit as a highly non-local \(C\) may lead to exponentially vanishing gradients in Eq. 6, which can severely impede the optimization of the circuit [32].

The Fourier transform of the real boolean function \(C\) and its quantum extension \(\hat{C}\) provides a natural strategy to investigate the locality of the objective function \(C\). First, \(\hat{C}\) can be represented by an Ising Hamiltonian given by sums of tensor products of Pauli \(\sigma_{i}^{z}\) operators weighted by \(C\)'s Fourier expansion coefficients [33]. Thus, for an \(N\)-bit real function \(C:\{0,1\}^{N}\rightarrow\mathbb{R}\), we can decompose \(\hat{C}|\sigma\rangle=C(\sigma)|\sigma\rangle\) as

\[\hat{C}=\sum_{\hat{\sigma}_{1},\dots,\hat{\sigma}_{N}}f(\hat{\sigma}_{1},\dots \hat{\sigma}_{N})\bigotimes_{i=1}^{N}\hat{\sigma}_{i}, \tag{8}\]

where \(\hat{\sigma}_{i}=\{\mathbf{1},\hat{\sigma}_{i}^{z}\}\). Here the Fourier coefficients are given by \(f(\hat{\sigma}_{1},\dots\hat{\sigma}_{N})=\frac{1}{2^{N}}\text{Tr}\left[\hat{ C}\otimes_{i=1}^{N}\hat{\sigma}_{i}\right]\in\mathbb{R}\). This follows from the fact that the tensor products of Pauli operators and the identity form an orthogonal basis for the vector space of \(2^{N}\times 2^{N}\) complex matrices, in particular the subspace of diagonal operators such as \(\hat{C}\), for which only the \(2\times 2\) identity matrix \(\mathbf{1}\) and \(\sigma_{i}^{z}\) are required in the expansion.

We evaluate the \(N\)-bit function \(f(\hat{\sigma}_{1},\dots\hat{\sigma}_{N})\) and define the amplitude

\[W(S)=\sum_{\hat{\sigma}_{1},\dots\hat{\sigma}_{N}}|f(\hat{\sigma}_{1},\dots \hat{\sigma}_{N})|^{2}\delta_{S,S(\hat{\sigma}_{1},\dots\hat{\sigma}_{N})}. \tag{9}\]

as the total sum of the Fourier coefficients squared associated with diagonal Pauli strings with weight \(S\). Here the weight \(S(\hat{\sigma}_{1},\dots\hat{\sigma}_{N})\in\{0..N\}\) of an \(N\)-length Pauli string \(\bigotimes_{i=1}^{N}\hat{\sigma}_{i}\) corresponds to the number of non-identity Pauli matrices in it.

The structure of the function \(W(S)\) reflects the locality of the effective Ising Hamiltonian. For instance, when \(W(S)\neq 0\) only for \(S=0,1\) means that the effective Ising Hamiltonian corresponds to a set of local fields acting independently on the variables \(\sigma_{i}\). In contrast, if \(W(S)\neq 0\) for \(S=0,1,2\) means that the Ising Hamiltonian contains only pairwise interactions and local fields, etc. Speaking

Figure 4: **BiNNs for the reduced MNIST dataset.** (a) The BiNN used to classify the reduced MNIST dataset. (b) A KDE of \(E(\mathbf{\theta})\) resulting from repeating the optimization procedure 200 times. The optimizations are performed for a product state, as well as for circuits with 1,2, and 3 layers. We also show the density of configurations with a cost \(C(\mathbf{w})\). (c) A plot of the probability of success within a threshold \(\epsilon=5\times 10^{-5}\) for the different quantum circuit architectures.
informally, \(W(S)\) defines how well we can approximate \(\hat{C}\) with a polynomial of degree \(S\).

In Fig. 5(a-c) we show \(W(S)\) for the tasks of classification of Gaussians with function activation search (a), Gaussians with activation function and hidden dimension search (b), and logistic regression of MNIST with binary weights (c). For all systems, the highest \(W(S)\) happens at \(S=0\), which corresponds to a simple constant shift in the effective Hamiltonian. As the weight \(S\) increases, the amplitude \(W(S)\) is seen to decrease exponentially fast even for moderate \(S\). This means that all the objectives \(C\) are essentially local, which bodes well for circuit optimization as the locality of \(C\) will not induce barren plateaus [32]. For the Gaussian mixture tasks, we see that the most important contributions to \(W\) occur at \(S=2,3\) with the highest values occurring at \(S=2\), which means that the effective Hamiltonian is nearly an Ising Hamiltonian with pairwise interactions. Instead, for MNIST the most dominant non-trivial contribution comes from \(S=1\), which means that the effective Hamiltonian is a set of local fields acting on the binary weights of the model. This in part explains why the quantum optimization of the MNIST task is superior since the solution of a fully independent set of binary variables coupled to local fields can be found by independently optimizing the energy of each binary variable. This means that a product state is perfectly suited to find it with high probability, as we have found. Additionally, these observations support the idea that short-depth circuits with one- and two-qubit gates can tackle the optimization of the BiNNs without resorting to full implementations of unitaries of the form \(e^{i\hat{C}}\), which have been typically prescribed in earlier proposals for training neural networks using quantum computers [14; 19].

### Overfitting and model selection

In contrast with the standard ML workflow where the hyperparameter and architectural choices are optimized based on the model's performance on a validation set, we have defined an augmented model encapsulating the parameters, hyperparameters and architecture of a neural network, which we jointly optimize on a training dataset. We now briefly explore the generalization and overfitting behaviour of the augmented model and investigate how the resulting trends can guide the selection of an optimal augmented model.

As an example, we revisit the training of a BiNN with architectural choice of non-linearity to the the mixture of Gaussians dataset as a testbed to explore overfitting and generalization. To amplify overfitting, we simultaneously bring the Gaussians spatially closer to each other with respect to the example in Fig. 2 and decrease the size of the training dataset. As a function of the training iterations, we investigate the behaviour of \(\overline{E(\mathbf{\theta})}\), which is an average of \(E(\mathbf{\theta})\) over 100 independent realizations of training datasets of sizes \(N_{s}=2,4,6,8\). We also consider training datasets with \(N_{s}=10^{3}\), significantly larger than the dimensionality of the input (\(d=2\)). We fix the total number of circuit training iterations to 50 and the choose a large validation set of size 1000.

Overall, we find that the augmented model adheres to the anticipated behaviour of an ML model. In all of our examples, the average training curves on the training sets are monotonically decreasing. For small training sets, e.g. \(N_{s}=2\), the validation set curve initially decreases and later on increases, which suggests that the simple "early stopping" strategy may be employed to choose optimal models located at the minimum of the validation curve as a way to avoid overfitting [34]. For \(N_{s}>2\), the validation curves exhibit a monotonic decreasing behaviour as a function of training iterations, which is the typical dynamics for large training sets \(N_{s}\) where the dynamics is less prone to overfitting. As expected, the generalization gap, i.e. the difference between the validation and training set curves near the end of the training, decreases quickly as a function of the \(N_{s}\) and is seen to grow small for large datasets \(N_{s}=10^{3}\), as expected.

## III Discussion

We have introduced quantum hypernetworks, variational quantum circuits that search for optimal BiNNs over an augmented space comprising its parameters, hyperparameters, and any desired architectural choices, in

Figure 5: **Fourier analysis of \(\hat{C}\)**. The amplitudes \(W(S)\) associated with Pauli string weights \(S\) for (a) the classification of Gaussians with activation function search, (b) the classification of gaussians with the hidden neurons and activation function search, (c) the logistic regression of reduced MNIST.
a single optimization loop. Using classical simulations, we have shown that quantum hypernetworks effectively find optimal parameters, hyperparmeters and architectural choices with high probability on toy classification problems including a two-dimensional Gaussian dataset and a scaled-down version of the MNIST handwritten digits. We find that the probability of finding performant BiNNs is tied to the circuit depth, and consequently, to the amount of entanglement supported by the circuit. This indicates that entanglement and quantum effects play a role and decrease the probability that the optimization finds poor local minima.

Even though expressing quantum hypernetworks in terms circuits with a simple linear connectivity have proven successful in our setting, other ansatze constructed considering knowledge of the problem, e.g., circuit designs adaptively grown guided by the objective function and gate availability [35], may simultaneously shorten the circuit depth and significantly improve the effectiveness and scalability of our approach. To explore training large models beyond what's feasible with limited-size quantum processors, it is natural to consider a layer-by-layer optimization of the BiNN, which would operate analogously to the density matrix renormalization group algorithm [36]. Additionally, distributed quantum computing [37], as well as a multi-basis encoding of the problem [38], may extend the scalability of our approach to larger ML models. The application of fault tolerant quantum algorithms may also prove useful to the success of the unified training strategy presented here and may lead to provable speedups [17].

Our approach naturally connects with Bayesian inference as the the quantum hypernetwork \(|\Psi_{\mathbf{\theta}}\rangle\) defines a probability distribution over the weights of the BiNNs, a defining property of a Bayesian neural network. A full Bayesian approach prescribes the evaluation of the posterior distribution over the parameters, which is fundamentally intractable in our setting. It may be possible, however, to estimate the evidence lower bound [39] by performing a decomposition of the circuit distribution, taking inspiration from Titsias and Ruiz [40], Molchanov _et al._[41]. Additionally, although we have arrived at our unified strategy through a variational quantum optimization lens, our approach suggests that it is possible to introduce classical or quantum-inspired hypernetworks based on, e.g., recurrent neural networks or product states [25; 42], where a variational Bayesian approach to BiNN optimization is possible.

Quantum computers are currently reaching the ability to vastly outperform supercomputers' energy efficiency by many orders of magnitude over classical computers [43], so it stands to reason that the efficiency and energetic consumption of complex tasks in the ML workflow such as neural network training and hyperparameter search may be significantly reduced through the use of quantum computational resources. A combination of the energy efficiency of BiNN's classical operation with the energetic advantages of quantum devices for their training along with the unified single-loop optimization introduced here may offer a compelling approach to train large ML models with a reduced carbon footprint in the future.

###### Acknowledgements.

 We acknowledge Maciej Koch-Janusz, Roeland Wiersema, Roger Melko, and Behnam Javanparast for discussions. JC acknowledges support from the Natural Sciences and Engineering Research Council (NSERC), the Shared Hierarchical Academic Research Computing Network (SHARCNET), Compute Canada, and the Canadian Institute for Advanced Research (CIFAR) AI chair program. Resources used in preparing this research were provided, in part, by the Province of Ontario, the Government of Canada through CIFAR, and companies sponsoring the Vector Institute www.vectorinstitute.ai/#partners.
