Skip to content

Commit 3038029

Browse files
authored
Merge pull request #3 from ionq/add-get-job-probabilities
Add get_job_probabilities endpoint via overlay
2 parents 5ebc7c4 + ffa6182 commit 3038029

6 files changed

Lines changed: 326 additions & 0 deletions

File tree

.github/workflows/generated.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
--path /tmp/patched-spec.json \
3737
--meta none \
3838
--config openapi-python-client-config.yaml \
39+
--custom-template-path custom-templates \
3940
--output-path ionq_core \
4041
--overwrite
4142
- name: Check for uncommitted changes
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{% from "helpers.jinja" import safe_docstring %}
2+
3+
{{ safe_docstring(package_description) }}
4+
from ._exceptions import (
5+
APIConnectionError,
6+
APIError,
7+
APITimeoutError,
8+
AuthenticationError,
9+
BadRequestError,
10+
IonQError,
11+
NotFoundError,
12+
PermissionDeniedError,
13+
RateLimitError,
14+
ServerError,
15+
)
16+
from ._extensions import AsyncEventHook, ClientExtension, EventHook
17+
from ._pagination import aiter_jobs, aiter_session_jobs, iter_jobs, iter_session_jobs
18+
from ._polling import (
19+
JobFailedError,
20+
JobTimeoutError,
21+
async_wait_for_job,
22+
wait_for_job,
23+
)
24+
from .client import AuthenticatedClient, Client
25+
from .ionq_client import IonQClient, __version__
26+
27+
__all__ = (
28+
"APIConnectionError",
29+
"APIError",
30+
"APITimeoutError",
31+
"AsyncEventHook",
32+
"AuthenticatedClient",
33+
"AuthenticationError",
34+
"BadRequestError",
35+
"Client",
36+
"ClientExtension",
37+
"EventHook",
38+
"IonQClient",
39+
"IonQError",
40+
"JobFailedError",
41+
"JobTimeoutError",
42+
"NotFoundError",
43+
"PermissionDeniedError",
44+
"RateLimitError",
45+
"ServerError",
46+
"__version__",
47+
"aiter_jobs",
48+
"aiter_session_jobs",
49+
"async_wait_for_job",
50+
"iter_jobs",
51+
"iter_session_jobs",
52+
"wait_for_job",
53+
)
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
from http import HTTPStatus
2+
from typing import Any, cast
3+
from urllib.parse import quote
4+
5+
import httpx
6+
7+
from ...client import AuthenticatedClient, Client
8+
from ...types import Response, UNSET
9+
from ... import errors
10+
11+
from ...models.get_job_probabilities_response_200 import GetJobProbabilitiesResponse200
12+
from typing import cast
13+
14+
15+
16+
def _get_kwargs(
17+
uuid: str,
18+
19+
) -> dict[str, Any]:
20+
21+
22+
23+
24+
25+
26+
_kwargs: dict[str, Any] = {
27+
"method": "get",
28+
"url": "/jobs/{uuid}/results/probabilities".format(uuid=quote(str(uuid), safe=""),),
29+
}
30+
31+
32+
return _kwargs
33+
34+
35+
36+
def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | GetJobProbabilitiesResponse200 | None:
37+
if response.status_code == 200:
38+
response_200 = GetJobProbabilitiesResponse200.from_dict(response.json())
39+
40+
41+
42+
return response_200
43+
44+
if response.status_code == 404:
45+
response_404 = cast(Any, None)
46+
return response_404
47+
48+
if client.raise_on_unexpected_status:
49+
raise errors.UnexpectedStatus(response.status_code, response.content)
50+
else:
51+
return None
52+
53+
54+
def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any | GetJobProbabilitiesResponse200]:
55+
return Response(
56+
status_code=HTTPStatus(response.status_code),
57+
content=response.content,
58+
headers=response.headers,
59+
parsed=_parse_response(client=client, response=response),
60+
)
61+
62+
63+
def sync_detailed(
64+
uuid: str,
65+
*,
66+
client: AuthenticatedClient,
67+
68+
) -> Response[Any | GetJobProbabilitiesResponse200]:
69+
""" Fetch the probability distribution for a completed job.
70+
71+
Args:
72+
uuid (str):
73+
74+
Raises:
75+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
76+
httpx.TimeoutException: If the request takes longer than Client.timeout.
77+
78+
Returns:
79+
Response[Any | GetJobProbabilitiesResponse200]
80+
"""
81+
82+
83+
kwargs = _get_kwargs(
84+
uuid=uuid,
85+
86+
)
87+
88+
response = client.get_httpx_client().request(
89+
**kwargs,
90+
)
91+
92+
return _build_response(client=client, response=response)
93+
94+
def sync(
95+
uuid: str,
96+
*,
97+
client: AuthenticatedClient,
98+
99+
) -> Any | GetJobProbabilitiesResponse200 | None:
100+
""" Fetch the probability distribution for a completed job.
101+
102+
Args:
103+
uuid (str):
104+
105+
Raises:
106+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
107+
httpx.TimeoutException: If the request takes longer than Client.timeout.
108+
109+
Returns:
110+
Any | GetJobProbabilitiesResponse200
111+
"""
112+
113+
114+
return sync_detailed(
115+
uuid=uuid,
116+
client=client,
117+
118+
).parsed
119+
120+
async def asyncio_detailed(
121+
uuid: str,
122+
*,
123+
client: AuthenticatedClient,
124+
125+
) -> Response[Any | GetJobProbabilitiesResponse200]:
126+
""" Fetch the probability distribution for a completed job.
127+
128+
Args:
129+
uuid (str):
130+
131+
Raises:
132+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
133+
httpx.TimeoutException: If the request takes longer than Client.timeout.
134+
135+
Returns:
136+
Response[Any | GetJobProbabilitiesResponse200]
137+
"""
138+
139+
140+
kwargs = _get_kwargs(
141+
uuid=uuid,
142+
143+
)
144+
145+
response = await client.get_async_httpx_client().request(
146+
**kwargs
147+
)
148+
149+
return _build_response(client=client, response=response)
150+
151+
async def asyncio(
152+
uuid: str,
153+
*,
154+
client: AuthenticatedClient,
155+
156+
) -> Any | GetJobProbabilitiesResponse200 | None:
157+
""" Fetch the probability distribution for a completed job.
158+
159+
Args:
160+
uuid (str):
161+
162+
Raises:
163+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
164+
httpx.TimeoutException: If the request takes longer than Client.timeout.
165+
166+
Returns:
167+
Any | GetJobProbabilitiesResponse200
168+
"""
169+
170+
171+
return (await asyncio_detailed(
172+
uuid=uuid,
173+
client=client,
174+
175+
)).parsed

