qrisp.QuantumCircuit.extend#
- QuantumCircuit.extend(other: QuantumCircuit, translation_dic: dict | None = None) None[source]#
Extends this QuantumCircuit in-place by appending instructions from another QuantumCircuit.
- Parameters:
- otherQuantumCircuit
The QuantumCircuit whose instructions will be appended to this circuit.
- 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 None (default), uses identity mapping by matching identifiers. This only works if identifiers match between circuits.
Examples
We create two QuantumCircuits and extend the first with reversed qubit order by the other:
>>> from qrisp import QuantumCircuit >>> extension_qc = 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: ───────────■─>>> qc_to_extend = QuantumCircuit(4) >>> 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: ────────────■── ┌───┐ │ qb_5: ─────┤ Y ├──┼── ┌───┐└─┬─┘ │ qb_6: ┤ X ├──┼────┼── └─┬─┘ │ │ qb_7: ──■────■────■──