autoq-qec 0.2.1__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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ronaldo Rodrigues
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,141 @@
1
+ Metadata-Version: 2.4
2
+ Name: autoq-qec
3
+ Version: 0.2.1
4
+ Summary: Multi-code QEC resource estimator for arbitrary Qiskit circuits
5
+ Author-email: Ronaldo Rodrigues <Ronaldoengenhariadacomputacao@hotmail.com>
6
+ License: MIT
7
+ Project-URL: Repository, https://github.com/Ronaldoengenhariadacomputacao/autoq-qec
8
+ Project-URL: Issues, https://github.com/Ronaldoengenhariadacomputacao/autoq-qec/issues
9
+ Project-URL: ORCID, https://orcid.org/0009-0006-7449-1190
10
+ Keywords: quantum,qec,surface-code,fault-tolerant,qiskit
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Topic :: Scientific/Engineering :: Physics
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: qiskit>=1.0.0
22
+ Requires-Dist: numpy>=1.24
23
+ Provides-Extra: ibm
24
+ Requires-Dist: qiskit-ibm-runtime>=0.20; extra == "ibm"
25
+ Provides-Extra: sim
26
+ Requires-Dist: qiskit-aer>=0.14; extra == "sim"
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7; extra == "dev"
29
+ Requires-Dist: pytest-cov; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # AutoQ QEC Estimator
33
+
34
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.21327566.svg)](https://doi.org/10.5281/zenodo.21327566)
35
+
36
+ **Multi-code fault-tolerant quantum error correction estimator for arbitrary Qiskit circuits.**
37
+
38
+ Given any Qiskit circuit and a set of hardware profiles, AutoQ QEC returns a ranked comparison of QEC codes (Surface Code, Floquet Code, Bacon-Shor, Steane [[7,1,3]]) with physically grounded resource estimates: physical qubit count, execution time, and circuit fidelity.
39
+
40
+ ## What this does that nothing else does
41
+
42
+ | Tool | Multi-code | Arbitrary circuit | Analytic model | Hardware-agnostic |
43
+ |---|---|---|---|---|
44
+ | Azure Resource Estimator | ❌ Surface Code only | ✅ | ✅ | ❌ Azure only |
45
+ | stim | ✅ | ❌ needs rewrite | ❌ simulation | ❌ |
46
+ | qiskit-qec | ✅ | ❌ no estimator | ❌ | ✅ |
47
+ | **AutoQ QEC** | ✅ | ✅ | ✅ | ✅ |
48
+
49
+ ## Install
50
+
51
+ ```bash
52
+ pip install autoq-qec
53
+ # With IBM Quantum integration:
54
+ pip install "autoq-qec[ibm,sim]"
55
+ ```
56
+
57
+ ## Quickstart
58
+
59
+ ```python
60
+ from qiskit import QuantumCircuit
61
+ from autoq_qec import compare, rank
62
+ from autoq_qec import HARDWARE_PROFILES, CalibratedHardware, HardwareProfile
63
+
64
+ # Any Qiskit circuit
65
+ circuit = QuantumCircuit(4)
66
+ circuit.h(0); circuit.cx(0,1); circuit.cx(1,2); circuit.cx(2,3)
67
+
68
+ # Hardware profiles (built-in or custom)
69
+ hardwares = [
70
+ HardwareProfile("IBM_Eagle", t_gate_ns=391, p_phys=0.0062, topology="heavy-hex"),
71
+ HardwareProfile("IBM_Heron", t_gate_ns=100, p_phys=0.003, topology="heavy-hex"),
72
+ HardwareProfile("Quantinuum_H2", t_gate_ns=100e3, p_phys=0.00029,topology="all-to-all"),
73
+ ]
74
+
75
+ # One call — returns all codes × all hardwares
76
+ result = compare(circuit, hardwares, fidelity_target=0.99)
77
+
78
+ # Pass hardware_calibrations to exclude combinations that violate T1
79
+ # (t_circuit >= 0.5×T1) — matches by name or by (t_gate_ns, p_phys)
80
+ recommendations = rank(result, hardware_calibrations=HARDWARE_PROFILES)
81
+
82
+ for r in recommendations[:3]:
83
+ print(f"#{r.rank} {r.hardware} + {r.code}: "
84
+ f"{r.total_physical_qubits}q, {r.execution_time_us:.1f}µs, "
85
+ f"fidelity={r.fidelity_circuit:.4f}")
86
+ ```
87
+
88
+ ## With real IBM calibration data
89
+
90
+ ```python
91
+ from autoq_qec.real_hardware import from_ibm_backend, noise_model_from_ibm
92
+
93
+ # Pulls today's calibration — T1, T2, CX error per qubit pair
94
+ hw = from_ibm_backend("ibm_brisbane", token="YOUR_IBM_TOKEN")
95
+
96
+ # Simulate locally with real noise model (no queue, no cost)
97
+ sim = noise_model_from_ibm("ibm_brisbane", token="YOUR_IBM_TOKEN")
98
+ ```
99
+
100
+ ## Physical models
101
+
102
+ | Code | Model | Reference |
103
+ |---|---|---|
104
+ | Surface Code | $p_L \approx A(p/p_{th})^{(d+1)/2}$, $q=2d^2-1$, overhead $=d^3$ | Fowler et al., PRA 86, 032324 (2012) |
105
+ | Floquet Code | $p_L \approx 0.07(p/p_{th})^{(d+1)/2}$, $q=4d^2+8(d-1)$, overhead $=\lfloor d/2\rfloor$ | Gidney & Fowler, arXiv:2202.11829 |
106
+ | Bacon-Shor | $p_L \approx (p/p_{th})^d$, $q=d^2$ | Aliferis & Cross (2007) |
107
+ | Steane [[7,1,3]] | $p_L \approx 21p^2$, $q=13$ | Steane, PRL 77, 793 (1996) |
108
+
109
+ Thresholds are enforced: `p ≥ p_th` raises `ValueError` — no silent wrong results.
110
+
111
+ ## Algorithm Estimator
112
+
113
+ Order-of-magnitude T-count estimates for known algorithms, without building the full circuit:
114
+
115
+ ```python
116
+ from autoq_qec import AlgorithmEstimator
117
+
118
+ est = AlgorithmEstimator.shor(2048)
119
+ print(est.t_count_estimate, est.t_count_uncertainty) # ±5x — build the real circuit for precise numbers
120
+ ```
121
+
122
+ Covers `shor`, `grover`, `qft`, `vqe`. These are rough estimates (±2×–±10× depending on the algorithm) — use `extract_circuit_profile()` on a real circuit whenever possible.
123
+
124
+ ## Test
125
+
126
+ ```bash
127
+ pytest tests/ -v # 49 tests, all verify physics not arithmetic
128
+ ```
129
+
130
+ ## What the tests check (unlike most QEC tools)
131
+
132
+ - `p ≥ threshold` raises `ValueError`, not wrong overhead
133
+ - `d` is always odd for Surface Code (rotated lattice requirement)
134
+ - `p_L ≤ p_L_target` guaranteed after distance selection
135
+ - Noisier hardware requires larger `d` (monotonicity)
136
+ - Circuit with 0 gates raises `ValueError` (destroyed by transpiler)
137
+ - Fidelity scales correctly with `t_gate`
138
+
139
+ ## Author
140
+
141
+ Ronaldo Rodrigues — ORCID: [0009-0006-7449-1190](https://orcid.org/0009-0006-7449-1190)
@@ -0,0 +1,110 @@
1
+ # AutoQ QEC Estimator
2
+
3
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.21327566.svg)](https://doi.org/10.5281/zenodo.21327566)
4
+
5
+ **Multi-code fault-tolerant quantum error correction estimator for arbitrary Qiskit circuits.**
6
+
7
+ Given any Qiskit circuit and a set of hardware profiles, AutoQ QEC returns a ranked comparison of QEC codes (Surface Code, Floquet Code, Bacon-Shor, Steane [[7,1,3]]) with physically grounded resource estimates: physical qubit count, execution time, and circuit fidelity.
8
+
9
+ ## What this does that nothing else does
10
+
11
+ | Tool | Multi-code | Arbitrary circuit | Analytic model | Hardware-agnostic |
12
+ |---|---|---|---|---|
13
+ | Azure Resource Estimator | ❌ Surface Code only | ✅ | ✅ | ❌ Azure only |
14
+ | stim | ✅ | ❌ needs rewrite | ❌ simulation | ❌ |
15
+ | qiskit-qec | ✅ | ❌ no estimator | ❌ | ✅ |
16
+ | **AutoQ QEC** | ✅ | ✅ | ✅ | ✅ |
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ pip install autoq-qec
22
+ # With IBM Quantum integration:
23
+ pip install "autoq-qec[ibm,sim]"
24
+ ```
25
+
26
+ ## Quickstart
27
+
28
+ ```python
29
+ from qiskit import QuantumCircuit
30
+ from autoq_qec import compare, rank
31
+ from autoq_qec import HARDWARE_PROFILES, CalibratedHardware, HardwareProfile
32
+
33
+ # Any Qiskit circuit
34
+ circuit = QuantumCircuit(4)
35
+ circuit.h(0); circuit.cx(0,1); circuit.cx(1,2); circuit.cx(2,3)
36
+
37
+ # Hardware profiles (built-in or custom)
38
+ hardwares = [
39
+ HardwareProfile("IBM_Eagle", t_gate_ns=391, p_phys=0.0062, topology="heavy-hex"),
40
+ HardwareProfile("IBM_Heron", t_gate_ns=100, p_phys=0.003, topology="heavy-hex"),
41
+ HardwareProfile("Quantinuum_H2", t_gate_ns=100e3, p_phys=0.00029,topology="all-to-all"),
42
+ ]
43
+
44
+ # One call — returns all codes × all hardwares
45
+ result = compare(circuit, hardwares, fidelity_target=0.99)
46
+
47
+ # Pass hardware_calibrations to exclude combinations that violate T1
48
+ # (t_circuit >= 0.5×T1) — matches by name or by (t_gate_ns, p_phys)
49
+ recommendations = rank(result, hardware_calibrations=HARDWARE_PROFILES)
50
+
51
+ for r in recommendations[:3]:
52
+ print(f"#{r.rank} {r.hardware} + {r.code}: "
53
+ f"{r.total_physical_qubits}q, {r.execution_time_us:.1f}µs, "
54
+ f"fidelity={r.fidelity_circuit:.4f}")
55
+ ```
56
+
57
+ ## With real IBM calibration data
58
+
59
+ ```python
60
+ from autoq_qec.real_hardware import from_ibm_backend, noise_model_from_ibm
61
+
62
+ # Pulls today's calibration — T1, T2, CX error per qubit pair
63
+ hw = from_ibm_backend("ibm_brisbane", token="YOUR_IBM_TOKEN")
64
+
65
+ # Simulate locally with real noise model (no queue, no cost)
66
+ sim = noise_model_from_ibm("ibm_brisbane", token="YOUR_IBM_TOKEN")
67
+ ```
68
+
69
+ ## Physical models
70
+
71
+ | Code | Model | Reference |
72
+ |---|---|---|
73
+ | Surface Code | $p_L \approx A(p/p_{th})^{(d+1)/2}$, $q=2d^2-1$, overhead $=d^3$ | Fowler et al., PRA 86, 032324 (2012) |
74
+ | Floquet Code | $p_L \approx 0.07(p/p_{th})^{(d+1)/2}$, $q=4d^2+8(d-1)$, overhead $=\lfloor d/2\rfloor$ | Gidney & Fowler, arXiv:2202.11829 |
75
+ | Bacon-Shor | $p_L \approx (p/p_{th})^d$, $q=d^2$ | Aliferis & Cross (2007) |
76
+ | Steane [[7,1,3]] | $p_L \approx 21p^2$, $q=13$ | Steane, PRL 77, 793 (1996) |
77
+
78
+ Thresholds are enforced: `p ≥ p_th` raises `ValueError` — no silent wrong results.
79
+
80
+ ## Algorithm Estimator
81
+
82
+ Order-of-magnitude T-count estimates for known algorithms, without building the full circuit:
83
+
84
+ ```python
85
+ from autoq_qec import AlgorithmEstimator
86
+
87
+ est = AlgorithmEstimator.shor(2048)
88
+ print(est.t_count_estimate, est.t_count_uncertainty) # ±5x — build the real circuit for precise numbers
89
+ ```
90
+
91
+ Covers `shor`, `grover`, `qft`, `vqe`. These are rough estimates (±2×–±10× depending on the algorithm) — use `extract_circuit_profile()` on a real circuit whenever possible.
92
+
93
+ ## Test
94
+
95
+ ```bash
96
+ pytest tests/ -v # 49 tests, all verify physics not arithmetic
97
+ ```
98
+
99
+ ## What the tests check (unlike most QEC tools)
100
+
101
+ - `p ≥ threshold` raises `ValueError`, not wrong overhead
102
+ - `d` is always odd for Surface Code (rotated lattice requirement)
103
+ - `p_L ≤ p_L_target` guaranteed after distance selection
104
+ - Noisier hardware requires larger `d` (monotonicity)
105
+ - Circuit with 0 gates raises `ValueError` (destroyed by transpiler)
106
+ - Fidelity scales correctly with `t_gate`
107
+
108
+ ## Author
109
+
110
+ Ronaldo Rodrigues — ORCID: [0009-0006-7449-1190](https://orcid.org/0009-0006-7449-1190)
@@ -0,0 +1,24 @@
1
+ """
2
+ AutoQ QEC Estimator
3
+ Multi-code fault-tolerant quantum error correction estimator.
4
+ """
5
+ from .qec_estimator import (
6
+ CircuitProfile,
7
+ HardwareProfile,
8
+ CodeResult,
9
+ extract_circuit_profile,
10
+ estimate,
11
+ compare,
12
+ )
13
+ from .real_hardware import CalibratedHardware, HARDWARE_PROFILES
14
+ from .recommender import rank, Recommendation
15
+ from .algorithm_estimator import AlgorithmEstimator, AlgorithmEstimate
16
+
17
+ __version__ = "0.2.1"
18
+ __all__ = [
19
+ "CircuitProfile", "HardwareProfile", "CodeResult",
20
+ "CalibratedHardware", "HARDWARE_PROFILES",
21
+ "Recommendation",
22
+ "AlgorithmEstimator", "AlgorithmEstimate",
23
+ "extract_circuit_profile", "estimate", "compare", "rank",
24
+ ]
@@ -0,0 +1,101 @@
1
+ """
2
+ AutoQ QEC — Algorithm Estimator
3
+ Estimativas analíticas de T-count para algoritmos quânticos conhecidos.
4
+ ATENÇÃO: estimativas de ordem de grandeza. Usar circuito real quando possível.
5
+ """
6
+ import math
7
+ from dataclasses import dataclass
8
+
9
+
10
+ @dataclass
11
+ class AlgorithmEstimate:
12
+ algorithm: str
13
+ n_logical_qubits: int
14
+ t_count_estimate: int
15
+ t_count_uncertainty: str # "±5×" ou "±2×"
16
+ source: str
17
+ notes: str
18
+
19
+
20
+ class AlgorithmEstimator:
21
+
22
+ @staticmethod
23
+ def shor(N: int) -> AlgorithmEstimate:
24
+ """
25
+ Shor factoring de N.
26
+ T-count ≈ 20n³ onde n = ⌈log₂N⌉.
27
+ Fonte: Beauregard (2003) + síntese de portas fault-tolerant.
28
+ Incerteza: ±5× dependendo da implementação de aritmética modular
29
+ (verificado contra Shor N=15 real: fórmula subestima ~4,7×).
30
+ """
31
+ if N <= 2:
32
+ raise ValueError(
33
+ f"Shor requer N > 2 (N={N} não tem fatoração não-trivial a estimar)"
34
+ )
35
+ n = math.ceil(math.log2(N))
36
+ t_count = 20 * n**3
37
+ return AlgorithmEstimate(
38
+ algorithm=f"Shor N={N}",
39
+ n_logical_qubits=2*n + 3,
40
+ t_count_estimate=t_count,
41
+ t_count_uncertainty="±5×",
42
+ source="Beauregard, QIC 3:175 (2003); Fowler gate synthesis",
43
+ notes=f"n={n} bits. Implementações simples podem ter até 5× mais T-gates.",
44
+ )
45
+
46
+ @staticmethod
47
+ def grover(N: int) -> AlgorithmEstimate:
48
+ """
49
+ Grover search em N itens.
50
+ T-count ≈ 7n por iteração × ⌈π/4·√N⌉ iterações, com n=⌈log₂N⌉.
51
+ Nota: como n cresce com log₂N, o T-count total escala com √N·log₂N,
52
+ não apenas √N — o fator log₂N vem do custo do oracle genérico por
53
+ iteração, não só do número de iterações.
54
+ Fonte: estimativa com oracle genérico.
55
+ """
56
+ if N <= 1:
57
+ raise ValueError(f"Grover requer N > 1 itens de busca (N={N})")
58
+ n = math.ceil(math.log2(N))
59
+ iterations = math.ceil(math.pi/4 * math.sqrt(N))
60
+ t_per_iter = 7 * n
61
+ t_count = t_per_iter * iterations
62
+ return AlgorithmEstimate(
63
+ algorithm=f"Grover N={N}",
64
+ n_logical_qubits=n + 1,
65
+ t_count_estimate=t_count,
66
+ t_count_uncertainty="±10×",
67
+ source="Estimativa com oracle genérico de n T-gates",
68
+ notes="Depende fortemente do oracle. Incerteza alta sem oracle específico.",
69
+ )
70
+
71
+ @staticmethod
72
+ def qft(n: int) -> AlgorithmEstimate:
73
+ """
74
+ QFT em n qubits.
75
+ T-count ≈ n²/2 (rotações CP com síntese Solovay-Kitaev).
76
+ """
77
+ t_count = n*n // 2
78
+ return AlgorithmEstimate(
79
+ algorithm=f"QFT n={n}",
80
+ n_logical_qubits=n,
81
+ t_count_estimate=t_count,
82
+ t_count_uncertainty="±2×",
83
+ source="Rotações CP decompostas em Clifford+T",
84
+ notes="CP(π/2^k) para k>2 requer síntese com T-gates.",
85
+ )
86
+
87
+ @staticmethod
88
+ def vqe(n_qubits: int, depth: int) -> AlgorithmEstimate:
89
+ """
90
+ VQE com n_qubits e profundidade depth.
91
+ T-count ≈ 4 · n · depth (Trotterizado).
92
+ """
93
+ t_count = 4 * n_qubits * depth
94
+ return AlgorithmEstimate(
95
+ algorithm=f"VQE n={n_qubits} d={depth}",
96
+ n_logical_qubits=n_qubits,
97
+ t_count_estimate=t_count,
98
+ t_count_uncertainty="±3×",
99
+ source="Hamiltoniano Trotterizado com RZZ gates",
100
+ notes="Depende do Hamiltoniano. Incerteza moderada.",
101
+ )