# qcircuits.density_operator module¶

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 pure State objects.

The DensityOperator class is aliased at the top-level module, so that one can call qcircuits.DensityOperator() instead of qcircuits.state.DensityOperator().

class qcircuits.density_operator.DensityOperator(tensor)

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.
static from_ensemble(states, ps=None)

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.

Parameters: 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. DensityOperator
measure(qubit_indices=None, remove=False)

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.

Parameters: 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