lqcloud 0.4.2__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 (42) hide show
  1. lqcloud-0.4.2/LICENSE +201 -0
  2. lqcloud-0.4.2/MANIFEST.in +17 -0
  3. lqcloud-0.4.2/PKG-INFO +204 -0
  4. lqcloud-0.4.2/README.en.md +167 -0
  5. lqcloud-0.4.2/README.md +167 -0
  6. lqcloud-0.4.2/lqcloud/__init__.py +75 -0
  7. lqcloud-0.4.2/lqcloud/auth/__init__.py +5 -0
  8. lqcloud-0.4.2/lqcloud/auth/config.py +189 -0
  9. lqcloud-0.4.2/lqcloud/backend/__init__.py +1 -0
  10. lqcloud-0.4.2/lqcloud/backend/serialization.py +824 -0
  11. lqcloud-0.4.2/lqcloud/circuit/__init__.py +87 -0
  12. lqcloud-0.4.2/lqcloud/circuit/circuit.py +1349 -0
  13. lqcloud-0.4.2/lqcloud/circuit/classical_register.py +46 -0
  14. lqcloud-0.4.2/lqcloud/circuit/gates.py +907 -0
  15. lqcloud-0.4.2/lqcloud/circuit/parameter.py +182 -0
  16. lqcloud-0.4.2/lqcloud/circuit/pauli_op.py +25 -0
  17. lqcloud-0.4.2/lqcloud/circuit/quantum_register.py +25 -0
  18. lqcloud-0.4.2/lqcloud/exceptions.py +70 -0
  19. lqcloud-0.4.2/lqcloud/http_session.py +337 -0
  20. lqcloud-0.4.2/lqcloud/http_utils.py +164 -0
  21. lqcloud-0.4.2/lqcloud/job/__init__.py +7 -0
  22. lqcloud-0.4.2/lqcloud/job/job.py +855 -0
  23. lqcloud-0.4.2/lqcloud/job/result.py +1056 -0
  24. lqcloud-0.4.2/lqcloud/job/status.py +42 -0
  25. lqcloud-0.4.2/lqcloud/per_shot_config.py +85 -0
  26. lqcloud-0.4.2/lqcloud/primitives/__init__.py +149 -0
  27. lqcloud-0.4.2/lqcloud/primitives/simulator.py +326 -0
  28. lqcloud-0.4.2/lqcloud/provider/__init__.py +10 -0
  29. lqcloud-0.4.2/lqcloud/provider/cloud_provider.py +1719 -0
  30. lqcloud-0.4.2/lqcloud/py.typed +1 -0
  31. lqcloud-0.4.2/lqcloud/visualization/__init__.py +22 -0
  32. lqcloud-0.4.2/lqcloud/visualization/_draw_circuit.py +408 -0
  33. lqcloud-0.4.2/lqcloud/visualization/_plot_histogram.py +77 -0
  34. lqcloud-0.4.2/lqcloud/visualization/format_circuit.py +118 -0
  35. lqcloud-0.4.2/lqcloud/visualization/styles.py +15 -0
  36. lqcloud-0.4.2/lqcloud.egg-info/PKG-INFO +204 -0
  37. lqcloud-0.4.2/lqcloud.egg-info/SOURCES.txt +40 -0
  38. lqcloud-0.4.2/lqcloud.egg-info/dependency_links.txt +1 -0
  39. lqcloud-0.4.2/lqcloud.egg-info/requires.txt +30 -0
  40. lqcloud-0.4.2/lqcloud.egg-info/top_level.txt +1 -0
  41. lqcloud-0.4.2/pyproject.toml +69 -0
  42. lqcloud-0.4.2/setup.cfg +4 -0
