Quantum circuit benchmarking is only useful when simulator and hardware results are measured under comparable conditions. This guide presents a reproducible Python workflow for recording circuit structure, execution time, shot count, noise settings, fidelity, and result variance so you can compare backends without confusing a faster run with a more accurate one.
Overview
A quantum circuit benchmark is a controlled experiment. You run the same logical circuit through two or more execution environments, collect the results, and explain differences using consistent metrics. The environments might include an ideal statevector simulator, a noisy simulator, and a real quantum processor.
The purpose is not to produce a permanent ranking of quantum platforms. Backend performance depends on circuit width, depth, gate set, connectivity, compilation choices, queue conditions, noise assumptions, and measurement settings. A useful benchmark instead answers a narrower question: How does this circuit behave under the conditions relevant to my application?
For each run, record at least:
- Logical qubit count and circuit depth
- Gate counts, especially one-qubit and two-qubit operations
- Transpiled or compiled circuit depth, if available
- Number of shots and execution time
- Noise model or hardware identifier
- Output distribution and the random seed, where supported
- Accuracy or fidelity against a defined reference distribution
- Variation across repeated runs
An ideal simulator can provide a reference, but it does not reproduce hardware behavior. A noisy simulator can isolate selected error mechanisms, while hardware adds device-specific effects and operational variability. Treating these as separate test conditions makes the final comparison easier to interpret.
How to compare options
Start by defining the benchmark question and the acceptance criteria. For example, you might want to know whether a circuit remains within an acceptable error range after compilation, or whether a variational workload produces stable expectation values across repeated executions.
1. Freeze the circuit definition
Keep the logical circuit constant while comparing backends. Record the number of qubits, logical gates, barriers, measurements, parameter values, and any circuit-generation seed. If the benchmark changes the circuit for each backend, the result measures different programs rather than different execution environments.
2. Separate logical and physical metrics
Logical depth describes the circuit before backend-specific compilation. Physical depth describes the compiled circuit that is actually executed. Both matter. Logical depth helps compare algorithm designs, while physical depth reveals the cost of mapping the circuit to a particular instruction set or connectivity layout.
3. Use a reference distribution
For small circuits, an ideal simulator can generate a reference probability distribution. Compare each backend's measured distribution with that reference. For larger circuits, an exact reference may be impractical, so use a smaller validation circuit, an analytical expectation, or another trusted baseline. State which reference you used rather than calling every difference a hardware error.
4. Repeat measurements
One run can hide variance. Repeat the same job when the platform permits it and calculate the mean, standard deviation, or confidence interval for the metric that matters. For shot-based results, also distinguish statistical sampling noise from changes caused by compilation, calibration, scheduling, or device conditions.
5. Keep execution conditions visible
Store the backend name, software versions, circuit hash, shot count, noise configuration, optimization settings, timestamp, and job identifier. These fields turn a one-off experiment into a reproducible record. They also make it possible to rerun the benchmark after a framework or hardware update.
If backend selection is part of your decision, use this workflow alongside our guide to choosing a quantum computing backend. The right option depends on the circuit and objective, not on a single headline metric.
Feature-by-feature breakdown
Circuit size and depth
Width is the number of qubits. Depth is the number of sequential layers after a defined representation of the circuit. Report both logical and compiled depth when possible. A circuit with few gates can still be difficult if its gates require connectivity changes or long-range interactions.
Gate counts
Record total gates and break them into categories. Two-qubit gates often deserve separate attention because they can dominate both compilation overhead and noise sensitivity. Also record inserted routing operations if the framework exposes them. A lower logical gate count does not necessarily produce a lower compiled count.
Execution time
Define what timing means before collecting it. A local simulator may be measured from circuit submission through result retrieval. A remote hardware experiment might separately report client preparation time, queue delay, device execution time, and result retrieval time. Mixing these values produces a misleading comparison. For algorithm performance, device execution and total wall-clock time answer different questions.
Shots and sampling error
Shots are repeated measurements of a circuit. Increasing shots generally gives a more stable estimate of output frequencies, but it does not remove systematic device errors. Always report the shot count with accuracy and runtime metrics. If two backends use different shot counts, label the comparison accordingly.
Noise and hardware conditions
For a noisy simulator, document the error channels and their parameters. For hardware, record the backend identifier and any available execution metadata. Avoid describing a noisy simulation as a prediction of hardware unless the model has been deliberately calibrated for that purpose.
Fidelity and distribution distance
For a measured distribution p and reference distribution q, several comparison measures are possible. A simple option is total variation distance:
TV(p, q) = 0.5 * sum(abs(p[x] - q[x]))Lower distance indicates closer distributions. You can also report a classical fidelity-style measure such as:
F(p, q) = (sum(sqrt(p[x] * q[x]))) ** 2These metrics describe agreement with the chosen reference; they do not prove that the reference is physically correct for every workload. If the circuit has a known target bitstring, success probability may be more interpretable than a full-distribution metric.
A reusable Python benchmark record
The following framework-neutral template separates circuit execution from metric collection. Add adapters for the simulator and hardware SDK you use, then keep the result schema unchanged.
from dataclasses import dataclass, asdict
from time import perf_counter
from statistics import mean, stdev
import json
@dataclass
class RunRecord:
backend: str
circuit_id: str
qubits: int
logical_depth: int
compiled_depth: int | None
gate_counts: dict
shots: int
elapsed_seconds: float
distribution: dict
noise_model: str | None = None
seed: int | None = None
def total_variation(observed, reference):
keys = set(observed) | set(reference)
return 0.5 * sum(abs(observed.get(k, 0.0) - reference.get(k, 0.0))
for k in keys)
def classical_fidelity(observed, reference):
keys = set(observed) | set(reference)
return sum((observed.get(k, 0.0) * reference.get(k, 0.0)) ** 0.5
for k in keys) ** 2
def run_once(adapter, circuit, metadata, shots):
start = perf_counter()
result = adapter.run(circuit, shots=shots)
elapsed = perf_counter() - start
return RunRecord(
backend=metadata['backend'],
circuit_id=metadata['circuit_id'],
qubits=metadata['qubits'],
logical_depth=metadata['logical_depth'],
compiled_depth=metadata.get('compiled_depth'),
gate_counts=metadata['gate_counts'],
shots=shots,
elapsed_seconds=elapsed,
distribution=result['distribution'],
noise_model=metadata.get('noise_model'),
seed=metadata.get('seed'))
def summarize(records, reference):
distances = [total_variation(r.distribution, reference)
for r in records]
fidelities = [classical_fidelity(r.distribution, reference)
for r in records]
times = [r.elapsed_seconds for r in records]
return {
'runs': len(records),
'mean_total_variation': mean(distances),
'mean_fidelity': mean(fidelities),
'mean_elapsed_seconds': mean(times),
'stdev_elapsed_seconds': stdev(times) if len(times) > 1 else 0.0,
'records': [asdict(r) for r in records]
}
# Save the summary with json.dump for later comparison.
# json.dump(summary, open('benchmark.json', 'w'), indent=2)The adapter is intentionally small: it should compile or submit the circuit, collect counts, normalize counts into probabilities, and return metadata needed for interpretation. Do not hide compilation inside one adapter and omit it from another. If compilation occurs, capture the resulting depth and gate counts consistently.
Before hardware execution, review these circuit optimization considerations. For noisy results, compare the raw output with any mitigated output as separate records rather than replacing the original.
Best fit by scenario
Algorithm development
Use an ideal simulator for correctness checks and a noisy simulator for controlled experiments. Track depth, gate counts, and distribution distance as the circuit grows. This is often the fastest way to identify a circuit design that is too deep before sending it to hardware.
Hardware readiness testing
Compile the same circuit for the target device, then compare physical depth, execution time, output fidelity, and repeated-run variance. Include a small circuit with a known reference before testing the full workload. This helps distinguish an adapter or measurement mistake from a device-performance issue.
Hybrid and quantum machine learning workflows
For variational circuits, distribution fidelity may not be the only useful metric. Record expectation-value error, objective-function variance, optimizer steps, and total end-to-end runtime. A circuit can produce a reasonable distribution while still creating unstable gradients or an unreliable training signal. If the workload includes data encoding, document preprocessing and parameter initialization as part of the experiment. The quantum machine learning data preparation checklist can help define those inputs.
Framework comparisons
When comparing Qiskit, Cirq, PennyLane, or another quantum software development kit, hold the circuit semantics constant rather than copying source code line by line. Gate decompositions and default compilation behavior may differ. A porting checklist such as this framework conversion guide can help verify that the implementations measure the same operation.
Small educational experiments
For a beginner-friendly benchmark, use a two- or three-qubit circuit, an ideal reference, a fixed shot count, and several repeated runs. Start with a circuit containing a small number of quantum gates, then add depth or entangling operations one change at a time. This makes the relationship between circuit structure and output variance easier to see.
When to revisit
Revisit a quantum circuit benchmark whenever an input that affects the result changes. That includes a framework or compiler version, backend availability, device selection, optimization setting, noise model, shot count, circuit size, or measurement strategy. Hardware results should also be rerun when you need a decision based on current device behavior rather than an earlier snapshot.
Keep a baseline file under version control with the circuit definition, metadata, raw distributions, and summary metrics. When rerunning, compare the new record with the baseline and explain any change in compiled depth, runtime, fidelity, or variance. Do not overwrite the original run.
A practical maintenance cycle is:
- Run an ideal reference test to confirm circuit correctness.
- Run the same circuit through the noisy simulator, if used.
- Compile and execute on the selected hardware backend.
- Repeat hardware runs enough to estimate variability.
- Save raw results and environment metadata.
- Compare metrics by circuit size and execution condition.
- Update conclusions only when the evidence supports a change.
Use this workflow as a living benchmark rather than a one-time scorecard. For debugging unexpected results, see our quantum circuit debugging workflow; for interpreting noisy outputs, see the guide to quantum error mitigation. Consistent records will make future simulator and hardware comparisons faster, clearer, and easier to reproduce.