Skip to main content
Create your own
Lesson illustration

Measuring Expectation Values of Pauli String Hamiltonians

Hello! Welcome back to our deep dive into quantum computing.

In our previous lesson, we tackled the crucial step of translating physical Hamiltonians into the language of quantum computers. We saw how mappings like Jordan-Wigner transform a fermionic or spin Hamiltonian into a weighted sum of Pauli strings, .

Today, we will build directly on that foundation to address the next step in the Variational Quantum Eigensolver (VQE) algorithm: actually measuring the energy. This lesson focuses on the learning outcome: For a given Hamiltonian expressed as a sum of Pauli strings, devise a measurement strategy to estimate its expectation value by measuring each term individually.

We will break down how to measure the expectation value of any given Pauli string on a quantum computer and then combine these measurements to estimate the total energy of the state prepared by our ansatz.

1. The Core Task: Measuring Pauli Operator Expectation Values

The expectation value of our Hamiltonian for a given trial state is:

Due to the linearity of quantum mechanics, this simplifies to:

The problem of finding the total energy thus reduces to finding the expectation value for each Pauli string in the sum.

The challenge is that most quantum hardware is designed to perform measurements in only one basis, the computational or Z-basis, which distinguishes between the and states. Our task is to find a way to measure operators like and using only Z-basis measurements.

The following resource provides a clear, mathematical derivation of how this is done.

Expectation Values

These lecture notes, 'Expectation Values' by Ryan LaRose, provide a concise guide to measuring the expectation values of single-qubit Pauli operators and their tensor products.

Please read the sections 'Expectation Value of Z', 'Expectation Value of X', and 'Expectation Value of Y' on pages 6 and 7. Focus on how each measurement is related back to a measurement in the Z-basis via a basis change.

Let's summarize the key techniques derived in the notes.

Measuring

This is the most direct case. The Pauli-Z operator has eigenvalues +1 for state and -1 for state . Therefore, its expectation value is the difference between the probabilities of measuring these two outcomes:

To estimate this on a quantum computer, you prepare the state , measure in the Z-basis many times (taking many "shots"), count the occurrences of '0' () and '1' (), and compute .

Measuring and

To measure operators that are not diagonal in the Z-basis, we perform a change of basis. The key is to find a unitary transformation that turns the operator we want to measure into . For the Pauli-X operator, we know that , where is the Hadamard gate.

So, the expectation value is:

where . This shows that measuring for the state is equivalent to measuring for the state . Operationally, this means we simply apply a Hadamard gate to our qubit just before performing the standard Z-basis measurement.

Similarly, for the Pauli-Y operator, we can use the identity . This means to measure , we apply the sequence followed by just before the Z-measurement.

The general strategy is summarized in this table:

To Measure Basis Transformation Circuit Operation (before measurement)
None
Apply
Apply , then

2. Measuring Multi-Qubit Pauli Strings

The strategy for single qubits extends naturally to multi-qubit Pauli strings like . The required basis transformation is simply the tensor product of the individual single-qubit transformations.

For example, to measure :

  1. On qubit 0, apply .
  2. On qubit 1, apply then .
  3. On qubit 2, do nothing.
  4. Perform a Z-basis measurement on all three qubits.

After collecting measurement statistics for the bit string outcomes , we calculate the expectation value. The eigenvalue of the Pauli string for a basis state is the product of the individual eigenvalues. For , the eigenvalues are not as simple as for , but after the basis rotation, we are effectively measuring . The eigenvalue for an outcome is .

The expectation value is then the weighted average of these eigenvalues:

where is the probability of measuring the bit string .

Let's return to the notes to see a concrete example.

Expectation Values

This section of the same notes demonstrates the extension to a two-qubit Pauli string.

Please read the section 'String of Pauli’s' on pages 8-9. Pay close attention to how the expectation value of X ⊗ Z is calculated from the probabilities of the four possible outcomes after the basis change.

3. Devising a Measurement Strategy: From Naive to Efficient

We now have all the tools to devise a measurement strategy.

Strategy 1: The Naive Approach

