Neural network encoded variational quantum algorithms
We introduce a general framework called neural network (NN) encoded
variational quantum algorithms (VQAs), or NN-VQA for short, to address the
challenges of implementing VQAs on noisy intermediate-scale quantum (NISQ)
computers. Specifically, NN-VQA feeds input (such as parameters of a
Hamiltonian) from a given problem to a neural network and uses its outputs to
parameterize an ansatz circuit for the standard VQA. Combining the strengths of
NN and parameterized quantum circuits, NN-VQA can dramatically accelerate the
training process of VQAs and handle a broad family of related problems with
varying input parameters with the pre-trained NN. To concretely illustrate the
merits of NN-VQA, we present results on NN-variational quantum eigensolver
(VQE) for solving the ground state of parameterized XXZ spin models. Our
results demonstrate that NN-VQE is able to estimate the ground-state energies
of parameterized Hamiltonians with high precision without fine-tuning, and
significantly reduce the overall training cost to estimate ground-state
properties across the phases of XXZ Hamiltonian. We also employ an
active-learning strategy to further increase the training efficiency while
maintaining prediction accuracy. These encouraging results demonstrate that
NN-VQAs offer a new hybrid quantum-classical paradigm to utilize NISQ resources
for solving more realistic and challenging computational problems.
Jiaqi Miao, Chang-Yu Hsieh, Shi-Xin Zhang
# Neural network encoded variational quantum algorithms

###### Abstract

We introduce a general framework called neural network (NN) encoded variational quantum algorithms (VQAs), or NN-VQA for short, to address the challenges of implementing VQAs on noisy intermediate-scale quantum (NISQ) computers. Specifically, NN-VQA feeds input (such as parameters of a Hamiltonian) from a given problem to a neural network and uses its outputs to parameterize an ansatz circuit for the standard VQA. Combining the strengths of NN and parameterized quantum circuits, NN-VQA can dramatically accelerate the training process of VQAs and handle a broad family of related problems with varying input parameters with the pre-trained NN. To concretely illustrate the merits of NN-VQA, we present results on NN-variational quantum eigensolver (VQE) for solving the ground state of parameterized XXZ spin models. Our results demonstrate that NN-VQE is able to estimate the ground-state energies of parameterized Hamiltonians with high precision without fine-tuning, and significantly reduce the overall training cost to estimate ground-state properties across the phases of XXZ Hamiltonian. We also employ an active-learning strategy to further increase the training efficiency while maintaining prediction accuracy. These encouraging results demonstrate that NN-VQAs offer a new hybrid quantum-classical paradigm to utilize NISQ resources for solving more realistic and challenging computational problems.

_Introduction._ - Today's noisy intermediate-scale quantum (NISQ) computers [1] are far from delivering an unambiguous quantum advantage. Variational quantum algorithms (VQAs), as one of the most representative algorithm primitives in the NISQ era [2; 3; 4; 5], utilize a quantum-classical hybrid scheme, where the quantum processor prepares target quantum states and measurement is made to extract useful information for the classical computer to explore and optimize. VQAs have now been widely applied to solve quantum optimization, quantum simulation, and quantum machine learning problems [6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 16].

Among various VQAs, the variational quantum eigensolver (VQE) [6; 7] certainly stands out as one of the most exemplary algorithms. VQE employs Rayleigh-Ritz variational principle to approximate the ground state of a given Hamiltonian \(\hat{H}\) with a parameterized quantum circuit (PQC). Many studies on the strengths and fundamental limitations of VQAs are first systematically investigated and revealed by studying how VQE performs in different contexts. Despite some early hopes of VQAs' potential quantum advantages in addressing some realistic computational problems, this goal still remains elusive. In fact, it is now known that the current formulation of the vanilla VQAs faces way too many obstacles for them to deliver any practical advantages.

There is a pressing need to develop novel hybrid quantum-classical approachs to better utilize the full power of quantum computational resources while avoiding as many shortcomings of the vanilla VQAs as possible. For instance, a core problem of the standard VQA is to identify the suitable circuit parameters for a given problem, i.e. the optimization or training procedure. From a practical perspective, the training procedure often takes many steps which leads to a large budget for measurement shots. Besides, the training procedure could be more sensitive to noise and decoherence compared to the inference procedure. Therefore, training of VQAs is expensive as it must be conducted on very high-quality quantum devices with a large budget of measurement shots.

