Probability of each computational basis state.
This measurement function accepts either a wire specification or an observable. Passing wires to the function instructs the QNode to return a flat array containing the probabilities \(|\langle i | \psi \rangle |^2\) of measuring the computational basis state \(| i \rangle\) given the current state \(| \psi \rangle\).
Marginal probabilities may also be requested by restricting the wires to a subset of the full system; the size of the returned array will be
dev = qml.device("default.qubit", wires=2) @qml.qnode(dev) def circuit(): qml.Hadamard(wires=1) return qml.probs(wires=[0, 1])
Executing this QNode:
>>> circuit() array([0.5, 0.5, 0. , 0. ])
The returned array is in lexicographic order, so corresponds to a \(50\%\) chance of measuring either \(|00\rangle\) or \(|01\rangle\).
dev = qml.device("default.qubit", wires=2) H = 1 / np.sqrt(2) * np.array([[1, 1], [1, -1]]) @qml.qnode(dev) def circuit(): qml.PauliZ(wires=0) qml.PauliX(wires=1) return qml.probs(op=qml.Hermitian(H, wires=0))
The returned array is in lexicographic order, so corresponds to a \(14.6\%\) chance of measuring the rotated \(|0\rangle\) state and \(85.4\%\) of measuring the rotated \(|1\rangle\) state.
Note that the output shape of this measurement process depends on whether the device simulates qubit or continuous variable quantum systems.
wires (Sequence[int] or int) – the wire the operation acts on
op (Observable) – Observable (with a diagonalzing_gates attribute) that rotates the computational basis