Skip to content

observe

Compute the expectation value of an observable for a given state.

observe

observe(
    state: Union[MPS, MPO, Sequence[Tensor]],
    observable: Union[MPO, Sequence[Tensor]],
) -> float

Compute the expectation value of an observable for a given state.

Dispatches to the appropriate contraction routine based on the type of state:

  • MPS (or a plain sequence of tensors): evaluates ⟨ψ|O|ψ⟩ via a left-to-right MPS-MPO-MPS transfer-matrix sweep.
  • NormalMPO (thermal density matrix): evaluates Tr[ρ O] / Tr[ρ] by forming the MPO product ρ · O, compressing it, and returning the ratio of traces.

Parameters:

Name Type Description Default
state Union[MPS, MPO, Sequence[Tensor]]

The state to evaluate. Either an MPS object, a plain sequence of MPS site tensors, or a NormalMPO thermal density matrix.

required
observable Union[MPO, Sequence[Tensor]]

The observable encoded as an MPO object, or a plain sequence of MPO site tensors, of the same length as state.

required

Returns:

Type Description
float

The expectation value of the observable.

Raises:

Type Description
TypeError

If state is not an MPS, NormalMPO, or a sequence of tensors.

NotImplementedError

If state is a plain MPO (use a NormalMPO for thermal states).

Notes

observe performs a left-to-right MPS–MPO–MPS transfer-matrix sweep. At each site it contracts the bra (conjugated MPS tensor), the MPO tensor, and the ket (MPS tensor) into an updated environment. The final environment is a 1×1×1 tensor; the scalar value — corrected for SU(2) Bridge normalization — is returned.

See Also