# DensityMatrix¶

class DensityMatrix(data, dims=None)[source]

DensityMatrix class

Initialize a density matrix object.

Parameters
• data (matrix_like or vector_like) – a density matrix or statevector. If a vector the density matrix is constructed as the projector of that vector.

• dims (int or tuple or list) – Optional. The subsystem dimension of the state (See additional information).

Raises

QiskitError – if input data is not valid.

The dims kwarg can be None, an integer, or an iterable of integers.

• Iterable – the subsystem dimensions are the values in the list with the total number of subsystems given by the length of the list.

• Int or None – the leading dimension of the input matrix specifies the total dimension of the density matrix. If it is a power of two the state will be initialized as an N-qubit state. If it is not a power of two the state will have a single d-dimensional subsystem.

Attributes

 DensityMatrix.atol The absolute tolerance parameter for float comparisons. DensityMatrix.data Return data. DensityMatrix.dim Return total state dimension. DensityMatrix.num_qubits Return the number of qubits if a N-qubit state or None otherwise. DensityMatrix.rtol The relative tolerance parameter for float comparisons.

Methods

 DensityMatrix.add(other) Return the linear combination self + other. Return the conjugate of the density matrix. Make a copy of current operator. DensityMatrix.dims([qargs]) Return tuple of input dimension for specified subsystems. DensityMatrix.evolve(other[, qargs]) Evolve a quantum state by an operator. Return the tensor product state other ⊗ self. DensityMatrix.expectation_value(oper[, qargs]) Compute the expectation value of an operator. DensityMatrix.from_instruction(instruction) Return the output density matrix of an instruction. DensityMatrix.from_int(i, dims) Return a computational basis state density matrix. Return a tensor product of Pauli X,Y,Z eigenstates. DensityMatrix.is_valid([atol, rtol]) Return True if trace 1 and positive semidefinite. DensityMatrix.measure([qargs]) Measure subsystems and return outcome and post-measure state. Return the scalar multipled state other * self. DensityMatrix.probabilities([qargs, decimals]) Return the subsystem measurement probability vector. DensityMatrix.probabilities_dict([qargs, …]) Return the subsystem measurement probability dictionary. Return the purity of the quantum state. DensityMatrix.reset([qargs]) Reset state or subsystems to the 0-state. DensityMatrix.sample_counts(shots[, qargs]) Sample a dict of qubit measurement outcomes in the computational basis. DensityMatrix.sample_memory(shots[, qargs]) Sample a list of qubit measurement outcomes in the computational basis. DensityMatrix.seed([value]) Set the seed for the quantum state RNG. Set the class default absolute tolerance parameter for float comparisons. Set the class default relative tolerance parameter for float comparisons. Return the linear operator self - other. Return the tensor product state self ⊗ other. Returns the density matrix as a counts dict of probabilities. DensityMatrix.to_dict([decimals]) Convert the density matrix to dictionary form. Convert to Operator DensityMatrix.to_statevector([atol, rtol]) Return a statevector from a pure density matrix. Return the trace of the density matrix.