# How to calculate $\operatorname{Var}[H]$ in the context of VQEs?

Given a Hermitian operator $$H$$, I can calculate the variance of the Hamiltonian $$Var[H]$$ as

$$Var[H] = \langle H^2 \rangle -\langle H \rangle^2$$

Now, $$H$$ can be decomposed as

$$H = \sum_i \alpha_i P_i \hspace{1 cm} P_i \in \{ I,X,Y,Z\}^{\otimes n}$$

Hence by linearity we have $$\langle H \rangle = \sum_i \alpha_i \langle P_i \rangle$$

In the Variational Quantum Eigensolver (VQE), we want to minimize the above expression, that is, $$\min \langle H \rangle_{|\psi (\theta) \rangle}$$.

Note that if $$|\psi (\theta)\rangle$$ is indeed an eigenvector of $$H$$ then $$Var[H] = 0$$. And so one can verify whether they have indeed reached/found an eigenstate by performing such calculation.

### The question is how do we calculate $$\langle H^2 \rangle$$?

Yes, I can decomposed $$H^2$$ into sum of Pauli terms, that is

$$H^2 = \sum_k \beta_k P_k \hspace{1 cm} P_i \in \{ I,X,Y,Z\}^{\otimes n}$$

and then using the optimized $$|\psi (\theta) \rangle$$ I have found through VQE to perform $$\langle H^2 \rangle = \langle \psi(\theta) | \sum_k \beta_k P_k | \psi(\theta) \rangle$$

This would be the same process as I did to calculate $$\langle H \rangle$$, applying the appropriate rotations to my circuit before measuring in the $$Z$$ basis... Then once I have this, $$\langle H^2 \rangle$$, I can put it together with the expectation value I have found through VQE to calculate $$Var[H]$$. This is the naive way of doing it I guess...

What is a better way to do this?

• Phase estimation? Commented Mar 20, 2021 at 10:17
• @NorbertSchuch Thanks for reading through the question and the comment. Yes, that is one way to do it. I was thinking about something more resource friendly. I thought there might be some properties that of $H^2$ that I can take advantage of... for instance, if $H$ was a pauli string then $\langle H^2 \rangle = 1$. Commented Mar 20, 2021 at 17:55
• Well, that would be a rather boring Hamiltonian. Do you know something about the Hamiltonian, structure etc? Commented Mar 20, 2021 at 18:18
• I am thinking about Hamiltonian that is chemistry related. In particular, the electronic structure problem Hamiltonian, which has the form of equation 1 on page 4 in the following paper ihttps://arxiv.org/pdf/1001.3855v3.pdf Commented Mar 20, 2021 at 18:55
• What I am doing right now is I took that Hamiltonian, map it into the form of qubit operators which is a linear combinations of Pauli string ($P_i$) as described in my question. Then I calculate the decomposition of $H^2$ using the linear combinations of Pauli strings of $H$. My program go through the terms to do the multiplication and simplification... at the end I will again have a linear combination of pauli strings. Since $H$ has polynomial number of Pauli strings, $H^2$ will too as well. Then I calculate $\langle H^2 \rangle$ as I have calculated $\langle H \rangle$. Commented Mar 20, 2021 at 18:57