qrisp.QuantumCircuit.append#

QuantumCircuit.append(operation_or_instruction: Operation | Instruction, qubits: Sequence[QubitLike] | None = None, clbits: Sequence[ClbitLike] | None = None)[source]#

Append an Operation or Instruction to this QuantumCircuit.

Each qubit or classical-bit argument may be specified as a Qubit / Clbit object, an integer index into self.qubits / self.clbits, or a (possibly nested) list thereof. When a list argument contains n elements, the operation is broadcast and applied n times β€” once per element β€” with the remaining scalar arguments reused for every application.

If an Instruction is given instead of an Operation, the qubits and clbits arguments are ignored; the instruction’s own qubit and classical-bit lists are used directly.

Parameters:
operation_or_instructionOperation or Instruction

The operation or instruction to append.

qubitsQubitLike, optional

The qubit(s) on which to apply the operation. The default is [].

clbitsClbitLike, optional

The classical bit(s) on which to apply the operation. The default is [].

Returns:
None

Examples

We create a \(H^{\otimes 4}\) gate and append it to every second qubit of another QuantumCircuit:

>>> from qrisp import QuantumCircuit
>>> multi_h_qc = QuantumCircuit(4)
>>> multi_h_qc.h(range(4))
>>> multi_h = multi_h_qc.to_gate(name="multi h")
>>> qc = QuantumCircuit(8)
>>> qc.append(multi_h, [2*i for i in range(4)])
>>> print(qc)
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 qb_4: ─0         β”œ
       β”‚          β”‚
 qb_5: ─          β”œ
       β”‚          β”‚
 qb_6: ─1         β”œ
       β”‚          β”‚
 qb_7: ─  multi h β”œ
       β”‚          β”‚
 qb_8: ─2         β”œ
       β”‚          β”‚
 qb_9: ─          β”œ
       β”‚          β”‚
qb_10: ─3         β”œ
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
qb_11: ────────────