Define the number of qubits directly in the quantum circuit and access the qubits with their index
by Frank ZickertOctober 16, 2025
The fundamental element of quantum computing is the quantum circuit. This is a computational routine that can be run, one shot at a time, on a quantum processing unit (QPU). A circuit will act on a predefined amount of quantum data (in Qiskit, we only directly support qubits) with unitary operations (gates), measurements and resets. In addition, a quantum circuit can contain operations on classical data, including real-time computations and control-flow constructs, which are executed by the controllers of the QPU.
The QuantumCircuit-class is the native format in which to represent quantum instructions, and operators represent the observables to be measuredIBM, 2025, IBM Quantum Hello World, . It is the entrypoint to develop any quantum algorithm, subroutine, or even a custom quantum operator.
When you view a A quantum circuit is a sequence of quantum gates applied to qubits, representing the operations in a quantum computation. Each gate changes the qubits’ state using quantum mechanics principles like superposition and entanglement. The final qubit states, when measured, yield the circuit’s computational result probabilistically. Learn more about Quantum Circuit as a program, a fixed sequence of instructions, it emphasizes the internal interactions between operations. However, Qiskit's QuantumCircuit represents the abstract concept of a A quantum circuit is a sequence of quantum gates applied to qubits, representing the operations in a quantum computation. Each gate changes the qubits’ state using quantum mechanics principles like superposition and entanglement. The final qubit states, when measured, yield the circuit’s computational result probabilistically. Learn more about Quantum Circuit, which defines a mathematical mapping from input states to output states. Viewing it as a model instead highlights the overall behavior and outcomes of the system. In short, the program view focuses on how the circuit works, while the model view focuses on what it does.
? depicts the simplest use of the QuantumCircuit-class.
quantum-circuit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
from qiskit import QuantumCircuit
# Create a new circuit with two qubits
qc = QuantumCircuit(2)
# Add a Hadamard gate to qubit 0
qc.h(0)
# Perform a controlled-X gate on qubit 1, controlled by qubit 0
qc.cx(0, 1)
# Return a text drawing of the circuit.
qc.draw()
Listing 1 Direct initialization with the number of qubits
the QuantumCircuit-class directly from Qiskit.
The simplest way to instantiate the QuantumCircuit-class is by and passing the number of qubits as first argument.
You can add A quantum gate is a basic operation that changes the state of one or more qubits, similar to how a logic gate operates on bits in classical computing. It uses unitary transformations, meaning it preserves the total probability (the state’s length in complex space). Quantum gates enable superposition and entanglement, allowing quantum computers to perform computations that classical ones cannot efficiently replicate. Learn more about Quantum Gate to the QuantumCircuit by (usually corresponding to the letter of the A quantum gate is a basic operation that changes the state of one or more qubits, similar to how a logic gate operates on bits in classical computing. It uses unitary transformations, meaning it preserves the total probability (the state’s length in complex space). Quantum gates enable superposition and entanglement, allowing quantum computers to perform computations that classical ones cannot efficiently replicate. Learn more about Quantum Gate) and passing the position of the qubit as an argument.