cirq.to_valid_density_matrix

cirq.to_valid_density_matrix(density_matrix_rep: Union[int, numpy.ndarray], num_qubits: Optional[int] = None, *, qid_shape: Optional[Tuple[int, ...]] = None, dtype: Type[numpy.number] = <class 'numpy.complex64'>, atol: float = 1e-07) → numpy.ndarray[source]

Verifies the density_matrix_rep is valid and converts it to ndarray form.

This method is used to support passing a matrix, a vector (wave function),
or a computational basis state as a representation of a state.
Parameters
  • density_matrix_rep – If an numpy array, if it is of rank 2 (a matrix), then this is the density matrix. If it is a numpy array of rank 1 (a vector) then this is a wave function. If this is an int, then this is the computation basis state.

  • num_qubits – The number of qubits for the density matrix. The density_matrix_rep must be valid for this number of qubits.

  • qid_shape – The qid shape of the state vector. Specify this argument when using qudits.

  • dtype – The numpy dtype of the density matrix, will be used when creating the state for a computational basis state (int), or validated against if density_matrix_rep is a numpy array.

  • atol – Numerical tolerance for verifying density matrix properties.

Returns

A numpy matrix corresponding to the density matrix on the given number of qubits.

Raises

ValueError if the density_matrix_rep is not valid.