def validate_normalized_state_vector(
    state_vector: np.ndarray,
    *,  # Force keyword arguments
    qid_shape: tuple[int, ...],
    dtype: DTypeLike | None = None,
    atol: float = 1e-7,
) -> None:
    """Checks that the given state vector is valid.

    Args:
        state_vector: The state vector to validate.
        qid_shape: The expected qid shape of the state.
        dtype: The expected dtype of the state.
        atol: Absolute numerical tolerance.

    Raises:
        ValueError: State has invalid dtype.
        ValueError: State has incorrect size.
        ValueError: State is not normalized.
    """
    if dtype and state_vector.dtype != dtype:
        raise ValueError(
            f'state_vector has invalid dtype. Expected {dtype} but was {state_vector.dtype}'
        )
    if state_vector.size != np.prod(qid_shape, dtype=np.int64):
        raise ValueError(
            'state_vector has incorrect size. '
            f'Expected {np.prod(qid_shape, dtype=np.int64)} but was {state_vector.size}.'
        )
    norm = np.sum(np.abs(state_vector) ** 2)
    if not np.isclose(norm, 1, atol=atol):
        raise ValueError(f'State_vector is not normalized instead had norm {norm}')
Checks that the given state vector is valid.

    Args:
        state_vector: The state vector to validate.
        qid_shape: The expected qid shape of the state.
        dtype: The expected dtype of the state.
        atol: Absolute numerical tolerance.

    Raises:
        ValueError: State has invalid dtype.
        ValueError: State has incorrect size.
        ValueError: State is not normalized.
    
cirq-core/cirq/qis/states.py