def infer_qid_shape(*states: cirq.QUANTUM_STATE_LIKE) -> tuple[int, ...]:
    """Infer the qid shape of a set of states.

    This is a heuristic to determine a qid shape compatible with all of the
    given states. It works by attempting to find the intersection of the sets
    of potential qid shapes for each given state. It may fail (raising an
    error) even if there is a unique compatible qid shape. If the dimension of
    a state vector or density matrix (but not state tensor) is a power of 2,
    then the state space is assumed to be composed of qubits; otherwise, it is
    assumed to be composed of a single qudit. If the qid shape is ambiguous,
    an error is raised.

    Args:
        *states: The states for which to infer the qid shape.

    Returns:
        The inferred qid shape.

    Raises:
        ValueError: The qid shape of the given states is ambiguous.
        ValueError: Failed to infer the qid shape of the given states.
    """
    if not states:
        raise ValueError('No states were specified.')

    integer_states: list[int] = []
    non_integer_states: list[_NON_INT_STATE_LIKE] = []
    for state in states:
        if isinstance(state, int):
            integer_states.append(state)
        else:
            non_integer_states.append(state)

    # if all states are specified as integers, use the minimal possible dimensions
    if not non_integer_states:
        return (max(integer_states) + 1,)

    # attempt to infer qid shape from non-integer states
    potential_shapes = _potential_qid_shapes(non_integer_states[0])
    for state in non_integer_states[1:]:
        potential_shapes = potential_shapes.intersection_subset(_potential_qid_shapes(state))
    qid_shape = potential_shapes.infer_qid_shape()
    if qid_shape is None:
        raise ValueError(
            'Failed to infer the qid shape of the given states. '
            'If you think there is an unambiguous result for this case, please raise '
            'an issue at https://github.com/quantumlib/Cirq.'
        )

    # check if the shape is compatible with the states specified as integers
    if integer_states and np.prod(qid_shape, dtype=np.int64) <= max(integer_states):
        raise ValueError(
            'Failed to infer the qid shape of the given states. '
            f'The given integer state {max(integer_states)} is too high for the '
            f'qid shape {qid_shape} inferred from some other given states.'
        )

    return qid_shape
Infer the qid shape of a set of states.

    This is a heuristic to determine a qid shape compatible with all of the
    given states. It works by attempting to find the intersection of the sets
    of potential qid shapes for each given state. It may fail (raising an
    error) even if there is a unique compatible qid shape. If the dimension of
    a state vector or density matrix (but not state tensor) is a power of 2,
    then the state space is assumed to be composed of qubits; otherwise, it is
    assumed to be composed of a single qudit. If the qid shape is ambiguous,
    an error is raised.

    Args:
        *states: The states for which to infer the qid shape.

    Returns:
        The inferred qid shape.

    Raises:
        ValueError: The qid shape of the given states is ambiguous.
        ValueError: Failed to infer the qid shape of the given states.
    
cirq-core/cirq/qis/states.py