measurement_ops.measure

Apply measurement to a quantum state.

Functions

measure(state, measurement[, tol, state_update])

Apply measurement to a quantum state.

Module Contents

measurement_ops.measure.measure(state, measurement, tol=1e-10, state_update=False)

Apply measurement to a quantum state.

The measurement can be provided as a single operator (POVM element or Kraus operator) or as a list of operators (assumed to be Kraus operators) describing a complete quantum measurement.

When a single operator is provided:
  • Returns the measurement outcome probability if state_update is False.

  • Returns a tuple (probability, post_state) if state_update is True.

When a list of operators is provided, the function verifies that they satisfy the completeness relation when state_update is True.

\[\sum_i K_i^\dagger K_i = \mathbb{I},\]

when state_update is True. Then, for each operator \(K_i\), the outcome probability is computed as

\[p_i = \mathrm{Tr}\Bigl(K_i^\dagger K_i\, \rho\Bigr),\]

and, if \(p_i > tol\), the post‐measurement state is updated via

\[\rho_i = \frac{K_i\, \rho\, K_i^\dagger}{p_i}.\]

If \(p_i \le tol\), the corresponding post‐measurement state is a zero matrix.

Examples

Single operator (POVM element):

import numpy as np
from toqito.measurement_ops.measure import measure
rho = np.array([[0.5, 0.5], [0.5, 0.5]])
proj_0 = np.array([[1, 0], [0, 0]])

# Without update; simply returns the probability.
print(measure(rho, proj_0))

# With state update; returns (probability, post_state).
p, post_state = measure(rho, proj_0, state_update=True)
print(p)
0.5
0.5

Multiple operators (Kraus operators):

import numpy as np
from toqito.measurement_ops.measure import measure
rho = np.array([[0.5, 0.5], [0.5, 0.5]])
K0 = np.array([[1, 0], [0, 0]])
K1 = np.array([[0, 0], [0, 1]])

# Returns list of probabilities.
print(measure(rho, [K0, K1]))

# Returns list of (probability, post_state) tuples.
print(measure(rho, [K0, K1], state_update=True))
[np.float64(0.5), np.float64(0.5)]
[(np.float64(0.5), array([[1., 0.],
       [0., 0.]])), (np.float64(0.5), array([[0., 0.],
       [0., 1.]]))]
Parameters:
  • state (numpy.ndarray) – Quantum state as a density matrix shape (d, d) where d is the dimension of the Hilbert space.

  • measurement (numpy.ndarray | list[numpy.ndarray] | tuple[numpy.ndarray, Ellipsis]) – Either a single measurement operator (an np.ndarray) or a list/tuple of operators. When providing a list, they are assumed to be Kraus operators satisfying the completeness relation.

  • tol (float) – Tolerance for numerical precision (default is 1e-10).

  • state_update (bool) – If True, also return the post-measurement state(s); otherwise, only the probability or probabilities are returned.

Raises:

ValueError – If a list of operators does not satisfy the completeness relation.

Returns:

If a single operator is provided, returns a float (probability) or a tuple (probability, post_state) if state_update is True. If a list is provided, returns a list of probabilities or a list of tuples if state_update is True.

Return type:

float | tuple[float, numpy.ndarray] | list[float | tuple[float, numpy.ndarray]]