ionq_core/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from .get_job_estimate_query_params import GetJobEstimateQueryParams
4444
from .get_job_estimate_response import GetJobEstimateResponse
4545
from .get_job_estimate_response_rate_information import GetJobEstimateResponseRateInformation
46+
from .get_job_probabilities_response_200 import GetJobProbabilitiesResponse200
4647
from .get_job_response import GetJobResponse
4748
from .get_jobs_query_params import GetJobsQueryParams
4849
from .get_jobs_response import GetJobsResponse
@@ -155,6 +156,7 @@
155156
"GetJobEstimateQueryParams",
156157
"GetJobEstimateResponse",
157158
"GetJobEstimateResponseRateInformation",
159+
"GetJobProbabilitiesResponse200",
158160
"GetJobResponse",
159161
"GetJobsQueryParams",
160162
"GetJobsResponse",
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from __future__ import annotations
2+
3+
from collections.abc import Mapping
4+
from typing import Any, TypeVar, BinaryIO, TextIO, TYPE_CHECKING, Generator
5+
6+
from attrs import define as _attrs_define
7+
from attrs import field as _attrs_field
8+
9+
from ..types import UNSET, Unset
10+
11+
12+
13+
14+
15+
16+
17+
T = TypeVar("T", bound="GetJobProbabilitiesResponse200")
18+
19+
20+
21+
@_attrs_define
22+
class GetJobProbabilitiesResponse200:
23+
"""
24+
"""
25+
26+
additional_properties: dict[str, float] = _attrs_field(init=False, factory=dict)
27+
28+
29+
30+
31+
32+
def to_dict(self) -> dict[str, Any]:
33+
34+
field_dict: dict[str, Any] = {}
35+
field_dict.update(self.additional_properties)
36+
37+
return field_dict
38+
39+
40+
41+
@classmethod
42+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
43+
d = dict(src_dict)
44+
get_job_probabilities_response_200 = cls(
45+
)
46+
47+
48+
get_job_probabilities_response_200.additional_properties = d
49+
return get_job_probabilities_response_200
50+
51+
@property
52+
def additional_keys(self) -> list[str]:
53+
return list(self.additional_properties.keys())
54+
55+
def __getitem__(self, key: str) -> float:
56+
return self.additional_properties[key]
57+
58+
def __setitem__(self, key: str, value: float) -> None:
59+
self.additional_properties[key] = value
60+
61+
def __delitem__(self, key: str) -> None:
62+
del self.additional_properties[key]
63+
64+
def __contains__(self, key: str) -> bool:
65+
return key in self.additional_properties

openapi-overlay.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,33 @@ actions:
112112
- target: $.components.schemas.Gate_NativeGate_
113113
update:
114114
required: [gate]
115+
116+
# Results endpoints: API v0.4 returns results as URLs that must be
117+
# fetched separately. The spec omits these endpoints entirely.
118+
- target: $.paths
119+
update:
120+
/jobs/{UUID}/results/probabilities:
121+
get:
122+
operationId: getJobProbabilities
123+
summary: Fetch the probability distribution for a completed job.
124+
tags: [default]
125+
parameters:
126+
- description: The UUID of the job.
127+
in: path
128+
name: UUID
129+
required: true
130+
schema:
131+
type: string
132+
responses:
133+
"200":
134+
description: Probability distribution keyed by decimal qubit state.
135+
content:
136+
application/json:
137+
schema:
138+
type: object
139+
additionalProperties:
140+
type: number
141+
"404":
142+
description: Job not found or not yet completed.
143+
security:
144+
- apiKeyAuth: []

0 commit comments

Comments
 (0)