lqcloud-0.4.2/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.
@@ -0,0 +1,17 @@
1
+ # sdist 内容策略:仅打包 lqcloud 源码 + 必要元数据(LICENSE / README)。
2
+ # 完整 SDK 文档已发布在云平台网站(backend/docs_sdk);examples/、docs/、
3
+ # CHANGELOG.md(含后端/服务端内部开发信息)、CONTRIBUTING.md、QUICKSTART.md
4
+ # 仅保留在仓库中,不随 sdist 发布。
5
+ prune server
6
+ prune tests
7
+ prune logs
8
+ prune plans
9
+ prune examples
10
+ prune docs
11
+
12
+ global-exclude __pycache__
13
+ global-exclude *.py[cod]
14
+
15
+ include LICENSE
16
+ include README.md
17
+ include README.en.md
lqcloud-0.4.2/PKG-INFO ADDED
@@ -0,0 +1,204 @@
1
+ Metadata-Version: 2.4
2
+ Name: lqcloud
3
+ Version: 0.4.2
4
+ Summary: A Cloud Quantum Computing SDK
5
+ Author: Lianming LQ
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: Apache Software License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: numpy>=1.21.0
13
+ Requires-Dist: requests>=2.31.0
14
+ Provides-Extra: visualization
15
+ Requires-Dist: matplotlib>=3.3.0; extra == "visualization"
16
+ Provides-Extra: qiskit
17
+ Requires-Dist: qiskit>=1.0.0; extra == "qiskit"
18
+ Requires-Dist: qiskit-aer>=0.13.0; extra == "qiskit"
19
+ Provides-Extra: full
20
+ Requires-Dist: matplotlib>=3.3.0; extra == "full"
21
+ Requires-Dist: qiskit>=1.0.0; extra == "full"
22
+ Requires-Dist: qiskit-aer>=0.13.0; extra == "full"
23
+ Requires-Dist: networkx>=2.5; extra == "full"
24
+ Provides-Extra: pennylane
25
+ Requires-Dist: pennylane>=0.30.0; extra == "pennylane"
26
+ Provides-Extra: ci
27
+ Requires-Dist: pytest>=7.0.0; extra == "ci"
28
+ Requires-Dist: pytest-timeout>=2.0.0; extra == "ci"
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
31
+ Requires-Dist: pytest-timeout>=2.0.0; extra == "dev"
32
+ Requires-Dist: pytest-cov>=3.0.0; extra == "dev"
33
+ Requires-Dist: black>=22.0.0; extra == "dev"
34
+ Requires-Dist: flake8>=4.0.0; extra == "dev"
35
+ Requires-Dist: mypy>=0.950; extra == "dev"
36
+ Dynamic: license-file
37
+
38
+ # LQCloud SDK
39
+
40
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
41
+ [![Python Version](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
42
+ ![Version](https://img.shields.io/badge/version-0.4.2-brightgreen.svg)
43
+
44
+ LQCloud SDK 是连接 LQCloud 量子云平台的 Python 开发工具包。通过本 SDK,您可以构建量子线路、提交云端任务(线路 / 波形 / 脚本),并获取执行结果。
45
+
46
+ > **关于 API 风格**:LQCloud SDK 的线路编排接口(`QuantumCircuit` / `h` / `cx` / `measure_all` / `Parameter` / …)在命名与用法上**借鉴 Qiskit 风格**,便于熟悉 Qiskit 的用户上手;但 SDK 自身**不依赖 Qiskit**——核心运行时只需 `numpy` 与 `requests` 两个轻量依赖。`qiskit` 仅作为可选互操作组件存在。
47
+
48
+ ---
49
+
50
+ ## 核心功能
51
+
52
+ ### 量子线路构建
53
+
54
+ - **Native 门**(QPU 原生门,一对一映射硬件)
55
+ - Pauli / Hadamard 族:`H`, `HY`, `X`, `Y`, `Z`, `MX`, `MY`, `MZ`, `I`
56
+ - 半角旋转:`XHalf`, `YHalf`, `MXHalf`, `MYHalf`, `XYHalf`, `MXYHalf`, `MXMYHalf`, `XMYHalf`
57
+ - Z 旋转族:`S`, `Sdg`, `T`, `RZ(θ)`
58
+ - 两比特:`CZ`(原生)
59
+ - 2 态读出脉冲:`X21`, `X21Half`(`|1⟩↔|2⟩` 子空间)
60
+ - 测量 / 重置 / 控制:`Measure`, `Reset`, `Barrier`, `Delay`
61
+ - 手动 DD 门:`timeanchor` / `dd`(在成对时间锚点间精确插入 DD 脉冲)
62
+ - **Composite 门**(便捷门,**提交前自动分解为 native 门**)
63
+ - 单比特:`RX(θ)`, `RY(θ)`, `U(θ,φ,λ)`, `P(θ)`, `Tdg`, `SX`, `SXdg`
64
+ - 两比特:`CX`(CNOT), `CY`, `CH`, `SWAP`, `iSWAP`, `CRZ(θ)`, `CRX(θ)`, `CRY(θ)`, `CP(θ)`
65
+ - 三比特:`CCX`(Toffoli), `CCZ`
66
+ - 任意单比特 SU(2) 门:`qc.su2(matrix, q)` / `qc.unitary(matrix, q)`
67
+ - **统一测量接口**:使用 `measure` / `measure_all`,SDK 按后端能力自动改写(必要时展开为 `X21 + Measure`)
68
+ - **多重测量(Multi-Window)**:同一 qubit 可被多次测量,每次结果独立映射到不同 clbit,支持重复码 / 表面码 stabilizer 线路
69
+ - **参数化线路**:`Parameter` + `assign_parameters()`;提交时仍有未绑定参数会在客户端立即抛 `CircuitError`
70
+ - **线路工具**:`qc.decompose()`、`qc.depth()`、`qc.draw()`(ASCII 绘图,支持经典寄存器与多比特门连线)
71
+
72
+ ### 云端任务提交
73
+
74
+ - **线路模式**:提交 `QuantumCircuit` 到云端 QPU,序列化时自动 `decompose()`
75
+ - **波形模式**:`backend.run_wave(waves, shots=..., result_format="counts"|"memory"|"raw")` 直接上传原始脉冲波形;`raw` 返回未经态判别的原始 IQ 数据
76
+ - **批量线路**:`backend.run([qc1, qc2, ...], shots=...)` 把多条线路作为同一云端任务提交,单次最多 64 条(`MAX_BATCH_CIRCUITS`)
77
+ - **shots 上限**:单次提交 `shots ≤ 50_000`,由**服务端**校验拦截(SDK 本身不做该范围强校验)
78
+ - **指定物理比特**:`initial_layout=[3, 4]`(语义同 Qiskit)
79
+ - **读出矫正(Readout Correction)**:`qc.set_readout_correction(True)` / `backend.run(..., readout_correction=True)`,矫正失败自动降级
80
+ - **动态解耦(DD)**:空闲窗口自动插入 CPMG / CP π 脉冲;线路级与提交级写法均支持
81
+ - **网络健壮性**:瞬态错误自动指数退避重试;自动携带 `Idempotency-Key` 防重复入队
82
+ - **提交前本地校验**:缺测量 / 缺 barrier / 测量类型混用等会直接抛 `CircuitError`
83
+ - 自动按测量比特数切换 counts / memory 结果格式
84
+
85
+ ### 任务管理
86
+
87
+ - 状态查询(`JobStatus`:`QUEUED` / `RUNNING` / `COMPLETED` / `FAILED` / `CANCELLED`)
88
+ - 阻塞等待并获取结果(支持 `timeout` / 静默模式)
89
+ - 队列位置查询、任务取消 `job.cancel()`
90
+ - 失败任务携带 `error_type`,便于编程化重试
91
+
92
+ ### 结果访问
93
+
94
+ `get_counts()` · `get_memory()` · `get_iq_data()`(波形 raw)· `get_probabilities()` · `get_dynamic_decoupling_info()`;Jupyter 自动渲染结果表格(`_repr_html_()`)
95
+
96
+ ### 异常体系
97
+
98
+ `LQCloudError`(基类)、`AuthenticationError`、`BackendNotFoundError`、`JobError`、`JobTimeoutError`、`CircuitError`,支持精确与粗粒度捕获
99
+
100
+ ### 轻量依赖 & 日志
101
+
102
+ 核心依赖仅 `numpy` + `requests`,`qiskit` / `matplotlib` / `networkx` 均为可选;库内统一使用 `logging.getLogger("lqcloud")`,可自行配置日志级别。
103
+
104
+ ---
105
+
106
+ ## 安装
107
+
108
+ ```bash
109
+ pip install lqcloud
110
+ ```
111
+
112
+ 可选依赖:
113
+
114
+ ```bash
115
+ pip install lqcloud[visualization] # matplotlib 直方图可视化
116
+ pip install lqcloud[qiskit] # Qiskit 互操作
117
+ pip install lqcloud[full] # matplotlib + qiskit + networkx
118
+ ```
119
+
120
+ 验证安装:
121
+
122
+ ```bash
123
+ python -c "import lqcloud; print(lqcloud.__version__)"
124
+ ```
125
+
126
+ ---
127
+
128
+ ## 快速开始
129
+
130
+ ### 1. 配置认证
131
+
132
+ ```python
133
+ from lqcloud import save_account
134
+
135
+ save_account(
136
+ api_key="your_api_key_here",
137
+ url="https://cloud.logicalqubit.com", # 或替换为实际服务器地址
138
+ )
139
+ ```
140
+
141
+ 配置保存在 `~/.lqcloud/config.json`,之后无需重复配置。也可改用环境变量 `LQCLOUD_API_KEY`(或 `LQCLOUD_TOKEN`)+ `LQCLOUD_URL`;无终端环境(CI / Docker)可传 `LQCloudProvider(interactive=False)`,无凭证时直接抛 `AuthenticationError`。
142
+
143
+ ### 2. 提交量子线路任务
144
+
145
+ ```python
146
+ from lqcloud import LQCloudProvider, QuantumCircuit
147
+
148
+ provider = LQCloudProvider()
149
+ backend = provider.get_backend("QZ02")
150
+
151
+ qc = QuantumCircuit(2, 2)
152
+ qc.h(0)
153
+ qc.cx(0, 1) # CX 会被自动分解为 native 门
154
+ qc.barrier() # 计算与读出窗口的分隔
155
+ qc.measure_all()
156
+
157
+ job = backend.run(qc, shots=1000)
158
+ result = job.result()
159
+ print(result.get_counts()) # {'00': 503, '11': 497}
160
+ ```
161
+
162
+ ### 3. 批量线路提交
163
+
164
+ ```python
165
+ jobs = backend.run([qc1, qc2, qc3], shots=2000) # 单次最多 64 条
166
+ results = jobs.result()
167
+ results[0].get_counts() # 每个子项仍是 Result,全部老 API 可用
168
+ ```
169
+
170
+ ### 4. 异常处理
171
+
172
+ ```python
173
+ from lqcloud import LQCloudError, JobError, JobTimeoutError
174
+
175
+ try:
176
+ result = job.result(timeout=300)
177
+ except JobTimeoutError:
178
+ job.cancel()
179
+ except JobError as e:
180
+ print(f"Job failed: {e}")
181
+ except LQCloudError as e:
182
+ print(f"SDK error: {e}")
183
+ ```
184
+
185
+ > 完整的 API 文档、快速入门与示例代码发布在 **LQCloud 云平台文档中心**。
186
+
187
+ ---
188
+
189
+ ## 依赖
190
+
191
+ | 包 | 用途 |
192
+ |----|------|
193
+ | `numpy`, `requests` | 必需(核心运行时) |
194
+ | `matplotlib` | 可选,直方图可视化 |
195
+ | `qiskit`, `qiskit-aer` | 可选,Qiskit 互操作 |
196
+ | `networkx` | 可选,拓扑可视化 |
197
+
198
+ Python 版本要求:**≥ 3.10**
199
+
200
+ ---
201
+
202
+ ## 许可证
203
+
204
+ 本项目采用 Apache License 2.0(见随包附带的 LICENSE 文件)。
@@ -0,0 +1,167 @@
1
+ # LQCloud SDK
2
+
3
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
4
+ [![Python Version](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
5
+ ![Version](https://img.shields.io/badge/version-0.4.2-brightgreen.svg)
6
+
7
+ LQCloud SDK is the Python client library for the LQCloud quantum cloud platform. With it you can build quantum circuits, submit cloud jobs (circuit / waveform / script), and retrieve execution results.
8
+
9
+ > **API style**: LQCloud SDK's circuit-building API (`QuantumCircuit` / `h` / `cx` / `measure_all` / `Parameter` / …) **follows Qiskit conventions** so Qiskit users feel at home — yet the SDK **does not depend on Qiskit**. The core runtime needs only `numpy` and `requests`. `qiskit` is an optional interop component.
10
+
11
+ ---
12
+
13
+ ## Features
14
+
15
+ ### Circuit construction
16
+
17
+ - **Native gates** (map 1:1 to hardware)
18
+ - Pauli / Hadamard family: `H`, `HY`, `X`, `Y`, `Z`, `MX`, `MY`, `MZ`, `I`
19
+ - Half-angle rotations: `XHalf`, `YHalf`, `MXHalf`, `MYHalf`, `XYHalf`, `MXYHalf`, `MXMYHalf`, `XMYHalf`
20
+ - Z-rotation family: `S`, `Sdg`, `T`, `RZ(θ)`
21
+ - Two-qubit: `CZ` (native)
22
+ - 2-state readout pulses: `X21`, `X21Half` (`|1⟩↔|2⟩` subspace)
23
+ - Measure / reset / control: `Measure`, `Reset`, `Barrier`, `Delay`
24
+ - Manual DD gates: `timeanchor` / `dd` (precise DD pulses between paired time anchors)
25
+ - **Composite gates** (**auto-decomposed into native gates before submission**)
26
+ - Single-qubit: `RX(θ)`, `RY(θ)`, `U(θ,φ,λ)`, `P(θ)`, `Tdg`, `SX`, `SXdg`
27
+ - Two-qubit: `CX`(CNOT), `CY`, `CH`, `SWAP`, `iSWAP`, `CRZ(θ)`, `CRX(θ)`, `CRY(θ)`, `CP(θ)`
28
+ - Three-qubit: `CCX`(Toffoli), `CCZ`
29
+ - Arbitrary single-qubit SU(2): `qc.su2(matrix, q)` / `qc.unitary(matrix, q)`
30
+ - **Unified measure interface**: use `measure` / `measure_all`; the SDK rewrites per backend capability (expanding to `X21 + Measure` when needed)
31
+ - **Multi-window measurement**: a single qubit can be measured multiple times, each mapped to a distinct clbit — enables repetition-code / surface-code stabiliser circuits
32
+ - **Parametrised circuits**: `Parameter` + `assign_parameters()`; unbound parameters raise `CircuitError` at submission
33
+ - **Circuit tools**: `qc.decompose()`, `qc.depth()`, `qc.draw()` (ASCII drawer, supports classical registers and multi-qubit wiring)
34
+
35
+ ### Cloud job submission
36
+
37
+ - **Circuit mode**: submit a `QuantumCircuit` to the cloud QPU; `decompose()` runs automatically on serialisation
38
+ - **Waveform mode**: `backend.run_wave(waves, shots=..., result_format="counts"|"memory"|"raw")` uploads raw pulse waveforms; `raw` returns unclassified IQ data
39
+ - **Batch circuits**: `backend.run([qc1, qc2, ...], shots=...)` submits multiple circuits as one cloud job, up to 64 per submission (`MAX_BATCH_CIRCUITS`)
40
+ - **Shots ceiling**: `shots ≤ 50_000`, enforced **server-side** (the SDK does not strongly validate this range)
41
+ - **Pin physical qubits**: `initial_layout=[3, 4]` (Qiskit semantics)
42
+ - **Readout correction (RC)**: `qc.set_readout_correction(True)` / `backend.run(..., readout_correction=True)`, with graceful fallback
43
+ - **Dynamic decoupling (DD)**: auto-inserts CPMG / CP π-pulses in idle windows; circuit-level and submission-level forms both supported
44
+ - **Network resilience**: automatic exponential back-off retry; `Idempotency-Key` prevents duplicate enqueuing
45
+ - **Pre-submission local validation**: missing measurement / barrier or mixed measure kinds raise `CircuitError`
46
+ - Auto-selects counts / memory result format based on the number of measured qubits
47
+
48
+ ### Job management
49
+
50
+ - Status query (`JobStatus`: `QUEUED` / `RUNNING` / `COMPLETED` / `FAILED` / `CANCELLED`)
51
+ - Blocking wait + result retrieval (supports `timeout` / quiet mode)
52
+ - Queue-position query and cancellation via `job.cancel()`
53
+ - Failed jobs carry `error_type` for programmatic retries
54
+
55
+ ### Result access
56
+
57
+ `get_counts()` · `get_memory()` · `get_iq_data()` (waveform raw) · `get_probabilities()` · `get_dynamic_decoupling_info()`; Jupyter auto-renders result tables (`_repr_html_()`)
58
+
59
+ ### Exception hierarchy
60
+
61
+ `LQCloudError` (base), `AuthenticationError`, `BackendNotFoundError`, `JobError`, `JobTimeoutError`, `CircuitError` — supports precise and coarse-grained catching
62
+
63
+ ### Lightweight deps & logging
64
+
65
+ Core dependencies are just `numpy` + `requests`; `qiskit` / `matplotlib` / `networkx` are optional. Logging uses `logging.getLogger("lqcloud")` and is user-configurable.
66
+
67
+ ---
68
+
69
+ ## Installation
70
+
71
+ ```bash
72
+ pip install lqcloud
73
+ ```
74
+
75
+ Optional extras:
76
+
77
+ ```bash
78
+ pip install lqcloud[visualization] # matplotlib histogram plotting
79
+ pip install lqcloud[qiskit] # Qiskit interop
80
+ pip install lqcloud[full] # matplotlib + qiskit + networkx
81
+ ```
82
+
83
+ Verify:
84
+
85
+ ```bash
86
+ python -c "import lqcloud; print(lqcloud.__version__)"
87
+ ```
88
+
89
+ ---
90
+
91
+ ## Quick start
92
+
93
+ ### 1. Configure authentication
94
+
95
+ ```python
96
+ from lqcloud import save_account
97
+
98
+ save_account(
99
+ api_key="your_api_key_here",
100
+ url="https://cloud.logicalqubit.com", # or your actual server
101
+ )
102
+ ```
103
+
104
+ Credentials are stored in `~/.lqcloud/config.json`. You can also use environment variables `LQCLOUD_API_KEY` (or `LQCLOUD_TOKEN`) + `LQCLOUD_URL`; in headless environments (CI / Docker) pass `LQCloudProvider(interactive=False)` to raise `AuthenticationError` instead of blocking on input.
105
+
106
+ ### 2. Submit a circuit job
107
+
108
+ ```python
109
+ from lqcloud import LQCloudProvider, QuantumCircuit
110
+
111
+ provider = LQCloudProvider()
112
+ backend = provider.get_backend("QZ02")
113
+
114
+ qc = QuantumCircuit(2, 2)
115
+ qc.h(0)
116
+ qc.cx(0, 1) # CX is auto-decomposed into native gates
117
+ qc.barrier() # separates compute and readout windows
118
+ qc.measure_all()
119
+
120
+ job = backend.run(qc, shots=1000)
121
+ result = job.result()
122
+ print(result.get_counts()) # {'00': 503, '11': 497}
123
+ ```
124
+
125
+ ### 3. Batch circuit submission
126
+
127
+ ```python
128
+ jobs = backend.run([qc1, qc2, qc3], shots=2000) # up to 64 per submission
129
+ results = jobs.result()
130
+ results[0].get_counts() # each child is still a Result with the full API
131
+ ```
132
+
133
+ ### 4. Exception handling
134
+
135
+ ```python
136
+ from lqcloud import LQCloudError, JobError, JobTimeoutError
137
+
138
+ try:
139
+ result = job.result(timeout=300)
140
+ except JobTimeoutError:
141
+ job.cancel()
142
+ except JobError as e:
143
+ print(f"Job failed: {e}")
144
+ except LQCloudError as e:
145
+ print(f"SDK error: {e}")
146
+ ```
147
+
148
+ > Full API docs, the quick-start guide, and example code are published in the **LQCloud cloud platform docs center**.
149
+
150
+ ---
151
+
152
+ ## Dependencies
153
+
154
+ | Package | Purpose |
155
+ |---------|---------|
156
+ | `numpy`, `requests` | required (core runtime) |
157
+ | `matplotlib` | optional, histogram plotting |
158
+ | `qiskit`, `qiskit-aer` | optional, Qiskit interop |
159
+ | `networkx` | optional, topology plotting |
160
+
161
+ Python version: **≥ 3.10**
162
+
163
+ ---
164
+
165
+ ## License
166
+
167
+ This project is licensed under the Apache License 2.0 (see the LICENSE file bundled with the package).