Quantum Programming with Qiskit
You've learned the theory: qubits, gates, and circuits. Now let's write code. Qiskit is IBM's free, open-source Python toolkit for quantum programming. In this guide you'll install it, build your first quantum circuit, create an entangled pair of qubits, and learn how to read the results.
What is Qiskit?
Qiskit (pronounced "kiss-kit") is a Python library for describing quantum circuits and running them. The same code can run on a simulator on your laptop or on a real quantum computer in IBM's cloud.
Is quantum programming like normal programming?
Partly. You still write Python: variables, loops, functions. But the quantum part isn't a list of instructions that run one after another on data. It's a circuit: a recipe of gates applied to qubits, followed by measurement. You build the circuit in Python, then run it many times and look at the pattern of results.
How do you install Qiskit?
You need Python 3.9 or newer. Create a virtual environment so Qiskit doesn't clash with other projects, then install it with pip:
python3 -m venv qenv
source qenv/bin/activate # on Windows: qenv\Scripts\activate
pip install qiskit Tip: Jupyter notebooks (pip install jupyter) are a comfortable way to experiment. You can change one line and re-run instantly.
The four building blocks you'll use first
Almost every beginner program uses these four operations. Pick one to see what it does:
Essential Qiskit operations
qc.h(0)
Hadamard gate. Puts a qubit into an equal superposition: measured, it gives 0 or 1 with 50% probability each.
qc.h(0) # |0⟩ → equal mix of |0⟩ and |1⟩ qc.x(0)
X (NOT) gate. Flips 0 to 1 and 1 to 0, just like a classical NOT.
qc.x(0) # |0⟩ → |1⟩ qc.cx(0, 1)
CNOT (controlled-X). Flips the target qubit (1) only when the control qubit (0) is 1. Combined with H, it creates entanglement.
qc.cx(0, 1) # control = qubit 0, target = qubit 1 measure_all()
Measurement. Reads every qubit into a classical bit. This collapses superposition, so the qubit becomes a plain 0 or 1.
qc.measure_all() # adds classical bits named "meas" Your first quantum circuit: a coin flip
A single qubit in superposition behaves like a perfectly fair coin. Let's build it and "flip" it 1,000 times:
from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler
qc = QuantumCircuit(1) # a circuit with 1 qubit, starting in state 0
qc.h(0) # Hadamard: put qubit 0 into superposition
qc.measure_all() # measure it
sampler = StatevectorSampler() # a simulator that runs on your computer
result = sampler.run([qc], shots=1000).result()
counts = result[0].data.meas.get_counts()
print(counts) QuantumCircuit(1)— creates a circuit with one qubit. Every qubit starts as 0.qc.h(0)— applies the Hadamard gate to qubit 0.StatevectorSampler()— Qiskit's built-in simulator for running circuits and sampling results.shots=1000— run the circuit 1,000 times. Each run gives one random 0 or 1.data.meas.get_counts()— tally the results.measis the namemeasure_all()gives the classical bits.
You'll get roughly 500 zeros and 500 ones, for example {'0': 509, '1': 491}. The exact numbers change every run,
just like real coin flips. Add print(qc.draw()) to see a text diagram of your circuit.
Let's see it in action: entangling two qubits
Now for something no classical coin can do. We'll create a Bell state: two qubits that always agree when measured, even though each one on its own is completely random. This is entanglement.
from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler
qc = QuantumCircuit(2)
qc.h(0) # qubit 0 into superposition
qc.cx(0, 1) # entangle: qubit 1 copies qubit 0's fate
qc.measure_all()
counts = StatevectorSampler().run([qc], shots=1000).result()[0].data.meas.get_counts()
print(counts) What the Bell state measures to
| Result | Probability | Meaning |
|---|---|---|
00 | ≈ 50% | Both qubits measured 0 |
11 | ≈ 50% | Both qubits measured 1 |
01 or 10 | 0%: never happens | The qubits never disagree |
Each qubit alone is a fair coin, but the two coins always land the same way. Measuring one instantly tells you the other. That perfect correlation is the signature of entanglement.
Why do Qiskit results look backwards?
Run this, which flips only qubit 0:
qc = QuantumCircuit(2)
qc.x(0) # flip qubit 0 only
qc.measure_all()
print(StatevectorSampler().run([qc], shots=10).result()[0].data.meas.get_counts()) {'01': 10}
You might expect '10'. Qiskit writes results little-endian:
qubit 0 is the rightmost character. Read result strings from right to left to match qubit numbers. It's
a convention, and once you know it you'll never be confused by it again.
Scaling up: a three-qubit GHZ state
Chain more CNOTs and the entanglement spreads. All three qubits now share one fate:
qc = QuantumCircuit(3)
qc.h(0)
qc.cx(0, 1)
qc.cx(1, 2)
qc.measure_all()
Measuring gives only 000 or 111, about half the time each. States like this are used in
quantum error correction and to benchmark real quantum hardware.
How do you run on a real quantum computer?
IBM offers free monthly time on real quantum processors through the IBM Quantum Platform. The steps are:
- Create an IBM Quantum account and get an API key.
- Install the runtime client:
pip install qiskit-ibm-runtime. - Transpile your circuit: rewrite it using only the gates and qubit connections the chosen processor actually supports.
- Submit it with the runtime
Samplerand wait in the queue for results.
Will real hardware give the same results as the simulator?
Not exactly. Real qubits are noisy, so your Bell state will show mostly 00 and 11, plus
a small percentage of "impossible" 01 and 10 results caused by errors. Seeing that noise
for yourself is one of the best lessons in why error correction matters.
Other quantum programming frameworks
| Framework | Backed by | Language | Known for |
|---|---|---|---|
| Qiskit | IBM | Python | Largest community; free access to real hardware |
| Cirq | Python | Fine control over circuits for near-term devices | |
| PennyLane | Xanadu | Python | Quantum machine learning; works with PyTorch and JAX |
| Amazon Braket SDK | AWS | Python | One API for hardware from several vendors |
| Q# | Microsoft | Q# (own language) | Azure Quantum and resource estimation |
The concepts (qubits, gates, circuits, and measurement) are the same everywhere, so skills transfer easily between them.
Quick recap
- Qiskit is IBM's open-source Python SDK; install it with
pip install qiskit. - Build a
QuantumCircuit, add gates (h,x,cx), thenmeasure_all(). - Run many shots and read the counts; the pattern is the answer.
h+cxcreates an entangled Bell state: only00or11.- Qiskit result strings put qubit 0 on the right.
What's next?
Try implementing Deutsch's algorithm in Qiskit, the simplest algorithm with a real quantum advantage. Then see where this is all heading in quantum machine learning.
Frequently Asked Questions
What is Qiskit?
Qiskit is IBM's open-source software development kit for quantum computing, written in Python. You use it to build quantum circuits, simulate them on your own computer, and send them to real IBM quantum processors over the cloud.
Do I need a quantum computer to learn quantum programming?
No. Qiskit includes simulators that run on an ordinary laptop, and they're perfect for learning. Small circuits of a few dozen qubits or fewer simulate quickly. You only need real hardware when you want to see how noise affects results or run experiments at scale.
Which programming language is used for quantum programming?
Mostly Python. Qiskit, Cirq, PennyLane, and Amazon Braket's SDK are all Python libraries. Microsoft's Q# is a dedicated quantum language. Python is the best place to start because the major tools and tutorials use it.
Why do my Qiskit results look reversed?
Qiskit orders bits 'little-endian': qubit 0 is the rightmost character of the result string. So flipping only qubit 0 in a two-qubit circuit gives '01', not '10'. It's a convention, not a bug, and it trips up almost every beginner.
Why do quantum results come out as counts instead of one answer?
Measuring a qubit in superposition gives a random outcome, so programs are run many times (called shots) and the results are tallied. The pattern of counts, such as about half 00 and half 11, is the real answer, not any single run.