In terms of theoretical perspective, the difficulties associated with the optimization of VQAs stem from at least two fundamental obstacles. One severe challenge is the phenomenon of vanishing gradients named barren plateaus (BPs) [17; 18; 19; 20; 21]. Though there are many attempts to mitigate BP issues [22; 23; 24; 25; 26; 27; 28; 29; 30; 31; 32], the occurrence of BP, in general, implies that exponential quantum resources are required to navigate through the exponentially flattened cost function landscape \(C(\theta)\), which could negate the potential quantum advantages of VQAs. Another related problem for VQAs' non-convexity energy landscape is the occurrence of many local minima [33; 34], which can easily trap the training trajectories.

In the plain VQA setups, application problems are optimized and solved instance by instance with the same circuit structure, namely, we need to retrain the model for each instance. This workflow renders the optimization issues discussed above more detrimental in the VQA context. Therefore, a general framework to solve the parameterized problem instances jointly and to separate the pre-training process from the inference process is highly desired. Such a framework would address the optimization bottlenecks from two angles. For the pre-training procedure, the joint training on multiple problem instances speeds up the optimization convergence by al
leviating the BP and local minima issues. And for the inference procedure conducted by the end-users, there is no need to retrain or fine-tune the model so that the end-users with limited quantum resources are free from the thorny training issues.

In this Letter, we introduce a general framework - neural network encoded variational quantum algorithms (NN-VQAs). There are many works that integrate the neural network with the quantum circuit from different angles such as quantum state tomography, quantum error mitigation, quantum architecture search, and expressive capacity enhancement [28; 35; 36; 37; 38; 39; 40; 41; 42; 43; 44; 45; 46]. Our framework further expands the possibility of such an interplay from a new perspective. NN-VQAs successfully address all the aforementioned challenges: (i) NN-VQAs use the Hamiltonian parameters as the input to a neural network, which enables to solve a parameterized model through only a single pre-training process; (ii) the pre-trained NN-VQAs can give a good estimation with test Hamiltonians beyond the training set with good generalization capability; (iii) active learning method can be adopted to further reduce the number of training samples and thus the number of total measurement shots; (iv) NN-VQAs could significantly speedup the optimization convergence of VQAs, alleviating the issues of BP and local minima. Therefore, by using a neural network as the encoding module, our approach provides a good ground state approximation using only a small number of training points and greatly saves the required quantum resources. Moreover, our framework can enable the separation of training and inference and sketch a potential future interface to utilize VQAs for end-users.

_Theoretical Framework._ - In this section, we introduce the framework of NN-VQE for ground state problems, and the framework can be similarly generalized to VQE for excited states [47; 48; 49] or other VQA scenarios.

The schematic workflow for NN-VQE is shown in Fig. 1. Given a parameterized Hamiltonian \(\hat{H}=\hat{H}(\mathbf{\lambda})\), where \(\mathbf{\lambda}\) consists of \(p\) different Hamiltonian parameters, our aim is to solve the ground state of the parameterized Hamiltonian. We choose a subset of \(\mathbf{\lambda}\) as the training set \(\mathbf{\tilde{\lambda}}=\{\mathbf{\tilde{\lambda}}_{i}\}\).

To train an NN-VQE, we use \(\mathbf{\tilde{\lambda}}\) as the input of the encoding neural network, and get the output

\[\mathbf{\theta}_{i}=f_{\mathbf{\phi}}(\mathbf{\tilde{\lambda}}_{i}), \tag{1}\]

where we denote the neural network as a general parameterized function \(f_{\mathbf{\phi}}\) with the training neural weights as \(\mathbf{\phi}\). The number of the output of the neural network is the same as the number of the PQC parameters, and we load each neural network output element to the corresponding circuit parameters. The PQC \(U(\mathbf{\theta})\) for VQE is initialized in the \(\ket{\mathbf{0}}=\ket{0}^{\otimes n}\) state. Therefore, the output target state for Hamiltonian \(\hat{H}(\mathbf{\tilde{\lambda}}_{i})\) should be

