Quantum Programming Explained: How Developers Write Quantum Code

Quantum programming is writing instructions for a quantum computer. You don’t write a sequence of statements that update variables. You describe a circuit: a fixed arrangement of operations on qubits. You send it to a simulator or quantum processor, run it many times, and read the distribution of outcomes it produces.
Put simply, you are not writing a program that returns an answer. You are building an experiment that produces a statistic.
A few things set quantum programming apart from anything else a developer writes:
- A program is a circuit, not a list of statements. You lay out the whole structure first, then hand it over to be executed as a unit.
- You get a distribution, not a return value. One run gives one random sample. The answer lives in thousands of runs.
- Superposition is not “trying every answer at once.” That is the most common misconception about the topic. The real craft is arranging interference so that wrong answers cancel and the right one survives.
- You cannot if on a qubit, copy one, or print one. Each of these fails for a physical reason, and one of them fails silently.
- The hardware runs a different circuit from the one you wrote. Your code is rewritten into the device’s native gates, and noise grows with every gate added.
- Most of the code is classical. Useful programs are loops where Python runs the show and a small circuit acts as a subroutine.
- Getting started costs nothing. Simulators run on any laptop, and every snippet below ran on a plain CPU.
This guide teaches that programming model to someone who already codes. Each claim is shown with working code and its real output.
How Quantum Programming Works: From Writing a Circuit to Running Quantum Code
This section covers the shift that everything else depends on. A quantum program is not a script that executes line by line. It is a structure you build and then run. The two subsections show what that looks like and where your classical instincts will mislead you.
What Is a Quantum Circuit? How Developers Represent a Quantum Program
In a quantum circuit, each horizontal wire is a qubit and time runs left to right. You are not stepping through instructions. You are laying out a fixed structure that runs as a whole.
The closest idea you already know is building a computation graph before executing it, or writing a shader: you describe everything, then hand it over.
Here is a complete quantum program in Qiskit. It builds a two-qubit circuit, draws it, and runs it 1,024 times on a local simulator:

The two gates each need only one sentence here. h puts qubit 0 into an even mix of 0 and 1, and cx ties qubit 1 to it. How each gate works is the subject of our quantum gates guide. What matters here is the shape: you declare wires, place operations, add measurements, then run.

There is no if on a qubit, and here is what happens when you try
Every developer eventually reaches for if qubit == 1. It does not work, and the reason it fails matters more than the fact that it fails.
Look at what a qubit actually is in your code:

Writing if bad.qubits[0]: does not raise an error. It is valid Python and always evaluates to true, so it silently builds a circuit you did not intend. There is no exception to catch.
The object is a wire label, not a value. Nothing on it can be read.
The correct approach is to measure the qubit into a classical bit and branch on that bit. This is called a dynamic circuit: a circuit that measures a qubit partway through and uses the result to decide what happens next.
The precise rule: branching is allowed, but it costs you the superposition. To get something to branch on, you have to measure, and measuring destroys the state you were exploiting.
That is why quantum algorithms are mostly branch-free structures. The decision-making is pushed out to the classical code around them.
Why Quantum Circuits Run Thousands of Times: Understanding Shots and Measurement Results
A classical function returns a value. A circuit returns a sample. This section shows why a single run tells you almost nothing, and why shots means something different from what a developer expects.
The loop below runs the same Bell circuit from snippet 1 at four different shot counts. A shot is one complete run of the circuit, ending in one measured result.
python
for shots in (1, 10, 100, 4096):
print(shots, sim.run(transpile(qc, sim), shots=shots).result().get_counts())
The table shows what each run returned and what you could honestly conclude from it:
| Shots | Result | What you learn |
| 1 | {’11’: 1} | Almost nothing. It looks like a certain answer, and it isn’t one |
| 10 | {’00’: 4, ’11’: 6} | Two outcomes exist, but the ratio is still noise |
| 100 | {’11’: 50, ’00’: 50} | A 50/50 split starts to show |
| 4096 | {’11’: 2065, ’00’: 2031} | A clear, stable distribution |
Shots is not a performance knob. It is your sample size. It is closer to n in an experiment than to a tuning parameter. Too few shots and your answer is noise. Too many and you burn processor time you may be paying for.
Most real algorithms don’t want a histogram at all. They want one number, the expectation value, which is the average of some measured quantity across all shots. That single number is what gets passed back to classical code, and it drives the hybrid programs covered later.
How Quantum Programs Run: From Local Simulation to Real Quantum Hardware
In practice, a quantum program moves through three stages: you write and simulate it locally, it gets rewritten for a specific machine, and you read results that include errors. Each stage below covers something developers tend to learn the hard way.
How to Run Quantum Code on a Local Simulator Before Using Real Hardware
You write the circuit on your laptop, offline, with no quantum hardware involved. You then run it on a simulator, which is instant and free. Most development happens here.
A simulator is an ordinary computer doing linear algebra to imitate a quantum one. It is exact, which makes it the only place where you can verify your logic.
Simulators do hit a wall. On a typical laptop they stop scaling at roughly the low 30s of qubits, because the state they track doubles with every qubit you add. The maths behind that doubling is covered in our tensor products guide.
What Is Quantum Circuit Transpilation? Why Hardware Runs a Different Circuit
Real devices only support a small set of physical operations, called basis gates, and only some pairs of qubits are physically connected. Before your circuit runs, it is transpiled: rewritten into the device’s basis gates and routed onto qubits that can actually interact.
Here is the two-gate Bell circuit transpiled for a device whose native gates are rz, sx, x and cz:
python
bell = QuantumCircuit(2)
bell.h(0); bell.cx(0, 1)
t = transpile(bell, basis_gates=[“rz”, “sx”, “x”, “cz”], optimization_level=1)
print(dict(bell.count_ops()), bell.depth()) # {‘h’: 1, ‘cx’: 1} 2
print(dict(t.count_ops()), t.depth()) # {‘rz’: 6, ‘sx’: 3, ‘cz’: 1} 7
Circuit depth is the number of sequential steps a circuit takes. The table compares the circuit you wrote with the one the machine runs:
| Measure | As written | After transpiling |
| Gates | 2 (h, cx) | 10 (rz ×6, sx ×3, cz ×1) |
| Depth | 2 | 7 |
This matters because the circuit that has to survive the hardware’s errors is the transpiled one, not the tidy one you wrote. Make a habit of printing count_ops() after transpiling. That habit alone puts you ahead of most tutorials.

