Physics informed neural networks learning a two-qubit Hamiltonian
Machine learning techniques are employed to perform the full characterization
of a quantum system. The particular artificial intelligence technique used to
learn the Hamiltonian is called physics informed neural network (PINN). The
idea behind PINN is the universal approximation theorem, which claims that any
function can be approximate by a neural network if it contains enough
complexity. Consequently, a neural network can be a solution of a physical
model. Moreover, by means of extra data provided by the user, intrinsic
physical parameters can be extracted from the approach called inverse-PINN.
Here, we apply inverse-PINN with the goal of extracting all the physical
parameters that constitutes a two qubit Hamiltonian. We find that this approach
is very efficient. To probe the robustness of the inverse-PINN to learn the
Hamiltonian of a two-qubit system, we use the IBM quantum computers as
experimental platforms to obtain the data that is plugged in the PINN. We found
that our method is able to predict the two-qubit parameters with 5% of accuracy
on average.
Leonardo K. Castelano, Iann Cunha, Fabricio S. Luiz, Marcelo V. de Souza Prado, Felipe F. Fanchini
# Physics informed neural networks learning a two-qubit Hamiltonian

###### Abstract

Machine learning techniques are employed to perform the full characterization of a quantum system. The particular artificial intelligence technique used to learn the Hamiltonian is called physics informed neural network (PINN). The idea behind PINN is the universal approximation theorem, which claims that any function can be approximate by a neural network if it contains enough complexity. Consequently, a neural network can be a solution of a physical model. Moreover, by means of extra data provided by the user, intrinsic physical parameters can be extracted from the approach called inverse-PINN. Here, we apply inverse-PINN with the goal of extracting all the physical parameters that constitutes a two qubit Hamiltonian. We find that this approach is very efficient. To probe the robustness of the inverse-PINN to learn the Hamiltonian of a two-qubit system, we use the IBM quantum computers as experimental platforms to obtain the data that is plugged in the PINN. We found that our method is able to predict the two-qubit parameters with 5% of accuracy on average.

## I Introduction

A significant amount of effort has been invested in the development of new technologies aimed at advancing the field of quantum computing due to its potential to revolutionize digital computing. Precise knowledge of the quantum system, described by a Hamiltonian containing both local and non-local terms, is essential for performing quantum operations and subsequently implementing quantum algorithms. Therefore, the extraction of this information from experimental data becomes a crucial task. Interest in the application of artificial intelligence (AI) to address scientific challenges has been rapidly growing [1; 2; 3; 4].The use of AI in physics began with the analysis of particle physics experiments [5; 6; 7]. Other applications include the application of machine learning (ML) in condensed matter systems [8; 9], exploring the AdS/CFT correspondence [10], and phase transition determination [11].

More recently, the concept of physics-informed neural network (PINN) has been introduced, where differential equations describing the physics of the problem are introduced in the training of the neural network [12; 13; 14]. This approach offers the advantage of reducing the amount of training data required, as the neural network is constrained to satisfy the differential equations that adhere to physical laws [12; 13; 14]. Furthermore, the idea of learning and extracting information from a collection of data can also be implemented through the inverse-PINN [12; 13; 14]. In this case, data is provided along with the equations and physical parameters can be extracts from the model.

Several approaches to learn a Hamiltonian have been proposed in the past. Some rely on the tomography of the density matrix [15; 16; 17], while other protocols focus on utilizing states that inherently encode information about the Hamiltonian, such as steady states and thermal states [18; 19].Various learning proposals have been put forward that eliminate the need for preparing specialized initial states [20]. For instance, the parameters of the Hamiltonian can be derived from the Ehrenfest theorem [21] or from measuring state properties through their evolution to identify the nearest-neighbor coupled Hamiltonian in superconducting systems [22]. Yu at al. [23] proposed a method that utilizes short-time Hamiltonian evolution and exploits ideas from randomized benchmarking [24].

In this paper, we apply the technique of inverse-PINN to perform the Hamiltonian tomography for a two-qubit system. Experimental data at specific points is also required to extract these parameters. As is well-known, measurements in quantum mechanics are probabilistic and necessitate repeated preparation of the initial configuration for statistical measurement. If measurements are performed as a function of time, statistical measurements must be conducted for each time step. Therefore, probing all observables as a function of time requires a significant number of repetitions of the experiment. To address this issue, we investigate the accuracy of inverse-PINN as a function of the number of collocation points for density matrix tomography measurements. Here, collocation points refer to the points in the time domain where density matrix tomography is performed. We found that inverse-PINN can accurately provide the coupling between the qubits with a reduced number of collocation points. We also incorporate errors into our theoretical model for density matrix tomography to estimate the robustness of the predicted parameters. Finally, we implemented an experiment on IBM quantum computers to address a real-world problem, and we successfully learned the two-qubit Hamiltonian with an error of less than 5% on average, using only 20 collocation data points.
Theoretical model

The general Hamiltonian for two-qubit can be written as

\[H=-\frac{\hbar}{2}\sum_{l=0}^{3}\sum_{k=0}^{3}J_{k,l}\sigma_{k}\otimes\sigma_{l}, \tag{1}\]

