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.

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

1 Answer 1


TL;DR: With QuantumCircuit.num_qubits:

>>> print(qc.num_qubits)

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$.


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.