quonic 0.2.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 (81) hide show
  1. quonic-0.2.0/LICENSE +201 -0
  2. quonic-0.2.0/PKG-INFO +254 -0
  3. quonic-0.2.0/README.md +215 -0
  4. quonic-0.2.0/pyproject.toml +48 -0
  5. quonic-0.2.0/setup.cfg +4 -0
  6. quonic-0.2.0/src/quonic/__init__.py +39 -0
  7. quonic-0.2.0/src/quonic/algorithms/__init__.py +27 -0
  8. quonic-0.2.0/src/quonic/algorithms/grover.py +109 -0
  9. quonic-0.2.0/src/quonic/algorithms/hamiltonians.py +34 -0
  10. quonic-0.2.0/src/quonic/algorithms/oracle.py +42 -0
  11. quonic-0.2.0/src/quonic/algorithms/qaoa.py +93 -0
  12. quonic-0.2.0/src/quonic/algorithms/qpe.py +55 -0
  13. quonic-0.2.0/src/quonic/algorithms/quantum_counting.py +109 -0
  14. quonic-0.2.0/src/quonic/algorithms/shor.py +284 -0
  15. quonic-0.2.0/src/quonic/algorithms/vqe.py +79 -0
  16. quonic-0.2.0/src/quonic/backends/__init__.py +72 -0
  17. quonic-0.2.0/src/quonic/backends/base.py +25 -0
  18. quonic-0.2.0/src/quonic/backends/cirq.py +102 -0
  19. quonic-0.2.0/src/quonic/backends/native.py +107 -0
  20. quonic-0.2.0/src/quonic/backends/pennylane.py +114 -0
  21. quonic-0.2.0/src/quonic/backends/qi.py +141 -0
  22. quonic-0.2.0/src/quonic/backends/qiskit.py +122 -0
  23. quonic-0.2.0/src/quonic/compare.py +88 -0
  24. quonic-0.2.0/src/quonic/compiler.py +294 -0
  25. quonic-0.2.0/src/quonic/gates.py +83 -0
  26. quonic-0.2.0/src/quonic/ir.py +150 -0
  27. quonic-0.2.0/src/quonic/noise.py +52 -0
  28. quonic-0.2.0/src/quonic/qft.py +32 -0
  29. quonic-0.2.0/src/quonic/qgate.py +17 -0
  30. quonic-0.2.0/src/quonic/qif.py +312 -0
  31. quonic-0.2.0/src/quonic/qint.py +152 -0
  32. quonic-0.2.0/src/quonic/qshow.py +124 -0
  33. quonic-0.2.0/src/quonic/result.py +37 -0
  34. quonic-0.2.0/src/quonic/scheduler/__init__.py +91 -0
  35. quonic-0.2.0/src/quonic/scheduler/benchmark.py +342 -0
  36. quonic-0.2.0/src/quonic/scheduler/capabilities.py +85 -0
  37. quonic-0.2.0/src/quonic/scheduler/data/benchmarks.json +197 -0
  38. quonic-0.2.0/src/quonic/scheduler/features.py +76 -0
  39. quonic-0.2.0/src/quonic/scheduler/registry.py +180 -0
  40. quonic-0.2.0/src/quonic/simulator.py +86 -0
  41. quonic-0.2.0/src/quonic/simulators/__init__.py +21 -0
  42. quonic-0.2.0/src/quonic/simulators/_density.py +141 -0
  43. quonic-0.2.0/src/quonic/simulators/_gates.py +66 -0
  44. quonic-0.2.0/src/quonic/simulators/_mps.py +164 -0
  45. quonic-0.2.0/src/quonic/simulators/_stabilizer.py +179 -0
  46. quonic-0.2.0/src/quonic/simulators/_statevector.py +88 -0
  47. quonic-0.2.0/src/quonic/stack.py +48 -0
  48. quonic-0.2.0/src/quonic/topology.py +65 -0
  49. quonic-0.2.0/src/quonic/viz/__init__.py +73 -0
  50. quonic-0.2.0/src/quonic/viz/_mpl.py +62 -0
  51. quonic-0.2.0/src/quonic/viz/algorithm.py +264 -0
  52. quonic-0.2.0/src/quonic/viz/circuit.py +270 -0
  53. quonic-0.2.0/src/quonic/viz/gate.py +87 -0
  54. quonic-0.2.0/src/quonic/viz/noise.py +193 -0
  55. quonic-0.2.0/src/quonic/viz/result.py +53 -0
  56. quonic-0.2.0/src/quonic/viz/routing.py +75 -0
  57. quonic-0.2.0/src/quonic/viz/scheduler.py +370 -0
  58. quonic-0.2.0/src/quonic/viz/state.py +449 -0
  59. quonic-0.2.0/src/quonic.egg-info/PKG-INFO +254 -0
  60. quonic-0.2.0/src/quonic.egg-info/SOURCES.txt +79 -0
  61. quonic-0.2.0/src/quonic.egg-info/dependency_links.txt +1 -0
  62. quonic-0.2.0/src/quonic.egg-info/requires.txt +29 -0
  63. quonic-0.2.0/src/quonic.egg-info/top_level.txt +1 -0
  64. quonic-0.2.0/tests/test_algorithms.py +164 -0
  65. quonic-0.2.0/tests/test_backends.py +97 -0
  66. quonic-0.2.0/tests/test_bell.py +31 -0
  67. quonic-0.2.0/tests/test_capabilities.py +118 -0
  68. quonic-0.2.0/tests/test_cif.py +142 -0
  69. quonic-0.2.0/tests/test_compare.py +154 -0
  70. quonic-0.2.0/tests/test_compiler.py +187 -0
  71. quonic-0.2.0/tests/test_cwhile.py +120 -0
  72. quonic-0.2.0/tests/test_examples.py +70 -0
  73. quonic-0.2.0/tests/test_noise.py +54 -0
  74. quonic-0.2.0/tests/test_qi.py +118 -0
  75. quonic-0.2.0/tests/test_qif.py +286 -0
  76. quonic-0.2.0/tests/test_qint.py +51 -0
  77. quonic-0.2.0/tests/test_scheduler.py +172 -0
  78. quonic-0.2.0/tests/test_shor.py +61 -0
  79. quonic-0.2.0/tests/test_simulators.py +242 -0
  80. quonic-0.2.0/tests/test_validation.py +161 -0
  81. quonic-0.2.0/tests/test_viz.py +490 -0
