qubitra-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.
- qubitra_sdk-0.1.0/.gitignore +12 -0
- qubitra_sdk-0.1.0/LICENSE +202 -0
- qubitra_sdk-0.1.0/PKG-INFO +128 -0
- qubitra_sdk-0.1.0/README.md +103 -0
- qubitra_sdk-0.1.0/examples/list_backends.py +25 -0
- qubitra_sdk-0.1.0/examples/submit_bell_pair.py +119 -0
- qubitra_sdk-0.1.0/examples/submit_ionq_circuit.py +77 -0
- qubitra_sdk-0.1.0/pyproject.toml +75 -0
- qubitra_sdk-0.1.0/src/qubitra/__init__.py +45 -0
- qubitra_sdk-0.1.0/src/qubitra/_providers/__init__.py +5 -0
- qubitra_sdk-0.1.0/src/qubitra/_providers/base.py +51 -0
- qubitra_sdk-0.1.0/src/qubitra/_providers/qubitra.py +312 -0
- qubitra_sdk-0.1.0/src/qubitra/client.py +130 -0
- qubitra_sdk-0.1.0/src/qubitra/credentials.py +30 -0
- qubitra_sdk-0.1.0/src/qubitra/errors.py +49 -0
- qubitra_sdk-0.1.0/src/qubitra/models.py +115 -0
- qubitra_sdk-0.1.0/src/qubitra/py.typed +0 -0
- qubitra_sdk-0.1.0/tests/test_facade.py +145 -0
- qubitra_sdk-0.1.0/tests/test_qubitra_adapter.py +386 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Docs-site build output and Astro's generated types. The generated SDK reference
|
|
2
|
+
# (docs/src/data/reference.json) is NOT ignored — it is committed, so the site builds
|
|
3
|
+
# without a Python toolchain.
|
|
4
|
+
docs/dist/
|
|
5
|
+
docs/.astro/
|
|
6
|
+
# Astro writes its content/type declarations to <root>/.astro regardless of `cacheDir`.
|
|
7
|
+
.astro/
|
|
8
|
+
|
|
9
|
+
# Also load-bearing for packaging: hatchling builds the sdist from this directory and
|
|
10
|
+
# honours this file, so anything listed here stays out of the distribution. Without the
|
|
11
|
+
# line below a source distribution swallows the whole docs-site dependency tree.
|
|
12
|
+
node_modules/
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: qubitra-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Qubitra Python SDK (ADR-0041, codename niobium) — the brand-owning qubitra.* facade over a provider-adapter seam; targets the Qubitra API's /v1 surface.
|
|
5
|
+
Project-URL: Homepage, https://github.com/Qubitra/q-platform
|
|
6
|
+
Project-URL: Repository, https://github.com/Qubitra/q-platform
|
|
7
|
+
Project-URL: Issues, https://github.com/Qubitra/q-platform/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/Qubitra/q-platform/blob/main/pkg/niobium/CHANGELOG.md
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: qpu,quantum,quantum-computing,qubitra,sdk
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Requires-Dist: httpx>=0.28
|
|
23
|
+
Requires-Dist: pydantic>=2.5
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# niobium — the Qubitra Python SDK
|
|
27
|
+
|
|
28
|
+
The Python client for the Qubitra platform. Codename `niobium`; it installs as
|
|
29
|
+
`qubitra-sdk` and imports as `qubitra` (ADR-0041 D1).
|
|
30
|
+
|
|
31
|
+
The SDK speaks q-platform vocabulary — Backends, Jobs, Offerings — and talks to the
|
|
32
|
+
Qubitra API's public `/v1` surface. Which backend a Job actually lands on, and the
|
|
33
|
+
supply chain behind it, is the platform's business: the SDK never names a vendor.
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install qubitra-sdk
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Inside this repo it is a uv workspace member, so `uv sync` at the root installs it
|
|
42
|
+
editable and no publish step is involved.
|
|
43
|
+
|
|
44
|
+
## Quickstart
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from qubitra import QubitraClient
|
|
48
|
+
|
|
49
|
+
with QubitraClient() as client:
|
|
50
|
+
for backend in client.backends.list():
|
|
51
|
+
print(backend.id, backend.qubit_count, backend.supported_formats)
|
|
52
|
+
|
|
53
|
+
job = client.jobs.submit(
|
|
54
|
+
backend_id="qpu-superconducting-127q",
|
|
55
|
+
circuit="OPENQASM 3.0; qubit[2] q; bit[2] c; h q[0]; cx q[0], q[1]; c = measure q;",
|
|
56
|
+
shots=1024,
|
|
57
|
+
name="bell-pair",
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
job = client.jobs.wait(job.id, timeout=600)
|
|
61
|
+
if job.status.is_terminal and job.error:
|
|
62
|
+
raise SystemExit(f"job {job.id} failed: {job.error}")
|
|
63
|
+
|
|
64
|
+
print(client.jobs.result(job.id).counts) # {"00": 512, "11": 512}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Two runnable versions of that sit in `examples/`: `submit_bell_pair.py` is the whole path,
|
|
68
|
+
and `list_backends.py` is the read-only smoke test. Both take their key from the environment:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
QUBITRA_API_KEY=qpk_... uv run pkg/niobium/examples/submit_bell_pair.py
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Against a local stack (`mise run dev:qplat`), add `QUBITRA_API_URL=http://localhost:8080` and
|
|
75
|
+
mint a key on the console's API keys page.
|
|
76
|
+
|
|
77
|
+
## Configuration
|
|
78
|
+
|
|
79
|
+
| Variable | Default | Meaning |
|
|
80
|
+
| --- | --- | --- |
|
|
81
|
+
| `QUBITRA_API_KEY` | — | API key (`qpk_…`), required. Resolves to your organization. |
|
|
82
|
+
| `QUBITRA_API_URL` | `http://localhost:8080` | The Qubitra deployment to reach. |
|
|
83
|
+
|
|
84
|
+
Both are also constructor arguments — `QubitraClient(api_key=…, api_url=…)` — which
|
|
85
|
+
take precedence over the environment.
|
|
86
|
+
|
|
87
|
+
## Surface
|
|
88
|
+
|
|
89
|
+
| Call | What it does |
|
|
90
|
+
| --- | --- |
|
|
91
|
+
| `client.backends.list()` / `.get(id)` | The backends available to you, and one by id. |
|
|
92
|
+
| `client.jobs.submit(...)` | Submit a circuit; returns a `Job` immediately. |
|
|
93
|
+
| `client.jobs.list()` | Your organization's jobs, newest first. |
|
|
94
|
+
| `client.jobs.get(id)` / `.result(id)` / `.cancel(id)` | Read status, fetch counts, cancel. |
|
|
95
|
+
| `client.jobs.wait(id)` | Poll until the Job reaches a terminal status. |
|
|
96
|
+
| `client.marketplace.offerings()` | The marketplace catalogue. |
|
|
97
|
+
|
|
98
|
+
`jobs.result` is valid once a Job is `COMPLETED`; asking earlier raises
|
|
99
|
+
`InvalidRequestError`.
|
|
100
|
+
|
|
101
|
+
Every failure is a `QubitraError`: `AuthenticationError`, `NotFoundError`,
|
|
102
|
+
`InvalidRequestError`, `InsufficientCreditsError`, or `ProviderError`. Each carries
|
|
103
|
+
the platform's RFC 9457 Problem Details body (ADR-0008) on `.detail` and its HTTP
|
|
104
|
+
status on `.status_code`.
|
|
105
|
+
|
|
106
|
+
Models are frozen pydantic models; the package ships `py.typed`, so a caller's type
|
|
107
|
+
checker sees the whole surface.
|
|
108
|
+
|
|
109
|
+
## Layout
|
|
110
|
+
|
|
111
|
+
- `src/qubitra/` — the public facade: `client.py`, `models.py`, `errors.py`,
|
|
112
|
+
`credentials.py`.
|
|
113
|
+
- `src/qubitra/_providers/` — the adapter seam (ADR-0041 D2). `base.py` is the
|
|
114
|
+
protocol the facade depends on; `qubitra.py` implements it over `/v1`. A second
|
|
115
|
+
platform slots in here without touching the facade.
|
|
116
|
+
- `tests/` — facade behaviour over a fake adapter, plus contract tests driving the
|
|
117
|
+
adapter's real request path against an httpx `MockTransport`.
|
|
118
|
+
|
|
119
|
+
The SDK is synchronous (ADR-0041 D7); client objects own their transport, so an
|
|
120
|
+
async twin is additive.
|
|
121
|
+
|
|
122
|
+
## Tasks
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
mise exec -- uv run pytest pkg/niobium -q # tests
|
|
126
|
+
mise exec -- mypy pkg/niobium # types
|
|
127
|
+
mise exec -- ruff check pkg/niobium # lint
|
|
128
|
+
```
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# niobium — the Qubitra Python SDK
|
|
2
|
+
|
|
3
|
+
The Python client for the Qubitra platform. Codename `niobium`; it installs as
|
|
4
|
+
`qubitra-sdk` and imports as `qubitra` (ADR-0041 D1).
|
|
5
|
+
|
|
6
|
+
The SDK speaks q-platform vocabulary — Backends, Jobs, Offerings — and talks to the
|
|
7
|
+
Qubitra API's public `/v1` surface. Which backend a Job actually lands on, and the
|
|
8
|
+
supply chain behind it, is the platform's business: the SDK never names a vendor.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install qubitra-sdk
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Inside this repo it is a uv workspace member, so `uv sync` at the root installs it
|
|
17
|
+
editable and no publish step is involved.
|
|
18
|
+
|
|
19
|
+
## Quickstart
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from qubitra import QubitraClient
|
|
23
|
+
|
|
24
|
+
with QubitraClient() as client:
|
|
25
|
+
for backend in client.backends.list():
|
|
26
|
+
print(backend.id, backend.qubit_count, backend.supported_formats)
|
|
27
|
+
|
|
28
|
+
job = client.jobs.submit(
|
|
29
|
+
backend_id="qpu-superconducting-127q",
|
|
30
|
+
circuit="OPENQASM 3.0; qubit[2] q; bit[2] c; h q[0]; cx q[0], q[1]; c = measure q;",
|
|
31
|
+
shots=1024,
|
|
32
|
+
name="bell-pair",
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
job = client.jobs.wait(job.id, timeout=600)
|
|
36
|
+
if job.status.is_terminal and job.error:
|
|
37
|
+
raise SystemExit(f"job {job.id} failed: {job.error}")
|
|
38
|
+
|
|
39
|
+
print(client.jobs.result(job.id).counts) # {"00": 512, "11": 512}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Two runnable versions of that sit in `examples/`: `submit_bell_pair.py` is the whole path,
|
|
43
|
+
and `list_backends.py` is the read-only smoke test. Both take their key from the environment:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
QUBITRA_API_KEY=qpk_... uv run pkg/niobium/examples/submit_bell_pair.py
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Against a local stack (`mise run dev:qplat`), add `QUBITRA_API_URL=http://localhost:8080` and
|
|
50
|
+
mint a key on the console's API keys page.
|
|
51
|
+
|
|
52
|
+
## Configuration
|
|
53
|
+
|
|
54
|
+
| Variable | Default | Meaning |
|
|
55
|
+
| --- | --- | --- |
|
|
56
|
+
| `QUBITRA_API_KEY` | — | API key (`qpk_…`), required. Resolves to your organization. |
|
|
57
|
+
| `QUBITRA_API_URL` | `http://localhost:8080` | The Qubitra deployment to reach. |
|
|
58
|
+
|
|
59
|
+
Both are also constructor arguments — `QubitraClient(api_key=…, api_url=…)` — which
|
|
60
|
+
take precedence over the environment.
|
|
61
|
+
|
|
62
|
+
## Surface
|
|
63
|
+
|
|
64
|
+
| Call | What it does |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| `client.backends.list()` / `.get(id)` | The backends available to you, and one by id. |
|
|
67
|
+
| `client.jobs.submit(...)` | Submit a circuit; returns a `Job` immediately. |
|
|
68
|
+
| `client.jobs.list()` | Your organization's jobs, newest first. |
|
|
69
|
+
| `client.jobs.get(id)` / `.result(id)` / `.cancel(id)` | Read status, fetch counts, cancel. |
|
|
70
|
+
| `client.jobs.wait(id)` | Poll until the Job reaches a terminal status. |
|
|
71
|
+
| `client.marketplace.offerings()` | The marketplace catalogue. |
|
|
72
|
+
|
|
73
|
+
`jobs.result` is valid once a Job is `COMPLETED`; asking earlier raises
|
|
74
|
+
`InvalidRequestError`.
|
|
75
|
+
|
|
76
|
+
Every failure is a `QubitraError`: `AuthenticationError`, `NotFoundError`,
|
|
77
|
+
`InvalidRequestError`, `InsufficientCreditsError`, or `ProviderError`. Each carries
|
|
78
|
+
the platform's RFC 9457 Problem Details body (ADR-0008) on `.detail` and its HTTP
|
|
79
|
+
status on `.status_code`.
|
|
80
|
+
|
|
81
|
+
Models are frozen pydantic models; the package ships `py.typed`, so a caller's type
|
|
82
|
+
checker sees the whole surface.
|
|
83
|
+
|
|
84
|
+
## Layout
|
|
85
|
+
|
|
86
|
+
- `src/qubitra/` — the public facade: `client.py`, `models.py`, `errors.py`,
|
|
87
|
+
`credentials.py`.
|
|
88
|
+
- `src/qubitra/_providers/` — the adapter seam (ADR-0041 D2). `base.py` is the
|
|
89
|
+
protocol the facade depends on; `qubitra.py` implements it over `/v1`. A second
|
|
90
|
+
platform slots in here without touching the facade.
|
|
91
|
+
- `tests/` — facade behaviour over a fake adapter, plus contract tests driving the
|
|
92
|
+
adapter's real request path against an httpx `MockTransport`.
|
|
93
|
+
|
|
94
|
+
The SDK is synchronous (ADR-0041 D7); client objects own their transport, so an
|
|
95
|
+
async twin is additive.
|
|
96
|
+
|
|
97
|
+
## Tasks
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
mise exec -- uv run pytest pkg/niobium -q # tests
|
|
101
|
+
mise exec -- mypy pkg/niobium # types
|
|
102
|
+
mise exec -- ruff check pkg/niobium # lint
|
|
103
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Live smoke: list backends and marketplace offerings through the SDK.
|
|
2
|
+
|
|
3
|
+
Run against a Qubitra deployment with an API key::
|
|
4
|
+
|
|
5
|
+
QUBITRA_API_KEY=qpk_... QUBITRA_API_URL=http://localhost:8080 \
|
|
6
|
+
uv run pkg/niobium/examples/list_backends.py
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from qubitra import QubitraClient
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main() -> None:
|
|
13
|
+
with QubitraClient() as client:
|
|
14
|
+
for backend in client.backends.list():
|
|
15
|
+
kind = backend.type.value if backend.type else "?"
|
|
16
|
+
qubits = f"{backend.qubit_count}q" if backend.qubit_count else ""
|
|
17
|
+
state = "available" if backend.available else "unavailable"
|
|
18
|
+
print(f"{backend.id:32} {kind:10} {qubits:6} {state:12} {backend.name or ''}")
|
|
19
|
+
print()
|
|
20
|
+
for offering in client.marketplace.offerings():
|
|
21
|
+
print(f"{offering.id:38} {offering.type.value:14} {offering.name or ''}")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
if __name__ == "__main__":
|
|
25
|
+
main()
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"""Live smoke: dispatch a workload and read its measured counts.
|
|
2
|
+
|
|
3
|
+
Submits a Bell pair, waits for the platform to run it, and prints the counts. This is the
|
|
4
|
+
whole path — SDK to the Qubitra API to a Temporal workflow to whichever backend the identifier
|
|
5
|
+
resolves to — so it failing says something real about the stack rather than about the SDK.
|
|
6
|
+
|
|
7
|
+
Run it against a Qubitra deployment with an API key::
|
|
8
|
+
|
|
9
|
+
QUBITRA_API_KEY=qpk_... uv run pkg/niobium/examples/submit_bell_pair.py
|
|
10
|
+
|
|
11
|
+
Against a local stack (``mise run dev:qplat``), point it at onyx as well. Create a key on the
|
|
12
|
+
console's API keys page, or mint one with an OIDC token::
|
|
13
|
+
|
|
14
|
+
QUBITRA_API_KEY=qpk_... QUBITRA_API_URL=http://localhost:8080 \
|
|
15
|
+
uv run pkg/niobium/examples/submit_bell_pair.py
|
|
16
|
+
|
|
17
|
+
Pass a backend id as the first argument to choose one; the default is a simulator, which is
|
|
18
|
+
where a circuit belongs until it is worth queueing for hardware. Pass a circuit format as the
|
|
19
|
+
second (``OPENQASM_2`` / ``OPENQASM_3``) to force one — otherwise the backend's own
|
|
20
|
+
``supported_formats`` decides, because backends differ in what they accept and the newest
|
|
21
|
+
format is not always the one available.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import sys
|
|
27
|
+
|
|
28
|
+
from qubitra import CircuitFormat, QubitraClient
|
|
29
|
+
|
|
30
|
+
# A Bell pair: entangle two qubits, measure both. On a simulator the counts land almost
|
|
31
|
+
# entirely on "00" and "11", so a result that is spread across all four outcomes is a
|
|
32
|
+
# visible sign something ran the wrong circuit.
|
|
33
|
+
BELL = {
|
|
34
|
+
CircuitFormat.OPENQASM_3: """
|
|
35
|
+
OPENQASM 3.0;
|
|
36
|
+
qubit[2] q;
|
|
37
|
+
bit[2] c;
|
|
38
|
+
h q[0];
|
|
39
|
+
cx q[0], q[1];
|
|
40
|
+
c = measure q;
|
|
41
|
+
""",
|
|
42
|
+
# Backends differ in what they accept, and not every one has caught up to OpenQASM 3 —
|
|
43
|
+
# `client.backends.list()` reports each one's `supported_formats`.
|
|
44
|
+
CircuitFormat.OPENQASM_2: """
|
|
45
|
+
OPENQASM 2.0;
|
|
46
|
+
include "qelib1.inc";
|
|
47
|
+
qreg q[2];
|
|
48
|
+
creg c[2];
|
|
49
|
+
h q[0];
|
|
50
|
+
cx q[0],q[1];
|
|
51
|
+
measure q -> c;
|
|
52
|
+
""",
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
DEFAULT_BACKEND = "sim-statevector-30q"
|
|
56
|
+
SHOTS = 1024
|
|
57
|
+
|
|
58
|
+
# Preferred first: OpenQASM 3 where a backend takes it, OpenQASM 2 otherwise.
|
|
59
|
+
PREFERENCE = (CircuitFormat.OPENQASM_3, CircuitFormat.OPENQASM_2)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def pick_format(client: QubitraClient, backend_id: str) -> CircuitFormat:
|
|
63
|
+
"""The best format this backend accepts, out of the ones this circuit is written in.
|
|
64
|
+
|
|
65
|
+
A backend reports what it accepts, and a backend that reports nothing places no
|
|
66
|
+
constraint of its own — so an empty list means the newest format is worth trying rather
|
|
67
|
+
than that nothing is.
|
|
68
|
+
"""
|
|
69
|
+
accepted = set(client.backends.get(backend_id).supported_formats)
|
|
70
|
+
if not accepted:
|
|
71
|
+
return PREFERENCE[0]
|
|
72
|
+
for candidate in PREFERENCE:
|
|
73
|
+
if candidate in accepted:
|
|
74
|
+
return candidate
|
|
75
|
+
raise SystemExit(
|
|
76
|
+
f"{backend_id} accepts {sorted(accepted)}, and this example writes only "
|
|
77
|
+
f"{[f.value for f in PREFERENCE]}"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def main() -> int:
|
|
82
|
+
backend_id = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_BACKEND
|
|
83
|
+
forced = CircuitFormat(sys.argv[2]) if len(sys.argv) > 2 else None
|
|
84
|
+
|
|
85
|
+
with QubitraClient() as client:
|
|
86
|
+
circuit_format = forced or pick_format(client, backend_id)
|
|
87
|
+
print(f"using {circuit_format}")
|
|
88
|
+
|
|
89
|
+
job = client.jobs.submit(
|
|
90
|
+
backend_id=backend_id,
|
|
91
|
+
circuit=BELL[circuit_format],
|
|
92
|
+
circuit_format=circuit_format,
|
|
93
|
+
shots=SHOTS,
|
|
94
|
+
name="bell-pair example",
|
|
95
|
+
)
|
|
96
|
+
# submit returns once the platform has accepted the job, not once it has run, so the
|
|
97
|
+
# first status is PENDING and the id is what everything else is addressed by.
|
|
98
|
+
print(f"submitted {job.id} to {backend_id} — {job.status}")
|
|
99
|
+
|
|
100
|
+
job = client.jobs.wait(job.id, timeout=120, poll_interval=2)
|
|
101
|
+
print(f"finished {job.id} — {job.status}")
|
|
102
|
+
|
|
103
|
+
if job.status.value != "COMPLETED":
|
|
104
|
+
# A failed job is a result too, and its error is the useful part.
|
|
105
|
+
print(f"job did not complete: {job.error or '(no error recorded)'}", file=sys.stderr)
|
|
106
|
+
return 1
|
|
107
|
+
|
|
108
|
+
result = client.jobs.result(job.id)
|
|
109
|
+
counts = result.counts or {}
|
|
110
|
+
total = sum(counts.values()) or 1
|
|
111
|
+
print()
|
|
112
|
+
for outcome, count in sorted(counts.items(), key=lambda kv: -kv[1]):
|
|
113
|
+
share = 100 * count / total
|
|
114
|
+
print(f" {outcome} {count:6} {share:5.1f}% {'█' * round(share / 2)}")
|
|
115
|
+
return 0
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if __name__ == "__main__":
|
|
119
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Live smoke: dispatch an IonQ circuit and read its measured counts.
|
|
2
|
+
|
|
3
|
+
The same Bell pair as ``submit_bell_pair.py``, expressed as an IonQ circuit document rather
|
|
4
|
+
than as OpenQASM. Backends differ in what they accept — ``client.backends.list()`` reports each
|
|
5
|
+
one's ``supported_formats`` — and several providers accept the IonQ circuit schema, so this is
|
|
6
|
+
the path for a backend that does not take QASM.
|
|
7
|
+
|
|
8
|
+
QUBITRA_API_KEY=qpk_... uv run pkg/niobium/examples/submit_ionq_circuit.py <backend-id>
|
|
9
|
+
|
|
10
|
+
Against a local stack (``mise run dev:qplat``), add ``QUBITRA_API_URL=http://localhost:8080``.
|
|
11
|
+
|
|
12
|
+
The circuit is JSON, but it is still passed as a string: ``circuit`` is text whatever the
|
|
13
|
+
format, and the platform parses the document at the vendor edge.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import json
|
|
19
|
+
import sys
|
|
20
|
+
|
|
21
|
+
from qubitra import CircuitFormat, QubitraClient
|
|
22
|
+
|
|
23
|
+
# A Bell pair as an IonQ circuit: `h` on qubit 0, then `x` on qubit 1 controlled by qubit 0.
|
|
24
|
+
# `gateset: "qis"` is the standard gate-level set, as against IonQ's native-gate mode.
|
|
25
|
+
BELL = {
|
|
26
|
+
"gateset": "qis",
|
|
27
|
+
"qubits": 2,
|
|
28
|
+
"circuit": [
|
|
29
|
+
{"gate": "h", "targets": [0]},
|
|
30
|
+
{"gate": "x", "targets": [1], "controls": [0]},
|
|
31
|
+
],
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
SHOTS = 1024
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def main() -> int:
|
|
38
|
+
if len(sys.argv) < 2:
|
|
39
|
+
print(
|
|
40
|
+
"usage: submit_ionq_circuit.py <backend-id>\n"
|
|
41
|
+
" pick one whose supported_formats includes IONQ_CIRCUIT",
|
|
42
|
+
file=sys.stderr,
|
|
43
|
+
)
|
|
44
|
+
return 2
|
|
45
|
+
backend_id = sys.argv[1]
|
|
46
|
+
|
|
47
|
+
with QubitraClient() as client:
|
|
48
|
+
job = client.jobs.submit(
|
|
49
|
+
backend_id=backend_id,
|
|
50
|
+
circuit=json.dumps(BELL),
|
|
51
|
+
circuit_format=CircuitFormat.IONQ_CIRCUIT,
|
|
52
|
+
shots=SHOTS,
|
|
53
|
+
name="bell-pair (IonQ)",
|
|
54
|
+
)
|
|
55
|
+
print(f"submitted {job.id} to {backend_id} — {job.status}")
|
|
56
|
+
|
|
57
|
+
# A live queue can outlast a short wait, and the platform keeps polling either way —
|
|
58
|
+
# so this waits longer than the SDK's default rather than reporting a timeout as
|
|
59
|
+
# though the job had failed.
|
|
60
|
+
job = client.jobs.wait(job.id, timeout=900, poll_interval=5)
|
|
61
|
+
print(f"finished {job.id} — {job.status}")
|
|
62
|
+
|
|
63
|
+
if job.status.value != "COMPLETED":
|
|
64
|
+
print(f"job did not complete: {job.error or '(no error recorded)'}", file=sys.stderr)
|
|
65
|
+
return 1
|
|
66
|
+
|
|
67
|
+
counts = client.jobs.result(job.id).counts or {}
|
|
68
|
+
total = sum(counts.values()) or 1
|
|
69
|
+
print()
|
|
70
|
+
for outcome, count in sorted(counts.items(), key=lambda kv: -kv[1]):
|
|
71
|
+
share = 100 * count / total
|
|
72
|
+
print(f" {outcome} {count:6} {share:5.1f}% {'█' * round(share / 2)}")
|
|
73
|
+
return 0
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if __name__ == "__main__":
|
|
77
|
+
raise SystemExit(main())
|