\[\ket{\psi_{i}}=U(\mathbf{\theta})\ket{\mathbf{0}}=U\left(f_{\mathbf{\phi}}(\mathbf{\tilde{ \lambda}}_{i})\right)\ket{\mathbf{0}}. \tag{2}\]

The cost function for ground state VQE is the expecta

Figure 1: Schematic workflow for NN-VQE. The Hamiltonian parameters \(\mathbf{\lambda}\) are the input of the encoder neural network, which produces the parameterized quantum circuit (PQC) parameters \(\mathbf{\theta}\) as output. The PQC, parameterized by \(\mathbf{\theta}\), is then used in the processing module of the VQE to prepare an output state \(\ket{\psi}=U(\mathbf{\theta})\ket{\mathbf{0}}\), where \(\ket{\mathbf{0}}\) is the initial state. The cost function can be estimated according to Eq. (3), and the weights in the neural network are optimized using a gradient-based optimizer.

Figure 2: Results on \(n=8\) qubit one-tunable-parameter 1D XXZ spin chain with a transverse field strength \(\lambda=0.75\) within NN-VQE framework: (a) Relative errors of ground-state energies of different circuit block depth \(D\) with and without dropout from the pre-trained model. (b) Fidelity between the output state of NN-VQE and the exact ground state.
tion of \(\hat{H}(\mathbf{\lambda})\):

\[C\left(\mathbf{\phi}\right)=\sum_{i}\langle\hat{H}(\mathbf{\tilde{\lambda}} _{i})\rangle\] \[=\sum_{i}\left\langle\mathbf{0}\right|U^{\dagger}\left(f_{\mathbf{\phi}}( \tilde{\lambda}_{i})\right)\hat{H}(\tilde{\lambda}_{i})U\left(f_{\mathbf{\phi}}( \tilde{\lambda}_{i})\right)\left|\mathbf{0}\right\rangle. \tag{3}\]

Finally, we compute the gradients with respect to the neural network (back-propagation via the PQC parameters) and minimize the cost function \(C\left(\mathbf{\phi}\right)\) using gradient descent, obtaining the optimal weights \(\mathbf{\phi^{\star}}\) for the neural network. Since such a training procedure only happen once and the trained model can be used to approximate the ground state of the family of Hamiltonians, we call this stage pre-training. Upon completion of pre-training, the efficacy of the NN-VQE can be evaluated using a test set of different \(\mathbf{\lambda}\) from the training set.

_Results_. - In this section, we demonstrate the effectiveness of our framework using numerical simulation with TensorFlowCircuit [50]. The testbed model is the one-dimensional (1D) antiferromagnetic XXZ spin Hamiltonian with an external magnetic field subject to the periodic boundary conditions

\[\hat{H}=\sum_{i,i+1}\left(X_{i}X_{i+1}+Y_{i}Y_{i+1}+\Delta Z_{i}Z_{i+1} \right)+\lambda\sum_{i}Z_{i}, \tag{4}\]

where \(\Delta\) is the anisotropy parameter and \(\lambda\) is the transverse field strength.

We start from the one-parameter XXZ model with the transverse field strength fixed to \(\lambda=0.75\). The training set of \(\Delta\) is composed of 20 equispaced points in the interval of \([-3.0,3.0]\). The performance of the NN-VQE is evaluated on an expanded test set consisting of 201 equispaced values of \(\Delta\) in the interval of \([-4.0,4.0]\). The circuit ansatz we use in this section is inspired by MERA [51; 52]. Specifically, we employ deep multi-scale entanglement renormalization ansatz (DMERA) circuits [53; 54], where \(D\) is the circuit depth in each block (see the SM for details). The neural network we use is a simple fully connected neural network with a dropout layer. The size of the input layer is 1 corresponding to the number of Hamiltonian parameters \(\Delta\), and the size of the output layer corresponds to the number of PQC parameters (see the SM for the detailed neural structure).

