QisDebug: A Zero-Touch Debugger for Qiskit

7 min read

QisDebug cover

Update (November 2026): this post describes QisDebug 0.2. QisDebug 1.0 replaced the timeline and replay with findings; see QisDebug 1.0: Findings Instead of Replay. 0.2 stays available with pip install "qisdebug<1".

When a Qiskit program gives the wrong answer, the usual way to find out why is to sprinkle print(qc.draw()) and Statevector(qc) calls through the code, rerun it, and compare. That works, but it means editing the program you’re trying to debug, and it still can’t show you what the transpiler did to your circuit or what the simulator’s state looked like halfway through a run. QisDebug records all of that for you, without changing a line of your code.

What is QisDebug

QisDebug is a debugger and observability tool for Qiskit. It attaches to your existing code the way telemetry libraries like OpenTelemetry or Sentry attach to a web framework: one import and one call to start(). From then on, everything that happens to every circuit is recorded onto a single per-circuit timeline:

  • every gate added while the circuit is being built
  • every transpiler pass, with the circuit’s depth and size after it and what the pass changed in the transpiler’s property_set
  • the statevector after every gate when the circuit runs on Aer
  • the final counts and timing of each execution

QisDebug is on PyPI as qisdebug, and the source is on GitHub at github.com/kriss-u/QisDebug.

Getting started

Install it with the extras you want. aer enables statevector capture and gui enables the native timeline window:

pip install "qisdebug[aer,gui]"

Then wrap your existing code with start() and end():

import qisdebug

debug = qisdebug.QisDebug()
debug.start()

# Your existing Qiskit code, completely unchanged
from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator

qc = QuantumCircuit(2, 2, name="bell")
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])

backend = AerSimulator()
counts = backend.run(transpile(qc, backend), shots=1000).result().get_counts()

debug.end()
print(debug.get(qc).summary())
Timeline 'bell' (id=ae87255e3948, 2 qubits, 2 clbits, 42 events)
  gate_added             4
  transpile_started      1
  transpile_pass         31
  transpile_finished     1
  execution_submitted    1
  state_snapshot         3
  execution_finished     1

The three state snapshots are the actual simulator statevectors after each gate: $|00\rangle$, then $(|00\rangle + |01\rangle)/\sqrt{2}$, then the Bell state. They were captured during the run you already made, and counts is exactly what it would have been without QisDebug.

How it works

Qiskit is regular Python, so when your code calls qc.h(0), that call ends up in QuantumCircuit.append. QisDebug replaces methods like that at runtime with wrappers that call the original first, so behavior doesn’t change, and then record what happened. This is the same monkey patching technique telemetry libraries use. It works in three layers:

  • Construction. The append wrapper records each instruction, its qubits and clbits, and its parameters as the circuit is built
  • Transpilation. QisDebug hooks into the pass manager through Qiskit’s own callback mechanism and snapshots the circuit after every pass. Because this uses a supported extension point rather than patching internals, it’s the layer least likely to break across Qiskit versions
  • Execution. When a circuit runs on Aer, QisDebug quietly runs a copy with a save_statevector instruction after every gate, pulls the snapshots out of the result, and strips them before you see it. Sampler primitives are recorded too, including their counts

Patching only happens between start() and end(), never on import, and end() restores every original method. Every patch first checks that the thing it patches still exists, so if a Qiskit release renames an internal, that layer is switched off with a warning instead of crashing your program.

Exploring the timeline

debug.show() opens every recorded timeline in a viewer. It picks a native GUI window when a display is available and falls back to an interactive terminal viewer otherwise, such as over SSH:

debug.show()            # every timeline this session recorded
debug.show(qc)          # just this circuit
debug.show([qc1, qc2])  # several circuits merged into one view

Both viewers let you step through the full event sequence. At each step you see the circuit as it looked at that moment, drawn with Qiskit’s own drawer, the statevector with amplitudes and probabilities, or the transpiler’s statistics for that pass. A few more tools sit on top:

  • Watches. Pin a qubit, clbit, or register to follow its gate history, probability of measuring 1, and Bloch vector as you step
  • Diffs. Mark any two points as A and B, whether that’s two circuits or one circuit before and after transpilation, and QisDebug shows a per-gate diff, a side-by-side drawing, and how the states differ. The same comparison is available in code as debug.diff(a, b)
  • Breakpoints. Jump straight to the next event that matches a condition, like the next cx gate or the point where a watched qubit’s probability crosses a threshold

Pausing a live run

Breakpoints also work on code that is still running. Register a condition and the program pauses the instant it matches, between the exact two instructions that triggered it, so you can inspect the state before continuing:

from qisdebug import GateMatchCondition

handle = debug.add_breakpoint(GateMatchCondition(gate="cx"))

# On another thread, while the circuit is being built or run:
hit = debug.wait_for_breakpoint(timeout=10)
print(hit.condition, hit.event_summary)
debug.resume()

Conditions come from a small fixed set: a gate match, an event number, a watched value crossing a threshold, or the next anomaly. They are never arbitrary code, so nothing is ever evaluated.

Debugging with an AI agent

QisDebug also ships an MCP server, qisdebug-mcp, that exposes the same telemetry to coding agents. Instead of guessing what a circuit does by reading its source, an agent can run your script under QisDebug, read the statevector at any step, follow watches, compare two points in time, and pause a live run at a breakpoint:

pip install "qisdebug[aer,mcp]"
claude mcp add qisdebug -- qisdebug-mcp

The split is deliberate. QisDebug doesn’t try to decide what your program should do. The agent says what state or distribution it expects, and QisDebug supplies the ground truth and the arithmetic: fidelity against an expected statevector, total variation distance against expected counts, and exactly which basis states diverge.

Limitations

  • Statevector capture needs Aer. It’s skipped, with a note on the timeline explaining why, for circuits with resets, initialize, mid-circuit measurements, control flow, noise instructions, or parameter bindings, and for circuits wider than the configured qubit limit. Counts and timing are still recorded
  • Simulators only. QisDebug records what Qiskit and its simulators do; it doesn’t capture state from real quantum hardware
  • Per-pass detail is for single circuits. Transpiling a list of circuits records only where the transpilation started and finished, since Qiskit may spread that work across worker processes
  • Only what happens after start(). A circuit built before you call start() only records events from that point on

Source code

QisDebug is open source under the MIT license. The code is on GitHub at github.com/kriss-u/QisDebug, and every release is archived on Zenodo with a citable DOI. Issues, suggestions, and contributions are welcome.

If you’d rather experiment with Qiskit without installing anything, QisPlay runs it entirely in your browser.

Try it yourself

Install it with pip install "qisdebug[aer,gui]", add debug.start() above your Qiskit code, and call debug.show() at the end.

Related Posts