The most direct strategy, which directly follows from the "measure each term individually" part of our goal, is as follows:
For each term in the Hamiltonian :

  1. Prepare the ansatz state .
  2. Apply the tensor product of single-qubit gates corresponding to the Pauli string to perform the basis change.
  3. Measure all qubits in the computational basis.
  4. Repeat steps 1-3 for a sufficient number of shots to get good statistics for .
  5. After iterating through all , compute the total energy .

This approach is correct, but it can be highly inefficient. As you know from your work with numerical simulations, efficiency matters. For molecular Hamiltonians, the number of Pauli terms can be in the thousands or more, and running a separate quantum circuit for each term is prohibitively expensive.

What Is the Variational Quantum Eigensolver? | VQE Explained

This Qiskit video provides a high-level overview of the VQE algorithm and touches upon this exact measurement problem.

Please watch from 05:57 to 09:58. This segment discusses the decomposition of the Hamiltonian into Pauli strings and introduces the critical idea that non-commuting terms require separate measurements, hinting at the need for a more clever strategy.

Strategy 2: An Efficient Approach via Grouping

As the video suggests, we can do better. The key insight comes from a fundamental principle of quantum mechanics: commuting observables can be measured simultaneously. This is because they share a common set of eigenvectors.

Our goal is to partition the set of Pauli strings into the smallest possible number of groups, where all operators within each group commute with one another. We can then measure all operators in a group with a single experimental setup.

Expectation from samples - Qibochem

This documentation from the Qibochem library provides an excellent, practical discussion of how to reduce measurement cost by grouping commuting terms.

Please read the sections 'Reducing the measurement cost', 'Qubit-wise commuting terms', and 'Putting everything together'. Focus on the definition of qubit-wise commutativity and how it simplifies the process of finding a common measurement basis.

While general commutativity is powerful, finding the joint measurement basis can be complex. A more practical and widely used approach is to group terms based on qubit-wise commutativity.

Two Pauli strings and are qubit-wise commuting if for all qubits . Since non-identical Pauli operators anti-commute, this condition simplifies: for each qubit , either or at least one of them is the identity .

This leads to a much more efficient strategy:

  1. Partition: Group the Pauli terms of the Hamiltonian into sets where all terms in a set are mutually qubit-wise commuting. (As the resource notes, this is equivalent to solving the minimum clique cover problem on the graph of commuting operators).
  2. Determine Basis: For each group, determine the single measurement basis. For any qubit , if there is a non-identity operator (e.g., ) acting on it anywhere in the group, that determines the measurement basis for that qubit (-basis). If all terms have , that qubit is measured in the Z-basis by convention.
  3. Measure: For each group:
    a. Prepare the state .
    b. Apply the single set of basis-change gates for the entire group.
    c. Measure all qubits and repeat for many shots.
    d. From this single data set, you can compute the expectation value for every operator in the group.
  4. Combine: Sum the results: .

For example, the terms , , and are all qubit-wise commuting. They can all be measured simultaneously in the basis. From one set of shots, you can calculate , , and . This is a significant saving compared to running three separate experiments.

Conclusion

In this lesson, we have developed a complete and practical strategy for one of the most critical parts of the VQE algorithm: estimating the Hamiltonian's expectation value.

Key Takeaways:

  • The total energy is the weighted sum of the expectation values of the individual Pauli strings, .
  • The expectation value of any Pauli string can be measured by applying a specific unitary transformation (composed of ) to each qubit and then performing a measurement in the computational (Z) basis.
  • A naive strategy of measuring each Pauli term in a separate experiment is correct but inefficient.
  • A far more efficient strategy involves grouping qubit-wise commuting Pauli strings. All terms in such a group can be measured simultaneously, drastically reducing the number of required quantum circuit executions.

Preview of the Next Lesson

We have now assembled all the quantum components of the VQE algorithm. We know how to build a parameterized ansatz to prepare a trial state , and we know how to measure its energy . The final step is to use a classical computer to perform the optimization.

In our next lesson, Implement the VQE algorithm to find the ground state of a simple molecular Hamiltonian like H2, we will combine these pieces. We will see how a classical optimization algorithm iteratively updates the parameters , calling upon the quantum computer at each step to evaluate the energy, in order to find the parameter set that minimizes and thus approximates the ground state energy of the system.

Can't find a good explanation? Sign up and we'll make it for you

Sign up