For the 1D XXZ spin chain consisting of 8 qubits, we pre-train the model within the NN-VQA framework and evaluate the performance with different circuit block depths \(D\). The results for ground state (GS) energy prediction are shown in Fig. 2(a). The simulation accuracy improves with larger \(D\) and dropout in the neural network. We also display the corresponding fidelities with the exact ground state in Fig. 2(b). The results underscore the ability of the NN-VQE to effectively prepare the ground state as a function of the Hamiltonian parameters without fine-tuning or retraining. We note that NN-VQE demonstrates a favorable generalization capability. As shown in Fig. 2, in regions devoid of shadows on either side (regions of no training points), the NN-VQE still provides highly reliable estimations to some extent.

Compared with previous work on meta-VQE [55], when the PQC structures are the same, NN-VQE uses fewer quantum resources while yielding better ground-state energy estimation results (see the SM for details). Such advantages are mainly brought by the expressive power of general neural networks.

In the previous analysis, the training set is selected in an equispaced manner. Such a strategy can be improved by utilizing active learning techniques [56]. We can maintain the same level of ground-state energy accuracy while using a smaller number of training points.

Various active learning schemes can be easily incorporated into the NN-VQE. For example, we begin by randomly selecting one point from the \(\Delta\) pool \(P\) as the initial training set. We train the NN-VQE based on the training set and get the neural network weights \(\mathbf{\phi^{\star}}\). Obviously, the training set \(P^{*}\) is a subset of the pool \(P\). Subsequently, we calculate the acquisition function specifically designed in this scenario. The active learning acquisition function in our problem is defined as

\[C_{AL}=\langle\hat{H}^{2}(\Delta)\rangle_{\mathbf{\phi^{\star}}}-\langle\hat{H}( \Delta)\rangle_{\mathbf{\phi^{\star}}}^{2}+\mu\min|\Delta-\mathbf{\Delta^{\star}}|, \tag{5}\]

where \(\Delta\in P\), \(\Delta^{*}\in P^{*}\), \(\mu\) a preset hyperparameter. The first two terms are the variance of the Hamiltonian \(\hat{H}(\Delta)\) with \(\mathbf{\phi^{\star}}\) trained on the training set. In the last

Figure 3: Active learning for NN-VQE. We use MERA circuit with \(D=2\). The black line is the result of VQE separately trained on each point. The green line is the NN-VQE with dropout and has the same circuit structure as the black line. The blue line shares the same structure (NN encoder and circuit ansatz) as the green line but uses active learning to reduce sample size. The training set of the green line consists of a set of equispaced 20 \(\Delta\)s in the interval of \([-3.0,3.0]\) used in the previous analysis. However, by employing active learning, we use only 11 actively selected points to attain the blue line. The training set used for active learning is indicated by dots along the blue line. Remarkably, despite the reduced training set size, the blue line still exhibits a reliable estimation of the ground-state energy. The actively chosen dots are projected onto the x-axis as the orange dots, and the orange inverted triangles are the phase transition points.
term, we first calculate the distance between \(\Delta\) and all \(\mathbf{\Delta^{*}}\) in the training set and find the minimum distance. We employ the hyperparameter \(\mu\) to find a large variance but prevent a close point from being chosen. The two terms reflect the exploitation and exploration trade-off of the active learning technique. We add the \(\Delta\) with the largest \(C_{AL}(\Delta)\) to the training set. Iteratively, we repeat this process of expanding the training set until the test relative error of the ground-state energy falls below a predetermined threshold.

By this method, we obtain a training set consisting of 11 points. The corresponding results are shown in Fig. 3. Remarkably, even with a training set size that is only half of the previous set, the model still gives a reliable estimation of the ground-state energy. Moreover, when we visualize the training sets (see the orange dots in Fig. 3), we find them nearly equispaced except for the points near the phase transition point of the Hamiltonian (see the orange inverted triangles in Fig. 3). This observation roughly corresponds to an intuition that the ground-state wavefunction might experience a more dramatic change around the phase transition point which requires more training points to better capture.

Another remarkable advantage of NN-VQE is the training efficiency. As shown in Fig. 4 (a)(c), NN-VQE has a significant speedup in the optimization procedure compared with plain VQE. The energy cost function drops more rapidly, which offers great benefits for NISQ computers since fewer training epochs and thus fewer quantum resources are required. Such advantages benefit from the NN-PQC hybrid architecture. The neural network brings a more dramatic change in the PQC parameters at the beginning stage of the optimization process as shown in Fig. 4 (b)(d), which might also be relevant in mitigating the BP issue.

