|q⟩ Bad Qubits

intermediate · Programming · Variational Quantum Eigensolver (VQE)

Measuring Many Pauli Terms

Every VQE energy estimate requires computing H\langle H \rangle for a molecular Hamiltonian that may contain dozens or even thousands of Pauli string terms. Measuring each term in its own dedicated circuit run is correct but wasteful. Commuting Pauli terms can be measured simultaneously, so grouping them reduces the total circuit count and shot budget.

Why commutativity enables simultaneous measurement

Two observables AA and BB can be measured simultaneously (in the same basis rotation circuit) if and only if they commute: [A,B]=ABBA=0[A, B] = AB - BA = 0. For two Pauli strings of the same length, commutativity has a simple combinatorial test: count the positions where the two strings differ and neither is II. If that count is even the strings commute; if it is odd they anti-commute.

For example, on two qubits:

Because ZIZI, IZIZ, and ZZZZ all mutually commute they form a commuting group that can be measured in a single circuit — no basis-rotation overhead beyond the standard computational-basis measurement.

Measurement basis rotations

Each commuting group defines a shared measurement basis. The standard procedure is:

  1. Z terms require no rotation — measure directly in the computational basis.
  2. X terms require a Hadamard on each affected qubit before measurement, rotating +0|+\rangle \to |0\rangle and 1|-\rangle \to |1\rangle.
  3. Y terms require an SHS^\dagger H (also written HSHS^\dagger) rotation before measurement.

For the ZZZZ term on a two-qubit state, after measuring bit string xyxy the contribution is:

ZZ=x,y{0,1}(1)x+yP(xy).\langle ZZ \rangle = \sum_{x,y \in \{0,1\}} (-1)^{x+y}\, P(xy).

The sign rule comes directly from Z0=+0Z|0\rangle = +|0\rangle and Z1=1Z|1\rangle = -|1\rangle: each qubit contributes a factor of (1)bit(-1)^{\text{bit}} and the factors multiply.

From grouping to circuit count

Given a Hamiltonian with TT Pauli terms partitioned into GG commuting groups, you need exactly GG distinct measurement circuits per VQE iteration instead of TT. Grouping reduces the shot budget by a factor of roughly T/GT/G, which can be significant: a hydrogen molecule in the STO-3G basis has 15 Pauli terms but only 2 commuting groups, cutting the measurement circuits from 15 to 2.

The full VQE measurement loop becomes:

  1. Prepare ψ(θ)|\psi(\boldsymbol{\theta})\rangle with the ansatz.
  2. For each commuting group: apply the shared basis rotation, measure, collect statistics.
  3. From each group's measurement results extract Pk\langle P_k \rangle for every term in the group.
  4. Return E(θ)=kckPkE(\boldsymbol{\theta}) = \sum_k c_k \langle P_k \rangle to the classical optimizer.

Try it

Consider the two-qubit Hamiltonian

H=0.5ZI+0.3IZ+0.2ZZ+0.4XX.H = 0.5\,ZI + 0.3\,IZ + 0.2\,ZZ + 0.4\,XX.

Use the commutativity rule to identify how many distinct measurement circuits are needed. Return that number.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.