quonic-0.2.0/LICENSE ADDED
@@ -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.
quonic-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,254 @@
1
+ Metadata-Version: 2.4
2
+ Name: quonic
3
+ Version: 0.2.0
4
+ Summary: 量子编程,像写 Python 一样简单
5
+ Author-email: ChrisLee <Christina_Llap_Yuen@outlook.com>
6
+ License-Expression: Apache-2.0
7
+ Keywords: quantum,quantum-computing,qiskit,cirq,pennylane
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Scientific/Engineering :: Physics
13
+ Requires-Python: >=3.9
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Provides-Extra: qiskit
17
+ Requires-Dist: qiskit>=1.0; extra == "qiskit"
18
+ Requires-Dist: qiskit-aer>=0.14; extra == "qiskit"
19
+ Provides-Extra: cirq
20
+ Requires-Dist: cirq>=1.0; extra == "cirq"
21
+ Provides-Extra: pennylane
22
+ Requires-Dist: pennylane>=0.36; extra == "pennylane"
23
+ Provides-Extra: quantum-inspire
24
+ Requires-Dist: qiskit-quantuminspire>=0.18; extra == "quantum-inspire"
25
+ Requires-Dist: quantuminspire>=4.0; extra == "quantum-inspire"
26
+ Requires-Dist: qiskit<2.4.0; extra == "quantum-inspire"
27
+ Provides-Extra: algorithms
28
+ Requires-Dist: numpy>=1.24; extra == "algorithms"
29
+ Requires-Dist: scipy>=1.10; extra == "algorithms"
30
+ Provides-Extra: viz
31
+ Requires-Dist: matplotlib>=3.5; extra == "viz"
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=7.0; extra == "dev"
34
+ Requires-Dist: numpy>=1.24; extra == "dev"
35
+ Requires-Dist: scipy>=1.10; extra == "dev"
36
+ Requires-Dist: matplotlib>=3.5; extra == "dev"
37
+ Requires-Dist: ruff>=0.9; extra == "dev"
38
+ Dynamic: license-file
39
+
40
+ # QuoNic — 量子编程,像写 Python 一样简单
41
+
42
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
43
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/)
44
+ [![Qiskit](https://img.shields.io/badge/Qiskit-1.0+-green.svg)](https://qiskit.org/)
45
+ [![Cirq](https://img.shields.io/badge/Cirq-1.0+-orange.svg)](https://quantumai.google/cirq)
46
+
47
+ **QuoNic 是一个让量子编程变得像写 Python 一样简单的工具。**
48
+
49
+ 不需要学 `QuantumCircuit`,不需要理解 `backend`,不需要手动 `measure`。你会写 Python,就会用量子计算。
50
+
51
+ ---
52
+
53
+ ## 🚀 30 秒快速开始
54
+
55
+ ```python
56
+ from quonic import qgate, qshow
57
+ from quonic.gates import H, CX
58
+
59
+ qgate(H, 0)
60
+ qgate(CX, 0, 1)
61
+ qshow()
62
+ ```
63
+
64
+ **这是量子计算中最经典的贝尔态(Bell State)。** 同样的功能,用 Qiskit 原生代码需要 10+ 行。QuoNic 只需要 3 行。运行结果会直接显示在终端或 Jupyter 中。
65
+
66
+ 更多**复制即跑**的示例(GHZ、`qif`、`QInt`、Grover、VQE、QAOA、噪声)见 [`examples/`](examples/)。
67
+
68
+ ---
69
+
70
+ ## 📦 安装
71
+
72
+ ```bash
73
+ pip install quonic
74
+ ```
75
+
76
+ 后端是可选依赖,按需安装。要一键装齐三个后端(含算法模板的 numpy/scipy):
77
+
78
+ ```bash
79
+ pip install 'quonic[qiskit,cirq,pennylane,algorithms]'
80
+ ```
81
+
82
+ 只装某一个后端,例如只用 Cirq:`pip install 'quonic[cirq]'`。未安装的后端在调用时会给出明确的中文提示。
83
+
84
+ 可视化是独立可选依赖:`pip install 'quonic[viz]'`(仅 matplotlib,不引入 Graphviz / Seaborn / NetworkX)。
85
+
86
+ ---
87
+
88
+ ## ✨ 核心特性
89
+
90
+ ### 1. 极简语法:3 行代码跑通贝尔态
91
+
92
+ 你不需要理解“量子电路对象”,不需要选择“后端模拟器”,不需要手动“测量”。QuoNic 替你处理一切。
93
+
94
+ ### 2. 一个参数切换所有后端
95
+
96
+ ```python
97
+ # 使用 Qiskit 模拟器(默认)
98
+ qshow(backend='qiskit')
99
+
100
+ # 切换到 Cirq
101
+ qshow(backend='cirq')
102
+
103
+ # 切换到 PennyLane
104
+ qshow(backend='pennylane')
105
+
106
+ # 真实硬件(IBM / AWS / Google 云端)规划中,暂未开放
107
+ qshow(backend='ibm_brisbane') # TODO: 尚未支持
108
+ ```
109
+
110
+ **同一段代码,不加修改,跑在任何后端上。** 极简语法 + 后端无关,是 QuoNic 的组合差异化。
111
+
112
+ ### 3. 条件门与”if = 叠加态”
113
+
114
+ QuoNic 用 `qif` 实现量子叠加控制,并严格区分两种概念:
115
+
116
+ - **量子叠加控制(`qif`,已实现)**:控制比特处于叠加态时**不测量**,两个分支
117
+ 相干叠加,产生真纠缠——这是”两种分支同时发生”,不是先测量再二选一。
118
+ ```python
119
+ from quonic import qgate, qif, qshow
120
+ from quonic.gates import H, X, I
121
+
122
+ qgate(H, 0) # 控制比特进入叠加态
123
+ qif(0).then(X, 1).else_(I, 1) # q0==1 翻转 q1,否则不动(= 受控 X)
124
+ qshow()
125
+ ```
126
+ `else_(I, ...)` 里的 `I` 是恒等门,让「受控门 = qif 特例」写得自然。
127
+ - **条件门(经典控制,规划中)**:先测量、再按结果选择分支,这是”坍缩之后的经典分支”。
128
+ ```python
129
+ # 规划中:基于测量结果的条件门
130
+ # qgate(H, 0)
131
+ # if qgate(MEASURE, 0) == 0:
132
+ # qgate(X, 1)
133
+ # else:
134
+ # qgate(Z, 1)
135
+ ```
136
+
137
+ 我们不把”测量后的经典分支”包装成”叠加态”——教错物理,比不教更糟。
138
+
139
+ ### 4. 真正的“技术惠普”
140
+
141
+ - **中文错误信息**:报错时告诉你“哪里错了、为什么错、怎么改”
142
+ - **自动补全**:在 VS Code / Jupyter 中自动提示门名称和参数
143
+ - **自动测量**:忘记写 `measure`?`qshow()` 自动补全
144
+
145
+ ### 5. 智能调度器:自动挑最快的方法
146
+
147
+ 量子模拟有四种方法,快慢差几个数量级,选错直接撞墙:
148
+
149
+ | 方法 | 复杂度 | 适合 |
150
+ |------|--------|------|
151
+ | `statevector` | 2^n | 通用默认 |
152
+ | `stabilizer` | 多项式 | 纯 Clifford 电路(如纠错码) |
153
+ | `matrix_product_state` | 随树宽增长 | 低树宽电路(如 QAOA) |
154
+ | `density_matrix` | 4^n | 噪声模拟 |
155
+
156
+ QuoNic 的调度器根据电路特征(门类型、树宽、是否含噪声)自动选择,不用你手动
157
+ 指定方法。实测证据:**GHZ(24) 快 36 倍、QAOA(24) 快 19 倍**,Grover 的
158
+ `mcz` 只有 `statevector` 能跑,调度器会自动绕开会崩溃的方法。
159
+
160
+ ```python
161
+ from quonic.scheduler import schedule
162
+ rec = schedule(circuit) # -> Recommendation(backend='qiskit', method='stabilizer')
163
+ ```
164
+
165
+ 详见 [调度器基准与实测数据](docs/benchmarks.md)。
166
+
167
+ ### 6. 全量可视化套件:23 类图,只用 Matplotlib
168
+
169
+ ```python
170
+ from quonic.viz import plot_circuit, plot_counts, plot_decision_tree
171
+
172
+ plot_circuit(circuit) # 门序列电路图
173
+ plot_counts(result) # 测量直方图
174
+ plot_decision_tree() # 调度决策树
175
+ ```
176
+
177
+ 23 类图覆盖四层:**用户刚需**(电路图 / 直方图 / 拓扑图)、**调度器证据**
178
+ (方法对比 / 决策树 / 热力图 / 降级链 / 特征雷达图)、**算法教学**(能量收敛
179
+ / Grover 振幅 / 态向量 / 布洛赫球)、**量子态**(密度矩阵 / 纠缠 / 门矩阵 /
180
+ 路由 / 逐门态演化 / 噪声成本)。全部只用 matplotlib 一个依赖,懒加载,
181
+ `import quonic` 零开销。详见 [可视化套件](docs/visualization.md)。
182
+
183
+ ---
184
+
185
+ ## 📊 对比:QuoNic vs Qiskit
186
+
187
+ | 场景 | Qiskit | QuoNic |
188
+ |------|--------|-------|
189
+ | **跑通第一个量子程序** | 需要理解 5-8 个新概念 | 只需要 2 个概念:`qgate` 和 `qshow` |
190
+ | **代码行数(贝尔态)** | 8-12 行 | **3 行** |
191
+ | **从安装到看到结果** | 30-60 分钟 | **2-3 分钟** |
192
+ | **切换后端** | 重写全部代码 | **改一个参数** |
193
+
194
+ ---
195
+
196
+ ## 🧠 为什么叫 QuoNic?
197
+
198
+ - **Qu** — Quantum(量子)
199
+ - **onic** — 词尾(photonic / electronic),意为“属于量子的、关于量子的”
200
+ - 读作 /ˈkwɑnɪk/(“阔尼克”),一句话:**“量子计算的”**(the quantum one)
201
+
202
+ ---
203
+
204
+ ## 🛠️ 当前支持的后端
205
+
206
+ | 后端 | 状态 | 说明 |
207
+ |------|------|------|
208
+ | Qiskit | ✅ 稳定 | IBM 生态 · 本地模拟器 |
209
+ | Cirq | ✅ 稳定 | Google 生态 · 本地模拟器 |
210
+ | PennyLane | ✅ 稳定 | 量子机器学习 · 本地模拟器 |
211
+ | 真实硬件 | 📅 规划中 | IBM / AWS / Google 云端量子硬件 |
212
+ | 更多后端 | 📅 规划中 | Amazon Braket, PyQuil... |
213
+
214
+ > **注意**:目前三个后端都运行在**本地模拟器**上,尚未接入真实量子硬件。接入云端硬件(IBM / AWS Braket / Google)是后续优先级,见 [路线图](#)。
215
+
216
+ 为硬件铺路,QuoNic 已内置 `CouplingMap`(耦合图)、`compile()` 编译 seam,以及 `decompose()` 门分解——把高阶门(`cp` / `ccx` / `mcz`)展开成基础门集。后者是 QuoNic 自己拥有的「可移植核心」:用户不被某个后端的电路形状绑住,Grover 的 `mcz` 分解成 `cx / h / p` 后能跑通所有后端方法。已内置 `route_swaps()` 贪心 SWAP 路由(配合 `plot_routing` 可视化),将来接 IBM / 国产引擎时,只需在编译层接入,无需改动 IR 或调度器。
217
+
218
+ ---
219
+
220
+ ## 📖 文档与教程
221
+
222
+ - [快速入门](docs/quickstart.md) — 5 分钟上手 QuoNic
223
+ - [Jupyter 教程](docs/tutorial.ipynb) — 可运行的交互单元
224
+ - [门列表](docs/gates.md) — 所有内置门及其用法
225
+ - [自定义门](docs/custom_gates.md) — 注册你自己的门
226
+ - [后端切换](docs/backends.md) — 一个参数切换所有引擎
227
+ - [调度器基准与实测数据](docs/benchmarks.md) — 自动选最快方法的护城河
228
+ - [可视化套件](docs/visualization.md) — 23 类图,只用 Matplotlib
229
+ - [国产硬件调研](docs/domestic-hardware.md) — QPanda3 / CqLib 接入评估
230
+
231
+ ---
232
+
233
+ ## 🤝 贡献指南
234
+
235
+ QuoNic 是一个开源项目(Apache 2.0),欢迎任何形式的贡献:
236
+
237
+ - 报告 Bug
238
+ - 提出新功能建议
239
+ - 提交代码(新后端适配器、新门、新功能)
240
+ - 完善文档和教程
241
+
242
+ 请阅读 [CONTRIBUTING.md](CONTRIBUTING.md) 了解详细信息。
243
+
244
+ ---
245
+
246
+ ## 📄 许可证
247
+
248
+ QuoNic 使用 [Apache License 2.0](LICENSE),对商用和闭源友好,同时提供专利保护。
249
+
250
+ ---
251
+
252
+ ## 🌟 给项目加星
253
+
254
+ 如果 QuoNic 对你有帮助,请在 GitHub 上给我们一个 ⭐️。你的支持是我们持续改进的动力。
quonic-0.2.0/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # QuoNic — 量子编程,像写 Python 一样简单
2
+
3
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
4
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/)
5
+ [![Qiskit](https://img.shields.io/badge/Qiskit-1.0+-green.svg)](https://qiskit.org/)
6
+ [![Cirq](https://img.shields.io/badge/Cirq-1.0+-orange.svg)](https://quantumai.google/cirq)
7
+
8
+ **QuoNic 是一个让量子编程变得像写 Python 一样简单的工具。**
9
+
10
+ 不需要学 `QuantumCircuit`,不需要理解 `backend`,不需要手动 `measure`。你会写 Python,就会用量子计算。
11
+
12
+ ---
13
+
14
+ ## 🚀 30 秒快速开始
15
+
16
+ ```python
17
+ from quonic import qgate, qshow
18
+ from quonic.gates import H, CX
19
+
20
+ qgate(H, 0)
21
+ qgate(CX, 0, 1)
22
+ qshow()
23
+ ```
24
+
25
+ **这是量子计算中最经典的贝尔态(Bell State)。** 同样的功能,用 Qiskit 原生代码需要 10+ 行。QuoNic 只需要 3 行。运行结果会直接显示在终端或 Jupyter 中。
26
+
27
+ 更多**复制即跑**的示例(GHZ、`qif`、`QInt`、Grover、VQE、QAOA、噪声)见 [`examples/`](examples/)。
28
+
29
+ ---
30
+
31
+ ## 📦 安装
32
+
33
+ ```bash
34
+ pip install quonic
35
+ ```
36
+
37
+ 后端是可选依赖,按需安装。要一键装齐三个后端(含算法模板的 numpy/scipy):
38
+
39
+ ```bash
40
+ pip install 'quonic[qiskit,cirq,pennylane,algorithms]'
41
+ ```
42
+
43
+ 只装某一个后端,例如只用 Cirq:`pip install 'quonic[cirq]'`。未安装的后端在调用时会给出明确的中文提示。
44
+
45
+ 可视化是独立可选依赖:`pip install 'quonic[viz]'`(仅 matplotlib,不引入 Graphviz / Seaborn / NetworkX)。
46
+
47
+ ---
48
+
49
+ ## ✨ 核心特性
50
+
51
+ ### 1. 极简语法:3 行代码跑通贝尔态
52
+
53
+ 你不需要理解“量子电路对象”,不需要选择“后端模拟器”,不需要手动“测量”。QuoNic 替你处理一切。
54
+
55
+ ### 2. 一个参数切换所有后端
56
+
57
+ ```python
58
+ # 使用 Qiskit 模拟器(默认)
59
+ qshow(backend='qiskit')
60
+
61
+ # 切换到 Cirq
62
+ qshow(backend='cirq')
63
+
64
+ # 切换到 PennyLane
65
+ qshow(backend='pennylane')
66
+
67
+ # 真实硬件(IBM / AWS / Google 云端)规划中,暂未开放
68
+ qshow(backend='ibm_brisbane') # TODO: 尚未支持
69
+ ```
70
+
71
+ **同一段代码,不加修改,跑在任何后端上。** 极简语法 + 后端无关,是 QuoNic 的组合差异化。
72
+
73
+ ### 3. 条件门与”if = 叠加态”
74
+
75
+ QuoNic 用 `qif` 实现量子叠加控制,并严格区分两种概念:
76
+
77
+ - **量子叠加控制(`qif`,已实现)**:控制比特处于叠加态时**不测量**,两个分支
78
+ 相干叠加,产生真纠缠——这是”两种分支同时发生”,不是先测量再二选一。
79
+ ```python
80
+ from quonic import qgate, qif, qshow
81
+ from quonic.gates import H, X, I
82
+
83
+ qgate(H, 0) # 控制比特进入叠加态
84
+ qif(0).then(X, 1).else_(I, 1) # q0==1 翻转 q1,否则不动(= 受控 X)
85
+ qshow()
86
+ ```
87
+ `else_(I, ...)` 里的 `I` 是恒等门,让「受控门 = qif 特例」写得自然。
88
+ - **条件门(经典控制,规划中)**:先测量、再按结果选择分支,这是”坍缩之后的经典分支”。
89
+ ```python
90
+ # 规划中:基于测量结果的条件门
91
+ # qgate(H, 0)
92
+ # if qgate(MEASURE, 0) == 0:
93
+ # qgate(X, 1)
94
+ # else:
95
+ # qgate(Z, 1)
96
+ ```
97
+
98
+ 我们不把”测量后的经典分支”包装成”叠加态”——教错物理,比不教更糟。
99
+
100
+ ### 4. 真正的“技术惠普”
101
+
102
+ - **中文错误信息**:报错时告诉你“哪里错了、为什么错、怎么改”
103
+ - **自动补全**:在 VS Code / Jupyter 中自动提示门名称和参数
104
+ - **自动测量**:忘记写 `measure`?`qshow()` 自动补全
105
+
106
+ ### 5. 智能调度器:自动挑最快的方法
107
+
108
+ 量子模拟有四种方法,快慢差几个数量级,选错直接撞墙:
109
+
110
+ | 方法 | 复杂度 | 适合 |
111
+ |------|--------|------|
112
+ | `statevector` | 2^n | 通用默认 |
113
+ | `stabilizer` | 多项式 | 纯 Clifford 电路(如纠错码) |
114
+ | `matrix_product_state` | 随树宽增长 | 低树宽电路(如 QAOA) |
115
+ | `density_matrix` | 4^n | 噪声模拟 |
116
+
117
+ QuoNic 的调度器根据电路特征(门类型、树宽、是否含噪声)自动选择,不用你手动
118
+ 指定方法。实测证据:**GHZ(24) 快 36 倍、QAOA(24) 快 19 倍**,Grover 的
119
+ `mcz` 只有 `statevector` 能跑,调度器会自动绕开会崩溃的方法。
120
+
121
+ ```python
122
+ from quonic.scheduler import schedule
123
+ rec = schedule(circuit) # -> Recommendation(backend='qiskit', method='stabilizer')
124
+ ```
125
+
126
+ 详见 [调度器基准与实测数据](docs/benchmarks.md)。
127
+
128
+ ### 6. 全量可视化套件:23 类图,只用 Matplotlib
129
+
130
+ ```python
131
+ from quonic.viz import plot_circuit, plot_counts, plot_decision_tree
132
+
133
+ plot_circuit(circuit) # 门序列电路图
134
+ plot_counts(result) # 测量直方图
135
+ plot_decision_tree() # 调度决策树
136
+ ```
137
+
138
+ 23 类图覆盖四层:**用户刚需**(电路图 / 直方图 / 拓扑图)、**调度器证据**
139
+ (方法对比 / 决策树 / 热力图 / 降级链 / 特征雷达图)、**算法教学**(能量收敛
140
+ / Grover 振幅 / 态向量 / 布洛赫球)、**量子态**(密度矩阵 / 纠缠 / 门矩阵 /
141
+ 路由 / 逐门态演化 / 噪声成本)。全部只用 matplotlib 一个依赖,懒加载,
142
+ `import quonic` 零开销。详见 [可视化套件](docs/visualization.md)。
143
+
144
+ ---
145
+
146
+ ## 📊 对比:QuoNic vs Qiskit
147
+
148
+ | 场景 | Qiskit | QuoNic |
149
+ |------|--------|-------|
150
+ | **跑通第一个量子程序** | 需要理解 5-8 个新概念 | 只需要 2 个概念:`qgate` 和 `qshow` |
151
+ | **代码行数(贝尔态)** | 8-12 行 | **3 行** |
152
+ | **从安装到看到结果** | 30-60 分钟 | **2-3 分钟** |
153
+ | **切换后端** | 重写全部代码 | **改一个参数** |
154
+
155
+ ---
156
+
157
+ ## 🧠 为什么叫 QuoNic?
158
+
159
+ - **Qu** — Quantum(量子)
160
+ - **onic** — 词尾(photonic / electronic),意为“属于量子的、关于量子的”
161
+ - 读作 /ˈkwɑnɪk/(“阔尼克”),一句话:**“量子计算的”**(the quantum one)
162
+
163
+ ---
164
+
165
+ ## 🛠️ 当前支持的后端
166
+
167
+ | 后端 | 状态 | 说明 |
168
+ |------|------|------|
169
+ | Qiskit | ✅ 稳定 | IBM 生态 · 本地模拟器 |
170
+ | Cirq | ✅ 稳定 | Google 生态 · 本地模拟器 |
171
+ | PennyLane | ✅ 稳定 | 量子机器学习 · 本地模拟器 |
172
+ | 真实硬件 | 📅 规划中 | IBM / AWS / Google 云端量子硬件 |
173
+ | 更多后端 | 📅 规划中 | Amazon Braket, PyQuil... |
174
+
175
+ > **注意**:目前三个后端都运行在**本地模拟器**上,尚未接入真实量子硬件。接入云端硬件(IBM / AWS Braket / Google)是后续优先级,见 [路线图](#)。
176
+
177
+ 为硬件铺路,QuoNic 已内置 `CouplingMap`(耦合图)、`compile()` 编译 seam,以及 `decompose()` 门分解——把高阶门(`cp` / `ccx` / `mcz`)展开成基础门集。后者是 QuoNic 自己拥有的「可移植核心」:用户不被某个后端的电路形状绑住,Grover 的 `mcz` 分解成 `cx / h / p` 后能跑通所有后端方法。已内置 `route_swaps()` 贪心 SWAP 路由(配合 `plot_routing` 可视化),将来接 IBM / 国产引擎时,只需在编译层接入,无需改动 IR 或调度器。
178
+
179
+ ---
180
+
181
+ ## 📖 文档与教程
182
+
183
+ - [快速入门](docs/quickstart.md) — 5 分钟上手 QuoNic
184
+ - [Jupyter 教程](docs/tutorial.ipynb) — 可运行的交互单元
185
+ - [门列表](docs/gates.md) — 所有内置门及其用法
186
+ - [自定义门](docs/custom_gates.md) — 注册你自己的门
187
+ - [后端切换](docs/backends.md) — 一个参数切换所有引擎
188
+ - [调度器基准与实测数据](docs/benchmarks.md) — 自动选最快方法的护城河
189
+ - [可视化套件](docs/visualization.md) — 23 类图,只用 Matplotlib
190
+ - [国产硬件调研](docs/domestic-hardware.md) — QPanda3 / CqLib 接入评估
191
+
192
+ ---
193
+
194
+ ## 🤝 贡献指南
195
+
196
+ QuoNic 是一个开源项目(Apache 2.0),欢迎任何形式的贡献:
197
+
198
+ - 报告 Bug
199
+ - 提出新功能建议
200
+ - 提交代码(新后端适配器、新门、新功能)
201
+ - 完善文档和教程
202
+
203
+ 请阅读 [CONTRIBUTING.md](CONTRIBUTING.md) 了解详细信息。
204
+
205
+ ---
206
+
207
+ ## 📄 许可证
208
+
209
+ QuoNic 使用 [Apache License 2.0](LICENSE),对商用和闭源友好,同时提供专利保护。
210
+
211
+ ---
212
+
213
+ ## 🌟 给项目加星
214
+
215
+ 如果 QuoNic 对你有帮助,请在 GitHub 上给我们一个 ⭐️。你的支持是我们持续改进的动力。