Skip to content

Commit f2f6ee1

Browse files
authored
Add ability to use experimental capabilities in program submission (#967)
* Add ability to use experimental capabilities in run and run_async * immediately return saved experimental capabilities instead of remotely fetching * Fix old typos * add experimental flag to __call__ and mock * lint * Fix failing tests * Fix lint
1 parent aada63a commit f2f6ee1

File tree

5 files changed

+32
-17
lines changed

5 files changed

+32
-17
lines changed

src/bloqade/ir/routine/braket.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class BraketHardwareRoutine(RoutineBase):
3434
def _compile(
3535
self,
3636
shots: int,
37+
use_experimental: bool = False,
3738
args: Tuple[LiteralType, ...] = (),
3839
name: Optional[str] = None,
3940
) -> RemoteBatch:
@@ -47,7 +48,7 @@ def _compile(
4748
generate_quera_ir,
4849
)
4950

50-
capabilities = self.backend.get_capabilities()
51+
capabilities = self.backend.get_capabilities(use_experimental)
5152

5253
circuit, params = self.circuit, self.params
5354

@@ -85,6 +86,7 @@ def run_async(
8586
shots: int,
8687
args: Tuple[LiteralType, ...] = (),
8788
name: Optional[str] = None,
89+
use_experimental: bool = False,
8890
shuffle: bool = False,
8991
**kwargs,
9092
) -> RemoteBatch:
@@ -99,14 +101,15 @@ def run_async(
99101
shots (int): number of shots
100102
args (Tuple): Values of the parameter defined in `args`, defaults to ()
101103
name (str | None): custom name of the batch, defaults to None
104+
use_experimental (bool): Use experimental hardware capabilities
102105
shuffle (bool): shuffle the order of jobs
103106
104107
Return:
105108
RemoteBatch
106109
107110
"""
108111

109-
batch = self._compile(shots, args, name)
112+
batch = self._compile(shots, use_experimental, args, name)
110113
batch._submit(shuffle, **kwargs)
111114
return batch
112115

@@ -116,6 +119,7 @@ def run(
116119
shots: int,
117120
args: Tuple[LiteralType, ...] = (),
118121
name: Optional[str] = None,
122+
use_experimental: bool = False,
119123
shuffle: bool = False,
120124
**kwargs,
121125
) -> RemoteBatch:
@@ -139,7 +143,7 @@ def run(
139143
140144
"""
141145

142-
batch = self.run_async(shots, args, name, shuffle, **kwargs)
146+
batch = self.run_async(shots, args, name, use_experimental, shuffle, **kwargs)
143147
batch.pull()
144148
return batch
145149

@@ -149,6 +153,7 @@ def __call__(
149153
*args: LiteralType,
150154
shots: int = 1,
151155
name: Optional[str] = None,
156+
use_experimental: bool = False,
152157
shuffle: bool = False,
153158
**kwargs,
154159
):
@@ -171,7 +176,7 @@ def __call__(
171176
RemoteBatch
172177
173178
"""
174-
return self.run(shots, args, name, shuffle, **kwargs)
179+
return self.run(shots, args, name, use_experimental, shuffle, **kwargs)
175180

176181

177182
@dataclass(frozen=True, config=__pydantic_dataclass_config__)

src/bloqade/ir/routine/quera.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class CustomSubmissionRoutine(RoutineBase):
5252
def _compile(
5353
self,
5454
shots: int,
55+
use_experimental: bool = False,
5556
args: Tuple[LiteralType, ...] = (),
5657
):
5758
from bloqade.compiler.passes.hardware import (
@@ -65,7 +66,7 @@ def _compile(
6566
from bloqade.submission.capabilities import get_capabilities
6667

6768
circuit, params = self.circuit, self.params
68-
capabilities = get_capabilities()
69+
capabilities = get_capabilities(use_experimental)
6970

7071
for batch_params in params.batch_assignments(*args):
7172
assignments = {**batch_params, **params.static_params}
@@ -92,6 +93,7 @@ def submit(
9293
method: str = "POST",
9394
args: Tuple[LiteralType] = (),
9495
request_options: Dict[str, Any] = {},
96+
use_experimental: bool = False,
9597
sleep_time: float = 0.1,
9698
) -> List[Tuple[NamedTuple, Response]]:
9799
"""Compile to QuEraTaskSpecification and submit to a custom service.
@@ -110,6 +112,7 @@ def submit(
110112
request_options: additional options to be passed into the request method,
111113
Note the `data` option will be overwritten by the
112114
`json_body_template.format(task_ir=task_ir_string)`.
115+
use_experimental (bool): Enable experimental hardware capabilities
113116
sleep_time (float): time to sleep between each request. Defaults to 0.1.
114117
115118
Returns:
@@ -147,7 +150,7 @@ def submit(
147150
)
148151

149152
out = []
150-
for metadata, task_ir in self._compile(shots, args):
153+
for metadata, task_ir in self._compile(shots, use_experimental, args):
151154
json_request_body = json_body_template.format(
152155
task_ir=task_ir.json(exclude_none=True, exclude_unset=True)
153156
)
@@ -166,6 +169,7 @@ class QuEraHardwareRoutine(RoutineBase):
166169
def _compile(
167170
self,
168171
shots: int,
172+
use_experimental: bool = False,
169173
args: Tuple[LiteralType, ...] = (),
170174
name: Optional[str] = None,
171175
) -> RemoteBatch:
@@ -179,7 +183,7 @@ def _compile(
179183
)
180184

181185
circuit, params = self.circuit, self.params
182-
capabilities = self.backend.get_capabilities()
186+
capabilities = self.backend.get_capabilities(use_experimental)
183187

184188
tasks = OrderedDict()
185189

@@ -215,6 +219,7 @@ def run_async(
215219
shots: int,
216220
args: Tuple[LiteralType, ...] = (),
217221
name: Optional[str] = None,
222+
use_experimental: bool = False,
218223
shuffle: bool = False,
219224
**kwargs,
220225
) -> RemoteBatch:
@@ -233,7 +238,7 @@ def run_async(
233238
RemoteBatch
234239
235240
"""
236-
batch = self._compile(shots, args, name)
241+
batch = self._compile(shots, use_experimental, args, name)
237242
batch._submit(shuffle, **kwargs)
238243
return batch
239244

@@ -243,10 +248,11 @@ def run(
243248
shots: int,
244249
args: Tuple[LiteralType, ...] = (),
245250
name: Optional[str] = None,
251+
use_experimental: bool = False,
246252
shuffle: bool = False,
247253
**kwargs,
248254
) -> RemoteBatch:
249-
batch = self.run_async(shots, args, name, shuffle, **kwargs)
255+
batch = self.run_async(shots, args, name, use_experimental, shuffle, **kwargs)
250256
batch.pull()
251257
return batch
252258

@@ -256,7 +262,8 @@ def __call__(
256262
*args: LiteralType,
257263
shots: int = 1,
258264
name: Optional[str] = None,
265+
use_experimental: bool = False,
259266
shuffle: bool = False,
260267
**kwargs,
261268
) -> RemoteBatch:
262-
return self.run(shots, args, name, shuffle, **kwargs)
269+
return self.run(shots, args, name, use_experimental, shuffle, **kwargs)

src/bloqade/submission/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class SubmissionBackend(BaseModel):
1515
class Config:
1616
extra = Extra.forbid
1717

18-
def get_capabilities(self) -> QuEraCapabilities:
19-
return get_capabilities()
18+
def get_capabilities(self, use_experimental: bool = False) -> QuEraCapabilities:
19+
return get_capabilities(use_experimental)
2020

2121
def validate_task(
2222
self, task_ir: Union[BraketTaskSpecification, QuEraTaskSpecification]

src/bloqade/submission/braket.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,23 @@ def device(self) -> AwsDevice:
3131

3232
return self._device
3333

34-
def get_capabilities(self) -> QuEraCapabilities:
34+
def get_capabilities(self, use_experimental: bool = False) -> QuEraCapabilities:
3535
from botocore.exceptions import BotoCoreError, ClientError
3636

37+
if use_experimental:
38+
return super().get_capabilities(use_experimental)
39+
3740
try:
3841
return to_quera_capabilities(self.device.properties.paradigm)
3942
except BotoCoreError:
4043
warnings.warn(
4144
"Could not retrieve device capabilities from braket API. "
42-
"Using local capabiltiiies file for Aquila."
45+
"Using local capabilities file for Aquila."
4346
)
4447
except ClientError:
4548
warnings.warn(
4649
"Could not retrieve device capabilities from braket API. "
47-
"Using local capabiltiiies file for Aquila."
50+
"Using local capabilities file for Aquila."
4851
)
4952

5053
return super().get_capabilities()

src/bloqade/submission/quera.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ def queue_api(self):
4141

4242
return self._queue_api
4343

44-
def get_capabilities(self) -> QuEraCapabilities:
44+
def get_capabilities(self, use_experimental: bool = False) -> QuEraCapabilities:
4545
try:
4646
return QuEraCapabilities(**self.queue_api.get_capabilities())
4747
except BaseException:
48-
return super().get_capabilities()
48+
return super().get_capabilities(use_experimental)
4949

5050
def submit_task(self, task_ir: QuEraTaskSpecification) -> str:
5151
return self.queue_api.submit_task(

0 commit comments

Comments
 (0)