8

I'm looking into the circuit for the VQE, but am stumped at how we can identify the expectation value of the Pauli series. Essentially, how do we find:

$$ \langle \psi | H_i | \psi \rangle $$

Given $H_i$ can be decomposed into Paulis?

The first strategy that comes to mind is simply applying the adjoint of the state prep routine and finding the average number of 0s measured, but this doubles the number of state prep calls necessary. Is there an alternative circuit I'm missing?

C. Kang
  • 1,716
  • 8
  • 23

1 Answers1

8

Let's denote $P$ as a Pauli tensor product term (Pauli term: e.g. $Z \otimes Z$, $X \otimes X$ or $Y \otimes X \otimes X$), then note that $P$ is a Hermitian matrix whose expectation value is real, the eigenvalues are $+1$ and $-1$ with corresponding eigenspaces. The expectation value of $P$ will be equal to:

$$ \langle \psi | P |\psi\rangle = p_{+} - p_{-}$$

where $p_{+}$ is the probability of $|\psi\rangle$ being in the $+1$ eigenspace and $p_{-}$ is the probability of $|\psi\rangle$ being in the $-1$ eigenspace of $P$. We will prove this. Note that $p_{+}$ and $p_{-}$ can be calculated by measuring in $P$ eigenbasis: $p_{+} = \frac{N_{+}}{N}$ and $p_{-} = \frac{N_{-}}{N}$, where $N_+$ is the number of measured eigenvectors that have $+1$ eigenvalue, $N_-$ is the number of measured eigenvectors that have $-1$ eigenvalue and $N$ is the total number of measurements.

Now the prove. Arbitrary $|\psi \rangle$ can be expressed as superposition of eigenbasis vectors of arbitrary Hermitian matrix (but we are interested in $P$) that acts in the same Hilbert space, so:

$$|\psi\rangle = \sum_{j_+} a_{j_+}|j_+\rangle + \sum_{j_-} b_{j_-}|j_-\rangle$$

where $a_{j_+}$ and $b_{j_-}$ are amplitudes of eigenvectors $|j_+\rangle$ and $|j_-\rangle$ of the $P$. We have separated the sum for our convenience: $|j_+\rangle$ are eigenvectors that have $+1$ eigenvalue (that means $P|j_+\rangle = |j_+\rangle$) and $|j_-\rangle$ are eigenvectors that have $-1$ eigenvalue (that means $P|j_-\rangle = -|j_-\rangle$). So:

$$P |\psi\rangle = \sum_{j_+} a_{j_+}|j_+\rangle - \sum_{j_-} b_{j_-}|j_-\rangle$$

By taking into account that all eigenbasis vectors $|j_+\rangle$, $|j_-\rangle$ are orthogonal to each other (e.g. $\langle j_+| k_+\rangle = 0$ when $j \ne k$ or $\langle j_+| k_-\rangle = 0$ ):

$$\langle \psi |P |\psi\rangle = \sum_{j_+} |a_{j_+}|^2 - \sum_{j_-} |b_{j_-}|^2= p_{+} - p_{-}$$

In this answer, one can find Qiskit implementation for $Z\otimes Z \otimes ... \otimes Z$ Pauli term. The answer also includes a discussion on how one can use the same procedure for calculating expectation value for an arbitrary Pauli term. Also, note that if the Hamiltonian $H = \sum_i c_i P_i$, where $P_i$ are Pauli terms and $c_i$ are real numberes, then $\langle \psi | H| \psi \rangle = \sum_i c_i \langle \psi | P_i | \psi \rangle$.


Replying to the comments of the answer

In Microsoft's docs it was proposed (not only) an approach of measuring $\langle ZZ \rangle$ and the question was how one can generalize their approach. Actually the generalization of their approach is not obvious to me and I suggest asking a separate question focused on generalizing their approach. Nevertheless, I want to mention that their approach is not the only way of finding $\langle ZZ \rangle$ and here are three alternative ways for doing it:

enter image description here

  1. If the measured bitstring has odd (even) $1$s then we have measured the state in $-1$ ($+1$) eigenspace. The generalized Qiskit implementation of this approach can be found in this answer. Also, this approach is used (if I have understood the paper right) in this paper from IBM (Fig. 1 shows not only measurements but also simple one qubit unitary transformations ($I$ or $X_{-\frac{\pi}{2}}$ or $Y_{-\frac{\pi}{2}}$) that are specific for each Pauli term).

  2. If we measure the ancillary qubit in $| 0\rangle$ ($|1\rangle$) state then we have measured it in $+1$ ($-1$) eigenspace. This circuit is also used for the Hadamard test / scattering circuit. Note that, Pauli terms have real expectation values, so the described circuit for calculating imaginary part of the expectation value in the Hadamard test is not relevant here. The generalization of this approach is fairly simple: for example, this is the circuit for $\langle XZZY \rangle$.

  3. If measure the target qubit (targeted by CNOT) $|0\rangle$ ($|1\rangle$) then we have measured the state in the $+1$ ($-1$) eigenspace. Although its working, but the generalization of this approach is not obvious for me and I think this question about generalizing the approach shown in Microsoft's docs deserves a separate question.