How Quantum Hardware Noise Changes Measurement Results
Real hardware returns outcomes that should be impossible. You can see this without hardware access by adding a noise model, a simulated set of errors, to the simulator.
The code below applies 2% depolarising error to one-qubit gates and 5% to two-qubit gates. Depolarising error means that with some probability, a gate scrambles the qubit’s state instead of applying its operation.
Here is the Bell circuit from snippet 1 on both simulators, 4,096 shots each:
| Outcome | Ideal simulator | Simulated noise |
| 00 | 2038 | 2014 |
| 01 | 0 | 54 |
| 10 | 0 | 45 |
| 11 | 2058 | 1983 |
The 01 and 10 results are not a bug in your code. They are errors. This is a simulated noise model that illustrates the effect, not a measurement of any specific device.

Hybrid Quantum-Classical Programming: How Quantum Circuits Work With Classical Code(H2)
Nearly every quantum program that does something useful is a hybrid algorithm, meaning classical and quantum code working in a loop. The quantum part is a subroutine, often a few dozen lines inside a program of a few hundred.
Every variational algorithm, the most common hybrid type, repeats the same four-step loop:
- Classical code chooses parameters, such as rotation angles.
- A small circuit runs with those parameters.
- An expectation value comes back.
- Classical code updates the parameters, and the loop repeats.
PennyLane shows this especially clearly because its circuits are differentiable: you can take a gradient through them, as you would through a neural network layer.
What to Learn Before Quantum Programming: A Step-by-Step Learning Path for Developers
Most developers who give up on quantum computing do so because they start in the wrong place. The sequence below starts with what you already know and builds from there. You can begin every step today.
Work through these in order:
- Python. You already have it. Nothing new is needed.
- Run snippet 1 on a simulator and change it until it breaks.
- Learn the few gates that matter, H, X, CNOT and the rotations, from a gates guide rather than a physics textbook.
- Learn to read a histogram and reason about shots.
- Learn just enough linear algebra to follow multi-qubit states: vectors and the tensor product, a small and specific topic.
- Run something on real hardware and see the noise for yourself.
- Then study an algorithm, such as Grover’s or a variational one.
Notice what is missing from the list: quantum mechanics. You don’t need it to start, and treating it as a prerequisite is the most common reason developers quit in the first week. It becomes worth learning at step 7, when you start asking why an algorithm works rather than what it does.
Writing your first circuit takes an afternoon. Knowing which problems are worth putting on a quantum machine, and how quantum and AI methods fit together, is the part that takes structure. If you want that grounding formally, look at the
Certification in Applied Quantum Computing and AI from IIT Delhi.
Frequently Asked Questions
Yes. Quantum programming can be combined with classical machine learning in hybrid approaches such as quantum machine learning. Quantum circuits can act as part of a larger machine learning workflow, with classical code handling tasks such as optimisation, data processing, and parameter updates.
The best framework depends on your goals and the ecosystem you want to work with. Qiskit is closely associated with IBM Quantum, PennyLane is useful for hybrid quantum-classical and machine learning workflows, while Cirq is designed around quantum circuit development and Google’s quantum computing ecosystem.
Yes. Quantum programs can be developed and tested using simulators on a classical computer. Simulators are useful for learning, debugging, and validating circuit logic before moving the same program to quantum hardware.
You do not need advanced Python to begin. Basic knowledge of variables, functions, loops, libraries, and object-oriented concepts is generally enough to start building quantum circuits with Python-based frameworks.
A regular laptop is sufficient for learning and developing small quantum programs because simulators can run locally. More demanding simulations become difficult as the number of qubits increases, while access to larger quantum experiments generally comes through cloud-based quantum computing platforms.
Yes. Developers can apply existing programming skills to quantum frameworks while learning concepts such as circuits, qubits, measurements, and quantum algorithms. Quantum programming can therefore complement conventional software development rather than requiring developers to abandon classical programming.
Yes. Python is widely used through frameworks such as Qiskit, Cirq, and PennyLane, but other options exist. Q# is Microsoft’s purpose-built quantum programming language, while quantum assembly and intermediate representations can also be used at lower levels.
Beginner projects can include quantum teleportation, simple search algorithms, optimisation experiments, quantum simulations, and small variational circuits. As your skills improve, projects can combine quantum circuits with classical machine learning, optimisation, or real quantum hardware.
The programming syntax may be familiar, but the underlying computational model is different from classical programming. Developers need to become comfortable with probabilistic measurement, quantum states, circuit-based computation, and the limitations imposed by quantum hardware.
Many quantum programming frameworks provide access to cloud-based quantum hardware. Developers can create and test circuits locally and then submit compatible circuits to remote quantum processors through services provided by quantum computing platforms.






