コード例 #1
0
ファイル: raw_types.py プロジェクト: asandbox/Cirq
    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,
        )
コード例 #2
0
ファイル: raw_types.py プロジェクト: LukeMcCulloch/Cirq
    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))
コード例 #3
0
ファイル: raw_types.py プロジェクト: jshede/Cirq
    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)
コード例 #4
0
ファイル: quirk_gate.py プロジェクト: verult-prowtest/Cirq
def controlled_unwrap(gate: ops.ControlledGate) -> Optional[QuirkOp]:
    sub = _gate_to_quirk_op(gate.sub_gate)
    if sub is None:
        return None
    return QuirkOp(*(('•', ) * gate.num_controls() + sub.keys),
                   can_merge=False)