P.S. There exist also other approaches for calculating $\langle ZZ \rangle$.

Davit Khachatryan
  • 4,301
  • 1
  • 10
  • 21
  • Thanks, Davit! super helpful on the intuition behind Pauli measurements. I'd love an add-on to the answer with a focus on the circuit for the measurement process - for instance, Microsoft has detailed some 1- and 2- Pauli circuits. However, do we need to worry about the scaling of the classical overhead in determining the unitary transformation? See also here – C. Kang Sep 10 '20 at 16:41
  • 1
    @Davit, good answer. So based on your answer then, in a VQE experiment, I will just measure each qubit and take the probabilities of getting a $|0\rangle$ or $|1\rangle$ state, multiply that by 1 or (-1) respectively, and add them altogether. For instance, if I have the state $|\psi \rangle = 1/\sqrt{2} ( |00> + |10> ) $ and $M = XZ$ then since the eigenvalues are 1 or -1 for both X, and Z (all Pauli matrices) I can calculate $$ as $$ \langle XZ \rangle_{|\psi\rangle} = Pr(q_0 = 0)1 + Pr(q_0 = 1)(-1) + Pr(q_1 = 0 )1 + Pr(q_1 = 1)(-1) \ = 1/2(1) + 1/2(-1) + 1(1) + 0(-1) = 1$$ – KAJ226 Sep 10 '20 at 18:07
  • 1
    @WantToLearn, no, we shouldn't look $X$ and $Z$ separately...we are interested in the $+1$ and $-1$ eigenspaces of $XZ$ operator and not in the $+1$ and $-1$ eigenspaces of $X$ and $Z$ operators separately. Also, note that $X$'s $+1$ ($-1$) eigenbasis vector is $|+\rangle$ ($|-\rangle$) state and is not $q_0 = 0$ ($q_0 = 1$) like it is written in your comment. In your example $|\psi \rangle = |+\rangle \otimes |0\rangle$ that is in the $+1$ eigenspace of $XZ$ operator and hence the expectation value $\langle \psi | XZ | \psi \rangle = 1$. – Davit Khachatryan Sep 10 '20 at 18:21
  • @C.Kang, you are welcome :). It depends on what is your strategy of determining the unitary transformation. If it's a fixed simple strategy that can be easily scaled, then I don't see any problem regarding classical overhead here. – Davit Khachatryan Sep 10 '20 at 18:26
  • 1
    @WantToLearn, if you are interested, at the end of my tutorial about VQE I have described a detailed procedure for finding $\langle XY \rangle$ (it can be done also for other Pauli term with similar ideas). – Davit Khachatryan Sep 10 '20 at 18:36
  • @Davit- Okay. So to calculate the expectation for an arbitrary Pauli string, $M$, $\langle M \rangle$, with respect to some $|\pi\rangle$, then I need to know the probabilities that $|\psi\rangle$ is in the +1 eigenspace (say $p_1$), and the probability that $|\psi\rangle$ in the -1 eigenspace (say $p_2$) then calculate $p_1 - p_2$. Don't you need $2^n$ output probabilities to do this then? If that is the case then the measurement need to be $O(c*2^n)$ where $c$ is some arbitrary number of shots. That to me would be too expensive, so I am pretty sure that is not how it is done... – KAJ226 Sep 10 '20 at 18:38
  • I meant to type $|\psi \rangle$ and not $|\pi \rangle$ in the comment above. – KAJ226 Sep 10 '20 at 18:57
  • @WantToLearn, actually I don't need $2^n$ output probabilities...I only need $N_+$ and $N_-$ in order to calculate $\text{expectation} = \frac{N_+ - N_-}{N}$. So I am not storing $2^n$ numbers and I am not worrying about the accuracy of estimating $|a_i|^2$ and $|b_i|^2$ probabilities. Also, look at Fig. 1 in this paper from IBM...they also apply measurements on each qubit. – Davit Khachatryan Sep 10 '20 at 18:58
  • @WantToLearn, also note that if all the Pauli terms $P_i$ are local (that act only on few qubits) then even $2^n$ (let's say $n \le 6$) is not a problem. – Davit Khachatryan Sep 10 '20 at 19:03
  • @Davit Okay. I guess I understand your point about if the Hermitian matrix only acts locally then not all the eigenbasis will show up... so even if you have $n$ qubit, you don't get all $2^n$ eigenbasis as output. Is this what you implying? And I think I understand your point about just counting $N_+$ and $N_{-}$ and use that to get the expectation. Basically, you send, says 1000 shots to the machine, each shot give you back some eignstate, you asked whether that state is $+$ or $-$. At the end of the 1000 experiment, you sum up all the states in $+$ which is $N_+$ and.. (cont below) – KAJ226 Sep 10 '20 at 19:13
  • ... all the states that in $-$ which is $N_{-}$ then calculate the expectation as $\dfrac{ N_+ - N_{- }}{N}$. As you do more experiments (shots) the accuracy of $N_+$ and $N_{-}$ will increase. Is this the right way to think about it? – KAJ226 Sep 10 '20 at 19:13
  • @WantToLearn, yes, at least this is the way I am thinking about it:). For local Pauli terms, we shouldn't even measure other qubits. – Davit Khachatryan Sep 10 '20 at 19:28
  • @DavitKhachatryan Thanks for the great discussion. This has been super helpful. I am grateful for your time, just so you know! – KAJ226 Sep 10 '20 at 19:51
  • @DavitKhachatryan the notes online are good, and I'd still like your help in generalizing the technique to longer Pauli strings. For example, the ZZZ / ZZZZ cases, which can be generalized into any 3/4 length Pauli strings. As seen in the MSFT link, this likely would need a unique series of CNOTs which is not detailed - am I missing something? – C. Kang Sep 10 '20 at 20:36
  • @WantToLearn, You are welcome. – Davit Khachatryan Sep 11 '20 at 15:00
  • @C.Kang, although I don't know the answer to your question (how to generalize the approach described in Microsoft's docs), I have added some more detailed discussion to my answer. – Davit Khachatryan Sep 11 '20 at 15:02
  • @DavitKhachatryan awesome response, and yes it seems like the Hadamard test is used in practice - even though it has an additional ancilla cost, there are other positive aspects of the test, including greater error resilience and eigenvector preservation – C. Kang Sep 11 '20 at 15:50
  • @Davit Khachatryan I found the way you calculate the expectation value of pauli operator is not fast. In the method you mentioned in your github, you calculate the expectation value by count the number from the simulator result. However, if there is 5 qubits, you need to count $2^5$ to get the answer right? Is't it slow and does not utilize the advantage of the quantum parallel? – narip Jan 01 '21 at 04:58
  • For example, if the question is Max-Cut, the process of calculating the expectation value of the Hamiltonian is totally bruce force. – narip Jan 01 '21 at 05:28
  • @ZhaoyiZhou, please look at the previous comments, where a similar question was discussed. Regarding the MaxCut note that in MaxCut The Hamiltonian is $H = \sum_{i,j \text{ pairs}} \frac{1}{2}(I - Z_i Z_j)$, so for each pair (each Pauli term in the Hamiltonian) only two qubits should be measured if we will use the number 1. technique from my answer (or the technique used in my Github tutorial). – Davit Khachatryan Jan 01 '21 at 14:00
  • @ZhaoyiZhou, but of course one can always use the number 2 technique described in the answer if one has an ancillary qubit and doesn't care about the two-qubit gate errors (there are a lot of control gates involved in the number 2 technique) – Davit Khachatryan Jan 01 '21 at 14:05
  • @DavitKhachatryan One more thing, I'm not sure if I'm right. Still the Max-Cut problem. We can change the problem to minimize $\Sigma Z_iZ_j$, a special case will be $H = Z_1Z_2 + Z_2Z_3 + Z_3Z_4 + Z_1Z_3$. If you measure them separately, i.e, $<Z_1Z_2>$ and then $<Z_2Z_3>$ ... The minimum of $<Z_1Z_2>$ is -1, so measure them separately means $-1*4 = -4$ while measure them together to get the expected value will be -3. – narip Jan 01 '21 at 14:20
  • @ZhaoyiZhou, I am not sure if I understand the question right, but in QAOA the goal is to minimize/maximize the expectation value of the Hamiltonian, not its separate parts and that is normal to have your described situation where the sum of minimum values of parts of the Hamiltonian is smaller than the minimum of the Hamiltonian expectation value. – Davit Khachatryan Jan 01 '21 at 14:48
  • @DavitKhachatryan Sorry to bother you again. Yeah, the goal of QAOA is to calculate the $$ together(i.e., we need to measure them together), so if we still use the way(count the result from the simulator), it seems just bruce force in Max-Cut question. For if there are 5 qubits, we need to count from 00000 to 11111 to count the expectation value. – narip Jan 01 '21 at 15:10
  • 1
    @ZhaoyiZhou, I have answered in the chat https://chat.stackexchange.com/rooms/117916/discussion-between-zhaoyi-zhou-and-davit-khachatryan – Davit Khachatryan Jan 02 '21 at 07:28