In order to demonstrate the effectiveness of the NN-VQE in estimating a multiparameter Hamiltonian, we extend our study to the two-parameter XXZ model. In this model, both the anisotropy parameter \(\Delta\) and the transverse field strength \(\lambda\) are tunable in the Hamiltonian in Eq. 4. The training set for \(\Delta\) consists of 10 equispaced points in the interval of \([-1.0,1.0]\), while for \(\lambda\) consists of 5 equispaced points in the interval of \([0.0,1.0]\). The ansatz used is the hardware-efficient ansatz [58] with two-qubit gates in the ladder layout of depth \(D\) (see the SM for details). The encoding neural network also shares a similar structure as the one-parameter case but now the input takes two values \(\Delta\) and \(\lambda\).

The numerical results are presented in Fig. 5. Remarkably, the NN-VQE, using a neural network with two inputs, yields excellent performance in estimating the ground state across different phases. This result implies the robustness and versatility of the NN-VQE in simulating complex quantum systems governed by a multiple-parameter Hamiltonian.

_Discussion. -_ In this Letter, we introduce the NN-VQA framework. More specifically, we first use a neural network to transform the Hamiltonian parameters to the optimized parameters in the PQC for VQA. We show the validity and effectiveness of the framework in solving the XXZ Hamiltonian ground state with different parameters through only one pre-training procedure without

Figure 5: Relative errors of ground-state energies for an \(n=12\) 1D XXZ spin chain with two tunable Hamiltonian parameters, using hardware-efficient ansatz with circuit depth \(D=1,2\). The red dots are the training set. The red lines are the exact phase transition line between the ferromagnetic phase (FM) and the XY phase [57].

Figure 4: Speedup in the optimization process of NN-VQE and the corresponding PQC parameter changes. (a)(c) The ground-state energy relative errors for an \(n=12\) XXZ spin chain when \(\Delta=1.5,2.0\) are shown with respect to epochs. Hardware-efficient ansatz with \(D=3\) is used. The red and blue lines correspond to the ground-state energy relative errors and standard deviation of NN-VQE and VQE respectively. (b)(d) The parameter differences when training VQE and NN-VQE in corresponding \(\Delta\). The difference is the sum of the absolute value of parameter differences between epochs. NN-VQE brings a more dramatic circuit parameter change at the beginning of the optimization process, which speedups the optimization process.
any problem instance specific fine-tuning. In order to further reduce the pre-training overhead, we also employ an active learning heuristic where the progressively built training set can be greatly reduced. We also find that the NN-VQE pipeline can speed up the training process.

In terms of the neural network part, we can introduce more physics-inspired neural network structures for multi-parameter Hamiltonian VQE problems. For example, considering the random Ising model where the couplings at each bond or site are different, we can abstract the Hamiltonian parameters as a graph where the node and edge weights describe the Hamiltonian form. In such cases, we believe a graph neural network (GNN) [59; 60] is more suitable for the encoding task as the symmetry and geometry can also be properly addressed in a well-designed GNN. And the power of considering local geometry as in the GNN approach is proven to be exponentially sample efficient in learning quantum state properties [61; 62; 63; 64].

Our framework envisions a future paradigm to utilize quantum computers. The encoding neural network can be pre-trained on high-quality quantum devices with a large time and measurement budget. The pre-trained model can be efficiently saved on classical computers and shared via the cloud. Since the NN-VQE can be targeted to a large family of quantum systems that can be connected via lots of parameters, a large pre-trained model could be of general interest for solving various problems. The end-users can download the large pre-trained classical model and extract the trained circuit parameters given the specific problem they are interested in solving. In this paradigm, the end users are free from training on quantum computers and can utilize the power of quantum computers more efficiently. It is also worth noting that at the training stage, due to the nature of multiple training points, it is very easy to utilize the data parallelism and pre-train the NN-VQE with many quantum computers.

_Acknowledgements:_ We gratefully thank Gaoxiang Ye for useful discussions.
