Skip to content

Hamiltonians and observables

The previous lesson used gates to change a state. A Hamiltonian describes how it evolves continuously. With ℏ absorbed into the units and a time-independent Hamiltonian, |ψ(t)⟩ = exp(−iHt)|ψ(0)⟩.

For one resonantly driven two-level system, choose H = ΩX/2. Starting in 0, the excited-state probability is sin²(Ωt/2). The Z expectation is 1 − 2p(1) = cos(Ωt). These formulas assume an isolated ideal two-level system with constant drive and zero detuning.

"""Evolve a two-level system with a matrix exponential and inspect observables."""

from __future__ import annotations

import json

import numpy as np
from scipy.linalg import expm


def experiment() -> dict[str, object]:
    omega, duration = 2.0, 0.4
    x = np.array([[0, 1], [1, 0]], dtype=complex)
    z = np.diag([1, -1])
    hamiltonian = omega * x / 2
    state = expm(-1j * hamiltonian * duration) @ np.array([1, 0])
    return {
        "omega_rad_per_us": omega,
        "duration_us": duration,
        "probability_one": float(abs(state[1]) ** 2),
        "z_expectation": float(np.vdot(state, z @ state).real),
        "hamiltonian_expectation": float(np.vdot(state, hamiltonian @ state).real),
        "norm_squared": float(np.vdot(state, state).real),
    }


if __name__ == "__main__":
    print(json.dumps(experiment(), sort_keys=True))

Download the full script

python examples/learning/foundations/hamiltonian_observables.py
{
  "duration_us": 0.4,
  "hamiltonian_expectation": 0.0,
  "norm_squared": 1.0,
  "omega_rad_per_us": 2.0,
  "probability_one": 0.15164664532641736,
  "z_expectation": 0.6967067093471654
}

This small calculation uses SciPy's matrix exponential as an independent reference, rather than calling the CASCAQit simulator. Compare the output with sin²(0.4) and cos(0.8). The norm squared should remain one.

An observable expectation is an average over repeated measurements, not necessarily a value from one shot. For this state, the Hamiltonian expectation stays zero even while the excitation probability changes. A constant mean energy therefore does not imply that every basis probability is constant.

Exercise: choose a duration that produces probability one, keeping Ω = 2 rad/µs. What happens to the Z expectation? Then double both Ω and the duration: is the pulse area unchanged?

Answer

Use t = π/Ω = π/2 µs; Z becomes −1. Doubling both quantities multiplies the pulse area Ωt by four. To keep this simple constant-drive evolution unchanged, doubling Ω requires halving t. With interactions, detuning or noise, matching pulse area alone generally is not enough.

Next: neutral atoms and interactions.

中文版

SDK 1.0.8a · `8b227bff`