paulicert 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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,288 @@
1
+ Metadata-Version: 2.4
2
+ Name: paulicert
3
+ Version: 0.1.0
4
+ Summary: Qiskit-native certification of the Pauli Twirl Approximation, minimal selective twirling, and exact logical channels for stabilizer and qLDPC codes.
5
+ Author-email: A Muh Mufqi Zuhudi <moefqy@rocketmail.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://paulicert.moefqy.com
8
+ Project-URL: Repository, https://github.com/moefqy/paulicert
9
+ Project-URL: Documentation, https://paulicert.moefqy.com
10
+ Project-URL: Issues, https://github.com/moefqy/paulicert/issues
11
+ Project-URL: Changelog, https://github.com/moefqy/paulicert/blob/main/CHANGELOG.md
12
+ Keywords: qiskit,quantum error correction,stabilizer codes,pauli twirling,coherent errors,quantum channels
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Education
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Scientific/Engineering :: Physics
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: qiskit<3,>=2.2
28
+ Requires-Dist: qiskit-aer>=0.15
29
+ Requires-Dist: numpy<3,>=2.0
30
+ Requires-Dist: matplotlib>=3.8
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=8.0; extra == "dev"
33
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
34
+ Requires-Dist: ruff>=0.6; extra == "dev"
35
+ Requires-Dist: mypy>=1.11; extra == "dev"
36
+ Requires-Dist: build>=1.2; extra == "dev"
37
+ Requires-Dist: twine>=5.0; extra == "dev"
38
+ Requires-Dist: readme-renderer[md]>=43.0; extra == "dev"
39
+ Requires-Dist: cffconvert>=2.0; extra == "dev"
40
+ Requires-Dist: tox>=4.0; extra == "dev"
41
+ Requires-Dist: nbformat>=5.10; extra == "dev"
42
+ Requires-Dist: nbclient>=0.10; extra == "dev"
43
+ Requires-Dist: ipykernel>=6.29; extra == "dev"
44
+ Dynamic: license-file
45
+
46
+ # paulicert
47
+
48
+ [![CI](https://github.com/moefqy/paulicert/actions/workflows/ci.yml/badge.svg)](https://github.com/moefqy/paulicert/actions/workflows/ci.yml)
49
+ [![PyPI](https://img.shields.io/pypi/v/paulicert.svg)](https://pypi.org/project/paulicert/)
50
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
51
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
52
+ [![Qiskit 2.x](https://img.shields.io/badge/Qiskit-2.x-6929C4.svg)](https://qiskit.org/)
53
+
54
+ ## Introduction
55
+
56
+ **Can you trust a Pauli-noise simulation of your quantum error-correcting code?**
57
+
58
+ Large-scale QEC simulations model noise as random Pauli errors (`X`, `Y`, `Z` flips) so stabilizer
59
+ tableaux run in polynomial time. Physical qubits, however, also suffer **coherent** and non-unital
60
+ processes — such as gate over-rotations `R_X(θ) = exp(-iθX/2)` and `T1` relaxation — which
61
+ stabilizer simulators approximate via the **Pauli Twirl Approximation (PTA)**, replacing `R_X(θ)`
62
+ with a stochastic `X` flip of probability `p = sin²(θ/2)`. `paulicert` certifies when that Pauli
63
+ replacement is exact, quantifies the exact logical-channel discrepancy when it fails, and finds
64
+ the minimum subset of qubits to Pauli-twirl — alongside local Clifford deformations that rotate
65
+ stabilizer checks away from coherent noise. Built on Qiskit 2.x and Qiskit Aer.
66
+
67
+ ## The problem in one table
68
+
69
+ Steane [[7, 1, 3]] code. Every qubit gets a small coherent X over-rotation, followed by one round
70
+ of perfect syndrome measurement and look-up-table correction:
71
+
72
+ | Physical error p | Pauli model | True coherent channel | Steane + twirl 3 qubits | Better than bare qubit? (Pauli / True / Twirl 3) |
73
+ | --- | --- | --- | --- | --- |
74
+ | 1.0% | 0.20% | 0.59% | 0.20% | yes / yes / yes |
75
+ | 1.5% | 0.44% | 1.28% | 0.44% | yes / yes / yes |
76
+ | **2.0%** | 0.76% | **2.19%** | **0.76%** | yes / **no** / **yes (2.6×)** |
77
+ | 3.0% | 1.64% | 4.60% | 1.64% | yes / **no** / **yes** |
78
+ | 5.0% | 4.15% | 11.06% | 4.15% | yes / **no** / **yes** |
79
+
80
+ The Pauli model puts the break-even point (logical = physical error) at **6.5%**; the true
81
+ value is **1.8%**. At p = 2.0%, untwirled Steane (2.19%) is worse than a bare qubit (2.00%) —
82
+ yet physically twirling just **3 of the 7 qubits** `(0, 1, 2)` breaks the interference and drops
83
+ the real error to **0.76%**. Reproduce with
84
+ [`examples/01_check_measure_fix.ipynb`](https://github.com/moefqy/paulicert/blob/main/examples/01_check_measure_fix.ipynb).
85
+
86
+ ![Steane code break-even shift under coherent X over-rotation](https://raw.githubusercontent.com/moefqy/paulicert/main/benchmarks/figures/steane_break_even.png)
87
+
88
+ ## Install
89
+
90
+ ```bash
91
+ pip install paulicert
92
+ ```
93
+
94
+ Or install from source:
95
+
96
+ ```bash
97
+ git clone https://github.com/moefqy/paulicert.git
98
+ cd paulicert
99
+ pip install -e .
100
+ ```
101
+
102
+ Runtime dependencies: `qiskit`, `qiskit-aer`, `numpy`, `matplotlib`.
103
+
104
+ ## Quickstart
105
+
106
+ ```python
107
+ import paulicert as pc
108
+
109
+ steane = pc.get_preset_code("7-1-3-steane")
110
+ noise = pc.CHANNEL_FAMILIES["coherent_x"](0.01) # small coherent X over-rotation
111
+
112
+ # 1. Certificate: a "witness" is a stabilizer (or normalizer element when full_channel=True)
113
+ # along which coherent error amplitudes can interfere. Zero witnesses => PTA is guaranteed exact.
114
+ cert = pc.pauli_exact(steane, noise)
115
+ print(f"exact={cert.exact} | witnesses={cert.num_witnesses} | min_weight={cert.min_witness_weight}")
116
+ # exact=False | witnesses=7 | min_weight=4
117
+
118
+ # 2. Exact decoded logical channel (Qiskit SuperOp) under true vs. twirled noise.
119
+ lc = pc.logical_channel(steane, noise)
120
+ print(
121
+ f"true={lc.infidelity:.4e} | PTA={lc.twirled_infidelity:.4e} | gap={lc.gap:.4f} | D_Choi={lc.choi_distance:.2e}"
122
+ )
123
+ # true=5.8784e-03 | PTA=2.0041e-03 | gap=2.9332 | D_Choi=1.28e-02
124
+
125
+ # 3. Which qubits must be twirled to make the Pauli model exact? (minimal: 3 qubits)
126
+ ts = pc.minimal_twirl_set(steane, noise)
127
+ print(
128
+ f"Qubits to twirl: {ts.qubits} ({len(ts.qubits)}/{steane.n} qubits, provably_minimal={ts.provably_minimal})"
129
+ )
130
+ # Qubits to twirl: (0, 1, 2) (3/7 qubits, provably_minimal=True)
131
+
132
+ # 4. Logical error rate sweeps: fast Pauli engine (warns here), exact channel, or Qiskit SamplerV2.
133
+ rates = pc.block_logical_error_rate(steane, "coherent_x", [1e-3, 1e-2])
134
+ exact = pc.block_logical_error_rate(steane, "coherent_x", [1e-3, 1e-2], method="exact_channel")
135
+ full = pc.block_logical_error_rate(steane, "coherent_x", [1e-2], method="aer_circuit", shots=8000)
136
+ ```
137
+
138
+ See the four executed, task-driven Jupyter notebooks in `examples/`:
139
+ - [`examples/01_check_measure_fix.ipynb`](https://github.com/moefqy/paulicert/blob/main/examples/01_check_measure_fix.ipynb) — 5-minute quickstart: check with `pauli_exact` (diagonal & `full_channel=True`), measure exact `gap` & `choi_distance`, fix with `minimal_twirl_set` (3/7 qubits on Steane), and see `PauliTwirlApproximationWarning` + `aer_circuit` in action.
140
+ - [`examples/02_custom_codes_and_hardware_noise.ipynb`](https://github.com/moefqy/paulicert/blob/main/examples/02_custom_codes_and_hardware_noise.ipynb) — bring your own stabilizers (`[[9, 1, 3]]` rotated surface vs. XZZX), plug in per-qubit `T1/T2` `thermal_relaxation` and composite Qiskit `Kraus` noise, compare decoders (`min_weight`, `mpe`, `ml`), and export Qiskit circuits.
141
+ - [`examples/03_qldpc_and_clifford_deformation.ipynb`](https://github.com/moefqy/paulicert/blob/main/examples/03_qldpc_and_clifford_deformation.ipynb) — scale certification to large HGP and bivariate bicycle qLDPC codes (`[[37]]` to `[[360]]`), slash twirling overhead via XZZX deformation (`174/360 → 4/360`), and certify inhomogeneous noise on `[[144, 12, 12]]` (`3/144`).
142
+ - [`examples/04_why_interference_happens.ipynb`](https://github.com/moefqy/paulicert/blob/main/examples/04_why_interference_happens.ipynb) — under-the-hood statevector walkthrough: enumerates all 7 Steane Z-syndromes and colliding weight-2 X errors, verifies exact 8-configuration Pauli-twirl sign cancellation on qubits `(0, 1, 2)`, and contrasts with `[[5, 1, 3]]` (zero pure-X syndrome collisions).
143
+
144
+ ## Why: amplitudes add, probabilities don't
145
+
146
+ The Steane stabilizers, written in textbook order (qubit 0 on the left):
147
+
148
+ ```
149
+ g1 = XIIXIXX g4 = ZIIZIZZ
150
+ g2 = IXIXXIX g5 = IZIZZIZ
151
+ g3 = IIXIXXX g6 = IIZIZZZ logical X̄ = IIIXXXI
152
+ ```
153
+
154
+ > **Qubit ordering:** Prose tables above place qubit `0` on the left (`XIIXIXX`). `pc.from_pauli_list` defaults to Qiskit's right-to-left label order; pass `qiskit_order=False` when supplying left-to-right textbook strings.
155
+
156
+ Take one syndrome, `000110`. The decoder reads it as "X on qubit 3" and applies `IIIXIII`.
157
+ Three different two-qubit errors also produce this syndrome:
158
+
159
+ | Actual error | After correction | Effect on the encoded qubit |
160
+ | --- | --- | --- |
161
+ | `IIIXIII` | `IIIIIII` | none ✅ |
162
+ | `XXIIIII` | `XXIXIII` = X̄ · g1g2 | logical X̄ ❌ |
163
+ | `IIXIIIX` | `IIXXIIX` = X̄ · g3 | logical X̄ ❌ |
164
+ | `IIIIXXI` | `IIIXXXI` = X̄ | logical X̄ ❌ |
165
+
166
+ The three failures differ only by stabilizers, so they act identically on the code: they all
167
+ apply X̄.
168
+
169
+ - **Pauli model.** They are three separate random events of probability p² each, so the
170
+ probabilities add: 3p². Summed over the 7 syndromes this gives **21 p²**.
171
+ - **Coherent noise.** They are three branches of one superposition, each with amplitude −p, and
172
+ they end in the same state. The amplitudes add *before* squaring: |3p|² = 9p². Summed over
173
+ the 7 syndromes this gives **63 p²**.
174
+
175
+ At leading order in `p`, constructive interference across stabilizer-equivalent failure paths
176
+ triples the logical infidelity (`63p²` vs. `21p²`; verify all 7 Steane syndromes and the 8-run
177
+ selective-twirling sign cancellation live in [`examples/04_why_interference_happens.ipynb`](https://github.com/moefqy/paulicert/blob/main/examples/04_why_interference_happens.ipynb)).
178
+
179
+ **The [[5, 1, 3]] code is immune to this fidelity bias under the same noise.** Coherent X noise only
180
+ produces X-type errors. For two of their branches to merge inside a stabilizer coset, they would
181
+ have to differ by a stabilizer made only of X's. Steane has 7 such stabilizers; the 5-qubit code
182
+ (`XZZXI`, …) has none. So its Pauli model reproduces the exact entanglement fidelity (`gap = 1.0`).
183
+ To certify **full superoperator identity** (`Λ = Λ_PTA`, zero residual logical coherence,
184
+ `choi_distance = 0`) — essential across `M` repeated QEC cycles, where a residual `O(θ^d)` logical
185
+ rotation would otherwise accumulate coherently as `M²` instead of `M` — pass `full_channel=True`;
186
+ on `[[5, 1, 3]]`, that flags the weight-5 logical X̄ (`XXXXX`) and finds the single qubit whose
187
+ twirling eliminates it.
188
+
189
+ ## What paulicert does
190
+
191
+ | Question | Function | Steane, coherent X |
192
+ | --- | --- | --- |
193
+ | Is the Pauli model guaranteed exact for fidelity (`S ∩ L`) or the full logical channel (`full_channel=True`, `N(S) ∩ L`)? | `pauli_exact` | no; 7 stabilizer witnesses |
194
+ | How wrong is it, exactly (`gap` and `choi_distance`)? | `logical_channel` (n ≤ 10) | true / Pauli = 2.93 at p = 1% |
195
+ | Which qubits must be twirled (e.g. by randomized compiling) to make it exact? | `minimal_twirl_set` | 3 of 7 qubits, provably minimal |
196
+ | What are the logical error rates over a sweep, Pauli or full channel? | `block_logical_error_rate` | Pauli engine warns; `method="exact_channel"` or `"aer_circuit"` (`SamplerV2`) evaluates the full channel |
197
+
198
+ The certificate uses bit-packed GF(2) linear algebra, so it scales directly to large and
199
+ non-CSS codes:
200
+ - On the `[[9, 1, 3]]` rotated surface code, XZZX Clifford deformation eliminates all 15 single-axis
201
+ witnesses and collapses the coherent `Z` and `X` gap from **2.73×** to **1.00000** (0 twirled qubits).
202
+ - On Bravyi et al.'s non-preset `[[108, 8, 10]]`, `[[288, 12, 18]]`, and `[[360, 12, ≤24]]` bivariate bicycle qLDPC codes,
203
+ non-CSS XZZX deformation collapses the minimal twirl set from **50/108 → 2/108**,
204
+ **138/288 → 20/288**, and **174/360 → 4/360** (~0.1 s for `[[288, 12, 18]]`).
205
+
206
+ Full API documentation, benchmarks (980 exact sweep evaluations), and worked derivations are hosted
207
+ at **[paulicert.moefqy.com](https://paulicert.moefqy.com)**; repository-level notes and benchmark
208
+ scripts live in [benchmarks/](https://github.com/moefqy/paulicert/tree/main/benchmarks), [docs/architecture.md](https://github.com/moefqy/paulicert/blob/main/docs/architecture.md),
209
+ [docs/theory.md](https://github.com/moefqy/paulicert/blob/main/docs/theory.md), and [docs/related-work.md](https://github.com/moefqy/paulicert/blob/main/docs/related-work.md).
210
+
211
+ ## What is in the box
212
+
213
+ | Module | Contents |
214
+ | --- | --- |
215
+ | `paulicert.codes` | `StabilizerCode` (GF(2)/GF(4) input, standard form, logicals, exact distance for n ≤ 18), presets (`[[3, 1, 1]]`, `[[5, 1, 3]]`, Steane, `[[8, 3, 3]]`, Shor, HGP `[[58, 16, 3]]`, bivariate bicycle `[[72, 12, 6]]`, `[[90, 8, 10]]`, `[[144, 12, 12]]`), hypergraph-product and bivariate-bicycle constructors, local-Clifford deformation, Qiskit `PauliList` / `StabilizerState` / `Clifford` interop |
216
+ | `paulicert.noise` | Single-qubit channels as Qiskit `Kraus`, built from `qiskit_aer.noise`: `pauli_channel`, `depolarizing`, `amplitude_damping`, `phase_damping`, `thermal_relaxation`, `coherent_rotation`; `pauli_twirl`; `ChannelFamily` and named families in `CHANNEL_FAMILIES` |
217
+ | `paulicert.decode` | `StabilizerLUTDecoder` with three rules: minimum weight, most probable error (`build_mpe_lut`), and exact coset maximum likelihood (`build_ml_decoder`, n ≤ 10); `compute_syndrome`, `pauli_string_to_symplectic` |
218
+ | `paulicert.certify` | `pauli_exact` (`PauliExactness`): certificate (with witnesses) for diagonal fidelity exactness (`S ∩ L`) or full superoperator identity (`full_channel=True`, `N(S) ∩ L`); `minimal_twirl_set` (`TwirlSet`): smallest qubit subset eliminating all algebraic witnesses (provably minimal for single-axis coherence and small witness spaces). Bit-packed GF(2) linear algebra, scales to Bravyi et al.'s `[[144, 12, 12]]` (~25 ms) and `[[288, 12, 18]]` (~0.1 s); per-qubit channels supported |
219
+ | `paulicert.analysis` | `logical_channel` (`LogicalChannel`: exact decoded logical channel as a Qiskit `SuperOp`, true vs. twirled, `gap` and `choi_distance`, n ≤ 10); `block_logical_error_rate`, `logical_error_rate_per_qubit` (uniform or per-qubit channel families; engines: `pauli_enumeration`, `pauli_sampling`, `exact_channel`, `aer_circuit` via Qiskit `SamplerV2`); `PauliTwirlApproximationWarning`; `bounded_distance_estimate`, `pseudo_threshold` |
220
+ | `paulicert.circuits` | `encoding_circuit`, `syndrome_circuit` (physical qubit order) |
221
+ | `paulicert.plotting` | `plot_logical_error_rates`, `plot_pauli_twirl`, `plot_stabilizer_tableau` |
222
+
223
+ ## Scope and limitations (read before citing numbers)
224
+
225
+ - **Algorithmic tool, established physics.** Coherent-error interference in stabilizer decoding is
226
+ well established (Gutiérrez et al., 2016; Beale et al., 2018; Iverson & Preskill, 2020).
227
+ `paulicert` operationalizes that theory into a polynomial-time GF(2) witness solver,
228
+ minimal partial-twirling selector, and exact Qiskit logical-channel evaluator.
229
+ - **Distance suppresses logical rotations, not low-weight check interference.** Off-diagonal
230
+ logical coherence scales as `O(θ^d)` and decays exponentially with code distance `d` (Beale et al.,
231
+ PRL 2018; Iverson & Preskill, NJP 2020). Diagonal infidelity bias (`gap != 1`), however, is
232
+ governed by minimum witness weight: it is sharpest in small near-term codes (`[[5, 1, 3]]`,
233
+ Steane, `d = 3` surface) and persists in large CSS/qLDPC families whenever constant-weight
234
+ checks align with a coherent error axis.
235
+ - **Independent single-qubit code-capacity model only.** Noise acts independently once per data
236
+ qubit (`⊗_q ℰ_q`); syndrome extraction is ideal; one round of correction. Correlated multi-qubit
237
+ coherent noise (such as two-qubit `ZZ` crosstalk during entangling gates), circuit-level noise,
238
+ and measurement errors are outside v0.1.
239
+ - **Small codes for logical error rates.** The built-in decoders are look-up tables, so
240
+ simulations need r ≤ 16 stabilizer generators; `pauli_enumeration`, `exact_channel`, `logical_channel`, and the ML decoder need n ≤ 10;
241
+ `aer_circuit` uses Qiskit `SamplerV2` with Pauli-frame post-processing and is limited to n + k ≤ 24 qubits. The certificate
242
+ tools (`pauli_exact`, `minimal_twirl_set`) scale to the large qLDPC presets.
243
+ - **The certificate is sufficient, not necessary.** Witnesses permit a gap but do not force one
244
+ (Steane under amplitude damping: 7 witnesses, gap 1.00002).
245
+ - **When certification is nontrivial.** For undeformed CSS codes under uniform single-axis coherence,
246
+ the witness subspace reduces to the Z-type (or X-type) stabilizer row space; `paulicert` targets
247
+ regimes that resist inspection: non-CSS codes, Clifford-deformed qLDPC codes (e.g., XZZX),
248
+ multi-axis coherence, and inhomogeneous per-qubit calibration noise.
249
+ - **Block logical error rate** is 1 − F_e of the decoded logical channel (the probability of
250
+ any logical error for Pauli noise). The Aer engine estimates the same quantity with a Bell-pair
251
+ reference, so all engines are directly comparable.
252
+ - `bounded_distance_estimate` is P(more than t errors), an upper bound for decoders that correct
253
+ all errors of weight ≤ t; it is not a prediction of the logical error rate.
254
+ - **Cross-validated against published benchmarks.** `tests/test_literature_benchmarks.py` checks
255
+ `paulicert` to machine precision against exact analytical formulas and tables from Geller & Zhou
256
+ (2013), Gutiérrez et al. (2016), Greenbaum & Dutton (2017), Beale et al. (2018), Iverson &
257
+ Preskill (2020), Rahn–Doherty–Mabuchi (2002), Tillich & Zémor (2014), Bonilla Ataides et al.
258
+ (2021), Iyer & Poulin (2015), and Bravyi et al. (2024), plus zero-shared-code density-matrix
259
+ verification and randomized CPTP fuzzing.
260
+
261
+ ## Related work
262
+
263
+ - [Stim](https://github.com/quantumlib/Stim): the standard fast stabilizer/Pauli-noise simulator.
264
+ It is far faster for Pauli noise; `paulicert` is about the cases where Pauli noise is not the
265
+ whole story, and stays inside the Qiskit stack.
266
+ - [qiskit-qec](https://github.com/qiskit-community/qiskit-qec): Qiskit's QEC framework, archived
267
+ in 2025.
268
+ - [MQT QECC](https://github.com/munich-quantum-toolkit/qecc) and
269
+ [Deltakit](https://github.com/Deltakit/deltakit): QEC code/decoder tooling.
270
+ - [chflow](https://github.com/paviudes/chflow): studies of logical channels under non-Pauli noise.
271
+ - Theory on coherent noise in QEC, randomized compiling, and Clifford-tailored codes includes
272
+ Greenbaum & Dutton (2017), Beale et al. (PRL 2018), Tuckett, Bartlett & Flammia (PRL 2018),
273
+ Debroy, Li, Newman & Brown (PRL 2018), Iverson & Preskill (NJP 2020), Ouyang (npj QI 2021),
274
+ Hashim et al. (PRX 2021), Bonilla Ataides et al. (Nat. Commun. 2021), and Dua et al. (Nat. Commun. 2024). See
275
+ [docs/related-work.md](https://github.com/moefqy/paulicert/blob/main/docs/related-work.md) and [docs/theory.md](https://github.com/moefqy/paulicert/blob/main/docs/theory.md) for a detailed
276
+ comparison.
277
+
278
+ ## Development
279
+
280
+ ```bash
281
+ pip install -e ".[dev]"
282
+ pytest -q
283
+ ruff check . && ruff format --check . && mypy src
284
+ ```
285
+
286
+ ## Contact
287
+
288
+ For any inquiries or feedback, you can reach me at moefqy@rocketmail.com.