qrisp.Operation.control#

Operation.control(num_ctrl_qubits=1, ctrl_state=- 1, method=None)[source]#

Returns the controlled version of this Operation (if applicable).

Parameters
num_ctrl_qubitsint, optional

The amount of control qubits. The default is 1.

ctrl_stateint or str, optional

The state on which to activate the basis gate. The default is “1111…”.

methodstr, optional

The method for synthesizing the required multi-controlled X gates. Available are gray and gray_pt and auto. Note that “gray_pt” introduces an extra phase (which needs to be uncomputed) but is more resource efficient. auto will be transformed into a more efficient ancilla supported version at compile time if used in a QuantumSession. The default is gray.

Returns
Operation

The controlled operation.

Raises
AttributeError

Tried to control non-unitary operation.

Examples

We control a parametrized X Rotation.

>>> from qrisp import QuantumCircuit, RXGate
>>> mcrx_gate = RXGate(0.5).control(3)
>>> qc = QuantumCircuit(4)
>>> qc.append(mcrx_gate, qc.qubits)
>>> print(qc)
qb_4: ─────■─────
           │
qb_5: ─────■─────
           │
qb_6: ─────■─────
      ┌────┴────┐
qb_7: ┤ Rx(0.5) ├
      └─────────┘