def controlled( self, num_controls: int = None, control_values: Optional[Sequence[Union[int, Collection[int]]]] = None, control_qid_shape: Optional[Tuple[int, ...]] = None, ) -> 'Gate': """Returns a controlled version of this gate. If no arguments are specified, defaults to a single qubit control. num_controls: Total number of control qubits. control_values: For which control qubit values to apply the sub gate. 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. control_qid_shape: The qid shape of the controls. A tuple of the expected dimension of each control qid. Defaults to `(2,) * num_controls`. Specify this argument when using qudits. """ # Avoids circular import. from cirq.ops import ControlledGate if num_controls == 0: return self return ControlledGate( self, num_controls=num_controls, control_values=control_values, control_qid_shape=control_qid_shape, )
def controlled_by(self, *control_qubits: Qid) -> 'Gate': """Returns a controlled version of this gate. Args: control_qubits: Optional qubits to control the gate by. """ # Avoids circular import. from cirq.ops import ControlledGate if len(control_qubits) == 0: return self return ControlledGate(self, control_qubits, len(control_qubits))
def controlled_by( self, *control_qubits: Qid, control_values: Optional[Sequence[Union[int, Collection[int]]]] = None ) -> 'Gate': """Returns a controlled version of this gate. Args: control_qubits: Optional qubits to control the gate by. """ # Avoids circular import. from cirq.ops import ControlledGate if len(control_qubits) == 0: return self return ControlledGate(self, control_qubits, len(control_qubits), control_values)