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[ρ] via a left-to-right transfer-matrix sweep that accumulates a small (ρ_bond, O_bond) environment, analogous to the MPS case.

Complex states (e.g. produced by real-time evolution) are supported, and may be paired with a real observable. The imaginary part of the final scalar is discarded provided it is at roundoff level.

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).

ValueError

If the expectation value has a non-negligible imaginary part, which means observable is not Hermitian on state.

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.

Complex states

Nicole contracts only operands sharing a single dtype. When either the state or the observable carries complex blocks — as a state evolved in real time by tdvp.run does — observe promotes the whole sweep to complex128, including the real-valued MPO and the identity-derived boundary tensor. The bra side is conjugated, so the result is the physical ⟨ψ|O|ψ⟩.

The imaginary part of the final scalar is discarded once it has been checked to be at roundoff level. A larger imaginary part means the observable is not Hermitian on this state, and raises ValueError instead of returning a misleading real number.

See Also