qrisp.QuantumCircuit.extend#

QuantumCircuit.extend(other, translation_dic='id')[source]#

Extends self in-place by another QuantumCircuit.

Parameters:
otherQuantumCircuit

The QuantumCircuit to extend by.

translation_dicdict, optional

The dictionary containing the information about which Qubits and Clbits should be plugged into each other. This dictionary should contain qubits of other as keys and qubits of self as values. If given none, it is assumed that both QuantumCircuits have matching Qubits.

Examples

We create two QuantumCircuits and extend the first with reversed qubit order by the other:

>>> from qrisp import QuantumCircuit
>>> extension_qc = QuantumCircuit(4)
>>> qc_to_extend = QuantumCircuit(4)
>>> extension_qc.cx(0, 1)
>>> extension_qc.cy(0, 2)
>>> extension_qc.cz(0, 3)
>>> print(extension_qc)
qb_0: ──■────■────■──
      ┌─┴─┐  │    │
qb_1: ┤ X ├──┼────┼──
      └───┘┌─┴─┐  │
qb_2: ─────┤ Y ├──┼──
           └───┘┌─┴─┐
qb_3: ──────────┤ Z ├
                └───┘
>>> translation_dic = {extension_qc.qubits[i] : qc_to_extend.qubits[-1-i]
>>> for i in range(4)}
>>> qc_to_extend.extend(extension_qc, translation_dic)
>>> print(qc_to_extend)
                ┌───┐
qb_4: ──────────┤ Z ├
           ┌───┐└─┬─┘
qb_5: ─────┤ Y ├──┼──
      ┌───┐└─┬─┘  │
qb_6: ┤ X ├──┼────┼──
      └─┬─┘  │    │
qb_7: ──■────■────■──