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
probabilities

Get the probability of observing each computational basis vector upon making a measurement.

Returns: The probability associated with each computational basis vector. numpy float64 multidimensional array
purify()

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. State
reduced_density_operator(qubit_indices)

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. The reduced density operator of the sub-system. DensityOperator