DensityMatrix.probabilities

DensityMatrix.probabilities(qargs=None, decimals=None)[source]

Return the subsystem measurement probability vector.

Measurement probabilities are with respect to measurement in the computation (diagonal) basis.

Parameters
  • qargs (None or list) – subsystems to return probabilities for, if None return for all subsystems (Default: None).

  • decimals (None or int) – the number of decimal places to round values. If None no rounding is done (Default: None).

Returns

The Numpy vector array of probabilities.

Return type

np.array

Examples

Consider a 2-qubit product state \(\rho=\rho_1\otimes\rho_0\) with \(\rho_1=|+\rangle\!\langle+|\), \(\rho_0=|0\rangle\!\langle0|\).

from qiskit.quantum_info import DensityMatrix

rho = DensityMatrix.from_label('+0')

# Probabilities for measuring both qubits
probs = rho.probabilities()
print('probs: {}'.format(probs))

# Probabilities for measuring only qubit-0
probs_qubit_0 = rho.probabilities([0])
print('Qubit-0 probs: {}'.format(probs_qubit_0))

# Probabilities for measuring only qubit-1
probs_qubit_1 = rho.probabilities([1])
print('Qubit-1 probs: {}'.format(probs_qubit_1))
probs: [0.5 0.  0.5 0. ]
Qubit-0 probs: [1. 0.]
Qubit-1 probs: [0.5 0.5]

We can also permute the order of qubits in the qargs list to change the qubit position in the probabilities output

from qiskit.quantum_info import DensityMatrix

rho = DensityMatrix.from_label('+0')

# Probabilities for measuring both qubits
probs = rho.probabilities([0, 1])
print('probs: {}'.format(probs))

# Probabilities for measuring both qubits
# but swapping qubits 0 and 1 in output
probs_swapped = rho.probabilities([1, 0])
print('Swapped probs: {}'.format(probs_swapped))
probs: [0.5 0.  0.5 0. ]
Swapped probs: [0.5 0.5 0.  0. ]