qrisp.QuantumCircuit.to_op#

QuantumCircuit.to_op(name: str | None = None) Operation[source]#

Method to return an Operation object generated out of this QuantumCircuit.

Operation objects can be appended to other QuantumCircuits.

An alias for Qiskit compatibility is the to_gate method.

Parameters:
namestr, optional

The name of the gate. By default, the QuantumCircuit’s name will be used.

Returns:
Operation

The Operation defined by this QuantumCircuit.

Examples

We create a QuantumCircuit and turn it into an Operation which we append to another QuantumCircuit:

>>> from qrisp import QuantumCircuit
>>> qc_0 = QuantumCircuit(4)
>>> qc_0.x(qc_0.qubits)
>>> operation = qc_0.to_op(name="converted_op")
>>> qc_1 = QuantumCircuit(4)
>>> qc_1.append(operation, qc_1.qubits)
>>> print(qc_1)
        ┌───────────────┐
qb_107: ┤0              ├
        │               │
qb_108: ┤1              ├
        │  converted_op │
qb_109: ┤2              ├
        │               │
qb_110: ┤3              ├
        └───────────────┘