cirq.measure_density_matrix

Performs a measurement of the density matrix in the computational basis.

Used in the notebooks

Used in the tutorials

This does not modify density_matrix unless the optional out is density_matrix.

density_matrix The density matrix to be measured. This matrix is assumed to be positive semidefinite and trace one. The matrix is assumed to be of shape (2 ** integer, 2 ** integer) or (2, 2, ..., 2).
indices Which qubits are measured. The matrix is assumed to be supplied in big endian order. That is the xth index of v, when expressed as a bitstring, has the largest values in the 0th index.
qid_shape The qid shape of the density matrix. Specify this argument when using qudits.
out An optional place to store the result. If out is the same as the density_matrix parameter, then density_matrix will be modified inline. If out is not None, then the result is put into out. If out is None a new value will be allocated. In all of these cases out will be the same as the returned ndarray of the method. The shape and dtype of out will match that of density_matrix if out is None, otherwise it will match the shape and dtype of out.
seed A seed for the pseudorandom number generator.

A tuple of a list and a numpy array. The list is an array of booleans corresponding to the measurement values (ordered by the indices). The numpy array is the post measurement matrix. This matrix has the same shape and dtype as the input matrix.

ValueError if the dimension of the matrix is not compatible with a matrix of n qubits. IndexError if the indices are out of range for the number of qubits corresponding to the density matrix.