# Number of qubits in quantum circuits in ibm qiskit

How to find number of Qubits ?

from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister

bob   = QuantumRegister(8,'b')
alice = ClassicalRegister(2,'a')
eve   = QuantumRegister(4,'e')
qc = QuantumCircuit(bob, alice, eve)


I know of syntax QuantumCircuit(2, 2) ie. 2 parameter but not sure about 3 parameter.

• It's IBM qiskit and language is python Commented Aug 14, 2023 at 13:04
• Is your question how to extract the number of qubits from an instance of QuantumCircuit? Theres a QuantumCircuit.num_qubits attribute for this. Commented Aug 14, 2023 at 13:37
• Yeah. But how to extract without using QuantumCircuit.num_qubits attribute ? Commented Aug 14, 2023 at 13:47
• So in your code why can't you just do print(qc.num_qubits) to get the number of qubits? Commented Aug 14, 2023 at 15:56
• Because I wanted to understand the code behavior and how it works in background. Commented Aug 16, 2023 at 9:52

TL;DR: With QuantumCircuit.num_qubits:

>>> print(qc.num_qubits)
12


A list of them, via QuantumCircuit.qubits:

>>> print(qc.qubits)
[Qubit(QuantumRegister(8, 'b'), 0),
Qubit(QuantumRegister(8, 'b'), 1),
Qubit(QuantumRegister(8, 'b'), 2),
Qubit(QuantumRegister(8, 'b'), 3),
Qubit(QuantumRegister(8, 'b'), 4),
Qubit(QuantumRegister(8, 'b'), 5),
Qubit(QuantumRegister(8, 'b'), 6),
Qubit(QuantumRegister(8, 'b'), 7),
Qubit(QuantumRegister(4, 'e'), 0),
Qubit(QuantumRegister(4, 'e'), 1),
Qubit(QuantumRegister(4, 'e'), 2),
Qubit(QuantumRegister(4, 'e'), 3)]


The QuantumCircuit constructor documentation can be found here:

regs (list(Register) or list(int) or list(list(Bit))) – The registers to be included in the circuit.

This means, that the registers bob, alice, and eve are included. Their length is 8, 2, and 4 respectably. However, alice is a classical register, which does not extend the amount of qubit. So, $$8+4=12$$.