From the perspective of building quantum computation software based on Qiskit, which approach to defining quantum circuits is more robust?

from qiskit.circuit import QuantumCircuit, QuantumRegister, ClassicalRegister

qr1 = QuantumRegister(3, 'qr1')
qr2 = QuantumRegister(4, 'qr2')
cr  = ClassicalRegister(4, 'cr')
circ = QuantumCircuit(qr1, qr2, cr)


circ = QuantumCircuit(7, 5)

So far I've been using the latter approach, but it seems like I might run into trouble later as the software matures and I add more functionalities. Any opinion from an experienced Quantum Computation Software Developer would be greatly appreciated!

  • 1
    $\begingroup$ As Qiskit dev, I use the following rule of thumb: In general I always use registerless circuits (QuantumCircuit(7,5)) because it saves me a few lines of code. But if I want to give my qubits names and want to print the circuit nicely, I use registers. $\endgroup$
    – Cryoris
    Feb 26, 2021 at 10:10

1 Answer 1


Registers are mostly a user-land element for convenience and organization. They are mostly inherited from OpenQASM. Currently (qiskit-terra 0.17) they are optional.

However, there is a notable exception (at least for now). To implement a classical conditional, the condition is on a classical register. If your circuit has a classical conditional, it needs a classical register. Because circuits cannot be a with-register/registerless mix, then also the quantum register is required:

from qiskit import *

qreg = QuantumRegister(1)
creg = ClassicalRegister(4)
circuit = QuantumCircuit(qreg, creg)
circuit.h(0).c_if(creg, 3)


enter image description here

  • $\begingroup$ Luciano, thanks for your response. I wasn't aware of the classical conditional issue. I was leaning on constructing register objects and passing them to initialize the circuits. It seems more organized/convenient to me, particularly for the Quantum Monte Carlo type circuits, to be able to access the qubits by their labels. Otherwise, when using them via indices (to apply some complicated sub routines), it would be less clear which qubits are meant to be ancillas. $\endgroup$ Feb 26, 2021 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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