In this section, we implement a variational quantum eigensolver for a two-qubit Heisenberg model.
5.1 Background
Quantum algorithms such as the Grover search [48], Shor factorization [70, 71] and HHL [50], have proven advantages over their best known classical counterparts. However, these algorithms cannot be efficiently implemented on near-term quantum devices due to inevitable physical noises in quantum gates. Variational quantum algorithms (VQA) [72–78], a class of algorithms under the hybrid quantum-classical framework, are more promising to have practical applications on noisy intermediate-scale quantum computers [79]. VQA use a parameterized quantum circuit to estimate the cost function \(C(\boldsymbol{\theta })\) and update θ with a classical optimizer. Variational quantum eigensolver (VQE) [73, 80] is a paradigmatic example of VQA that aims to find the ground state and ground state energy of a given Hamiltonian H. In this section, we will demonstrate the experimental realization of VQE on Gemini.
5.2 Algorithm
In classical computaitional physics (chemistry), we usually estimate the ground state energy of H through variational approaches: parameterize a wave function \(\mathopen \vert \psi \mathclose \rangle =\mathopen \vert \psi (\boldsymbol{\theta })\mathclose \rangle \), update θ to minimize the expectation value \(\mathopen \langle \psi (\boldsymbol{\theta })\mathclose \vert H\mathopen \vert \psi (\boldsymbol{\theta })\mathclose \rangle \) until convergence. VQE facilitates the above procedure with a quantum computer. The wave function is parameterized with a quantum circuit \(U(\boldsymbol{\theta })\) applied to the initial state \(\mathopen \vert \boldsymbol{0} \mathclose \rangle = \mathopen\vert 0\mathclose\rangle ^{\otimes n}\), and we optimize θ to minimize the expectation value,
$$ E(\boldsymbol{\theta })=\mathopen \langle \boldsymbol{0}\mathclose \vert U^{\dagger }(\boldsymbol{\theta }) H U(\boldsymbol{\theta }) \mathopen \vert \boldsymbol{0}\mathclose \rangle . $$
(17)
The classical optimizer can either be gradient-based methods like SGD, Adam, RMSprop, BFGD, or gradient-free methods like Nelder–Mead, Powell. Hardware-efficient ansatz [73], unitary coupled clustered ansatz [81], and Hamiltonian variational ansatz [82, 83] are common choices for \(U(\boldsymbol{\theta })\). In VQE, the gradient can be directly estimated via the parameter-shift rule [84, 85], i.e.,
$$ \frac{\partial E(\boldsymbol{\theta })}{\partial \theta _{i}}=\bigl(\mathopen \langle H\mathclose \rangle _{ \boldsymbol{\theta }_{i}^{+}}- \mathopen \langle H\mathclose \rangle _{ \boldsymbol{\theta }_{i}^{-}}\bigr)/2, $$
(18)
where \(\boldsymbol{\theta }_{i}^{\pm } = \boldsymbol{\theta }\pm \frac{\pi }{2} \boldsymbol{e}_{i}\), \(\boldsymbol{e}_{i}\) is the ith unit vector in the parameter space. Higher order derivatives \(\frac{\partial ^{2} E(\boldsymbol{\theta })}{\partial \theta ^{2}_{i}}\), \(\frac{\partial ^{3} E(\boldsymbol{\theta })}{\partial \theta ^{3} _{i}}\), which are required in some optimizers, can be estimated in a similar way [86].
5.3 Experimental protocol
In this work, we apply VQE to find the ground state of 2-qubit Heisenberg model. The Hamiltonian is
$$ H_{H} = X_{1}X_{2} + Y_{1} Y_{2} + Z_{1}Z_{2}, $$
(19)
where \(X_{j}\), \(Y_{j}\), \(Z_{j}\) are the Pauli operators on the jth qubit. The hardware efficient circuit is shown in Fig. 15.
We implement experiments on SpinQ Gemini and IBM Q Yorktown with initial parameter \(\boldsymbol{\theta }=[ 10.2^{\circ } , 8.35^{\circ }, 108^{\circ },91.5^{ \circ }]\), learning rate \(\alpha =0.25\), and carry out numerical simulations.
IBM Q Yorktown is a superconducting quantum computer with 5 qubits [87], the structure is shown in Fig. 16. We only use the first two qubits \(Q_{1}\) and \(Q_{2}\). The single-gate error rates are \(1.173 \times 10^{-3}\) and \(9.810 \times 10^{-4}\), the readout errors are \(2.280 \times 10^{-2}\) and \(3.660 \times 10^{-2}\), and the CNOT error rate is \(1.825 \times 10^{-2}\).
The experimental procedures are as follows:
-
Initialize the circuit parameters θ,
-
Estimate the derivatives of θ via parameter-shift rule, \(\frac{\partial E(\boldsymbol{\theta })}{\partial \theta _{i}}=(\mathopen \langle H \mathclose \rangle _{\boldsymbol{\theta }_{i}^{+}}-\mathopen \langle H\mathclose \rangle _{ \boldsymbol{\theta }_{i}^{-}})/2\).
-
Update the parameters with gradient descent, \(\boldsymbol{\theta '}=\boldsymbol{\theta }-\alpha \cdot \nabla E( \boldsymbol{\theta })\);
-
Estimate the expectation value \(\mathopen \langle \boldsymbol{0}\mathclose \vert U^{\dagger }(\boldsymbol{\theta }) H U(\boldsymbol{\theta }) \mathopen \vert \boldsymbol{0} \mathclose \rangle \);
-
Repeat steps 2–4 until convergence.
5.4 Results and simulation
Figure 17 (a) shows the original result of VQE experiment on SpinQ Gemini and IBMQ Yorktown, respectively. The ground state energy of \(H_{H}\) is −3, which is shown by the red line. SpinQ Gemini and IBM Q Yorktown perform similar, both converge to \(E(\boldsymbol{\theta }) \approx -2.6\) after enough iterations, as shown by the blue dot line and the green square line, respectively. According to our simulations and analysis, the error for Gemini mainly comes from the inhomogeneity of the magnetic field, while the error of IBMQ mainly comes from the readout error.
The noise in quantum computer cannot be neglected. To study the noise effect and stability of SpinQ Gemini, we construct a noise model to capture the quantum error of the SpinQ Genimi. In the realistic noisy NMR quantum device, the basic noise channels are dephasing and amplitude damping. For an initial state ρ of the system and the quantum circuit unitary transformation U, the local noise model for single-qubit and two-qubit quantum gates can be described by the Kraus representation
$$\begin{aligned} \rho \rightarrow \sum_{k} E_{k} U \rho U^{\dagger } E_{k}^{\dagger } = \sum _{k} E_{k} \rho ' E_{k}^{\dagger } , \end{aligned}$$
(20)
where \(E_{k}\)s are the Kraus operators and \(\sum_{k} E_{k} E_{k}^{\dagger } = I\). The \(E_{k}\)s act on the same single qubit and two qubits as U acts on. The amplitude damping noise can be characterized by the Kraus operators,
$$ K_{1}= \begin{pmatrix} 1 & 0 \\ 0 & \sqrt{1-p} \end{pmatrix}, \quad\quad K_{2}= \begin{pmatrix} 0 & \sqrt{p} \\ 0 & 0 \end{pmatrix}, $$
where \(p \in [0, 1]\) is the probability of the noise. For amplitude damping noise on single-qubit gate U, the Kraus operators \(E_{k}\)s in Eq. (20) run over the set \(\{K_{1}, K_{2}\}\). The Kraus operators \(E_{k}\)s run over the set \(\{K_{1}, K_{2}\}\otimes \{K_{1}, K_{2}\}\) for two-qubit noisy gate. The dephasing noise is characterized by the Kraus operators,
$$\begin{aligned} K_{1}=\sqrt{1-p}I_{2}, \quad\quad K_{2}= \sqrt{p}\sigma _{Z}, \end{aligned}$$
(21)
where \(I_{2}\) is the two dimensional identity matrix and \(\sigma _{Z}\) is Pauli operator. For dephasing noise on single-qubit gate U, the Kraus operators \(E_{k}\)s in Eq. (20) run over the set \(\{K_{1}, K_{2}\}\). The Kraus operators \(E_{k}\)s run over the set \(\{K_{1}, K_{2}\}\otimes \{K_{1}, K_{2}\}\) for two-qubit noisy gate.
We model the noise consisting of single-qubit thermal relaxation error and two-qubit thermal relaxation error. The thermal relaxation error model applies the amplitude damping noise and dephasing noise after each one- or two-qubit gate. This thermal relaxation error model is characterized through the parameters \((T_{1}, T_{2}^{*}, t_{q})\) and the noise probability is formulated by
$$\begin{aligned}& p_{\mathit{damping}} = 1 - e^{-\frac{t_{q}}{T_{1}}}, \end{aligned}$$
(22)
$$\begin{aligned}& p_{\mathit{dephasing}} = \frac{1}{2}\bigl(1- e^{-2\gamma }\bigr), \end{aligned}$$
(23)
where \(\gamma = \frac{t_{q}}{T_{2}^{*}} - \frac{t_{q}}{2T_{1}}\). When the thermal relaxation error model is applied to single-qubit gates, \(t_{q} = {t_{1q}}\) and \(t_{q} = {t_{2q}}\) for two-qubit gates. The final noise model to approximate the noise of NMR quantum device is characterized by the parameters \(\{T_{1}, T_{2}^{*}, t_{1q}, t_{2q} \}\). We set \(\{T_{1} = 5.6\text{ s} , T_{2}^{*}=0.025\text{ s}, t_{1q}=25\ \mu \text{s}, t_{2q}=800\ \mu \text{s}\}\) in the noise simulation for the NMR platform. In NMR system, the dephasing effect is caused by both the spin relaxation and the field inhomogeneity. \(T_{2}\) is used to measure the spin transversal relaxation rate, while \(T_{2}^{*}\) is used to measure the field inhomogeneity. The \(T_{2}\) data is measured using the technique called spin echo, which can refocus the magnetisation and remove the effect of inhomogeneous field. In our VQE experiment, we did not use such technique, so we use \(T_{2}^{*}\) instead of \(T_{2}\).
With the noise model described above, we first record every parameters θ in each iteration of the SpinQ Gemini VQE experiment. Then we take these parameters θ as the parameters of quantum circuit ansatz (Fig. 15) and calculate the energy of the Hamiltonian with respect to the ideal circuit and noisy circuit output in each iteration. As shown in Fig. 17 (b), the noisy circuit result shows great consistancy to the experiment data. The paramaters θ found by SpinQ Gemini is close to the parameters for ground state. These results indicate that our desktop quantum computing platform can run VQE algorithm well.
5.5 Error mitigation
Quantum error mitigation [88–90] is a technique to diminish the influence of errors from the statistical perspective.
From the comparison and the simulation described above, we can see that the dephasing error caused by the inhomogeneous magnetic field is dominant. Our circuit consists of four single-qubit rotations and one CNOT gate. The time for a CNOT gate is about 800 μs and for single-qubit gates is \({\sim }20\ \mu \text{s}\). Therefore, the imperfections of the CNOT gate causes primary error. Consider the error model:
$$\begin{aligned} \rho \rightarrow \rho _{f} =\sum_{k} E_{k} U \rho U^{\dagger } E_{k}^{ \dagger } = \sum _{k} E_{k} \rho ' E_{k}^{\dagger }, \end{aligned}$$
(24)
where \(E_{k}\)s are the Kraus operators, \(\rho '\) is the ideal density matrix, and \(\rho _{f}\) is the measured density matrix. Error mitigation is a procedure that for a given \(\rho _{f}\) obtained from the experiment, finds a density matrix \(\rho _{0}\), which is as close to \(\rho '\) as possible, so that the final experiment result could be improved. Here, we employ the superoperator formalism to obtain \(\rho _{0}\). This formalism works as follows. First, let us rewrite the density matrix \(\rho '\) from an \(n\times n\) matrix into an \(n^{2} \times 1\) vector \(\boldsymbol{\rho }'\):
$$ \rho '=\sum_{ij} \rho '_{ij}\mathopen \vert i\mathclose \rangle \mathopen\langle j\mathclose \vert \rightarrow \boldsymbol{\rho }'=\sum _{ij} \rho '_{ij}\mathopen \vert i\mathclose\rangle \mathopen \vert j\mathclose \rangle . $$
(25)
Then the final state \(\boldsymbol{\rho }_{f}\), which is also an \(n^{2} \times 1\) vector is
$$ \boldsymbol{\rho }_{f} = \hat{\hat{S}} \boldsymbol{\rho }', $$
(26)
where \(\hat{\hat{S}}\) is the superoperator. With known Kraus operators \(E_{k}\), it can be obtained as
$$ \hat{\hat{S}}=\sum_{k} E_{k}\otimes E_{k}^{\dagger }. $$
(27)
Therefore, with known \(\boldsymbol{\rho }_{f}\) and \(\hat{\hat{S}}\), we can get
$$ \boldsymbol{\rho }'=\hat{\hat{S}}^{-1}\boldsymbol{\rho }_{f}. $$
(28)
The original result and the mitigated result of Gemini is shown in Fig. 17(b). The blue line and the purple line show the original result and the CNOT error mitigated result. We can see that the error mitigated result of the ground state of \(H_{H}\) could reach about −2.98, much closer to the ideal result. With both the simulation result and the error mitigated result, we can see that the error model we used is a good approximation.
For the IBMQ devices, the readout errors are dominant. Here we consider the simplest linear algebra measurement error mitigation scheme. On IBMQ Santiago we do projective measurement and obtain one of the strings \(\{0,1\}^{\otimes 2}\). Through tomography of measurement process, we get the probability of string \(S_{j}\) becoming \(S_{k}\), denoted by \(P_{kj}\). Suppose we repeat the same measurement many times and have the string probability distribution \(C_{\text{noisy}}\), then
$$ C_{\text{mitigated}}=P^{-1} C_{\text{noisy}} $$
(29)
provides the probability distribution with measurement error mitigated, although \(P^{-1}\) is not a physical operation. Measurement error mitigation can efficiently improve the performance of VQE on IBMQ Santiago, as shown in Fig. 17(a).