Qubits and Registers
Qubits and Registers
QuantumRegister and ClassicalRegister give groups of qubits and bits meaningful names; each qubit still has a single index in the circuit.
For small circuits it is enough to give the number of qubits, but algorithms usually divide qubits into roles: a data register, ancilla qubits, a counting register and so on. Qiskit lets you name these groups with QuantumRegister(size, name) and store results in a ClassicalRegister.
When building QuantumCircuit(data, anc, out), the qubits are ordered by register order: data[0] and data[1] have indices 0 and 1, and anc[0] has index 2. The find_bit method returns this index. Methods accept a qubitQubit: The qubit is the unit of quantum information: a two-level system whose state is a unit vector α0⟩+β1⟩ in ℂ^2. by its index or by its register reference; qc.measure(data, out) measures the whole register at once.
Qiskit's Qubit OrderingQubit Ordering: Qiskit and the lab follow the little-endian convention: qubit 0 is the least significant bit, so strings are printed as q_n-1… q_1q_0 with qubit 0 on the far right. convention is Little-endian: qubit 0 is the least significant bit, and the printed string reads $q_{n-1}\dots q_0$. When there are several classical registers, their results are printed separated by spaces, and the last register appears first, on the left.
In the example: X on data[1], then a CNOT from it to anc[0], so data[1] and anc[0] are both in state 1 while data[0] stays at 0; measuring the data register will give “10” (bit 1 = 1, bit 0 = 0). Note in the drawing that the measurement of data_0 appears early because it does not depend on any gate; the drawer places each operation in the earliest possible column.
Requirements: pip install qiskit qiskit-aer
Code
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
data = QuantumRegister(2, "data")
anc = QuantumRegister(1, "anc")
out = ClassicalRegister(2, "out")
qc = QuantumCircuit(data, anc, out)
qc.x(data[1])
qc.cx(data[1], anc[0])
qc.measure(data, out)
print("registers:", [r.name for r in qc.qregs], [r.name for r in qc.cregs])
print("total qubits:", qc.num_qubits)
print("index of anc[0]:", qc.find_bit(anc[0]).index)
print(qc.draw("text"))
Line-by-line explanation of the code
| Line | Explanation |
|---|---|
| 1 | Import the circuit and the two register classes. |
| 3 | A two-qubit quantum register named data. |
| 4 | A quantum register with one ancilla qubit named anc. |
| 5 | A two-bit classical register named out. |
| 6 | Build the circuit from the registers; their order determines qubit indexing. |
| 8 | X gate on the second qubit of the data register. |
| 9 | CNOT from data[1] to the ancilla qubit. |
| 10 | Measure the whole data register into the classical register. |
| 12 | Print the names of the quantum and classical registers. |
| 13 | Total number of qubits (3). |
| 14 | The unified index of qubit anc[0] within the circuit. |
| 15 | A text drawing that shows the register names. |
Output (from an actual run)
registers: ['data', 'anc'] ['out']
total qubits: 3
index of anc[0]: 2
┌─┐
data_0: ─────┤M├────────
┌───┐└╥┘ ┌─┐
data_1: ┤ X ├─╫───■──┤M├
└───┘ ║ ┌─┴─┐└╥┘
anc: ──────╫─┤ X ├─╫─
║ └───┘ ║
out: 2/══════╩═══════╩═
0 1
Run with Python 3.13.18 on 2026-11-20 08:14 UTC.
The output is deterministic.
References
- IBM Quantum (2025). Qiskit SDK API documentation. IBM Quantum Documentation quantum.cloud.ibm.com
- IBM Quantum (2025). IBM Quantum Documentation – Guides. IBM Quantum Documentation quantum.cloud.ibm.com
