qisdebug 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. qisdebug-0.1.0/LICENSE +21 -0
  2. qisdebug-0.1.0/PKG-INFO +436 -0
  3. qisdebug-0.1.0/README.md +372 -0
  4. qisdebug-0.1.0/pyproject.toml +125 -0
  5. qisdebug-0.1.0/setup.cfg +4 -0
  6. qisdebug-0.1.0/src/qisdebug/__init__.py +77 -0
  7. qisdebug-0.1.0/src/qisdebug/_analysis.py +900 -0
  8. qisdebug-0.1.0/src/qisdebug/_breakpoints.py +373 -0
  9. qisdebug-0.1.0/src/qisdebug/_cli/__init__.py +2 -0
  10. qisdebug-0.1.0/src/qisdebug/_cli/app.py +126 -0
  11. qisdebug-0.1.0/src/qisdebug/_cli/commands.py +101 -0
  12. qisdebug-0.1.0/src/qisdebug/_compat.py +62 -0
  13. qisdebug-0.1.0/src/qisdebug/_config.py +73 -0
  14. qisdebug-0.1.0/src/qisdebug/_debug.py +325 -0
  15. qisdebug-0.1.0/src/qisdebug/_dispatcher.py +150 -0
  16. qisdebug-0.1.0/src/qisdebug/_errors.py +11 -0
  17. qisdebug-0.1.0/src/qisdebug/_events.py +470 -0
  18. qisdebug-0.1.0/src/qisdebug/_frontends/__init__.py +14 -0
  19. qisdebug-0.1.0/src/qisdebug/_frontends/_ascii_charts.py +122 -0
  20. qisdebug-0.1.0/src/qisdebug/_frontends/_breakpoints.py +844 -0
  21. qisdebug-0.1.0/src/qisdebug/_frontends/_circuit_diff.py +343 -0
  22. qisdebug-0.1.0/src/qisdebug/_frontends/_cli_session.py +995 -0
  23. qisdebug-0.1.0/src/qisdebug/_frontends/_display.py +25 -0
  24. qisdebug-0.1.0/src/qisdebug/_frontends/_guided.py +253 -0
  25. qisdebug-0.1.0/src/qisdebug/_frontends/_render.py +956 -0
  26. qisdebug-0.1.0/src/qisdebug/_frontends/_tui.py +988 -0
  27. qisdebug-0.1.0/src/qisdebug/_frontends/_web/__init__.py +0 -0
  28. qisdebug-0.1.0/src/qisdebug/_frontends/_web/app.js +599 -0
  29. qisdebug-0.1.0/src/qisdebug/_frontends/_web/index.html +144 -0
  30. qisdebug-0.1.0/src/qisdebug/_frontends/_web/style.css +544 -0
  31. qisdebug-0.1.0/src/qisdebug/_frontends/base.py +34 -0
  32. qisdebug-0.1.0/src/qisdebug/_frontends/bridge.py +441 -0
  33. qisdebug-0.1.0/src/qisdebug/_frontends/cli.py +121 -0
  34. qisdebug-0.1.0/src/qisdebug/_frontends/detect.py +68 -0
  35. qisdebug-0.1.0/src/qisdebug/_frontends/gui.py +86 -0
  36. qisdebug-0.1.0/src/qisdebug/_hooks/__init__.py +1 -0
  37. qisdebug-0.1.0/src/qisdebug/_hooks/construction.py +226 -0
  38. qisdebug-0.1.0/src/qisdebug/_hooks/execution.py +698 -0
  39. qisdebug-0.1.0/src/qisdebug/_hooks/transpile.py +601 -0
  40. qisdebug-0.1.0/src/qisdebug/_mcp/__init__.py +7 -0
  41. qisdebug-0.1.0/src/qisdebug/_mcp/server.py +110 -0
  42. qisdebug-0.1.0/src/qisdebug/_mcp/tools.py +654 -0
  43. qisdebug-0.1.0/src/qisdebug/_store.py +428 -0
  44. qisdebug-0.1.0/src/qisdebug/py.typed +0 -0
  45. qisdebug-0.1.0/src/qisdebug/visualizer.py +13 -0
  46. qisdebug-0.1.0/src/qisdebug.egg-info/PKG-INFO +436 -0
  47. qisdebug-0.1.0/src/qisdebug.egg-info/SOURCES.txt +64 -0
  48. qisdebug-0.1.0/src/qisdebug.egg-info/dependency_links.txt +1 -0
  49. qisdebug-0.1.0/src/qisdebug.egg-info/entry_points.txt +3 -0
  50. qisdebug-0.1.0/src/qisdebug.egg-info/requires.txt +39 -0
  51. qisdebug-0.1.0/src/qisdebug.egg-info/top_level.txt +1 -0
  52. qisdebug-0.1.0/tests/test_activation.py +201 -0
  53. qisdebug-0.1.0/tests/test_analysis.py +311 -0
  54. qisdebug-0.1.0/tests/test_ascii_charts.py +105 -0
  55. qisdebug-0.1.0/tests/test_breakpoints.py +677 -0
  56. qisdebug-0.1.0/tests/test_cli.py +71 -0
  57. qisdebug-0.1.0/tests/test_construction.py +183 -0
  58. qisdebug-0.1.0/tests/test_execution.py +215 -0
  59. qisdebug-0.1.0/tests/test_frontends.py +188 -0
  60. qisdebug-0.1.0/tests/test_mcp_tools.py +571 -0
  61. qisdebug-0.1.0/tests/test_store.py +109 -0
  62. qisdebug-0.1.0/tests/test_transpile.py +273 -0
  63. qisdebug-0.1.0/tests/test_tui.py +760 -0
  64. qisdebug-0.1.0/tests/test_tui_layout.py +228 -0
  65. qisdebug-0.1.0/tests/test_visualizer.py +13 -0
  66. qisdebug-0.1.0/tests/test_watch.py +260 -0
