Let there be a custom gate (simply called gate that takes $N$ qubits as input. Also, let $A$ of those qubits be in first_register and $B$ of those qubits be in second_register ($B = N-A$, obviously). Both registers are QuantumRegisters.

How to append this custom gate to circuit, like what to write in circuit.append(gate, HERE).


You can simply merge the lists of qubits from two quantum registers or more as any python lists using "+" sign. For example

gate = UnitaryGate(random_unitary(2 ** 4).data, 'RND-U16')

qr1 = QuantumRegister(2, 'q')
qr2 = QuantumRegister(3, 'a')
circ = QuantumCircuit(qr1, qr2)

circ.mct(qr1[0:2] + qr2[0:2], qr2[2])
circ.append(gate, qr1[1:2] + qr2[0:3])

The result:

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.