def _validate_qid_shape(val: Any, qubits: Sequence[cirq.Qid]) -> None:
    """Helper function to validate qubits for gates and operations.

    Raises:
        ValueError: The operation had qids that don't match it's qid shape.
    """
    qid_shape = protocols.qid_shape(val)
    if len(qubits) != len(qid_shape):
        raise ValueError(
            f'Wrong number of qubits for <{val!r}>. '
            f'Expected {len(qid_shape)} qubits but got <{qubits!r}>.'
        )
    if any(qid.dimension != dimension for qid, dimension in zip(qubits, qid_shape)):
        raise ValueError(
            f'Wrong shape of qids for <{val!r}>. '
            f'Expected {qid_shape} but got {tuple(qid.dimension for qid in qubits)} <{qubits!r}>.'
        )
    if len(set(qubits)) != len(qubits):
        raise ValueError(
            f'Duplicate qids for <{val!r}>. Expected unique qids but got <{qubits!r}>.'
        )
Helper function to validate qubits for gates and operations.

    Raises:
        ValueError: The operation had qids that don't match it's qid shape.
    
cirq-core/cirq/ops/raw_types.py