def __init__(
        self,
        controls: Sequence[cirq.Qid],
        sub_operation: cirq.Operation,
        control_values: cv.AbstractControlValues | Sequence[int | Collection[int]] | None = None,
    ):
        """Initializes the controlled operation.

        Args:
            controls: The qubits that control the sub-operation.
            sub_operation: The operation that will be controlled.
            control_values: Which control qubit values to apply the sub
                operation.  Either an object that inherits from AbstractControlValues
                or a sequence of length `num_controls` where each
                entry is an integer (or set of integers) corresponding to the
                qubit value (or set of possible values) where that control is
                enabled.  When all controls are enabled, the sub gate is
                applied.  If unspecified, control values default to 1.

        Raises:
            ValueError: If the `control_values` or `control_qid_shape` does not
                match the number of qubits, if the `control_values` are out of
                bounds, if the qubits overlap, or if the sub_operation is not a
                unitary or mixture.
        """
        controlled_gate._validate_sub_object(sub_operation)
        if control_values is None:
            control_values = ((1,),) * len(controls)
        if not isinstance(control_values, cv.AbstractControlValues):
            control_values = cv.ProductOfSums(control_values)

        if protocols.num_qubits(control_values) != len(controls):
            raise ValueError('cirq.num_qubits(control_values) != len(controls)')

        # Verify qubits control qubits unique
        control_set = set(controls)
        if len(controls) != len(control_set):
            seen = set()
            dupes = [x for x in controls if x in seen or seen.add(x)]  # type: ignore
            raise ValueError(f'Duplicate control qubits {[str(x) for x in dupes]}.')

        # Verify qubits don't overlap
        if not control_set.isdisjoint(sub_operation.qubits):
            overlap = control_set.intersection(sub_operation.qubits)
            raise ValueError(f'Sub-op and controls share qubits {[str(x) for x in overlap]}.')

        self._control_values = control_values

        # Verify control values not out of bounds
        self._control_values.validate([q.dimension for q in controls])

        if not isinstance(sub_operation, ControlledOperation):
            self._controls = tuple(controls)
            self._sub_operation = sub_operation
        else:
            # Auto-flatten nested controlled operations.
            self._controls = tuple(controls) + sub_operation.controls
            self._sub_operation = sub_operation.sub_operation
            self._control_values = self._control_values & sub_operation.control_values
Initializes the controlled operation.

        Args:
            controls: The qubits that control the sub-operation.
            sub_operation: The operation that will be controlled.
            control_values: Which control qubit values to apply the sub
                operation.  Either an object that inherits from AbstractControlValues
                or a sequence of length `num_controls` where each
                entry is an integer (or set of integers) corresponding to the
                qubit value (or set of possible values) where that control is
                enabled.  When all controls are enabled, the sub gate is
                applied.  If unspecified, control values default to 1.

        Raises:
            ValueError: If the `control_values` or `control_qid_shape` does not
                match the number of qubits, if the `control_values` are out of
                bounds, if the qubits overlap, or if the sub_operation is not a
                unitary or mixture.
        
cirq-core/cirq/ops/controlled_operation.py