def _validate_dd_sequence(dd_sequence: tuple[ops.Gate, ...]) -> None:
    """Validates a given dynamical decoupling sequence.

    The sequence should only consists of Pauli gates and is essentially an identity gate.

    Args:
        dd_sequence: Input dynamical sequence to be validated.

    Raises:
        ValueError: If dd_sequence is not valid.
    """
    if len(dd_sequence) < 2:
        raise ValueError('Invalid dynamical decoupling sequence. Expect more than one gates.')
    for gate in dd_sequence:
        if _pauli_up_to_global_phase(gate) is None:
            raise ValueError(
                'Dynamical decoupling sequence should only contain gates that are essentially'
                ' Pauli gates.'
            )
    matrices = [unitary_protocol.unitary(gate) for gate in dd_sequence]
    product = reduce(np.matmul, matrices)

    if not protocols.equal_up_to_global_phase(product, np.eye(2)):
        raise ValueError(
            'Invalid dynamical decoupling sequence. Expect sequence production equals'
            f' identity up to a global phase, got {product}.'.replace('\n', ' ')
        )
Validates a given dynamical decoupling sequence.

    The sequence should only consists of Pauli gates and is essentially an identity gate.

    Args:
        dd_sequence: Input dynamical sequence to be validated.

    Raises:
        ValueError: If dd_sequence is not valid.
    
cirq-core/cirq/transformers/dynamical_decoupling.py