py-quantum-verifier 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.
@@ -0,0 +1,5 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ dist/
5
+ .pytest_cache/
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lokesh Pullakandam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.
@@ -0,0 +1,172 @@
1
+ Metadata-Version: 2.5
2
+ Name: py-quantum-verifier
3
+ Version: 0.1.0
4
+ Summary: Deterministic pre-flight verification for quantum circuits: catches silent transpiler blowups, topology traps and noise-only 'signals' before you spend hardware time.
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Keywords: noise,qiskit,quantum,transpiler,verification
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Topic :: Scientific/Engineering :: Physics
11
+ Requires-Python: >=3.10
12
+ Requires-Dist: numpy
13
+ Requires-Dist: qiskit-aer
14
+ Requires-Dist: qiskit>=2.0
15
+ Provides-Extra: all
16
+ Requires-Dist: cudaq; extra == 'all'
17
+ Requires-Dist: pennylane>=0.38; extra == 'all'
18
+ Requires-Dist: pytest>=7; extra == 'all'
19
+ Requires-Dist: pytket; extra == 'all'
20
+ Requires-Dist: pytket-qiskit; extra == 'all'
21
+ Provides-Extra: cuda
22
+ Requires-Dist: cudaq; extra == 'cuda'
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=7; extra == 'dev'
25
+ Provides-Extra: pennylane
26
+ Requires-Dist: pennylane>=0.38; extra == 'pennylane'
27
+ Provides-Extra: tket
28
+ Requires-Dist: pytket; extra == 'tket'
29
+ Requires-Dist: pytket-qiskit; extra == 'tket'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # py-quantum-verifier
33
+
34
+ Deterministic, offline pre-flight checks for quantum circuits. Run them before you spend hardware time.
35
+
36
+ ```python
37
+ from py_quantum_verifier import verify_experiment, falsify_claim
38
+ from qiskit import QuantumCircuit
39
+ qc = QuantumCircuit(2, 2); qc.h(0); qc.cx(0, 1); qc.measure([0, 1], [0, 1])
40
+ print(verify_experiment(qc, "ionq-forte-1")) # GO (ionq-forte-1): All checks passed.
41
+ print(falsify_claim(qc, "ionq-forte-1", ["00", "11"]).verdict) # SUPPORTED
42
+ ```
43
+
44
+ No API tokens, no network, no GPU. Everything runs on Qiskit Aer with built-in device models.
45
+
46
+ ## Install
47
+
48
+ ```bash
49
+ pip install py-quantum-verifier # core: qiskit>=2.0, qiskit-aer, numpy
50
+ pip install "py-quantum-verifier[pennylane]" # + analyze_circuit_gradients
51
+ pip install "py-quantum-verifier[cuda]" # + cudaq (Linux/macOS with CUDA-Q wheels)
52
+ pip install "py-quantum-verifier[tket]" # + Qiskit-vs-TKET diffing
53
+ pip install "py-quantum-verifier[all]" # everything, incl. pytest
54
+ ```
55
+
56
+ Optional integrations are imported lazily inside `try/except ImportError`, so the core
57
+ install is small and identical on macOS, Windows and Linux. `optional_features()` reports
58
+ which extras are importable.
59
+
60
+ ## Real bugs this catches
61
+
62
+ **Silent gate-synthesis blowup (`rzz` on IonQ-style native gates).** IonQ's native `ZZ`
63
+ gate is tunable, so a logical `rzz(θ)` should compile to exactly **one** native gate:
64
+ `RZZ(θ) == ZZ(θ/2π)`. If the compiler has no direct `rzz → zz` equivalence it silently falls
65
+ back to a generic `cx` decomposition: **2** native two-qubit gates plus a pile of single-qubit
66
+ gates. The circuit still runs and still "looks right"; it just carries double the two-qubit
67
+ error. `gate_synthesis_check` compares logical and native gate counts and blocks it:
68
+
69
+ ```python
70
+ from py_quantum_verifier import gate_synthesis_check, get_device, verify_experiment
71
+
72
+ device = get_device("ionq-forte-1").with_native_equivalences(direct_rzz=False) # unpatched compiler
73
+ verify_experiment(qc_with_rzz, device)
74
+ # BLOCK: 1 logical two-qubit gate(s) became 2 native two-qubit gate(s) (2.0x, limit 1.5x for tunable ...)
75
+ ```
76
+
77
+ Limits are device-aware: on CZ/CX/ECR-native hardware an arbitrary-angle `rzz` legitimately
78
+ needs 2 gates, so that is not flagged there (limit 2.5x).
79
+
80
+ **Topology traps.** On heavy-hex devices a qubit with more than 3 interaction partners forces
81
+ SWAP routing that multiplies two-qubit gate count. `topology_check` flags it before transpiling.
82
+ All-to-all devices report "not applicable" rather than silently passing.
83
+
84
+ **Noise passed off as a signal.** A forgotten `h` before a `cx` gives `00` at 99%, which looks
85
+ like a great Bell-state result. `falsify_claim` builds a control with the entangling gates removed,
86
+ runs both under the same noise model, and compares: readout bias and SPAM hit both arms equally
87
+ and cancel. If the control reproduces the signal, the claim is `NOT_SUPPORTED`.
88
+
89
+ **Claims the shot budget can't support.** `verify_experiment` computes the shots needed to separate
90
+ a claimed amplification from uniform noise and blocks under-powered runs up front.
91
+
92
+ **Fragile winners.** `find_robust_circuit` ranks candidates by mean minus variance under the device
93
+ noise model and re-validates the winner on a seed it was never scored on, so a circuit that wins
94
+ only in ideal simulation loses.
95
+
96
+ ## Benchmark (synthetic suite)
97
+
98
+ These numbers describe this 30-circuit test suite, not real hardware.
99
+
100
+ 30 circuits (Bell, GHZ incl. star fan-out, QAOA, hardware-efficient ansätze, `rzz` pairs/chains, plus
101
+ deliberately broken and buggy-compiler variants) × 2 device presets, 4096 shots, fixed seeds,
102
+ produced by `benchmarks/run_benchmark.py`:
103
+
104
+ | Metric | ibm-heron | ionq-forte-1 |
105
+ |---|---|---|
106
+ | Circuits run | 30 | 30 |
107
+ | `verify_experiment` GO | 28 (93.3%) | 22 (73.3%) |
108
+ | `verify_experiment` BLOCK | 2 (6.7%) | 8 (26.7%) |
109
+ |   of which gate-synthesis inflation | 0 | 8 |
110
+ |   of which topology (routing) | 2 | 0 |
111
+ |   of which ground-truth claim failed | 0 | 0 |
112
+ | Buggy-compiler `rzz` variants caught | 0/8 (n/a: cz-native, 2 cz is the minimum) | 8/8 |
113
+ | Clean-compiler `rzz` circuits falsely blocked | 0/9 | 0/9 |
114
+ | Fake-entanglement circuits (missing `h`) passed by `verify_experiment` | 3/3 | 3/3 |
115
+ | Fake-entanglement circuits rejected by `falsify_claim` | 3/3 | 3/3 |
116
+ | Non-broken circuits rejected by `falsify_claim` | 2/27 | 2/27 |
117
+
118
+ Takeaways:
119
+ - The 8 IonQ blocks are exactly the 8 buggy-compiler variants; none of the 9 clean `rzz` circuits is flagged.
120
+ - The fake-entanglement circuits (a `cx` on `|0>`, or an all-zero-parameter ansatz) show a ~99% "Bell/GHZ signal", so
121
+ `verify_experiment` passes them. Only the control-circuit test in `falsify_claim` rejects them, which is why both exist.
122
+ - The 2 non-broken `falsify_claim` rejections are the `rzz(0.3)` pair and its buggy-compiler duplicate: a rotation that
123
+ small can't be separated from noise.
124
+
125
+ Reproduce:
126
+
127
+ ```bash
128
+ pip install -e ".[dev]" && python benchmarks/run_benchmark.py --json benchmarks/results.json
129
+ ```
130
+
131
+ ## API
132
+
133
+ | Function | What it does |
134
+ |---|---|
135
+ | `verify_experiment(circuit, device, *, shots, expected_marked_bitstrings, expected_amplification, tolerance)` | Parse → semantic → topology → shot-budget → ideal sim → native translation + synthesis check → noisy sim → ground truth. Returns a `Verdict`. |
136
+ | `falsify_claim(circuit, device, marked_bitstrings=None)` | Control-circuit test. With marked bitstrings: isolated effect size + one-sided z-test. Without: TVD vs. the sampling-noise floor. |
137
+ | `find_robust_circuit(candidates, device, marked_bitstrings)` | Noise-aware candidate ranking with held-out validation. |
138
+ | `gate_synthesis_check(circuit, device)` | Native-gate inflation check; can also audit your own `transpiled=` circuit. |
139
+ | `analyze_circuit_gradients(build_fn, params, n_qubits)` | Barren-plateau / dead-parameter check via PennyLane autodiff. Raises an install hint if PennyLane is missing. |
140
+ | `diff_compilers(circuit, device)` | Qiskit vs. TKET onto the device's native basis; each output is checked by exact unitary equivalence (≤12 qubits). Degrades to Qiskit-only without TKET. |
141
+
142
+ `circuit` is a `QuantumCircuit` or an OpenQASM 2/3 string. `Verdict` has `.status` (`"GO"`/`"BLOCK"`),
143
+ `.reason`, `.checks` (every stage's raw result) and `.metrics`.
144
+
145
+ ### Devices and offline noise
146
+
147
+ Presets: `ionq-forte-1` (all-to-all, native `zz`), `ibm-heron` (heavy-hex degree 3, native `cz`), `ideal`.
148
+ Noise rates are representative order-of-magnitude figures, **not live calibration data**. Supply your own:
149
+
150
+ ```python
151
+ from py_quantum_verifier import get_device
152
+ dev = get_device("ibm-heron").with_noise(p1=3e-4, p2=5e-3, readout=2e-2)
153
+ ```
154
+
155
+ The native-gate models are offline approximations (single-qubit gates compile to `rz`/`sx`/`x`, with `rz`
156
+ treated as a free frame change). They reproduce the structural failure modes above, not vendor-exact
157
+ pulse counts. Treat a `GO` as "passed these checks", not as a hardware guarantee.
158
+
159
+ ## Limitations
160
+
161
+ - The "buggy compiler" is emulated (`Device.with_native_equivalences(direct_rzz=False)`), not a run of IonQ's real software.
162
+ - Noise rates are representative presets, not live calibration data.
163
+ - A `GO` means the circuit passed these checks, not that it will work on hardware.
164
+
165
+ ## Development
166
+
167
+ ```bash
168
+ pip install -e ".[dev]"
169
+ pytest
170
+ ```
171
+
172
+ MIT licensed.
@@ -0,0 +1,141 @@
1
+ # py-quantum-verifier
2
+
3
+ Deterministic, offline pre-flight checks for quantum circuits. Run them before you spend hardware time.
4
+
5
+ ```python
6
+ from py_quantum_verifier import verify_experiment, falsify_claim
7
+ from qiskit import QuantumCircuit
8
+ qc = QuantumCircuit(2, 2); qc.h(0); qc.cx(0, 1); qc.measure([0, 1], [0, 1])
9
+ print(verify_experiment(qc, "ionq-forte-1")) # GO (ionq-forte-1): All checks passed.
10
+ print(falsify_claim(qc, "ionq-forte-1", ["00", "11"]).verdict) # SUPPORTED
11
+ ```
12
+
13
+ No API tokens, no network, no GPU. Everything runs on Qiskit Aer with built-in device models.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ pip install py-quantum-verifier # core: qiskit>=2.0, qiskit-aer, numpy
19
+ pip install "py-quantum-verifier[pennylane]" # + analyze_circuit_gradients
20
+ pip install "py-quantum-verifier[cuda]" # + cudaq (Linux/macOS with CUDA-Q wheels)
21
+ pip install "py-quantum-verifier[tket]" # + Qiskit-vs-TKET diffing
22
+ pip install "py-quantum-verifier[all]" # everything, incl. pytest
23
+ ```
24
+
25
+ Optional integrations are imported lazily inside `try/except ImportError`, so the core
26
+ install is small and identical on macOS, Windows and Linux. `optional_features()` reports
27
+ which extras are importable.
28
+
29
+ ## Real bugs this catches
30
+
31
+ **Silent gate-synthesis blowup (`rzz` on IonQ-style native gates).** IonQ's native `ZZ`
32
+ gate is tunable, so a logical `rzz(θ)` should compile to exactly **one** native gate:
33
+ `RZZ(θ) == ZZ(θ/2π)`. If the compiler has no direct `rzz → zz` equivalence it silently falls
34
+ back to a generic `cx` decomposition: **2** native two-qubit gates plus a pile of single-qubit
35
+ gates. The circuit still runs and still "looks right"; it just carries double the two-qubit
36
+ error. `gate_synthesis_check` compares logical and native gate counts and blocks it:
37
+
38
+ ```python
39
+ from py_quantum_verifier import gate_synthesis_check, get_device, verify_experiment
40
+
41
+ device = get_device("ionq-forte-1").with_native_equivalences(direct_rzz=False) # unpatched compiler
42
+ verify_experiment(qc_with_rzz, device)
43
+ # BLOCK: 1 logical two-qubit gate(s) became 2 native two-qubit gate(s) (2.0x, limit 1.5x for tunable ...)
44
+ ```
45
+
46
+ Limits are device-aware: on CZ/CX/ECR-native hardware an arbitrary-angle `rzz` legitimately
47
+ needs 2 gates, so that is not flagged there (limit 2.5x).
48
+
49
+ **Topology traps.** On heavy-hex devices a qubit with more than 3 interaction partners forces
50
+ SWAP routing that multiplies two-qubit gate count. `topology_check` flags it before transpiling.
51
+ All-to-all devices report "not applicable" rather than silently passing.
52
+
53
+ **Noise passed off as a signal.** A forgotten `h` before a `cx` gives `00` at 99%, which looks
54
+ like a great Bell-state result. `falsify_claim` builds a control with the entangling gates removed,
55
+ runs both under the same noise model, and compares: readout bias and SPAM hit both arms equally
56
+ and cancel. If the control reproduces the signal, the claim is `NOT_SUPPORTED`.
57
+
58
+ **Claims the shot budget can't support.** `verify_experiment` computes the shots needed to separate
59
+ a claimed amplification from uniform noise and blocks under-powered runs up front.
60
+
61
+ **Fragile winners.** `find_robust_circuit` ranks candidates by mean minus variance under the device
62
+ noise model and re-validates the winner on a seed it was never scored on, so a circuit that wins
63
+ only in ideal simulation loses.
64
+
65
+ ## Benchmark (synthetic suite)
66
+
67
+ These numbers describe this 30-circuit test suite, not real hardware.
68
+
69
+ 30 circuits (Bell, GHZ incl. star fan-out, QAOA, hardware-efficient ansätze, `rzz` pairs/chains, plus
70
+ deliberately broken and buggy-compiler variants) × 2 device presets, 4096 shots, fixed seeds,
71
+ produced by `benchmarks/run_benchmark.py`:
72
+
73
+ | Metric | ibm-heron | ionq-forte-1 |
74
+ |---|---|---|
75
+ | Circuits run | 30 | 30 |
76
+ | `verify_experiment` GO | 28 (93.3%) | 22 (73.3%) |
77
+ | `verify_experiment` BLOCK | 2 (6.7%) | 8 (26.7%) |
78
+ |   of which gate-synthesis inflation | 0 | 8 |
79
+ |   of which topology (routing) | 2 | 0 |
80
+ |   of which ground-truth claim failed | 0 | 0 |
81
+ | Buggy-compiler `rzz` variants caught | 0/8 (n/a: cz-native, 2 cz is the minimum) | 8/8 |
82
+ | Clean-compiler `rzz` circuits falsely blocked | 0/9 | 0/9 |
83
+ | Fake-entanglement circuits (missing `h`) passed by `verify_experiment` | 3/3 | 3/3 |
84
+ | Fake-entanglement circuits rejected by `falsify_claim` | 3/3 | 3/3 |
85
+ | Non-broken circuits rejected by `falsify_claim` | 2/27 | 2/27 |
86
+
87
+ Takeaways:
88
+ - The 8 IonQ blocks are exactly the 8 buggy-compiler variants; none of the 9 clean `rzz` circuits is flagged.
89
+ - The fake-entanglement circuits (a `cx` on `|0>`, or an all-zero-parameter ansatz) show a ~99% "Bell/GHZ signal", so
90
+ `verify_experiment` passes them. Only the control-circuit test in `falsify_claim` rejects them, which is why both exist.
91
+ - The 2 non-broken `falsify_claim` rejections are the `rzz(0.3)` pair and its buggy-compiler duplicate: a rotation that
92
+ small can't be separated from noise.
93
+
94
+ Reproduce:
95
+
96
+ ```bash
97
+ pip install -e ".[dev]" && python benchmarks/run_benchmark.py --json benchmarks/results.json
98
+ ```
99
+
100
+ ## API
101
+
102
+ | Function | What it does |
103
+ |---|---|
104
+ | `verify_experiment(circuit, device, *, shots, expected_marked_bitstrings, expected_amplification, tolerance)` | Parse → semantic → topology → shot-budget → ideal sim → native translation + synthesis check → noisy sim → ground truth. Returns a `Verdict`. |
105
+ | `falsify_claim(circuit, device, marked_bitstrings=None)` | Control-circuit test. With marked bitstrings: isolated effect size + one-sided z-test. Without: TVD vs. the sampling-noise floor. |
106
+ | `find_robust_circuit(candidates, device, marked_bitstrings)` | Noise-aware candidate ranking with held-out validation. |
107
+ | `gate_synthesis_check(circuit, device)` | Native-gate inflation check; can also audit your own `transpiled=` circuit. |
108
+ | `analyze_circuit_gradients(build_fn, params, n_qubits)` | Barren-plateau / dead-parameter check via PennyLane autodiff. Raises an install hint if PennyLane is missing. |
109
+ | `diff_compilers(circuit, device)` | Qiskit vs. TKET onto the device's native basis; each output is checked by exact unitary equivalence (≤12 qubits). Degrades to Qiskit-only without TKET. |
110
+
111
+ `circuit` is a `QuantumCircuit` or an OpenQASM 2/3 string. `Verdict` has `.status` (`"GO"`/`"BLOCK"`),
112
+ `.reason`, `.checks` (every stage's raw result) and `.metrics`.
113
+
114
+ ### Devices and offline noise
115
+
116
+ Presets: `ionq-forte-1` (all-to-all, native `zz`), `ibm-heron` (heavy-hex degree 3, native `cz`), `ideal`.
117
+ Noise rates are representative order-of-magnitude figures, **not live calibration data**. Supply your own:
118
+
119
+ ```python
120
+ from py_quantum_verifier import get_device
121
+ dev = get_device("ibm-heron").with_noise(p1=3e-4, p2=5e-3, readout=2e-2)
122
+ ```
123
+
124
+ The native-gate models are offline approximations (single-qubit gates compile to `rz`/`sx`/`x`, with `rz`
125
+ treated as a free frame change). They reproduce the structural failure modes above, not vendor-exact
126
+ pulse counts. Treat a `GO` as "passed these checks", not as a hardware guarantee.
127
+
128
+ ## Limitations
129
+
130
+ - The "buggy compiler" is emulated (`Device.with_native_equivalences(direct_rzz=False)`), not a run of IonQ's real software.
131
+ - Noise rates are representative presets, not live calibration data.
132
+ - A `GO` means the circuit passed these checks, not that it will work on hardware.
133
+
134
+ ## Development
135
+
136
+ ```bash
137
+ pip install -e ".[dev]"
138
+ pytest
139
+ ```
140
+
141
+ MIT licensed.