- If 2 quantum circuits have the same number of qubits, there is an easy way to do it, simply by adding these two quantum circuits. For example:
from qiskit import QuantumCircuit
qc1 = QuantumCircuit(2)
qc2 = QuantumCircuit(2)
qc1.h(0)
qc1.cx(1,0)
qc2.x(0)
qc3 = qc1 + qc2
qc3
is a circuit which applies the gates in qc1
then the gates in qc2
.
- If the two circuits have different number of qubits, you can use
QuantumRegister
to name your qubits, then qiskit will add the circuits by matching the same qubit names. For example:
from qiskit import QuantumCircuit
from qiskit import QuantumRegister
qr1_a = QuantumRegister(1, 'a')
qr1_b = QuantumRegister(2, 'b')
qc1 = QuantumCircuit(qr1_a, qr1_b)
qc2_b = QuantumRegister(2,'b')
qc2 = QuantumCircuit(qc2_b)
qc1.cx(1,0)
qc2.x(1)
qc2.z(0)
qc3 = qc1 + qc2
where qc3
is the circuit with qc2
being added behind qc1
's gates on the 'b' qubits.