This Qiskit noise simulation tutorial shows how to compare an ideal circuit, a controlled noisy simulation, and results from real quantum hardware. You will build a reusable Qiskit Aer noise model, add gate and readout errors, keep transpilation consistent, and use a troubleshooting checklist to explain why measured distributions differ.
Overview
An ideal simulator applies the circuit mathematics without modeling imperfect gates, measurement, or device connectivity. A noisy simulator adds selected error channels so you can test how those imperfections may affect the result. Hardware execution adds another layer: the device's current calibration, native gate set, qubit layout, queue conditions, and runtime behavior.
The goal is not to make a simulated distribution match hardware automatically. The goal is to separate causes of disagreement. Start with a reproducible circuit and fixed shot count, run the same logical experiment in three modes, and record the circuit after transpilation. This makes it easier to distinguish sampling variation from readout error, gate error, and changes introduced by routing.
The examples below use the qiskit_aer package and common Qiskit circuit primitives. Imports and backend-property methods can change across Qiskit releases, so confirm the API against the documentation for the environment you install.
Install and define a small test circuit
pip install qiskit qiskit-aer
from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator
from qiskit_aer.noise import NoiseModel, depolarizing_error, ReadoutError
shots = 20_000
circuit = QuantumCircuit(2, 2)
circuit.h(0)
circuit.cx(0, 1)
circuit.measure([0, 1], [0, 1])
This Bell-state circuit should ideally produce mostly 00 and 11. It is useful for a first test because gate errors can reduce correlation and readout errors can move probability into other bitstrings. For a larger experiment, keep the same pattern: create the logical circuit once, then derive execution circuits from it.
Checklist by scenario
Scenario 1: Establish the ideal baseline
Run the circuit on an ideal simulator before adding noise. Use a simulator method that supports the circuit and inspect counts with a fixed number of shots.
ideal_backend = AerSimulator()
ideal_circuit = transpile(circuit, ideal_backend)
ideal_result = ideal_backend.run(ideal_circuit, shots=shots).result()
ideal_counts = ideal_result.get_counts()
print(ideal_counts)
Save the circuit text, transpilation settings, shot count, and counts. The ideal result is your mathematical reference, not a prediction of hardware output.
Scenario 2: Add gate and readout noise
Build the noise model explicitly. The following example applies a two-qubit depolarizing channel to the entangling gate, a smaller one-qubit channel to single-qubit gates, and a symmetric measurement error to both qubits.
noise_model = NoiseModel()
one_qubit_error = depolarizing_error(0.001, 1)
two_qubit_error = depolarizing_error(0.02, 2)
noise_model.add_all_qubit_quantum_error(one_qubit_error, ['h'])
noise_model.add_all_qubit_quantum_error(two_qubit_error, ['cx'])
readout_error = ReadoutError([
[0.98, 0.02],
[0.03, 0.97]
])
noise_model.add_all_qubit_readout_error(readout_error)
noisy_backend = AerSimulator(noise_model=noise_model)
noisy_circuit = transpile(circuit, noisy_backend)
noisy_result = noisy_backend.run(noisy_circuit, shots=shots).result()
noisy_counts = noisy_result.get_counts()
print(noisy_counts)
The numerical values here are illustrative controls, not a calibration claim. Change them deliberately and document the reason. A useful experiment runs the circuit with no noise, gate noise only, readout noise only, and both together. That sequence identifies which component causes the largest change.
Scenario 3: Match the target hardware's circuit structure
A noise model only affects operations that appear in the executed circuit. If you add errors for cx but transpilation decomposes the circuit into a different basis, those errors may not represent the operations actually simulated. Likewise, a circuit that requires routing may contain additional swaps or entangling gates.
# For a real backend, replace this with the selected backend object.
# backend = service.backend('your-backend-name')
# compiled = transpile(circuit, backend=backend, optimization_level=1)
# Inspect the operations after compilation.
print(noisy_circuit.count_ops())
print(noisy_circuit)
For a closer device-style simulation, transpile against the same target basis gates and coupling map used by the backend, then build or select errors for the resulting operations. If you are using backend properties, treat them as a time-specific snapshot: calibration values can change, and property access differs between Qiskit providers and versions.
Scenario 4: Compare with hardware results
Submit the compiled circuit to the hardware provider only after the ideal and noisy baselines are saved. Use the same logical measurement mapping and, where practical, the same shot count. Compare normalized frequencies rather than raw counts when shot counts differ.
from collections import defaultdict
def probabilities(counts):
total = sum(counts.values())
return {state: count / total for state, count in counts.items()}
print(probabilities(ideal_counts))
print(probabilities(noisy_counts))
# hardware_counts = hardware_result.get_counts()
# print(probabilities(hardware_counts))
For a cloud workflow, preserve the backend name, job identifier, submission time, transpiled circuit, shots, and result payload. A reproducible experiment log is often more valuable than a single visual plot. See the reproducible quantum experiments workflow for a broader notebook and result-tracking pattern.
Noise-channel reference
| Channel or effect | What it models | Useful diagnostic |
|---|---|---|
| Depolarizing error | Generalized random gate disturbance | Test whether deeper circuits lose fidelity as operations accumulate |
| Pauli error | Specified bit-flip, phase-flip, or combined faults | Isolate sensitivity to a known error type |
| Thermal relaxation | Energy relaxation and dephasing over time | Study circuits whose durations or idle periods matter |
| Readout error | Classical assignment mistakes during measurement | Compare measured bitstrings with and without readout noise |
| Reset error | Imperfect initialization or reset operations | Check circuits that reuse qubits or explicitly reset them |
What to double-check
- Shot count: A finite sample fluctuates even when the circuit and noise model are unchanged. Repeat runs or increase shots before treating a small difference as a device effect.
- Bit order: Qiskit count keys use a defined classical-bit display order that can surprise readers. Verify which classical bit corresponds to each qubit before interpreting a state.
- Transpilation: Compare operation counts, depth, basis gates, and layout. Two circuits that are logically equivalent can have different exposure to noise.
- Error attachment: Confirm that the noise model targets operations present after transpilation. An error attached to an unused gate has no effect.
- Readout mapping: Readout error must be applied to the measured qubits and classical mapping used by the circuit.
- Hardware snapshot: If you derive parameters from backend properties, save those values with the experiment rather than assuming they remain constant.
- Comparison metric: Use a consistent metric such as total variation distance, a selected state's probability, or correlation. Do not rely only on the most frequent bitstring.
Common mistakes
Using a generic noise model as a hardware prediction. Illustrative depolarizing probabilities help with sensitivity testing, but they do not describe a particular device. Label them as assumptions and replace them with documented calibration inputs when appropriate.
Comparing pre-transpilation simulation with post-transpilation hardware. Hardware executes the compiled circuit. Simulate the compiled form when you want a meaningful structural comparison.
Blaming every difference on quantum noise. Sampling, measurement assignment, qubit mapping, gate decomposition, and provider-side execution details can all contribute. Change one factor at a time.
Applying readout mitigation too early. Mitigation changes the observed distribution and can obscure the raw behavior you are trying to diagnose. Save unmitigated counts first, then apply mitigation as a separate analysis step.
Ignoring version drift. Keep the Qiskit and Aer versions in an environment file, test imports in a clean environment, and check release documentation when a notebook stops running.
When to revisit
Return to this checklist whenever you change the circuit, target backend, transpiler settings, shot count, noise assumptions, or Qiskit/Aer version. It is especially useful before a seasonal planning cycle or a new project milestone, when old simulator results may otherwise be reused without their original assumptions.
- Re-run the ideal baseline and confirm the logical result.
- Recompile for the current target and save the operation counts.
- Run gate-only, readout-only, and combined noise cases.
- Compare normalized distributions using the same metric.
- Record environment versions, model parameters, backend details, and job identifiers.
- Only then decide whether the observed difference requires circuit redesign, a better noise model, measurement analysis, or further hardware testing.
For experiments that move from local validation to cloud execution, pair this workflow with a quantum cloud backend selection guide or an Azure Quantum Python workflow. The central practice remains the same: keep the logical circuit, compiled circuit, assumptions, and measured results together so every comparison can be explained later.