qisdebug-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 QisDebug contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,436 @@
1
+ Metadata-Version: 2.4
2
+ Name: qisdebug
3
+ Version: 0.1.0
4
+ Summary: Zero-touch instrumentation and timeline debugging for Qiskit circuits
5
+ Author-email: Krishna Upadhyay <krishnaupadhyay1997@gmail.com>
6
+ Maintainer-email: Krishna Upadhyay <krishnaupadhyay1997@gmail.com>
7
+ License-Expression: MIT
8
+ Project-URL: Homepage, https://github.com/kriss-u/QisDebug
9
+ Project-URL: Repository, https://github.com/kriss-u/QisDebug
10
+ Project-URL: Issues, https://github.com/kriss-u/QisDebug/issues
11
+ Project-URL: Changelog, https://github.com/kriss-u/QisDebug/blob/main/CHANGELOG.md
12
+ Keywords: qiskit,quantum,quantum-computing,debugging,instrumentation,telemetry,mcp
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Topic :: Scientific/Engineering :: Physics
25
+ Classifier: Topic :: Software Development :: Debuggers
26
+ Classifier: Typing :: Typed
27
+ Requires-Python: >=3.10
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: qiskit>=1.0
31
+ Requires-Dist: pydantic>=2.5
32
+ Requires-Dist: typer>=0.12
33
+ Requires-Dist: rich>=13
34
+ Requires-Dist: textual>=0.60
35
+ Provides-Extra: aer
36
+ Requires-Dist: qiskit-aer>=0.14; extra == "aer"
37
+ Provides-Extra: viz
38
+ Requires-Dist: matplotlib>=3.5; extra == "viz"
39
+ Provides-Extra: gui
40
+ Requires-Dist: pywebview>=5.0; extra == "gui"
41
+ Provides-Extra: mcp
42
+ Requires-Dist: mcp>=1.0; extra == "mcp"
43
+ Provides-Extra: dev
44
+ Requires-Dist: pytest>=7; extra == "dev"
45
+ Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
46
+ Requires-Dist: hypothesis>=6; extra == "dev"
47
+ Requires-Dist: qiskit-aer>=0.14; extra == "dev"
48
+ Requires-Dist: pylint==4.1.3; extra == "dev"
49
+ Requires-Dist: astroid==4.3.4; extra == "dev"
50
+ Requires-Dist: pylint-pydantic==0.4.1; extra == "dev"
51
+ Requires-Dist: pyright==1.1.414; extra == "dev"
52
+ Requires-Dist: pre-commit>=4; extra == "dev"
53
+ Requires-Dist: build>=1.2; extra == "dev"
54
+ Requires-Dist: twine>=6; extra == "dev"
55
+ Requires-Dist: python-semantic-release<11,>=10.7; extra == "dev"
56
+ Requires-Dist: pywebview>=5.0; extra == "dev"
57
+ Requires-Dist: mcp>=1.0; extra == "dev"
58
+ Provides-Extra: docs
59
+ Requires-Dist: sphinx>=7; extra == "docs"
60
+ Requires-Dist: furo>=2024.1; extra == "docs"
61
+ Requires-Dist: myst-parser>=2; extra == "docs"
62
+ Requires-Dist: sphinx-autodoc-typehints>=1.25; extra == "docs"
63
+ Dynamic: license-file
64
+
65
+ # QisDebug
66
+
67
+ Zero-touch instrumentation and timeline debugging for
68
+ [Qiskit](https://www.ibm.com/quantum/qiskit).
69
+
70
+ QisDebug attaches full circuit and execution visibility to your existing Qiskit
71
+ code the way OpenTelemetry or Sentry attach to a web framework: one import, one
72
+ activation call, and no changes to how you build, transpile, or run circuits.
73
+ Everything that happens to a circuit — every gate appended, every transpiler
74
+ pass, every statevector along the way, and the final results — is recorded onto
75
+ a single per-circuit **timeline** you can inspect, export, or explore
76
+ interactively in a notebook.
77
+
78
+ ```python
79
+ import qisdebug
80
+
81
+ debug = qisdebug.QisDebug()
82
+ debug.start()
83
+
84
+ # --- your existing Qiskit code, completely unchanged -----------------
85
+ from qiskit import QuantumCircuit, transpile
86
+ from qiskit_aer import AerSimulator
87
+
88
+ qc = QuantumCircuit(2, 2, name="bell")
89
+ qc.h(0)
90
+ qc.cx(0, 1)
91
+ qc.measure([0, 1], [0, 1])
92
+
93
+ backend = AerSimulator()
94
+ counts = backend.run(transpile(qc, backend), shots=1000).result().get_counts()
95
+ # ----------------------------------------------------------------------
96
+
97
+ print(debug.get(qc).summary())
98
+ debug.end()
99
+ ```
100
+
101
+ ```text
102
+ Timeline 'bell' (id=ae87255e3948, 2 qubits, 2 clbits, 42 events)
103
+ gate_added 4
104
+ transpile_started 1
105
+ transpile_pass 31
106
+ transpile_finished 1
107
+ execution_submitted 1
108
+ state_snapshot 3
109
+ execution_finished 1
110
+ ```
111
+
112
+ The three state snapshots are the actual simulator statevectors after each gate
113
+ — `|00⟩`, then `(|00⟩+|01⟩)/√2`, then the Bell state — captured during the run
114
+ you already made, and stripped from the results you see.
115
+
116
+ ## Install
117
+
118
+ ```bash
119
+ pip install qisdebug # core (requires qiskit>=1.0)
120
+ pip install "qisdebug[aer]" # + statevector capture on Aer
121
+ pip install "qisdebug[viz]" # + histogram/Bloch-sphere image rendering
122
+ pip install "qisdebug[gui]" # + native GUI timeline viewer
123
+ pip install "qisdebug[mcp]" # + MCP server for AI-agent debugging
124
+ ```
125
+
126
+ See [INSTALL.md](https://github.com/kriss-u/QisDebug/blob/main/INSTALL.md)
127
+ for installing from source and the development extras.
128
+
129
+ ## What gets recorded
130
+
131
+ | Phase | Event types | How |
132
+ | ------------- | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
133
+ | Construction | `gate_added` | Wraps `QuantumCircuit.append`/`_append`; records each instruction with qubits, clbits, and params after broadcasting resolves |
134
+ | Transpilation | `transpile_started`, `transpile_pass`, `transpile_finished` | Wraps `PassManager.run` and injects a per-pass callback through Qiskit's own `callback` mechanism; `transpile_pass` carries a `property_changes` diff too |
135
+ | Execution | `execution_submitted`, `state_snapshot`, `execution_finished` | Wraps `AerBackend.run` and the Sampler/Estimator primitives; on Aer, runs an instrumented copy with `save_statevector` after every gate and strips the snapshots from your results |
136
+ | Diagnostics | `note` | QisDebug explains itself, e.g. why snapshot capture was skipped for a circuit |
137
+
138
+ All three phases land on **one timeline per circuit**: transpiled outputs
139
+ inherit the source circuit's hidden id, so the run of a transpiled circuit is
140
+ recorded against the circuit you actually wrote.
141
+
142
+ ## Public API
143
+
144
+ `QisDebug` is a class, not a module-level singleton: each instance is an
145
+ independently scoped instrumentation session with its own telemetry and its own
146
+ configuration, so more than one can be started at once (e.g. one scoped to a
147
+ suspect region, another covering a whole script) without either seeing the
148
+ other's timelines. The surface on it is intentionally small:
149
+
150
+ | Method | Purpose |
151
+ | ----------------------- | --------------------------------------------------------------------------------------------------------- |
152
+ | `debug.start()` | Attach all instrumentation layers. Idempotent. Returns an `ActivationReport` saying which layers attached |
153
+ | `debug.end()` | Restore every original Qiskit method this instance was using |
154
+ | `debug.active` | Whether this instance's patches are currently applied |
155
+ | `debug.get(qc)` | The `Timeline` for a circuit, name, or `Timeline`; raises `TimelineNotFoundError` on a miss |
156
+ | `debug.timelines()` | Every timeline this instance has recorded, most recently touched first |
157
+ | `debug.circuits()` | The names of tracked circuits, most recently touched first |
158
+ | `debug.clear()` | Drop all recorded telemetry without touching active patches |
159
+ | `debug.configure(...)` | Adjust limits and switches (validated; see below) |
160
+ | `debug.diff(a, b, ...)` | Gate-alignment diff plus statevector/counts/depth deltas between two points in time; see below |
161
+
162
+ Importing `qisdebug` has **no side effects** — nothing is patched until
163
+ `start()` is called, and `with QisDebug() as debug:` is an optional shorthand
164
+ for `start()`/`end()` around a scoped block.
165
+
166
+ ### Timeline
167
+
168
+ ```python
169
+ tl = debug.get(qc)
170
+ tl.events # every event, in true order (monotonic seq numbers)
171
+ tl.gate_events # construction events
172
+ tl.transpile_events # transpilation events
173
+ tl.execution_events # submission / snapshots / completion
174
+ tl.snapshots # state snapshots, each with .amplitudes() / .probabilities()
175
+ tl.circuit_at(n) # rebuild the circuit as it looked after its first n gates
176
+ tl.summary() # compact text overview
177
+ ```
178
+
179
+ Exporting timelines to JSON-serializable dicts (amplitudes as `[re, im]` pairs)
180
+ goes through the `QisDebug` instance too, with the same argument shapes as
181
+ `show()`. It always returns a list, even for a single circuit, so callers never
182
+ need to branch on the shape of the result:
183
+
184
+ ```python
185
+ debug.export() # every timeline this instance has recorded, as a list of dicts
186
+ debug.export(qc) # just this circuit's timeline, as a one-item list
187
+ debug.export([qc1, qc2]) # several circuits, as a list of dicts
188
+ ```
189
+
190
+ ### Diffing two points in time
191
+
192
+ ```python
193
+ diff = debug.diff(qc_a, qc_b) # or debug.diff(qc, qc, seq_a=10, seq_b=40)
194
+ diff.gate_diff # aligned insert/delete/replace over gate_added events
195
+ diff.statevector_diff, diff.counts_diff # fidelity / total variation distance, when both sides have one
196
+ diff.depth_a, diff.depth_b # depth/size deltas from each side's last transpile event
197
+ ```
198
+
199
+ `a`/`b` take the same circuit/name/`Timeline` shapes as `debug.get()`;
200
+ `seq_a`/`seq_b` bound either side to "as of that event's `seq`" instead of the
201
+ whole timeline, so the same circuit can be diffed against an earlier moment of
202
+ its own replay. The interactive frontends (below) expose the same comparison as
203
+ "Mark A"/"Mark B" over the live timeline view.
204
+
205
+ ### Configuration
206
+
207
+ | Option | Default | Meaning |
208
+ | --------------------------- | ----------- | ---------------------------------------------------------------------------------- |
209
+ | `max_circuits` | `256` | Tracked-circuit cap; least recently touched timelines are evicted first |
210
+ | `capture_statevectors` | `True` | Insert statevector snapshots on Aer runs |
211
+ | `max_statevector_qubits` | `12` | Skip capture for wider circuits (snapshot memory grows as 2^n) |
212
+ | `max_snapshots_per_circuit` | `256` | Stop inserting snapshots past this count |
213
+ | `transpile_snapshots` | `"changed"` | Keep full circuit snapshots for `"all"` passes, only `"changed"` ones, or `"none"` |
214
+ | `capture_property_set` | `"changed"` | Diff/snapshot property_set for `"all"` passes, only `"changed"` ones, or `"none"` |
215
+
216
+ ## The timeline viewer
217
+
218
+ Everything is shown through the `QisDebug` instance itself:
219
+
220
+ ```python
221
+ debug.show() # every timeline this instance has recorded
222
+ debug.show(qc) # just this circuit's timeline
223
+ debug.show([qc1, qc2]) # several circuits, merged into one view
224
+ ```
225
+
226
+ Auto-detects a native GUI window (HTML/CSS rendered via pywebview) when a display is available, or falls
227
+ back to a text-based interactive CLI otherwise — force either with
228
+ `debug.show(frontend="gui"|"cli")` or the `QISDEBUG_FRONTEND` environment
229
+ variable. Either way, a slider/stepper walks the full event sequence; each
230
+ position shows the circuit as it existed at that moment (drawn with Qiskit's own
231
+ drawer), the statevector with amplitudes and probabilities, or per-pass
232
+ transpiler statistics. Both frontends read only the public `Timeline` fields, so
233
+ the instrumentation and the visualizer can evolve independently.
234
+
235
+ Pin the event currently on screen as one side of a diff — "Mark A"/"Mark B" in
236
+ the GUI, `mark a`/`mark b` in the CLI — and once both are pinned, the diff
237
+ between them (the same comparison `debug.diff()` returns) renders automatically:
238
+ a per-gate diff, a side-by-side circuit-drawing split view, a summary across
239
+ every element common to both marked points, and a diff of any currently active
240
+ watch.
241
+
242
+ ## Debugging with an AI agent (MCP)
243
+
244
+ The same telemetry both viewers read is also exposed to coding agents through a
245
+ [Model Context Protocol](https://modelcontextprotocol.io) server, so an agent
246
+ can debug the _runtime behavior_ of your circuits instead of reasoning about the
247
+ code blind:
248
+
249
+ ```bash
250
+ pip install -e ".[mcp,aer]"
251
+ claude mcp add qisdebug -- qisdebug-mcp # or the equivalent for your agent
252
+ ```
253
+
254
+ The division of labor is deliberate. QisDebug does not try to decide what a
255
+ quantum program _should_ do — the agent does. QisDebug extracts the ground truth
256
+ and does the arithmetic:
257
+
258
+ - **Run under instrumentation** — `run_script` executes a script with QisDebug
259
+ active and reports every circuit's id, registers, and an anomaly scan in one
260
+ shot. To focus on a suspect region, the agent has the script build its own
261
+ scoped `qisdebug.QisDebug()` and call `start()`/`end()` around it, passing
262
+ `auto_activate=false` so this server's own instance stays untouched.
263
+ - **Extract mid-execution state** — `get_events` (filtered, paged),
264
+ `get_state_snapshot` (raw amplitudes and probabilities at any captured step),
265
+ `get_circuit_text` (the circuit as it looked after any gate), and
266
+ `get_property_set` (the full layout/routing property_set a specific transpiler
267
+ pass wrote — `get_events` surfaces the added/removed/changed keys inline as
268
+ `property_changes`).
269
+ - **Watch what matters** — `add_watch` pins qubits, clbits, or registers;
270
+ `read_watches` reports their gate history, marginal P(1), and Bloch vector as
271
+ of any point in the sequence — the same watch feature the GUI and CLI expose
272
+ interactively.
273
+ - **Compare two points in time** —
274
+ `diff_timelines(circuit_id_a, circuit_id_b,
275
+ seq_a=..., seq_b=...)` reports
276
+ the same gate-alignment plus statevector/counts/depth diff as `debug.diff()`,
277
+ for two different circuits or two moments of the same circuit's replay.
278
+ - **Check an expectation** — the agent supplies the state or distribution it
279
+ believes the program should produce; `compare_statevector` and
280
+ `compare_counts` report fidelity, total variation distance, and exactly which
281
+ basis states or outcomes diverge. `find_anomalies` is expectation-free and
282
+ catches only impossible states (non-normalized or non-finite statevectors,
283
+ failed runs, transpile blow-ups).
284
+ - **Keep the evidence** — `save_timeline` writes the full JSON export to a file;
285
+ `set_configuration` tunes capture depth before a run.
286
+
287
+ The server is a thin protocol wrapper: every tool delegates to the same store,
288
+ rendering, and comparison code the GUI and CLI use.
289
+
290
+ ## Conditional breakpoints
291
+
292
+ Everything above is passive: it tells you what already happened. Conditional
293
+ breakpoints pause a **live** run the instant a condition matches, so you can
294
+ inspect state mid-execution instead of only replaying a finished timeline.
295
+ See [`examples/breakpoints.py`](https://github.com/kriss-u/QisDebug/blob/main/examples/breakpoints.py) for a runnable,
296
+ end-to-end example (`python examples/breakpoints.py`).
297
+
298
+ A condition is one of a small closed set of kinds — never arbitrary code, so
299
+ there's no `eval`-style injection surface:
300
+
301
+ | Kind | Matches when... |
302
+ | --------- | ------------------------------------------------------------------------- |
303
+ | `gate` | A named gate (optionally on specific qubits) is added to a circuit |
304
+ | `seq` | Any event reaches a given sequence number |
305
+ | `watch` | A watched qubit/clbit/register's value (P(1)) crosses a numeric threshold |
306
+ | `anomaly` | The next event `find_anomalies` would flag, at or above a chosen severity |
307
+
308
+ ### Python API
309
+
310
+ ```python
311
+ import qisdebug
312
+ from qisdebug import GateMatchCondition, WatchThresholdCondition
313
+
314
+ debug = qisdebug.QisDebug()
315
+ debug.start()
316
+
317
+ handle = debug.add_breakpoint(GateMatchCondition(gate="cx"))
318
+ # or: debug.add_breakpoint(WatchThresholdCondition(
319
+ # circuit_id=circuit_id, watch_kind="qubit", ref="0",
320
+ # comparator="gt", threshold=0.9))
321
+
322
+ # On the thread building/running the circuit, execution blocks the instant
323
+ # the breakpoint matches. From another thread (or the one driving the run):
324
+ hit = debug.wait_for_breakpoint(timeout=10) # -> BreakpointHit | None
325
+ print(hit.condition, hit.event_summary)
326
+ debug.resume() # release the paused thread
327
+
328
+ debug.remove_breakpoint(handle)
329
+ debug.list_breakpoints()
330
+ ```
331
+
332
+ ### MCP (agent-driven stepping)
333
+
334
+ Live pausing needs the script to run in the background, since a pause blocks the
335
+ thread — `run_script(..., background=True)` returns immediately with a `run_id`
336
+ instead of waiting for the script to finish:
337
+
338
+ ```text
339
+ add_breakpoint({"kind": "gate", "gate": "cx"})
340
+ run_script("script.py", background=True) # -> {"run_id": "..."}
341
+ poll_run(run_id) # -> running | paused | finished | error | stopped
342
+ # when paused, poll_run's response includes which condition hit and on what event
343
+ resume_run(run_id)
344
+ stop_run(run_id) # best-effort; guaranteed only while paused
345
+ ```
346
+
347
+ ### Interactive frontends
348
+
349
+ Breakpoints also work as a navigation aid over an **already-captured** timeline
350
+ — "jump to next hit" walks recorded events instead of blocking anything live:
351
+
352
+ - **CLI**: `break gate cx`, `break seq 40`, `break watch qubit 0 gt 0.9`,
353
+ `break anomaly warning`; `breakpoints` lists them, `unbreak <handle>` removes
354
+ one, and `continue` jumps to the next matching event.
355
+ - **GUI**: a condition-builder row (kind dropdown + argument field, same syntax
356
+ as the CLI) next to the watch row, a list of active breakpoints, and a "Run to
357
+ next breakpoint →" button.
358
+
359
+ ## Roadmap
360
+
361
+ Planned next, on top of what's above — see `CLAUDE.md` for the full design:
362
+
363
+ - **Visual polish** — a proper stylesheet for the GUI (buttons, spacing, type
364
+ scale) and consistent prompt/column formatting for the CLI; both are currently
365
+ unstyled toolkit defaults.
366
+
367
+ ## Version compatibility
368
+
369
+ Every patch target is checked for existence before patching; a missing internal
370
+ downgrades that layer with a logged warning instead of an error, and
371
+ `activate()` reports exactly which layers attached.
372
+
373
+ | Python | Qiskit | qiskit-aer | Status |
374
+ | ------ | ------ | ---------- | ------------------------------------------- |
375
+ | 3.14 | 2.4.2 | 0.17.2 | Tested (full suite) |
376
+ | ≥3.10 | ≥1.0 | ≥0.14 | Expected to work; layers degrade gracefully |
377
+
378
+ ## Limitations
379
+
380
+ - **Statevector capture** requires Aer and is skipped (with a `note` event
381
+ explaining why) for circuits containing reset, initialize, mid-circuit
382
+ measurement, control flow, noise instructions, or `parameter_binds`, and for
383
+ circuits wider than `max_statevector_qubits`. Counts and timing are still
384
+ recorded.
385
+ - `QuantumCircuit.compose(..., inplace=True)` writes to circuit data without
386
+ passing through any append method, so composed instructions are not recorded
387
+ as gate events.
388
+ - Per-pass transpile telemetry applies to single-circuit runs; transpiling a
389
+ list of circuits records start/finish boundaries only (multi-circuit runs may
390
+ fan out to worker processes).
391
+ - Primitives (`StatevectorSampler`, Aer `SamplerV2`, …) record submission and
392
+ completion timing; statevector capture happens when a primitive delegates to
393
+ an instrumented Aer backend.
394
+ - Circuits built before `activate()` only record events from that point on.
395
+ - `qc.copy()` carries the hidden id with it, so a copy reports onto the same
396
+ timeline as its source.
397
+
398
+ ## Development
399
+
400
+ ```bash
401
+ pip install -e ".[dev]"
402
+ pytest
403
+ ```
404
+
405
+ The suite covers each hook independently (construction, execution,
406
+ transpilation), the telemetry store, and the activation lifecycle, including
407
+ hypothesis property tests that any random gate sequence is recorded exactly and
408
+ the store never exceeds its cap.
409
+
410
+ See [CONTRIBUTING.md](https://github.com/kriss-u/QisDebug/blob/main/CONTRIBUTING.md) for the contribution workflow and ground
411
+ rules.
412
+
413
+ ## Documentation
414
+
415
+ Full API documentation is built with Sphinx:
416
+
417
+ ```bash
418
+ pip install -e ".[docs]"
419
+ cd docs
420
+ make html
421
+ ```
422
+
423
+ Open `docs/_build/html/index.html` in a browser.
424
+
425
+ ## Prior art
426
+
427
+ [Qiskit Trebugger](https://github.com/TheGupta2012/qiskit-timeline-debugger)
428
+ requires replacing `transpile` with a special debug call and covers only the
429
+ transpiler stage. CircInspect provides step-through debugging for PennyLane.
430
+ QisDebug's distinction is passive, near-zero-setup attachment with full
431
+ lifecycle coverage — construction through transpilation to execution — on
432
+ unmodified Qiskit code.
433
+
434
+ ## License
435
+
436
+ MIT