where \(\sigma_{k}\) denote the corresponding Pauli matrix for \(k=1,2,3\), and \(\sigma_{0}\) is the identity matrix. There are fifteen \(J_{k,l}\) terms that describe local and non-local interactions between the two-qubit. The term \(J_{0,0}\) only provides a reference for the energy and we set it equal to zero. The expected value for the corresponding observable can be calculated from

\[\langle\sigma_{k}\sigma_{l}\rangle(t)=\text{Tr}[\rho(t)\sigma_{k}\otimes\sigma _{l}], \tag{2}\]

where \(k,l\in\{0,3\}\) and \(\rho(t)\) is the density matrix for the two-qubit at time \(t\). Moreover, the dynamics of the observables must be included in the inverse-PINN, thus we use the Heisenberg equation

\[\frac{d\langle\hat{O}_{m}\rangle(t)}{dt}=\frac{i}{\hbar}\langle[H,\hat{O}_{m}]\rangle. \tag{3}\]

The above equation for \(\langle\hat{O}_{m}\rangle\), must be implemented for all 15 physical terms corresponding to all \(\sigma_{k}\sigma_{l}\) different from identity. In this case, we are let to 15 coupled ordinary differential equations that must be solved for an initial condition to obtain the desired parameters.

The idea behind PINN is to model the solutions of the differential equations by a neural network and to minimize the loss function. Particularly, the loss function can be written as

\[L=L_{model}+L_{data}, \tag{4}\]

where

\[L_{model}=\sum_{m=1}^{15}\sum_{j=1}\left|\left(\frac{d\langle\hat{O}_{m} \rangle}{dt}-\frac{i}{\hbar}\langle[H,\hat{O}_{m}]\rangle\right)\right|_{t_{j }}\right|^{2}. \tag{5}\]

The loss function associated to the model \(L_{model}\) provides the values of \(\langle\hat{O}_{m}\rangle\) at the collocation points \(t_{j}\), which are mapped onto the NN, consequently the solutions of the differential equations are represented by the NN. The loss function \(L_{data}\) is related to the data extracted from the experiment. This loss function impose the constraint for the solutions of the differential equations fit the experimental data in the collocation points. In this sense, the inverse-PINN forces the NN to be both the solutions of the differential equations and to represent the experimental data, thereby performing the Hamiltonian tomography and extracting the physical parameters \(J_{k,l}\).

## III Results

We start by analyzing two simpler models, the \(H_{Z}\) and the \(H_{XYZ}\) Hamiltonians. The first Hamiltonian is

\[H_{Z}=-\frac{\hbar}{2}\left(J_{0,3}\sigma_{0}\otimes\sigma_{3}+J_{3,0}\sigma_{ 3}\otimes\sigma_{0}+J_{3,3}\sigma_{3}\otimes\sigma_{3}\right), \tag{6}\]

which has been used to fit experimental data related to quantum dots [25]. The second Hamiltonian is the XYZ model without local terms, thus

\[H_{XYZ}=-\frac{\hbar}{2}\left(J_{1,1}\sigma_{1}\otimes\sigma_{1}+J_{2,2} \sigma_{2}\otimes\sigma_{2}+J_{3,3}\sigma_{3}\otimes\sigma_{3}\right). \tag{7}\]

Both cases have the advantage of decoupling some differential equations, thus there are only four coupled ode's for \(J_{0,3}\) and \(J_{3,3}\) (\(J_{1,1}\) and \(J_{3,3}\)). Symmetric equations for \(J_{3,0}\) and \(J_{3,3}\) (\(J_{2,2}\) and \(J_{3,3}\)) complete the set of ode's. Because these equations are symmetric, we can only solve a set of four ode's to study the results for these cases. First, we make an analysis concerned on the number of points of experimental data needed. To perform such a task, we provide data without errors by numerically solving equations 3 considering the values of the parameters \(J_{k,l}\) randomly sorted between \([-\omega_{0},\omega_{0}]\), where \(\omega_{0}=2\pi/T\) and \(T\) is the final time of evolution. The first analysis that we perform concerns on accuracy of the extracted parameter versus the number of collocations points. The accuracy is measured by the mean absolute error, which is defined as follows:

\[MAE=\frac{1}{D}\sum_{i=1}^{D}\frac{|P_{i}^{exact}-P_{i}^{pred}|}{|P_{i}^{ exact}|}, \tag{8}\]

where \(D\) is the number of physical parameters, \(P_{i}^{exact}\) (\(P_{i}^{pred}\)) denotes the i-th exact (predicted) physical pa

Figure 1: MAE for the \(H_{Z}\) Hamiltonian (top panel) and for the \(H_{XYZ}\) Hamiltonian (bottom panel) as a function of the number of collocation points.
rameter. In Figure 3, we plot the MAE as a function of the number of collocations points in time for both Hamiltonians \(H_{Z}\) (top panel) and \(H_{XYZ}\) (bottom panel). We use \(D=50\) in both cases and we plot the results using the boxplot method to show the spread of the data. Thus, the lowest (highest) marker shows the lowest (highest) data point in the data set excluding any outliers, which are data points that differ significantly from other observations. The lowest (highest) marker of the blue box is related to the lower (higher) quartile and the marker inside the blue box indicates the median. Figure 3 demonstrates that MAE is lower than 0.4% for only 5 collocation points, which is a evidence for performing the Hamiltonian tomography with very good accuracy.

