def validate(
        self, *, dtype: DTypeLike | None = None, atol=1e-7  # Force keyword arguments
    ) -> None:
        """Check if this quantum state is valid.

        Args:
            dtype: The expected data type of the quantum state.
            atol: Absolute numerical tolerance to use for validation.

        Raises:
            ValueError: Invalid quantum state.
        """
        is_state_vector = self.data.shape == (self._dim,)
        is_state_tensor = self.data.shape == self.qid_shape
        if is_state_vector or is_state_tensor:
            state_vector = self.state_vector()
            assert state_vector is not None
            validate_normalized_state_vector(
                state_vector, qid_shape=self.qid_shape, dtype=dtype, atol=atol
            )
        elif self._is_density_matrix():
            validate_density_matrix(
                self.density_matrix(), qid_shape=self.qid_shape, dtype=dtype, atol=atol
            )
        else:
            raise ValueError(
                'Invalid quantum state: '
                f'Data shape of {self.data.shape} is not '
                f'compatible with qid shape of {self.qid_shape}.'
            )
Check if this quantum state is valid.

        Args:
            dtype: The expected data type of the quantum state.
            atol: Absolute numerical tolerance to use for validation.

        Raises:
            ValueError: Invalid quantum state.
        
cirq-core/cirq/qis/states.py