QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
HomeLearnCatalogRanksPlaygroundDocs
06 · Observables, Hamiltonians & Real Applications0%

You are reading without signing in. Sign in or continue as guest to take quizzes and climb the ranks.

Learn/QC 302Cutting and Quantum ML·Lesson 6 of 7

Observables, Hamiltonians & Real Applications

Turn 0/1 counts into ⟨Z⟩, measure X and Y by rotating first, and add Pauli terms into the energy that chemistry and optimisation minimise.

Advanced14 min read8 sections · 2 questions+45
By the end you will be able to
  1. 01Compute ⟨Z⟩ = P(0) − P(1) from a histogram.
  2. 02Measure ⟨X⟩ and ⟨Y⟩ with a basis change before the measurement.
  3. 03Write a Hamiltonian as a weighted sum of Pauli strings and estimate its energy term by term.

A measurement gives bits, but chemistry and optimisation ask for numbers such as an energy or a cost. The bridge is an observable: give each outcome a value and average over the shots. For Z the rule is simple: outcome 0 counts as +1 and outcome 1 counts as −1.

⟨Z⟩=⟨ψ∣Z∣ψ⟩=(+1)P(0)+(−1)P(1)=P(0)−P(1)≈Nn0​−n1​​
⟨Z⟩ is +1 for |0⟩, −1 for |1⟩ and 0 for |+⟩. With N shots, n₀ zeros and n₁ ones, the estimate is (n₀ − n₁)/N.

01Measuring X and Y

ObservableGates before the measurementWhy
Znonethe hardware measures Z
XhH swaps the X and Z axes
Ysdg, hS† turns the Y axis into the X axis, then H as above
Hands-on

⟨Z⟩ and ⟨X⟩ of one state

ry(pi/3) tilts the qubit 60° from |0⟩. Simulate: P(0) ≈ 0.75 and P(1) ≈ 0.25, so ⟨Z⟩ ≈ 0.5. Now add h q[0]; before the measurement and simulate again: P(0) ≈ 0.933, so ⟨X⟩ = 2·0.933 − 1 ≈ 0.87, the exact value being √3/2.

OpenQASM 3
OPENQASM 3.0;
include "stdgates.inc";
qubit[1] q;
bit[1] c;
ry(pi/3) q[0];
c[0] = measure q[0];
Sign in to run (nothing is saved)
Open in the IDE Open in the Playground

02Several qubits: Pauli strings

A Pauli string such as Z₀Z₁ multiplies the ±1 values of its qubits: outcomes with an even number of 1s count +1, odd ones −1. For the Bell state (|00⟩ + |11⟩)/√2 every shot is 00 or 11, so ⟨Z₀Z₁⟩ = +1, while ⟨Z₀⟩ alone is 0. Measuring X₀X₁ means an h on both qubits first; the Bell state gives +1 there too.

Hands-on

Correlations as expectation values

Simulate: only 00 and 11, so ⟨Z₀Z₁⟩ = +1. Add h q[0]; h q[1]; before the measurement: still only 00 and 11, so ⟨X₀X₁⟩ = +1 as well. Two independent qubits in |+⟩|+⟩ would give ⟨Z₀Z₁⟩ = 0.

OpenQASM 3
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
bit[2] c;
h q[0];
cx q[0], q[1];
c = measure q;
Sign in to run (nothing is saved)
Open in the IDE Open in the Playground

03Hamiltonians: energy as a sum of Pauli terms

H=i∑​ci​Pi​⇒⟨H⟩=i∑​ci​⟨Pi​⟩
Expectation values are linear: estimate each Pauli string (strings that share a measurement basis can share the same shots) and add them with their weights. This is the job of the Estimator primitive.
  • Chemistry: once electrons are mapped to qubits, a molecule's energy becomes a sum of Pauli strings. The smallest textbook case, H₂ in a minimal basis, can be reduced to two qubits with terms such as Z₀, Z₁, Z₀Z₁, X₀X₁ and Y₀Y₁. VQE searches for the θ that makes ⟨H⟩ as low as possible; that minimum approximates the ground-state energy.
  • Optimisation: in MaxCut an edge (i, j) contributes (1 − ZᵢZⱼ)/2, which is 1 when the two nodes are on different sides and 0 otherwise. Summing over the edges gives the cost Hamiltonian that QAOA works with. Portfolio selection and scheduling problems are written the same way, as weighted Z and ZZ terms.
Knowledge check

2 questions · one try each counts

Question 1

1000 shots give 900 zeros and 100 ones. What is the estimate of ⟨Z⟩?

Sign in to answer and climb the ranks; you will come back to this lesson.

Question 2

H = 2Z − X and the state is |+⟩. What is ⟨H⟩?

Sign in to answer and climb the ranks; you will come back to this lesson.

Key takeaway

Give outcome 0 the value +1 and outcome 1 the value −1, and counts become expectation values. Rotate first to measure X or Y, multiply the ±1 values for Pauli strings, and add weighted terms to get the energy of a molecule or the cost of an optimisation problem.

Finished reading?

Knowledge check: 2 questions waiting above. Questions are optional. Mark it complete, or press Next: moving on marks it complete too.

Up next
Lesson 7 · 12 min
QAOA on a small graph
Cost and mixer layers for MaxCut, read off the cut from the histogram, and understand the depth p.
Further reading
  • Docs: Hamiltonians and expectation values
More in Cutting and Quantum ML
  • Circuit cutting
  • Classical ML vs. Quantum ML: The Hybrid Loop
  • Variational circuits
Hands-On 2-Qubit Variational ClassifierQAOA on a small graph
In this lesson0%
  1. Introduction
  2. Measuring X and Y
  3. Try it: ⟨Z⟩ and ⟨X⟩ of one state
  4. Several qubits: Pauli strings
  5. Try it: Correlations as expectation values
  6. Hamiltonians: energy as a sum of Pauli terms
  7. Knowledge check
  8. Key takeaway
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in