1
+ """Helper functions related to IR submission
2
+ co-ordinations between Bloqade and Braket"""
3
+
1
4
import braket .ir .ahs as braket_ir
2
5
from braket .ahs .pattern import Pattern
3
6
from braket .timings import TimeSeries
6
9
from braket .ahs .driving_field import DrivingField
7
10
from braket .ahs .shifting_field import ShiftingField
8
11
from braket .ahs .field import Field
9
-
10
12
from braket .task_result import AnalogHamiltonianSimulationTaskResult
13
+
14
+ import bloqade .submission .ir .capabilities as cp
11
15
from bloqade .submission .ir .task_results import (
12
16
QuEraTaskResults ,
13
17
QuEraTaskStatusCode ,
14
18
QuEraShotResult ,
15
19
QuEraShotStatusCode ,
16
20
)
17
-
18
21
from bloqade .submission .ir .task_specification import (
19
22
QuEraTaskSpecification ,
20
23
GlobalField ,
21
24
LocalField ,
22
25
)
26
+
23
27
from typing import Tuple , Union , List
24
28
from pydantic .v1 import BaseModel
25
29
from decimal import Decimal
26
30
27
31
28
32
class BraketTaskSpecification (BaseModel ):
33
+ """Class representing geometry of an atom arrangement.
34
+
35
+ Attributes:
36
+ nshots (int): Number of shots
37
+ program (braket_ir.Program): IR(Intermediate Representation)
38
+ program suitable for braket
39
+ """
40
+
29
41
nshots : int
30
42
program : braket_ir .Program
31
43
32
44
33
45
def to_braket_time_series (times : List [Decimal ], values : List [Decimal ]) -> TimeSeries :
46
+ """Converts to `TimeSeries` object supported by Braket.
47
+
48
+ Args:
49
+ times (List[Decimal]): Times of the value.
50
+ values (List[Decimal]): Corresponding values to add to the time series
51
+
52
+ Returns:
53
+ An object of the type `braket.timings.TimeSeries`
54
+ """
34
55
time_series = TimeSeries ()
35
56
for time , value in zip (times , values ):
36
57
time_series .put (time , value )
@@ -39,6 +60,18 @@ def to_braket_time_series(times: List[Decimal], values: List[Decimal]) -> TimeSe
39
60
40
61
41
62
def to_braket_field (quera_field : Union [GlobalField , LocalField ]) -> Field :
63
+ """Converts to `TimeSeries` object supported by Braket.
64
+
65
+ Args:
66
+ quera_field (Union[GlobalField, LocalField)]:
67
+ Field supported by Quera
68
+
69
+ Returns:
70
+ An object of the type `braket.ahs.field.Field`
71
+
72
+ Raises:
73
+ TypeError: If field is not of the type `GlobalField` or `LocalField`.
74
+ """
42
75
if isinstance (quera_field , GlobalField ):
43
76
times = quera_field .times
44
77
values = quera_field .values
@@ -56,6 +89,12 @@ def to_braket_field(quera_field: Union[GlobalField, LocalField]) -> Field:
56
89
57
90
58
91
def extract_braket_program (quera_task_ir : QuEraTaskSpecification ):
92
+ """Extracts the Braket program.
93
+
94
+ Args:
95
+ quera_task_ir (QuEraTaskSpecification):
96
+ Quera IR(Intermediate representation) of the task.
97
+ """
59
98
lattice = quera_task_ir .lattice
60
99
61
100
rabi_amplitude = (
@@ -90,18 +129,47 @@ def extract_braket_program(quera_task_ir: QuEraTaskSpecification):
90
129
def to_braket_task (
91
130
quera_task_ir : QuEraTaskSpecification ,
92
131
) -> Tuple [int , AnalogHamiltonianSimulation ]:
132
+ """Converts to `Tuple[int, AnalogHamiltonianSimulation]` object supported by Braket.
133
+
134
+ Args:
135
+ quera_task_ir (QuEraTaskSpecification):
136
+ Quera IR(Intermediate representation) of the task.
137
+
138
+ Returns:
139
+ An tuple of the type `Tuple[int, AnalogHamiltonianSimulation]`.
140
+ """
93
141
braket_ahs_program = extract_braket_program (quera_task_ir )
94
142
return quera_task_ir .nshots , braket_ahs_program
95
143
96
144
97
145
def to_braket_task_ir (quera_task_ir : QuEraTaskSpecification ) -> BraketTaskSpecification :
146
+ """Converts quera IR(Intermendiate Representation) to
147
+ to `BraketTaskSpecification` object.
148
+
149
+ Args:
150
+ quera_task_ir (QuEraTaskSpecification):
151
+ Quera IR(Intermediate representation) of the task.
152
+
153
+ Returns:
154
+ An object of the type `BraketTaskSpecification` in Braket SDK
155
+
156
+ """
98
157
nshots , braket_ahs_program = to_braket_task (quera_task_ir )
99
158
return BraketTaskSpecification (nshots = nshots , program = braket_ahs_program .to_ir ())
100
159
101
160
102
161
def from_braket_task_results (
103
162
braket_task_results : AnalogHamiltonianSimulationTaskResult ,
104
163
) -> QuEraTaskResults :
164
+ """Get the `QuEraTaskResults` object for working with Bloqade SDK.
165
+
166
+ Args:
167
+ braket_task_results: AnalogHamiltonianSimulationTaskResult
168
+ Quantum task result of braket system
169
+
170
+ Returns:
171
+ An object of the type `Field` in Braket SDK.
172
+ """
105
173
shot_outputs = []
106
174
for measurement in braket_task_results .measurements :
107
175
shot_outputs .append (
@@ -117,16 +185,34 @@ def from_braket_task_results(
117
185
)
118
186
119
187
120
- def from_braket_status_codes (braket_message : str ) -> QuEraTaskStatusCode :
121
- if braket_message == str ("QUEUED" ):
188
+ def from_braket_status_codes (braket_status : str ) -> QuEraTaskStatusCode :
189
+ """Gets the `QuEraTaskStatusCode` object for working with Bloqade SDK.
190
+
191
+ Args:
192
+ braket_status: str
193
+ The value of status in metadata() in the Amazon Braket.
194
+ `GetQuantumTask` operation. If `use_cached_value` is `True`,
195
+ the value most recently returned from
196
+ `GetQuantumTask` operation is used
197
+
198
+ Returns:
199
+ An object of the type `Field` in Braket SDK
200
+ """
201
+ if braket_status == str ("QUEUED" ):
122
202
return QuEraTaskStatusCode .Enqueued
123
203
else :
124
- return QuEraTaskStatusCode (braket_message .lower ().capitalize ())
204
+ return QuEraTaskStatusCode (braket_status .lower ().capitalize ())
205
+
125
206
207
+ def to_quera_capabilities (paradigm ) -> cp .QuEraCapabilities :
208
+ """Converts to `QuEraCapabilities` object supported by Braket.
126
209
127
- def to_quera_capabilities ( paradigm ) :
128
- import bloqade . submission . ir . capabilities as cp
210
+ Args :
211
+ paradigm: The `paradigm` property of the `AwsDevice` object for Aquila
129
212
213
+ Returns:
214
+ An object of the type `QuEraCapabilities` in Bloqade SDK.
215
+ """
130
216
rydberg_global = paradigm .rydberg .rydbergGlobal
131
217
132
218
return cp .QuEraCapabilities (
0 commit comments