To further analyze the performance of the Hamiltonian tomography, we add a random Gaussian error in the parameters, which is characterized by the standard deviation \(\sigma\). In this case, parameters \(J_{k,l}\) in equation (1) are modified according to \(J_{k,l}\to J_{k,l}^{0}+E_{k,l}\), where \(E_{k,l}\) is a random variable with Gaussian distribution characterized by \(\sigma\). The idea is to generate the input data for the inverse-PINN considering the error \(E_{k,l}\) and try to predict the value \(J_{k,l}^{0}\) without error.

In Figure 2, we plot the MAE as a function of the standard deviation \(\sigma\) related to the Gaussian distribution of the errors for both Hamiltonians \(H_{Z}\) (top panel) and \(H_{XYZ}\) (bottom panel) considering only \(N=5\) collocation points. In this case, we notice that the Hamiltonian tomography has at least 5% accuracy if the standard deviation is less than 1%. On the contrary, if the error has a 10% standard deviation, the accuracy measured by MAE is very poor when using only \(N=5\) collocation points. We repeated the same analysis by increasing the number of collocation numbers (results not shown here) and we found that it is possible to improve the Hamiltonian accuracy by increasing the number of collocations number, _e.g._, we can get MAE \(<7\%\) for \(\sigma=10\%\) when \(N=100\). After checking that the inverse-PINN provides a good accuracy for the tomography of \(H_{Z}\) and \(H_{XYZ}\), we repeat the same analysis for the general two qubit Hamiltonian (Eq. 1), whose results are shown in Figure 3. In the top panel of Figure 3, we plot MAE versus collocation points for the input data provided without errors. We can conclude that at least N=10 collocation points are necessary for an accurate prediction of the physical parameters of the general Hamiltonian (Eq. 1). In the bottom panel of Figure 3, we consider N=20 collocation points and we include the random Gaussian error in the input data. In this case, we can see that the MAE is less than 3% for a standard deviation of 1%, which is very similar to the results found for \(H_{Z}\) and \(H_{XYZ}\) Hamiltonians. This result demonstrates that the inverse-PINN can indeed learn the general Hamiltonian with good accuracy considering at least N=20 collocation points, even though errors in the measurements are present. As a final test, we simulate the \(H_{Z}\) the \(H_{XYZ}\) Hamiltonians in the IBM quantum computers. We use these two Hamiltonians because of their easy representation in terms of quantum gates, which do not require any Trotter approximation. In Figure 3, we plot the MAE for both \(H_{Z}\) and \(H_{XYZ}\) Hamiltonians as a function of the number of collocation points. The difference of these results from the previous ones is related to the input data, which was experimentally obtained from the IBM quantum computers. For the \(H_{Z}\) Hamiltonian (top panel of Figure 3), we find that the MAE only achieves values less than 5% for 20 collocation points. On the other hand, the results in the bottom panel of Figure 3 for the \(H_{XYZ}\) Hamiltonian, show that the MAE is already less than 5% on average for only 5 collocation points. We believe that this differ

Figure 3: MAE as a function of the number of collocation points (top panel). MAE as a function of the standard deviation for N=20 collocation points (bottom panel). Both panels are related to the general two qubit Hamiltonian and are plotted in logarithm scale.

Figure 2: MAE for the \(H_{Z}\) Hamiltonian (top panel) and for the \(H_{XYZ}\) Hamiltonian (bottom panel) as a function of the standard deviation for N=5 collocation points.
ence might be due to errors introduced in the realization of the quantum gates in the IBM quantum computer.

## IV Conclusion

We applied a technique called inverse-PINN, which is based on neural networks, to extract the parameters of a two-qubit Hamiltonian. First, we tested two Hamiltonians of interest, one containing only terms in the z-direction and the so called XYZ model without local terms. We found that the inverse-PINN is able to find the parameters of both Hamiltonians with great accuracy, when the input data is provided without errors. When we include errors, by considering a Gaussian dispersion in the parameters that generate the input data, we still are able to estimate the real parameters with 5% accuracy, if we use at least 20 collocation points. We also simulate a full two-qubit Hamiltonian, where there are 15 parameters to be learned and the results for the general case are similar to those found for the particular Hamiltonians. Furthermore, we use the input data obtained from the IBM quantum computers for the \(H_{Z}\) and \(H_{XYZ}\) Hamiltonians as an real scenario for our approach. In this case, we also found results with very good accuracy, similar to those found using the results with Gaussian dispersion. We believe that this approach is very powerful and can be used in other important tasks related to the improvement of quantum computation platforms.

###### Acknowledgements.

 The authors are grateful for financial support by the Brazilian Agencies FAPESP, CNPq and CAPES. LKC thanks to the Brazilian Agencies FAPESP (grant 2019/09624-3) for supporting this research.
