Skip to content

dq.overlap

overlap(x: ArrayLike, y: ArrayLike) -> Array

Returns the overlap between two quantum states.

The overlap is computed

  • as ψφ2\lvert\braket{\psi|\varphi}\rvert^2 if both arguments are kets ψ\ket\psi and φ\ket\varphi,
  • as ψρψ\lvert\bra\psi \rho \ket\psi\rvert if one argument is a ket ψ\ket\psi and the other is a density matrix ρ\rho,
  • as Tr ⁣[ρσ]\tr{\rho^\dag\sigma} if both arguments are density matrices ρ\rho and σ\sigma.

Parameters

  • x (array_like of shape (..., n, 1) or (..., n, n))

    Ket or density matrix.

  • y (array_like of shape (..., n, 1) or (..., n, n))

    Ket or density matrix.

Returns

(array of shape (...)) Real-valued overlap.

Examples

>>> fock0 = dq.fock(3, 0)
>>> dq.overlap(fock0, fock0)
Array(1., dtype=float32)
>>> fock01_dm = 0.5 * (dq.fock_dm(3, 0) + dq.fock_dm(3, 1))
>>> dq.overlap(fock0, fock01_dm)
Array(0.5, dtype=float32)