measure
¶
Apply measurement to a quantum state.
measure
¶
measure(
state: ndarray,
measurement: ndarray
| list[ndarray]
| tuple[ndarray, ...],
tol: float = 1e-10,
state_update: bool = False,
) -> (
float
| tuple[float, ndarray]
| list[float | tuple[float, ndarray]]
)
Apply measurement to a quantum state.
The measurement can be provided as a single operator or as a list of operators describing a complete quantum measurement.
A single operator is always treated as a Kraus operator \(K\): the outcome probability is \(\mathrm{Tr}(K \rho K^\dagger) = \mathrm{Tr}(K^\dagger K \rho)\) and the post-measurement state is \(K \rho K^\dagger / \mathrm{Tr}(K \rho K^\dagger)\). For a POVM element \(E\) the Born probability is \(\mathrm{Tr}(E \rho)\); this equals \(\mathrm{Tr}(K \rho K^\dagger)\) only when the operator is a projector (\(E^\dagger E = E\)), so to measure with a non-projector POVM element pass its Kraus operators in the list form.
When a single operator is provided:
- Returns the measurement outcome probability if
state_updateis False. - Returns a tuple (probability, post_state) if
state_updateis True.
When a list of operators is provided, the function verifies that they satisfy the completeness relation (which
depends only on the operators, not on the state or state_update).
when state_update is True. Then, for each operator \(K_i\), the outcome probability is computed as
and, if \(p_i > tol\), the post‐measurement state is updated via
where we define \(u u^* = \rho \in \text{D}(\mathcal{X})\).
Define measurement operators
```python exec="1" source="above" result="text"
import numpy as np
from toqito.states import basis
from toqito.measurement_ops import measure
e_0, e_1 = basis(2, 0), basis(2, 1)
u = 1/np.sqrt(3) * e_0 + np.sqrt(2/3) * e_1
rho = u @ u.conj().T
proj_0 = e_0 @ e_0.conj().T
proj_1 = e_1 @ e_1.conj().T
print(measure(proj_0, rho))
```
Then the probability of obtaining outcome \(0\) is given by
Similarly, the probability of obtaining outcome \(1\) is given by
```python exec="1" source="above" result="text"
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("```")
print(measure(rho, [K0, K1]))
# Returns list of (probability, post_state) tuples.
print(measure(rho, [K0, K1], state_update=True))
print("```")
```
Raises:
-
ValueError–If a list of operators does not satisfy the completeness relation.
Parameters:
-
state(ndarray) –Quantum state as a density matrix shape (d, d) where d is the dimension of the Hilbert space.
-
measurement(ndarray | list[ndarray] | tuple[ndarray, ...]) –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, default:1e-10) –Tolerance for numerical precision (default is 1e-10).
-
state_update(bool, default:False) –If True, also return the post-measurement state(s); otherwise, only the probability or probabilities are returned.
Returns:
-
float | tuple[float, ndarray] | list[float | tuple[float, ndarray]]–If a single operator is provided, returns a float (probability) or a tuple (probability, post_state) if
-
float | tuple[float, ndarray] | list[float | tuple[float, ndarray]]–state_updateis True. If a list is provided, returns a list of probabilities or a list of tuples if -
float | tuple[float, ndarray] | list[float | tuple[float, ndarray]]–state_updateis True.
Source code in toqito/measurement_ops/measure.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |