jiuzhang-sdk 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.
- jiuzhang_sdk-0.1.0/.gitignore +112 -0
- jiuzhang_sdk-0.1.0/PKG-INFO +269 -0
- jiuzhang_sdk-0.1.0/README.md +232 -0
- jiuzhang_sdk-0.1.0/pyproject.toml +150 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/__init__.py +56 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/auth/__init__.py +7 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/auth/token_manager.py +87 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/cloud/__init__.py +8 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/cloud/client.py +299 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/cloud/models.py +39 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/cloud/transport.py +130 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/errors.py +81 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/exceptions.py +132 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/gbs/__init__.py +14 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/gbs/analysis.py +146 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/gbs/mock.py +120 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/gbs/params.py +118 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/gbs/result.py +175 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/jupyter.py +60 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/local/__init__.py +5 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/local/gbs/__init__.py +25 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/local/gbs/_backends/__init__.py +3 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/local/gbs/_backends/math_backend.py +17 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/local/gbs/_validation.py +47 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/local/gbs/analysis.py +34 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/local/gbs/datasets.py +38 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/local/gbs/ir.py +149 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/local/gbs/math.py +125 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/local/gbs/sampling.py +75 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/local/gbs/serialization.py +115 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/logging_utils.py +58 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/result.py +61 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/settings.py +61 -0
- jiuzhang_sdk-0.1.0/src/jiuzhang/version.py +11 -0
- jiuzhang_sdk-0.1.0/tests/__init__.py +0 -0
- jiuzhang_sdk-0.1.0/tests/conftest.py +11 -0
- jiuzhang_sdk-0.1.0/tests/integration/test_cloud_platform_mock.py +98 -0
- jiuzhang_sdk-0.1.0/tests/integration/test_jupyter_integration.py +78 -0
- jiuzhang_sdk-0.1.0/tests/unit/__init__.py +0 -0
- jiuzhang_sdk-0.1.0/tests/unit/test_cloud_client.py +127 -0
- jiuzhang_sdk-0.1.0/tests/unit/test_cloud_transport.py +67 -0
- jiuzhang_sdk-0.1.0/tests/unit/test_domain.py +64 -0
- jiuzhang_sdk-0.1.0/tests/unit/test_exceptions.py +165 -0
- jiuzhang_sdk-0.1.0/tests/unit/test_gbs_analysis.py +50 -0
- jiuzhang_sdk-0.1.0/tests/unit/test_gbs_mock.py +37 -0
- jiuzhang_sdk-0.1.0/tests/unit/test_gbs_params.py +63 -0
- jiuzhang_sdk-0.1.0/tests/unit/test_gbs_result.py +61 -0
- jiuzhang_sdk-0.1.0/tests/unit/test_local_gbs.py +82 -0
- jiuzhang_sdk-0.1.0/tests/unit/test_logging_utils.py +77 -0
- jiuzhang_sdk-0.1.0/tests/unit/test_result.py +69 -0
- jiuzhang_sdk-0.1.0/tests/unit/test_smoke.py +132 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# ---------- Python ----------
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
|
|
8
|
+
# Build & dist
|
|
9
|
+
build/
|
|
10
|
+
dist/
|
|
11
|
+
release/
|
|
12
|
+
*.egg-info/
|
|
13
|
+
*.egg
|
|
14
|
+
*.whl
|
|
15
|
+
*.tar.gz
|
|
16
|
+
wheels/
|
|
17
|
+
pip-wheel-metadata/
|
|
18
|
+
share/python-wheels/
|
|
19
|
+
|
|
20
|
+
# Virtual envs
|
|
21
|
+
.venv/
|
|
22
|
+
venv/
|
|
23
|
+
env/
|
|
24
|
+
ENV/
|
|
25
|
+
|
|
26
|
+
# uv
|
|
27
|
+
.uv/
|
|
28
|
+
uv.lock.bak
|
|
29
|
+
|
|
30
|
+
# Testing & coverage
|
|
31
|
+
.pytest_cache/
|
|
32
|
+
.coverage
|
|
33
|
+
.coverage.*
|
|
34
|
+
htmlcov/
|
|
35
|
+
.tox/
|
|
36
|
+
.nox/
|
|
37
|
+
coverage.xml
|
|
38
|
+
*.cover
|
|
39
|
+
|
|
40
|
+
# Type checkers & linters
|
|
41
|
+
.mypy_cache/
|
|
42
|
+
.ruff_cache/
|
|
43
|
+
.pytype/
|
|
44
|
+
.dmypy.json
|
|
45
|
+
dmypy.json
|
|
46
|
+
|
|
47
|
+
# Docs build
|
|
48
|
+
docs/_build/
|
|
49
|
+
site/
|
|
50
|
+
|
|
51
|
+
# Jupyter
|
|
52
|
+
.ipynb_checkpoints/
|
|
53
|
+
|
|
54
|
+
# ---------- IDE ----------
|
|
55
|
+
.idea/
|
|
56
|
+
.vscode/
|
|
57
|
+
.claude/
|
|
58
|
+
*.swp
|
|
59
|
+
*.swo
|
|
60
|
+
*~
|
|
61
|
+
|
|
62
|
+
# ---------- OS ----------
|
|
63
|
+
.DS_Store
|
|
64
|
+
Thumbs.db
|
|
65
|
+
desktop.ini
|
|
66
|
+
|
|
67
|
+
# ---------- 项目私密 ----------
|
|
68
|
+
群聊记录/
|
|
69
|
+
*.local.md
|
|
70
|
+
.env
|
|
71
|
+
.env.*
|
|
72
|
+
!.env.example
|
|
73
|
+
doc/~$*
|
|
74
|
+
*.pptx
|
|
75
|
+
Claude Conversations/
|
|
76
|
+
|
|
77
|
+
# Python
|
|
78
|
+
.eggs/
|
|
79
|
+
|
|
80
|
+
# IDE
|
|
81
|
+
remote/
|
|
82
|
+
|
|
83
|
+
# Claude Code local settings
|
|
84
|
+
.claude/settings.local.json
|
|
85
|
+
# Python-generated files
|
|
86
|
+
*.py[oc]
|
|
87
|
+
*.egg-info
|
|
88
|
+
|
|
89
|
+
# IDE
|
|
90
|
+
|
|
91
|
+
# Database
|
|
92
|
+
*.db
|
|
93
|
+
*.sqlite
|
|
94
|
+
*.sqlite3
|
|
95
|
+
|
|
96
|
+
# Logs
|
|
97
|
+
logs/
|
|
98
|
+
*.log
|
|
99
|
+
*.log.*
|
|
100
|
+
|
|
101
|
+
# OS
|
|
102
|
+
dataset/
|
|
103
|
+
.claude
|
|
104
|
+
|
|
105
|
+
debug/
|
|
106
|
+
debug.ipynb
|
|
107
|
+
.agents/
|
|
108
|
+
.codex/
|
|
109
|
+
|
|
110
|
+
# user
|
|
111
|
+
/remote
|
|
112
|
+
/daily_report
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: jiuzhang-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for the JiuZhang photonic quantum cloud platform
|
|
5
|
+
Author: JiuZhang Quantum SDK Team
|
|
6
|
+
License: Proprietary
|
|
7
|
+
Keywords: gbs,jiuzhang,photonic,quantum,sdk
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: Other/Proprietary License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Requires-Dist: httpx<0.29,>=0.27
|
|
17
|
+
Requires-Dist: numpy>=1.26
|
|
18
|
+
Provides-Extra: dev
|
|
19
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
20
|
+
Requires-Dist: pytest-cov>=5; extra == 'dev'
|
|
21
|
+
Requires-Dist: pytest-mock>=3; extra == 'dev'
|
|
22
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
23
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
24
|
+
Provides-Extra: jupyter
|
|
25
|
+
Requires-Dist: ipython>=8; extra == 'jupyter'
|
|
26
|
+
Provides-Extra: local-gbs
|
|
27
|
+
Requires-Dist: numpy<2,>=1.26; extra == 'local-gbs'
|
|
28
|
+
Requires-Dist: scipy<1.14,>=1.10; extra == 'local-gbs'
|
|
29
|
+
Requires-Dist: thewalrus==0.21.0; extra == 'local-gbs'
|
|
30
|
+
Provides-Extra: local-ir
|
|
31
|
+
Requires-Dist: numpy<2,>=1.26; extra == 'local-ir'
|
|
32
|
+
Requires-Dist: quantum-blackbird==0.5.0; extra == 'local-ir'
|
|
33
|
+
Requires-Dist: quantum-xir==0.2.2; extra == 'local-ir'
|
|
34
|
+
Requires-Dist: scipy<1.14,>=1.10; extra == 'local-ir'
|
|
35
|
+
Requires-Dist: thewalrus==0.21.0; extra == 'local-ir'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# jiuzhang-sdk
|
|
39
|
+
|
|
40
|
+
Python SDK for the JiuZhang photonic quantum cloud platform.
|
|
41
|
+
|
|
42
|
+
The SDK provides two separate capability groups:
|
|
43
|
+
|
|
44
|
+
| Capability | Uses the JiuZhang cloud platform | Result source | Typical use |
|
|
45
|
+
| --- | --- | --- | --- |
|
|
46
|
+
| Cloud GBS tasks | Yes | Executed by the JiuZhang cloud platform | Submit GBS experiments, poll status, parse returned results |
|
|
47
|
+
| Local GBS sampling | No | Generated locally by numerical libraries | Teaching, prototyping, local validation, notebook demos |
|
|
48
|
+
|
|
49
|
+
Cloud tasks can be submitted from local Python scripts or Jupyter notebooks. In this case, "local" only describes where the user runs the client code; the task itself is executed by the cloud platform.
|
|
50
|
+
|
|
51
|
+
Local GBS sampling runs entirely on the user's machine and does not call the cloud API. Its results are generated by the local The Walrus numerical backend from the provided matrix and sampling parameters.
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
Install the SDK:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install jiuzhang-sdk
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Install local GBS math and sampling extras:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install "jiuzhang-sdk[local-gbs]"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Install local IR serialization extras:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install "jiuzhang-sdk[local-ir]"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Cloud Credentials
|
|
74
|
+
|
|
75
|
+
Before submitting a cloud task, prepare these values from the JiuZhang cloud workspace:
|
|
76
|
+
|
|
77
|
+
| Value | Description |
|
|
78
|
+
| --- | --- |
|
|
79
|
+
| `api_key` | Authentication credential used in the `X-Jiuzhang-API-Key` request header |
|
|
80
|
+
| `project_id` | Cloud project identifier used to associate tasks with a project |
|
|
81
|
+
| `quantum_computer_id` | Cloud device code, for example `PH_QC_04` |
|
|
82
|
+
|
|
83
|
+
Recommended environment variables:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
export JIUZHANG_API_KEY="your-api-key"
|
|
87
|
+
export JIUZHANG_PROJECT_ID="your-project-id"
|
|
88
|
+
export JIUZHANG_QUANTUM_COMPUTER_ID="PH_QC_04"
|
|
89
|
+
export JIUZHANG_BASE_URL="https://cloud.jiuzhangqt.com/api/v1"
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Cloud GBS Workflow
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from jiuzhang import CloudClient, GBSParams, parse_gbs_result
|
|
96
|
+
|
|
97
|
+
client = CloudClient(
|
|
98
|
+
base_url="https://cloud.jiuzhangqt.com/api/v1",
|
|
99
|
+
api_key="your-api-key",
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
params = GBSParams(
|
|
103
|
+
project_id="EXP-demo-project",
|
|
104
|
+
quantum_computer_id="PH_QC_04",
|
|
105
|
+
mt=500,
|
|
106
|
+
pump_energy_nj=4.6,
|
|
107
|
+
squeezing_param=0.35,
|
|
108
|
+
task_name="GBS experiment",
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
estimate = client.estimate_runtime(
|
|
112
|
+
quantum_computer_id=params.quantum_computer_id,
|
|
113
|
+
mt_value=params.mt,
|
|
114
|
+
pump_energy_nj=params.pump_energy_nj,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
task = client.submit_task(
|
|
118
|
+
project_id=params.project_id,
|
|
119
|
+
task_name=params.task_name,
|
|
120
|
+
quantum_computer_id=params.quantum_computer_id,
|
|
121
|
+
mt_value=params.mt,
|
|
122
|
+
pump_energy_nj=params.pump_energy_nj,
|
|
123
|
+
squeezing_param=params.squeezing_param,
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
task_id = task["data"]["task_id"]
|
|
127
|
+
raw_result = client.get_result(task_id)
|
|
128
|
+
result = parse_gbs_result(raw_result)
|
|
129
|
+
|
|
130
|
+
print(result.status_name)
|
|
131
|
+
print(result.sample_count)
|
|
132
|
+
print(result.experimental_distribution)
|
|
133
|
+
|
|
134
|
+
client.close()
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
One-call helper:
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
result = client.run_gbs(params, poll_interval=2.0, timeout=300.0)
|
|
141
|
+
print(result.status_name)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Cloud API Methods
|
|
145
|
+
|
|
146
|
+
| Method | Purpose |
|
|
147
|
+
| --- | --- |
|
|
148
|
+
| `CloudClient(base_url, api_key, timeout=30.0)` | Create an authenticated cloud API client |
|
|
149
|
+
| `CloudClient.from_env()` | Create a client from `JIUZHANG_*` environment variables |
|
|
150
|
+
| `estimate_runtime(quantum_computer_id, mt_value, pump_energy_nj)` | Estimate runtime before submitting a task |
|
|
151
|
+
| `submit_task(project_id, task_name, quantum_computer_id, mt_value, pump_energy_nj, squeezing_param=None)` | Submit a cloud GBS task |
|
|
152
|
+
| `get_result(task_id)` | Query a task result |
|
|
153
|
+
| `run_experiment(...)` | Estimate, submit, poll, and return raw responses |
|
|
154
|
+
| `estimate_gbs(params)` | Estimate using `GBSParams` |
|
|
155
|
+
| `submit_gbs(params)` | Submit using `GBSParams` |
|
|
156
|
+
| `run_gbs(params)` | Run the full workflow and return `GBSResult` |
|
|
157
|
+
| `close()` | Close the underlying HTTP client |
|
|
158
|
+
|
|
159
|
+
## Cloud Parameter Object
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from jiuzhang import GBSParams
|
|
163
|
+
|
|
164
|
+
params = GBSParams(
|
|
165
|
+
project_id="EXP-demo-project",
|
|
166
|
+
quantum_computer_id="PH_QC_04",
|
|
167
|
+
mt=500,
|
|
168
|
+
pump_energy_nj=4.6,
|
|
169
|
+
squeezing_param=0.35,
|
|
170
|
+
task_name="GBS experiment",
|
|
171
|
+
)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
| Field | Description |
|
|
175
|
+
| --- | --- |
|
|
176
|
+
| `project_id` | Cloud project ID |
|
|
177
|
+
| `quantum_computer_id` | Cloud device code |
|
|
178
|
+
| `mt` | Pump pulse time-bin count, validated as `1..500` |
|
|
179
|
+
| `pump_energy_nj` | Pump energy in nJ |
|
|
180
|
+
| `squeezing_param` | Optional squeezing parameter |
|
|
181
|
+
| `shots` | Optional shot count field |
|
|
182
|
+
| `task_name` | Display name for the task |
|
|
183
|
+
|
|
184
|
+
Helper methods:
|
|
185
|
+
|
|
186
|
+
| Method | Purpose |
|
|
187
|
+
| --- | --- |
|
|
188
|
+
| `validate()` | Validate fields locally |
|
|
189
|
+
| `input_mode_count()` | Return `3 * mt` |
|
|
190
|
+
| `output_mode_count()` | Return `9 * (mt + 80)` |
|
|
191
|
+
| `to_cloud_payload()` | Build a cloud payload dictionary |
|
|
192
|
+
| `summary()` | Build a compact parameter summary |
|
|
193
|
+
|
|
194
|
+
## Parsed Result Object
|
|
195
|
+
|
|
196
|
+
`GBSResult` is returned by `run_gbs()` or by `parse_gbs_result(raw_result)`.
|
|
197
|
+
|
|
198
|
+
| Field or property | Description |
|
|
199
|
+
| --- | --- |
|
|
200
|
+
| `task_id` | Cloud task ID |
|
|
201
|
+
| `status_name` | Normalized task status |
|
|
202
|
+
| `sample_count` | Returned sample count |
|
|
203
|
+
| `result_map_points` | Probability distribution curves |
|
|
204
|
+
| `experimental_distribution` | Experimental distribution points |
|
|
205
|
+
| `ground_truth_distribution` | Reference distribution points |
|
|
206
|
+
| `download_url` | Raw result download URL |
|
|
207
|
+
| `raw` | Original response dictionary |
|
|
208
|
+
|
|
209
|
+
## Local GBS Sampling
|
|
210
|
+
|
|
211
|
+
Local GBS sampling does not call the cloud API. Results are generated on the user's machine by The Walrus from the adjacency matrix and sampling parameters.
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
from jiuzhang.local.gbs import (
|
|
215
|
+
random_adjacency_matrix,
|
|
216
|
+
sample_gbs,
|
|
217
|
+
samples_to_distribution,
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
graph = random_adjacency_matrix(8, scale=0.16, seed=7)
|
|
221
|
+
samples = sample_gbs(
|
|
222
|
+
graph,
|
|
223
|
+
shots=24,
|
|
224
|
+
mean_photon_count=1.0,
|
|
225
|
+
detector="pnr",
|
|
226
|
+
cutoff=4,
|
|
227
|
+
max_photons=12,
|
|
228
|
+
seed=123,
|
|
229
|
+
)
|
|
230
|
+
distribution = samples_to_distribution(samples)
|
|
231
|
+
print(distribution)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
| Function | Purpose |
|
|
235
|
+
| --- | --- |
|
|
236
|
+
| `random_adjacency_matrix(modes, scale=0.2, seed=None)` | Generate a symmetric adjacency matrix |
|
|
237
|
+
| `sample_gbs(adjacency, shots=10, mean_photon_count=1.0, detector="pnr", cutoff=5, max_photons=30, seed=None, parallel=False)` | Generate local GBS samples |
|
|
238
|
+
| `samples_to_distribution(samples)` | Convert samples into a normalized pattern distribution |
|
|
239
|
+
|
|
240
|
+
## Local Math and IR Helpers
|
|
241
|
+
|
|
242
|
+
```python
|
|
243
|
+
from jiuzhang.local.gbs import (
|
|
244
|
+
GBSProgram,
|
|
245
|
+
dumps_ir,
|
|
246
|
+
hafnian,
|
|
247
|
+
loop_hafnian,
|
|
248
|
+
threshold_probability,
|
|
249
|
+
to_blackbird,
|
|
250
|
+
to_xir,
|
|
251
|
+
torontonian,
|
|
252
|
+
)
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
| Function | Purpose |
|
|
256
|
+
| --- | --- |
|
|
257
|
+
| `hafnian(matrix, loop=False, approx=False, num_samples=1000, method="glynn")` | Compute the Hafnian of a square matrix |
|
|
258
|
+
| `loop_hafnian(matrix, diagonal=None, reps=None, glynn=True)` | Compute the loop Hafnian |
|
|
259
|
+
| `torontonian(matrix, recursive=True)` | Compute the Torontonian |
|
|
260
|
+
| `threshold_probability(mean, covariance, pattern, hbar=2.0, atol=1e-10, rtol=1e-10)` | Compute a threshold detection probability |
|
|
261
|
+
| `GBSProgram(modes, operations=(), name="gbs_program")` | Build a local GBS program |
|
|
262
|
+
| `dumps_ir(program, format="json")` | Serialize a program to JSON, Blackbird, or XIR text |
|
|
263
|
+
| `loads_ir(payload)` | Parse JSON local IR |
|
|
264
|
+
| `to_blackbird(program)` | Serialize to Blackbird text |
|
|
265
|
+
| `to_xir(program)` | Serialize to XIR text |
|
|
266
|
+
|
|
267
|
+
## License
|
|
268
|
+
|
|
269
|
+
Proprietary. Copyright 2026 JiuZhang Quantum. All rights reserved.
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# jiuzhang-sdk
|
|
2
|
+
|
|
3
|
+
Python SDK for the JiuZhang photonic quantum cloud platform.
|
|
4
|
+
|
|
5
|
+
The SDK provides two separate capability groups:
|
|
6
|
+
|
|
7
|
+
| Capability | Uses the JiuZhang cloud platform | Result source | Typical use |
|
|
8
|
+
| --- | --- | --- | --- |
|
|
9
|
+
| Cloud GBS tasks | Yes | Executed by the JiuZhang cloud platform | Submit GBS experiments, poll status, parse returned results |
|
|
10
|
+
| Local GBS sampling | No | Generated locally by numerical libraries | Teaching, prototyping, local validation, notebook demos |
|
|
11
|
+
|
|
12
|
+
Cloud tasks can be submitted from local Python scripts or Jupyter notebooks. In this case, "local" only describes where the user runs the client code; the task itself is executed by the cloud platform.
|
|
13
|
+
|
|
14
|
+
Local GBS sampling runs entirely on the user's machine and does not call the cloud API. Its results are generated by the local The Walrus numerical backend from the provided matrix and sampling parameters.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
Install the SDK:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install jiuzhang-sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Install local GBS math and sampling extras:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install "jiuzhang-sdk[local-gbs]"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Install local IR serialization extras:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install "jiuzhang-sdk[local-ir]"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Cloud Credentials
|
|
37
|
+
|
|
38
|
+
Before submitting a cloud task, prepare these values from the JiuZhang cloud workspace:
|
|
39
|
+
|
|
40
|
+
| Value | Description |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| `api_key` | Authentication credential used in the `X-Jiuzhang-API-Key` request header |
|
|
43
|
+
| `project_id` | Cloud project identifier used to associate tasks with a project |
|
|
44
|
+
| `quantum_computer_id` | Cloud device code, for example `PH_QC_04` |
|
|
45
|
+
|
|
46
|
+
Recommended environment variables:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
export JIUZHANG_API_KEY="your-api-key"
|
|
50
|
+
export JIUZHANG_PROJECT_ID="your-project-id"
|
|
51
|
+
export JIUZHANG_QUANTUM_COMPUTER_ID="PH_QC_04"
|
|
52
|
+
export JIUZHANG_BASE_URL="https://cloud.jiuzhangqt.com/api/v1"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Cloud GBS Workflow
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from jiuzhang import CloudClient, GBSParams, parse_gbs_result
|
|
59
|
+
|
|
60
|
+
client = CloudClient(
|
|
61
|
+
base_url="https://cloud.jiuzhangqt.com/api/v1",
|
|
62
|
+
api_key="your-api-key",
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
params = GBSParams(
|
|
66
|
+
project_id="EXP-demo-project",
|
|
67
|
+
quantum_computer_id="PH_QC_04",
|
|
68
|
+
mt=500,
|
|
69
|
+
pump_energy_nj=4.6,
|
|
70
|
+
squeezing_param=0.35,
|
|
71
|
+
task_name="GBS experiment",
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
estimate = client.estimate_runtime(
|
|
75
|
+
quantum_computer_id=params.quantum_computer_id,
|
|
76
|
+
mt_value=params.mt,
|
|
77
|
+
pump_energy_nj=params.pump_energy_nj,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
task = client.submit_task(
|
|
81
|
+
project_id=params.project_id,
|
|
82
|
+
task_name=params.task_name,
|
|
83
|
+
quantum_computer_id=params.quantum_computer_id,
|
|
84
|
+
mt_value=params.mt,
|
|
85
|
+
pump_energy_nj=params.pump_energy_nj,
|
|
86
|
+
squeezing_param=params.squeezing_param,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
task_id = task["data"]["task_id"]
|
|
90
|
+
raw_result = client.get_result(task_id)
|
|
91
|
+
result = parse_gbs_result(raw_result)
|
|
92
|
+
|
|
93
|
+
print(result.status_name)
|
|
94
|
+
print(result.sample_count)
|
|
95
|
+
print(result.experimental_distribution)
|
|
96
|
+
|
|
97
|
+
client.close()
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
One-call helper:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
result = client.run_gbs(params, poll_interval=2.0, timeout=300.0)
|
|
104
|
+
print(result.status_name)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Cloud API Methods
|
|
108
|
+
|
|
109
|
+
| Method | Purpose |
|
|
110
|
+
| --- | --- |
|
|
111
|
+
| `CloudClient(base_url, api_key, timeout=30.0)` | Create an authenticated cloud API client |
|
|
112
|
+
| `CloudClient.from_env()` | Create a client from `JIUZHANG_*` environment variables |
|
|
113
|
+
| `estimate_runtime(quantum_computer_id, mt_value, pump_energy_nj)` | Estimate runtime before submitting a task |
|
|
114
|
+
| `submit_task(project_id, task_name, quantum_computer_id, mt_value, pump_energy_nj, squeezing_param=None)` | Submit a cloud GBS task |
|
|
115
|
+
| `get_result(task_id)` | Query a task result |
|
|
116
|
+
| `run_experiment(...)` | Estimate, submit, poll, and return raw responses |
|
|
117
|
+
| `estimate_gbs(params)` | Estimate using `GBSParams` |
|
|
118
|
+
| `submit_gbs(params)` | Submit using `GBSParams` |
|
|
119
|
+
| `run_gbs(params)` | Run the full workflow and return `GBSResult` |
|
|
120
|
+
| `close()` | Close the underlying HTTP client |
|
|
121
|
+
|
|
122
|
+
## Cloud Parameter Object
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from jiuzhang import GBSParams
|
|
126
|
+
|
|
127
|
+
params = GBSParams(
|
|
128
|
+
project_id="EXP-demo-project",
|
|
129
|
+
quantum_computer_id="PH_QC_04",
|
|
130
|
+
mt=500,
|
|
131
|
+
pump_energy_nj=4.6,
|
|
132
|
+
squeezing_param=0.35,
|
|
133
|
+
task_name="GBS experiment",
|
|
134
|
+
)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
| Field | Description |
|
|
138
|
+
| --- | --- |
|
|
139
|
+
| `project_id` | Cloud project ID |
|
|
140
|
+
| `quantum_computer_id` | Cloud device code |
|
|
141
|
+
| `mt` | Pump pulse time-bin count, validated as `1..500` |
|
|
142
|
+
| `pump_energy_nj` | Pump energy in nJ |
|
|
143
|
+
| `squeezing_param` | Optional squeezing parameter |
|
|
144
|
+
| `shots` | Optional shot count field |
|
|
145
|
+
| `task_name` | Display name for the task |
|
|
146
|
+
|
|
147
|
+
Helper methods:
|
|
148
|
+
|
|
149
|
+
| Method | Purpose |
|
|
150
|
+
| --- | --- |
|
|
151
|
+
| `validate()` | Validate fields locally |
|
|
152
|
+
| `input_mode_count()` | Return `3 * mt` |
|
|
153
|
+
| `output_mode_count()` | Return `9 * (mt + 80)` |
|
|
154
|
+
| `to_cloud_payload()` | Build a cloud payload dictionary |
|
|
155
|
+
| `summary()` | Build a compact parameter summary |
|
|
156
|
+
|
|
157
|
+
## Parsed Result Object
|
|
158
|
+
|
|
159
|
+
`GBSResult` is returned by `run_gbs()` or by `parse_gbs_result(raw_result)`.
|
|
160
|
+
|
|
161
|
+
| Field or property | Description |
|
|
162
|
+
| --- | --- |
|
|
163
|
+
| `task_id` | Cloud task ID |
|
|
164
|
+
| `status_name` | Normalized task status |
|
|
165
|
+
| `sample_count` | Returned sample count |
|
|
166
|
+
| `result_map_points` | Probability distribution curves |
|
|
167
|
+
| `experimental_distribution` | Experimental distribution points |
|
|
168
|
+
| `ground_truth_distribution` | Reference distribution points |
|
|
169
|
+
| `download_url` | Raw result download URL |
|
|
170
|
+
| `raw` | Original response dictionary |
|
|
171
|
+
|
|
172
|
+
## Local GBS Sampling
|
|
173
|
+
|
|
174
|
+
Local GBS sampling does not call the cloud API. Results are generated on the user's machine by The Walrus from the adjacency matrix and sampling parameters.
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from jiuzhang.local.gbs import (
|
|
178
|
+
random_adjacency_matrix,
|
|
179
|
+
sample_gbs,
|
|
180
|
+
samples_to_distribution,
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
graph = random_adjacency_matrix(8, scale=0.16, seed=7)
|
|
184
|
+
samples = sample_gbs(
|
|
185
|
+
graph,
|
|
186
|
+
shots=24,
|
|
187
|
+
mean_photon_count=1.0,
|
|
188
|
+
detector="pnr",
|
|
189
|
+
cutoff=4,
|
|
190
|
+
max_photons=12,
|
|
191
|
+
seed=123,
|
|
192
|
+
)
|
|
193
|
+
distribution = samples_to_distribution(samples)
|
|
194
|
+
print(distribution)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
| Function | Purpose |
|
|
198
|
+
| --- | --- |
|
|
199
|
+
| `random_adjacency_matrix(modes, scale=0.2, seed=None)` | Generate a symmetric adjacency matrix |
|
|
200
|
+
| `sample_gbs(adjacency, shots=10, mean_photon_count=1.0, detector="pnr", cutoff=5, max_photons=30, seed=None, parallel=False)` | Generate local GBS samples |
|
|
201
|
+
| `samples_to_distribution(samples)` | Convert samples into a normalized pattern distribution |
|
|
202
|
+
|
|
203
|
+
## Local Math and IR Helpers
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
from jiuzhang.local.gbs import (
|
|
207
|
+
GBSProgram,
|
|
208
|
+
dumps_ir,
|
|
209
|
+
hafnian,
|
|
210
|
+
loop_hafnian,
|
|
211
|
+
threshold_probability,
|
|
212
|
+
to_blackbird,
|
|
213
|
+
to_xir,
|
|
214
|
+
torontonian,
|
|
215
|
+
)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
| Function | Purpose |
|
|
219
|
+
| --- | --- |
|
|
220
|
+
| `hafnian(matrix, loop=False, approx=False, num_samples=1000, method="glynn")` | Compute the Hafnian of a square matrix |
|
|
221
|
+
| `loop_hafnian(matrix, diagonal=None, reps=None, glynn=True)` | Compute the loop Hafnian |
|
|
222
|
+
| `torontonian(matrix, recursive=True)` | Compute the Torontonian |
|
|
223
|
+
| `threshold_probability(mean, covariance, pattern, hbar=2.0, atol=1e-10, rtol=1e-10)` | Compute a threshold detection probability |
|
|
224
|
+
| `GBSProgram(modes, operations=(), name="gbs_program")` | Build a local GBS program |
|
|
225
|
+
| `dumps_ir(program, format="json")` | Serialize a program to JSON, Blackbird, or XIR text |
|
|
226
|
+
| `loads_ir(payload)` | Parse JSON local IR |
|
|
227
|
+
| `to_blackbird(program)` | Serialize to Blackbird text |
|
|
228
|
+
| `to_xir(program)` | Serialize to XIR text |
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
|
|
232
|
+
Proprietary. Copyright 2026 JiuZhang Quantum. All rights reserved.
|