def density_matrix(self) -> np.ndarray:
        """Return the density matrix of this state.

        A density matrix stores the entries of a density matrix as a matrix
        (a two-dimensional array).
        """
        if not self._is_density_matrix():
            state_vector = self.state_vector()
            assert state_vector is not None, 'only None if _is_density_matrix'
            return np.outer(state_vector, np.conj(state_vector))
        return self.data
Return the density matrix of this state.

        A density matrix stores the entries of a density matrix as a matrix
        (a two-dimensional array).
        
cirq-core/cirq/qis/states.py