triple-alpha 0.2.3__py3-none-any.whl
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.
- triple_alpha-0.2.3.dist-info/METADATA +454 -0
- triple_alpha-0.2.3.dist-info/RECORD +24 -0
- triple_alpha-0.2.3.dist-info/WHEEL +4 -0
- triple_alpha-0.2.3.dist-info/licenses/LICENSE +202 -0
- triplealpha/__init__.py +33 -0
- triplealpha/deployment/__init__.py +13 -0
- triplealpha/deployment/orchestrator/__init__.py +13 -0
- triplealpha/deployment/orchestrator/run_manager.py +589 -0
- triplealpha/deployment/runner/__init__.py +13 -0
- triplealpha/deployment/runner/asynchronous_runner.py +196 -0
- triplealpha/deployment/runner/synchronous_runner.py +191 -0
- triplealpha/models/__init__.py +13 -0
- triplealpha/models/api/__init__.py +13 -0
- triplealpha/models/api/execution.py +83 -0
- triplealpha/models/service/__init__.py +13 -0
- triplealpha/models/service/models.py +128 -0
- triplealpha/py.typed +0 -0
- triplealpha/utils/__init__.py +13 -0
- triplealpha/utils/constants.py +51 -0
- triplealpha/utils/exceptions.py +30 -0
- triplealpha/utils/logging.py +70 -0
- triplealpha/utils/rest.py +141 -0
- triplealpha/utils/rest_async.py +140 -0
- triplealpha/utils/utils.py +128 -0
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: triple-alpha
|
|
3
|
+
Version: 0.2.3
|
|
4
|
+
Summary: Package allows users to run jobs against the triple alpha system
|
|
5
|
+
License: Apache2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Author: Rahul Suresh
|
|
8
|
+
Author-email: rahul@horizonquantum.com
|
|
9
|
+
Requires-Python: >=3.10,<4.0
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: License :: Other/Proprietary License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
20
|
+
Provides-Extra: json-logging
|
|
21
|
+
Requires-Dist: httpx (>=0.28.1,<0.29.0)
|
|
22
|
+
Requires-Dist: pydantic (>=2.13.4,<3.0.0)
|
|
23
|
+
Requires-Dist: requests (>=2.33.0,<3.0.0)
|
|
24
|
+
Requires-Dist: setuptools (>=83.0.0,<84.0.0)
|
|
25
|
+
Project-URL: Homepage, https://github.com/horizon-quantum/triple-alpha
|
|
26
|
+
Project-URL: Issues, https://github.com/horizon-quantum/triple-alpha/issues
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# Triple Alpha Deployment API – Python client
|
|
30
|
+
|
|
31
|
+
Triple Alpha lets you write quantum programs in our languages (Beryllium, Helium and Hydrogen) and deploy a compiled program as an API (your deployment API). This package is the official Python client for your deployment API. With this package, you can:
|
|
32
|
+
|
|
33
|
+
1. Submit jobs
|
|
34
|
+
2. Check the status of your jobs
|
|
35
|
+
3. Provide inputs for your jobs
|
|
36
|
+
4. Retrieve results
|
|
37
|
+
5. Run the above operations as batches.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Table of contents
|
|
42
|
+
- [Prerequisites](#prerequisites)
|
|
43
|
+
- [Installation](#installation)
|
|
44
|
+
- [About the client](#about-the-client)
|
|
45
|
+
- [License](#license)
|
|
46
|
+
- [Quickstart](#quickstart)
|
|
47
|
+
- [1. Synchronous Runner](#1-synchronous-runner)
|
|
48
|
+
- [1.1. Creating a job](#11-creating-a-job)
|
|
49
|
+
- [1.2. Getting job status and results](#12-getting-job-status-and-results)
|
|
50
|
+
- [1.3. Updating inputs](#13-updating-inputs)
|
|
51
|
+
- [1.4. Canceling a job](#14-canceling-a-job)
|
|
52
|
+
- [1.5. Listing jobs](#15-listing-jobs)
|
|
53
|
+
- [2. Asynchronous Runner](#2-asynchronous-runner)
|
|
54
|
+
- [2.1. Creating a job](#21-creating-a-job)
|
|
55
|
+
- [2.2. Getting job status and results](#22-getting-job-status-and-results)
|
|
56
|
+
- [2.3. Updating inputs](#23-updating-inputs)
|
|
57
|
+
- [2.4. Canceling a job](#24-canceling-a-job)
|
|
58
|
+
- [2.5. Listing jobs](#25-listing-jobs)
|
|
59
|
+
- [3. Run Manager](#3-run-manager)
|
|
60
|
+
- [3.1. Submitting jobs](#31-submitting-jobs)
|
|
61
|
+
- [3.2. Listing jobs](#32-listing-jobs)
|
|
62
|
+
- [3.3. Getting job status](#33-getting-job-status)
|
|
63
|
+
- [3.4. Updating inputs](#34-updating-inputs)
|
|
64
|
+
- [3.5. Canceling jobs](#35-canceling-jobs)
|
|
65
|
+
- [3.6. Registering callbacks](#36-registering-callbacks)
|
|
66
|
+
|
|
67
|
+
## Prerequisites
|
|
68
|
+
Before using this client, ensure you have:
|
|
69
|
+
* Python 3.11 or higher
|
|
70
|
+
* A **deployment API**, created in Triple Alpha as part of successfully deploying your program. This client only works with an existing deployment API.
|
|
71
|
+
* Your deployment API's **URL** and **API token**. These are shown once you have successfully deployed your program. The URL is also available from the API dashboard.
|
|
72
|
+
|
|
73
|
+
## Installation
|
|
74
|
+
|
|
75
|
+
Install the package via `pip`:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install triple-alpha
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The package is imported as `triplealpha`:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
import triplealpha
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## About the client
|
|
88
|
+
Each deployment API exposes six endpoints, and this client wraps them 1:1:
|
|
89
|
+
|
|
90
|
+
| Client method | Endpoint | Purpose |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| `run_execution` | `/run/create` | Submit a job to the processor or simulator |
|
|
93
|
+
| `get_job_status` | `/run/get_status` | Get a job's status |
|
|
94
|
+
| `get_job_results` | `/run/get_results` | Retrieve results of a completed job |
|
|
95
|
+
| `update_inputs` | `/run/update_input` | Supply inputs to a job that is **Awaiting input** |
|
|
96
|
+
| `cancel_execution` | `/run/cancel` | Cancel a submitted job |
|
|
97
|
+
| `get_job_list` | `/run/list_jobs` | List job IDs and statuses for this deployment API |
|
|
98
|
+
|
|
99
|
+
* Two runners expose the same methods against a deployment API: the **Synchronous Runner** for blocking calls, and the **Asynchronous Runner** for non-blocking versions of the same methods (built on `asyncio`).
|
|
100
|
+
* Use a runner for individual jobs. For batches, use the **Run Manager**. It is a job orchestrator that queues jobs, limits how many are polled at once, throttles requests to stay within API rate limits, and polls for status updates. If you need custom polling logic, you can build it on the runners directly.
|
|
101
|
+
* The Run Manager can also run a **callback** when a job reaches a given status. For example, you can supply inputs automatically when a job becomes **Awaiting input**. See [3.6. Registering callbacks](#36-registering-callbacks) for more information.
|
|
102
|
+
* Job statuses are exposed as the `JobStatus` enum:
|
|
103
|
+
|
|
104
|
+
| `JobStatus` | Status in Triple Alpha | Definition |
|
|
105
|
+
|---|---|---|
|
|
106
|
+
| `CREATED` | Created | The job is successfully created. |
|
|
107
|
+
| `QUEUED` | Queued | The job is queued for processing on our servers. |
|
|
108
|
+
| `IN_PROGRESS` | In progress | The job is being processed. Cancellation may still be possible at this stage. |
|
|
109
|
+
| `AWAITING_QPU` | Awaiting QPU | The job has been submitted to the hardware provider. This status covers both queueing and running on the provider's QPU or simulator. Cancellation is not possible once a QPU job has started. |
|
|
110
|
+
| `IN_FLIGHT` | In flight | The job has returned from the hardware provider and is awaiting post-processing on our servers. |
|
|
111
|
+
| `AWAITING_INPUT` | Awaiting input | The job is paused, waiting for an input value to continue. This happens when your program uses user input or mid-circuit measurements that require interactive resolution. Provide it with `update_inputs`.|
|
|
112
|
+
| `SUCCESSFUL` | Successful | The job completed successfully. Retrieve results with `get_job_results`.|
|
|
113
|
+
| `CANCELLED` | Cancelled | The job was cancelled. |
|
|
114
|
+
| `FAILED` | Failed | The job failed. |
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
This client is distributed under the Apache 2.0 License. See LICENSE for more information.
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## Quickstart
|
|
122
|
+
Every example needs your deployment API's URL and API token (see [Prerequisites](#prerequisites)). You can replace the placeholders with your own values.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
### 1. Synchronous Runner
|
|
126
|
+
Use the Synchronous Runner when blocking calls are fine (e.g scripts, notebooks and simple pipelines). It provides the following methods:
|
|
127
|
+
|
|
128
|
+
#### 1.1. Creating a job
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
import json
|
|
132
|
+
|
|
133
|
+
# Import the Synchronous Runner
|
|
134
|
+
from triplealpha import SynchronousRunner, JobStatus
|
|
135
|
+
from triplealpha.models.service import Deployment
|
|
136
|
+
from triplealpha.utils.logging import logger
|
|
137
|
+
from triplealpha.utils.utils import serialize_json
|
|
138
|
+
|
|
139
|
+
# Your deployment API's URL and API token, from the "API successfully created" window
|
|
140
|
+
# shown after deployment (the URL is also available later in the API dashboard).
|
|
141
|
+
api_url = "https://quark-prod-spin-api.horizonquantum.com/execute-api/deployment/{deployment_id}/processor/{processor_name}/run/{endpoint}"
|
|
142
|
+
api_token = "{API token you get from the UI}"
|
|
143
|
+
|
|
144
|
+
runner = SynchronousRunner(api_url=api_url, api_token=api_token)
|
|
145
|
+
|
|
146
|
+
# num_shots is the number of complete runs of your program. If it exceeds the
|
|
147
|
+
# "Max. shots per call" set when the API was deployed, it is capped at that value.
|
|
148
|
+
# inputs is optional. Refer to 1.3 for the formats.
|
|
149
|
+
run_payload = {"inputs": [], "num_shots": 100}
|
|
150
|
+
response = runner.run_execution(payload=run_payload)
|
|
151
|
+
logger.info(f"Job created. Response: {response}")
|
|
152
|
+
created_job_id = response["job_id"]
|
|
153
|
+
|
|
154
|
+
# Alternatively, wrap the URL and API token in a Deployment object. It validates the
|
|
155
|
+
# URL format and can be reused across runners.
|
|
156
|
+
deployment = Deployment(api_url=api_url, api_token=api_token)
|
|
157
|
+
response = SynchronousRunner(deployment=deployment).run_execution(payload=run_payload)
|
|
158
|
+
logger.info(f"Job created. Response: {response}")
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### 1.2. Getting job status and results
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
# Get the job status (use this to implement polling logic).
|
|
165
|
+
# serialize_json handles the objects in the responses when printing.
|
|
166
|
+
response = runner.get_job_status(job_id=created_job_id)
|
|
167
|
+
logger.info(
|
|
168
|
+
f"Job status. Response: {json.dumps(response, indent=2, default=serialize_json)}"
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
# Get the job results. Results are available once the job is SUCCESSFUL and contain
|
|
172
|
+
# the values of variables flagged with `output` in your program, along with the measurement results.
|
|
173
|
+
response = runner.get_job_results(job_id=created_job_id)
|
|
174
|
+
logger.info(
|
|
175
|
+
f"Job results. Response: {json.dumps(response, indent=2, default=serialize_json)}"
|
|
176
|
+
)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### 1.3. Updating inputs
|
|
180
|
+
A job that needs an input value to continue will return the status **Awaiting input** (`JobStatus.AWAITING_INPUT`). Supply the inputs with `update_inputs` and the job will resume.
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
# Inputs as a dict, or as a list of [name, value] pairs (the format used by the API and the UI).
|
|
184
|
+
# Names must match the variables flagged with `input` in your program and are case-sensitive.
|
|
185
|
+
# Values are classical floats.
|
|
186
|
+
inputs = {"theta": 1.5708, "phi": 0.0}
|
|
187
|
+
# inputs = [["theta", 1.5708], ["phi", 0.0]]
|
|
188
|
+
|
|
189
|
+
# update_inputs only succeeds while the job is AWAITING_INPUT.
|
|
190
|
+
try:
|
|
191
|
+
response = runner.update_inputs(job_id=created_job_id, inputs=inputs)
|
|
192
|
+
logger.info(
|
|
193
|
+
f"Updated inputs. Response: {json.dumps(response, indent=2, default=serialize_json)}"
|
|
194
|
+
)
|
|
195
|
+
except Exception as e:
|
|
196
|
+
logger.error(f"Update inputs failed: {e}")
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
#### 1.4. Canceling a job
|
|
200
|
+
Canceling a job is handled on a best-effort basis. A job that is already running on a QPU may complete and still incur cost, particularly if the program uses mid-circuit measurement.
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
response = runner.cancel_execution(job_id=created_job_id)
|
|
204
|
+
logger.info(
|
|
205
|
+
f"Cancelled job. Response: {json.dumps(response, indent=2, default=serialize_json)}"
|
|
206
|
+
)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
#### 1.5. Listing jobs
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
# List all jobs associated with this deployment API
|
|
214
|
+
response = runner.get_job_list()
|
|
215
|
+
logger.info(
|
|
216
|
+
f"Job list. Response: {json.dumps(response, indent=2, default=serialize_json)}"
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
# Filter by status using the JobStatus enum (see "About the client" for the full list)
|
|
220
|
+
response = runner.get_job_list(status=JobStatus.CANCELLED)
|
|
221
|
+
logger.info(f"Job list. {json.dumps(response, indent=2, default=serialize_json)}")
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### 2. Asynchronous Runner
|
|
225
|
+
Use the Asynchronous Runner to call your deployment API in a non-blocking manner (built on `asyncio`). It exposes the same methods as the Synchronous Runner as coroutines.
|
|
226
|
+
|
|
227
|
+
All snippets in this section must run inside a coroutine:
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
import asyncio
|
|
231
|
+
|
|
232
|
+
async def main():
|
|
233
|
+
... # snippets from 2.1–2.5 go here
|
|
234
|
+
|
|
235
|
+
asyncio.run(main())
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
#### 2.1. Creating a job
|
|
239
|
+
|
|
240
|
+
```python
|
|
241
|
+
import json
|
|
242
|
+
|
|
243
|
+
# Import the Asynchronous Runner
|
|
244
|
+
from triplealpha import AsynchronousRunner, JobStatus
|
|
245
|
+
from triplealpha.models.service import Deployment
|
|
246
|
+
from triplealpha.utils.logging import logger
|
|
247
|
+
from triplealpha.utils.utils import serialize_json
|
|
248
|
+
|
|
249
|
+
# Your deployment API's URL and API token, from the "API successfully created" window
|
|
250
|
+
# shown after deployment (the URL is also available later in the API dashboard).
|
|
251
|
+
api_url = "https://quark-prod-spin-api.horizonquantum.com/execute-api/deployment/{deployment_id}/processor/{processor_name}/run/{endpoint}"
|
|
252
|
+
api_token = "{API token you get from the UI}"
|
|
253
|
+
|
|
254
|
+
async_runner = AsynchronousRunner(api_url=api_url, api_token=api_token)
|
|
255
|
+
|
|
256
|
+
run_payload = {"inputs": [], "num_shots": 100}
|
|
257
|
+
response = await async_runner.run_execution(payload=run_payload)
|
|
258
|
+
logger.info(f"Job created. Response: {response}")
|
|
259
|
+
async_created_job_id = response["job_id"]
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
#### 2.2. Getting job status and results
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
```python
|
|
266
|
+
response = await async_runner.get_job_status(job_id=async_created_job_id)
|
|
267
|
+
logger.info(
|
|
268
|
+
f"Job status. Response: {json.dumps(response, indent=2, default=serialize_json)}"
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
response = await async_runner.get_job_results(job_id=async_created_job_id)
|
|
272
|
+
logger.info(
|
|
273
|
+
f"Job results. Response: {json.dumps(response, indent=2, default=serialize_json)}"
|
|
274
|
+
)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
#### 2.3. Updating inputs
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
inputs = {"theta": 1.5708, "phi": 0.0}
|
|
282
|
+
# inputs = [["theta", 1.5708], ["phi", 0.0]]
|
|
283
|
+
|
|
284
|
+
# update_inputs only succeeds while the job is AWAITING_INPUT.
|
|
285
|
+
try:
|
|
286
|
+
response = await async_runner.update_inputs(
|
|
287
|
+
job_id=async_created_job_id, inputs=inputs
|
|
288
|
+
)
|
|
289
|
+
logger.info(
|
|
290
|
+
f"Updated inputs. Response: {json.dumps(response, indent=2, default=serialize_json)}"
|
|
291
|
+
)
|
|
292
|
+
except Exception as e:
|
|
293
|
+
logger.error(f"Update inputs failed: {e}")
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
#### 2.4. Canceling a job
|
|
297
|
+
|
|
298
|
+
```python
|
|
299
|
+
response = await async_runner.cancel_execution(job_id=async_created_job_id)
|
|
300
|
+
logger.info(
|
|
301
|
+
f"Cancelled job. Response: {json.dumps(response, indent=2, default=serialize_json)}"
|
|
302
|
+
)
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
#### 2.5. Listing jobs
|
|
306
|
+
|
|
307
|
+
```python
|
|
308
|
+
response = await async_runner.get_job_list()
|
|
309
|
+
logger.info(
|
|
310
|
+
f"Job list. Response: {json.dumps(response, indent=2, default=serialize_json)}"
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
response = await async_runner.get_job_list(status=JobStatus.CANCELLED)
|
|
314
|
+
logger.info(f"Job list. {json.dumps(response, indent=2, default=serialize_json)}")
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### 3. Run Manager
|
|
318
|
+
The Run Manager is the recommended way to run batches of jobs against a deployment API. It is an orchestrator: it queues jobs, limits concurrency, polls for status changes, and runs callbacks when a job reaches a given status.
|
|
319
|
+
|
|
320
|
+
Points to note:
|
|
321
|
+
|
|
322
|
+
* Only 25 jobs can be **active** (being polled for status updates) at any time, and the rest wait in the queue. There is no client-imposed limit on the number of queued jobs.
|
|
323
|
+
* You can register callbacks per job to automate actions on status changes — e.g. update a job's inputs when it changes to `AWAITING_INPUT`.
|
|
324
|
+
* The Run Manager holds job state **in memory only**. When the process exits, the manager forgets its queued and active jobs, and the jobs themselves continue on Triple Alpha. You will need to persist job IDs if you need to resume monitoring in a new process, and the methods below accept job IDs so you can continue work.
|
|
325
|
+
* The Run Manager is `asyncio`-based. All its methods are coroutines and must be called from within a running event loop (see the wrapper in [2. Asynchronous Runner](#2-asynchronous-runner)).
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
#### 3.1. Submitting jobs
|
|
329
|
+
|
|
330
|
+
```python
|
|
331
|
+
import json
|
|
332
|
+
|
|
333
|
+
from triplealpha import JobStatus
|
|
334
|
+
from triplealpha.deployment.orchestrator.run_manager import RunManager
|
|
335
|
+
from triplealpha.utils.logging import logger
|
|
336
|
+
from triplealpha.utils.utils import serialize_json
|
|
337
|
+
|
|
338
|
+
# No arguments are required to create the manager
|
|
339
|
+
manager = RunManager()
|
|
340
|
+
```
|
|
341
|
+
Each job payload carries the deployment API's URL and API token, the job parameters, and (optionally) callbacks:
|
|
342
|
+
|
|
343
|
+
```python
|
|
344
|
+
job_payload = {
|
|
345
|
+
"api_url": "https://quark-prod-spin-api.horizonquantum.com/execute-api/deployment/{deployment_id}/processor/{processor_key}/run/create",
|
|
346
|
+
"api_token": "{API token you get from the UI}",
|
|
347
|
+
"inputs": [],
|
|
348
|
+
"num_shots": 100,
|
|
349
|
+
"callbacks": {},
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
# Submit one job
|
|
353
|
+
response = await manager.submit_job(job_payload=job_payload)
|
|
354
|
+
logger.info(
|
|
355
|
+
f"Job submitted to manager. Response: {json.dumps(response, indent=2, default=serialize_json)}"
|
|
356
|
+
)
|
|
357
|
+
job_id = response["job_id"]
|
|
358
|
+
|
|
359
|
+
# Submit a batch – e.g. the same program over a sweep of input values
|
|
360
|
+
for theta in (0.0, 0.5, 1.0):
|
|
361
|
+
await manager.submit_job(job_payload={**job_payload, "inputs": [["theta", theta]]})
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
#### 3.2. Listing jobs
|
|
365
|
+
|
|
366
|
+
```python
|
|
367
|
+
queued_jobs = manager.queued_jobs
|
|
368
|
+
if len(queued_jobs) > 0:
|
|
369
|
+
logger.info(f"Jobs in queue: {queued_jobs}")
|
|
370
|
+
|
|
371
|
+
active_jobs = manager.active_jobs
|
|
372
|
+
if len(active_jobs) > 0:
|
|
373
|
+
logger.info(f"Jobs in active monitoring: {active_jobs}")
|
|
374
|
+
|
|
375
|
+
failed_jobs = manager.failed_jobs
|
|
376
|
+
if len(failed_jobs) > 0:
|
|
377
|
+
logger.info(f"Failed jobs: {failed_jobs}")
|
|
378
|
+
|
|
379
|
+
cancelled_jobs = manager.cancelled_jobs
|
|
380
|
+
if len(cancelled_jobs) > 0:
|
|
381
|
+
logger.info(f"Cancelled jobs: {cancelled_jobs}")
|
|
382
|
+
|
|
383
|
+
successful_jobs = manager.successful_jobs
|
|
384
|
+
if len(successful_jobs) > 0:
|
|
385
|
+
logger.info(f"Successful jobs: {successful_jobs}")
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
#### 3.3. Getting job status
|
|
389
|
+
|
|
390
|
+
```python
|
|
391
|
+
response = await manager.get_job_status(
|
|
392
|
+
job_ids=[job_id],
|
|
393
|
+
)
|
|
394
|
+
logger.info(
|
|
395
|
+
f"Job status. Response: {json.dumps(response, indent=2, default=serialize_json)}"
|
|
396
|
+
)
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
#### 3.4. Updating inputs
|
|
400
|
+
Update inputs for one or more jobs in a single call:
|
|
401
|
+
|
|
402
|
+
```python
|
|
403
|
+
inputs_payload = [
|
|
404
|
+
{
|
|
405
|
+
"job_id": job_id,
|
|
406
|
+
"inputs": {"theta": 1.5708, "phi": 0.0},
|
|
407
|
+
}
|
|
408
|
+
]
|
|
409
|
+
|
|
410
|
+
response = await manager.update_inputs(inputs_payload=inputs_payload)
|
|
411
|
+
logger.info(response)
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
#### 3.5. Canceling jobs
|
|
415
|
+
Canceling a job is handled on a best-effort basis, as mentioned in [1.4. Canceling a job](#14-canceling-a-job).
|
|
416
|
+
|
|
417
|
+
```python
|
|
418
|
+
response = await manager.cancel_job(job_ids=[job_id])
|
|
419
|
+
logger.info(response)
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
#### 3.6. Registering callbacks
|
|
423
|
+
|
|
424
|
+
* A callback is a coroutine the Run Manager runs when a job enters a given status. Register callbacks per job at submission, keyed by `JobStatus`. The callback receives the job object.
|
|
425
|
+
* The most useful callback is on `AWAITING_INPUT`: supply the job's inputs automatically so the batch proceeds without manual intervention.
|
|
426
|
+
|
|
427
|
+
```python
|
|
428
|
+
# Sample callbacks
|
|
429
|
+
async def supply_inputs(job):
|
|
430
|
+
# Runs when the job reaches AWAITING_INPUT
|
|
431
|
+
await manager.update_inputs(
|
|
432
|
+
inputs_payload=[{"job_id": job.job_id, "inputs": {"theta": 1.5708}}]
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
async def print_success(job):
|
|
436
|
+
print(f"SUCCESS: {job.job_id} finished")
|
|
437
|
+
|
|
438
|
+
job_payload = {
|
|
439
|
+
"api_url": "https://quark-prod-spin-api.horizonquantum.com/execute-api/deployment/{deployment_id}/processor/{processor_key}/run/create",
|
|
440
|
+
"api_token": "{API token you get from the UI}",
|
|
441
|
+
"inputs": [],
|
|
442
|
+
"num_shots": 100,
|
|
443
|
+
"callbacks": {
|
|
444
|
+
JobStatus.AWAITING_INPUT: supply_inputs,
|
|
445
|
+
JobStatus.SUCCESSFUL: print_success,
|
|
446
|
+
},
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
response = await manager.submit_job(job_payload=job_payload)
|
|
450
|
+
logger.info(
|
|
451
|
+
f"Job submitted to manager. Response: {json.dumps(response, indent=2, default=serialize_json)}"
|
|
452
|
+
)
|
|
453
|
+
```
|
|
454
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
triplealpha/__init__.py,sha256=vEpbZuxcq-yr0zVt_VpsM-j0svRE-HQGGPKpTG9NGVo,1134
|
|
2
|
+
triplealpha/deployment/__init__.py,sha256=ACc8ds9_bP3Xcbv7cfWkNHZ7x-SjDqzqu2PbrO4egPY,600
|
|
3
|
+
triplealpha/deployment/orchestrator/__init__.py,sha256=RbogtvCxDdJ7D3VeJvPc_qbd4Ag5KjBacEbolUqcO6U,593
|
|
4
|
+
triplealpha/deployment/orchestrator/run_manager.py,sha256=dBr0i9yTe_FPvMGMMLkfjYWn3el6AxO0IaVW4-VKMi4,22141
|
|
5
|
+
triplealpha/deployment/runner/__init__.py,sha256=RbogtvCxDdJ7D3VeJvPc_qbd4Ag5KjBacEbolUqcO6U,593
|
|
6
|
+
triplealpha/deployment/runner/asynchronous_runner.py,sha256=laUAbprqscHyzUCkrSrcJnR6wr-QIdctPPxLQUkNeds,6231
|
|
7
|
+
triplealpha/deployment/runner/synchronous_runner.py,sha256=g0WKufJyhSWrWSH3SB-RonPQ_i_quxBgQkkYAAX2ko4,6042
|
|
8
|
+
triplealpha/models/__init__.py,sha256=RbogtvCxDdJ7D3VeJvPc_qbd4Ag5KjBacEbolUqcO6U,593
|
|
9
|
+
triplealpha/models/api/__init__.py,sha256=RbogtvCxDdJ7D3VeJvPc_qbd4Ag5KjBacEbolUqcO6U,593
|
|
10
|
+
triplealpha/models/api/execution.py,sha256=ZnTX9Sb8-UUoJ73hdfPPJdXg8xb_h_gnE0oJICXAT4o,1924
|
|
11
|
+
triplealpha/models/service/__init__.py,sha256=RbogtvCxDdJ7D3VeJvPc_qbd4Ag5KjBacEbolUqcO6U,593
|
|
12
|
+
triplealpha/models/service/models.py,sha256=8d-mFTZqGkJa2l7iWnhh0dnzR0MmGWePHLmAbY4DxQ4,4435
|
|
13
|
+
triplealpha/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
triplealpha/utils/__init__.py,sha256=RbogtvCxDdJ7D3VeJvPc_qbd4Ag5KjBacEbolUqcO6U,593
|
|
15
|
+
triplealpha/utils/constants.py,sha256=4z0n2kDLvyOgABcd8XfkgDgFB7CRWfqK7zoGQ6LtL-M,1463
|
|
16
|
+
triplealpha/utils/exceptions.py,sha256=AJ6phSfb5jnPhp4awPlWbfuPE_8HRBndB0awJL1n4ag,1044
|
|
17
|
+
triplealpha/utils/logging.py,sha256=NNeE0MiIn7phmy341yYdg9PE_-edlNVFQ_vptobmQY0,2159
|
|
18
|
+
triplealpha/utils/rest.py,sha256=N41hbZoi5mLpN4VZK1N7lv57l5405dVPQfMw78zzXUY,4798
|
|
19
|
+
triplealpha/utils/rest_async.py,sha256=XiD3r8yCrDNsGWgoUcXe1fz6NsMYdCSDJWjeAu0vRQI,4784
|
|
20
|
+
triplealpha/utils/utils.py,sha256=t-WPR3yg4B5PTZ5UM9T7kEgXcX7EnqBLJHV2KzJR_Bw,3498
|
|
21
|
+
triple_alpha-0.2.3.dist-info/METADATA,sha256=TBEQTVM_fPOsgfQhuvo-SyAM7QhFUjQWWeGCcyLBytg,17804
|
|
22
|
+
triple_alpha-0.2.3.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
|
|
23
|
+
triple_alpha-0.2.3.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
24
|
+
triple_alpha-0.2.3.dist-info/RECORD,,
|
|
@@ -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.
|