The density_operator module contains the DensityOperator class,
instances of which represent mixed states of multi-qubit systems,
and functionality for creating density operators from mixtures of
The DensityOperator class is
aliased at the top-level module, so that one can call
qcircuits.DensityOperator() instead of
A density operator representing a mixed state for a quantum system, and associated methods.
Parameters: tensor (numpy complex128 multidimensional array) – The tensor representing the operator.
Produce a density operator from an ensemble, i.e., from a list of states and an equal-length list of probabilities that sum to one, representing classical uncertainty of the state. If the probabilities are not supplied, a uniform distribution is assumed.
- states (list of State) – A list of states.
- ps (list of float) – A list of probabilities summing to one.
A d-qubit density operator representing a mixed state.
Measure the state with respect to the computational bases of the qubits indicated by qubit_indices. Measuring a state will modify the state in-place. If no indices are indicated, the whole state is measured.
- qubit_indices (int or iterable) – An index or indices indicating the qubit(s) whose computational bases the measurement of the state will be made with respect to. If no qubit_indices are given, the whole state is measured.
- remove (bool) – Indicates whether the measured qubits should be removed from the density operator.
The measurement outcomes for the measured qubit(s). If the qubit_indices parameter is supplied as an int, an int is returned, otherwise a tuple.
int or tuple of int
Get the probability of observing each computational basis vector upon making a measurement.
Returns: The probability associated with each computational basis vector. Return type: numpy float64 multidimensional array
If this is a density operator for a \(d\) qubit system, produce a pure state for a \(2d\) qubit system with the same measurement probabilities for the first \(d\) qubits, and whose reduced density operator for the first \(d\) qubits is equal to the original density operator.
Returns: A 2d qubit pure state. Return type: State
Compute the reduced density operator of the given qubits by tracing out the qubits not given.
Parameters: qubit_indices (iterable) – Indices indicating the qubit(s) that we compute the reduced density operator of. Returns: The reduced density operator of the sub-system. Return type: DensityOperator