Skip to content

Commit 3186be0

Browse files
authored
Merge branch 'main' into uh/submission-ir-task_result
2 parents 171080c + de8013e commit 3186be0

File tree

9 files changed

+559
-381
lines changed

9 files changed

+559
-381
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.5.0
5+
rev: v4.6.0
66
hooks:
77
- id: check-yaml
88
args: ['--unsafe']
99
- id: end-of-file-fixer
1010
- id: trailing-whitespace
1111
- repo: https://github.com/psf/black
12-
rev: 24.1.0
12+
rev: 24.4.2
1313
hooks:
1414
- id: black
1515
- repo: https://github.com/charliermarsh/ruff-pre-commit
1616
# Ruff version.
17-
rev: "v0.0.264"
17+
rev: "v0.5.5"
1818
hooks:
1919
- id: ruff

docs/home/quick_start.md

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,25 @@ As you develop your Bloqade program, you are expected to rely on pop-up "hints"
1010

1111
In [VS Code](https://code.visualstudio.com/) this is automatic, just type the `.` and see what options pop up:
1212

13-
<div align="center">
14-
<picture>
15-
<img src="/assets/quick_start/vscode-hints.gif" alt="VSCode Hints">
16-
</picture>
17-
</div>
13+
![VSCode Hints](../assets/quick_start/vscode-hints.gif)
1814

1915
### JetBrains PyCharm
2016

2117
The same goes for [JetBrains PyCharm](https://www.jetbrains.com/pycharm/):
2218

23-
<div align="center">
24-
<picture>
25-
<img src="/assets/quick_start/pycharm-hints.gif" alt="PyCharm Hints">
26-
</picture>
27-
</div>
19+
![PyCharm Hints](../assets/quick_start/pycharm-hints.gif)
2820

2921
### Jupyter Notebook
3022

3123
In a [Jupyter Notebook](https://jupyter.org/) you'll need to type `.` and then hit tab for the hints to appear:
3224

33-
<div align="center">
34-
<picture>
35-
<img src="/assets/quick_start/jupyter-hints.gif" alt="Jupyter Notebook Hints">
36-
</picture>
37-
</div>
25+
![Jupyter Hints](../assets/quick_start/jupyter-hints.gif)
3826

3927
### IPython
4028

4129
The same goes for [IPython](https://ipython.readthedocs.io/en/stable/):
4230

43-
<div align="center">
44-
<picture>
45-
<img src="/assets/quick_start/ipython-hints.gif" alt="IPython Hints">
46-
</picture>
47-
</div>
31+
![IPython Hints](../assets/quick_start/ipython-hints.gif)
4832

4933
## Defining Atom Geometry
5034

@@ -62,11 +46,10 @@ You can easily visualize your geometries as well with `.show()`:
6246
```python
6347
more_complex_geometry.show()
6448
```
65-
<div align="center">
66-
<picture>
67-
<img src="/assets/quick_start/geometry-visualization.png" style="width: 50%" alt="Geometry Visualization">
68-
</picture>
69-
</div>
49+
<figure markdown="span">
50+
![IPython Hints](../assets/quick_start/geometry-visualization.png){ width="50%" }
51+
</figure>
52+
7053

7154
You can also add positions to a pre-defined geometry:
7255

pdm.lock

Lines changed: 314 additions & 321 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bloqade/emulate/ir/state_vector.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,20 @@ def tocsr(self, time: float) -> csr_matrix:
298298

299299
@dataclass(frozen=True)
300300
class RydbergHamiltonian:
301+
"""Hamiltonian for a given task.
302+
With the `RydbergHamiltonian` you can convert the Hamiltonian to CSR matrix form
303+
as well as obtaining the average energy/variance of a register.
304+
305+
Attributes:
306+
emulator_ir (EmulatorProgram): A copy of the original program
307+
used to generate the RydbergHamiltonian
308+
space (Space): The Hilbert space of the Hamiltonian, should align with the register the
309+
Hamiltonian is being applied on for average energy/variance
310+
rydberg (NDArray): Rydberg interaction operator
311+
detuning_ops (List[DetuningOperator]): Detuning Operators of the Hamiltonian
312+
rabi_ops (List[RabiOperator]): Rabi Operators of the Hamiltonian
313+
"""
314+
301315
emulator_ir: EmulatorProgram
302316
space: Space
303317
rydberg: NDArray

src/bloqade/ir/routine/bloqade.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,31 @@ def hamiltonian(
503503
waveform_runtime: str = "interpret",
504504
cache_matrices: bool = False,
505505
) -> List[BloqadeEmulation]:
506+
"""
507+
Generates a list of BloqadeEmulation objects which contain the Hamiltonian of your program.
508+
509+
If you have a variable(s) in your program you have assigned multiple values via `batch_assign()`
510+
there will be multiple `BloqadeEmulation` objects, one for each value. On the other hand
511+
if the program only assumes a singular value per each variable, there will only be
512+
one `BloqadeEmulation` object but it will still be encapsulated in a list.
513+
514+
515+
Args:
516+
*args (LiteralType): If your program has a variable that was declared as run-time assignable
517+
via `.args` you may pass a value to it here. If there are multiple
518+
variables declared via `.args` the order in which you assign values to those variables
519+
through this argument should follow the order in which the declaration occurred.
520+
blockade_radius (float): The radius in which atoms blockade eachother. Default value is 0.0 micrometers.
521+
use_hyperfine (bool): Should the Hamiltonian account for hyperfine levels. Default value is False.
522+
waveform_runtime (str): Specify which runtime to use for waveforms. If "numba" is specify the waveform
523+
is compiled, otherwise it is interpreted via the "interpret" argument. Defaults to "interpret".
524+
cache_matrices (bool): Speed up Hamiltonian generation by reusing data (when possible) from previously generated Hamiltonians.
525+
Default value is False.
526+
527+
Returns:
528+
List[BloqadeEmulation]
506529
530+
"""
507531
ir_iter = self._generate_ir(
508532
args, blockade_radius, waveform_runtime, use_hyperfine
509533
)

src/bloqade/submission/ir/braket.py

Lines changed: 93 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""Helper functions related to IR submission
2+
co-ordinations between Bloqade and Braket"""
3+
14
import braket.ir.ahs as braket_ir
25
from braket.ahs.pattern import Pattern
36
from braket.timings import TimeSeries
@@ -6,31 +9,49 @@
69
from braket.ahs.driving_field import DrivingField
710
from braket.ahs.shifting_field import ShiftingField
811
from braket.ahs.field import Field
9-
1012
from braket.task_result import AnalogHamiltonianSimulationTaskResult
13+
14+
import bloqade.submission.ir.capabilities as cp
1115
from bloqade.submission.ir.task_results import (
1216
QuEraTaskResults,
1317
QuEraTaskStatusCode,
1418
QuEraShotResult,
1519
QuEraShotStatusCode,
1620
)
17-
1821
from bloqade.submission.ir.task_specification import (
1922
QuEraTaskSpecification,
2023
GlobalField,
2124
LocalField,
2225
)
26+
2327
from typing import Tuple, Union, List
2428
from pydantic.v1 import BaseModel
2529
from decimal import Decimal
2630

2731

2832
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+
2941
nshots: int
3042
program: braket_ir.Program
3143

3244

3345
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+
"""
3455
time_series = TimeSeries()
3556
for time, value in zip(times, values):
3657
time_series.put(time, value)
@@ -39,6 +60,18 @@ def to_braket_time_series(times: List[Decimal], values: List[Decimal]) -> TimeSe
3960

4061

4162
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+
"""
4275
if isinstance(quera_field, GlobalField):
4376
times = quera_field.times
4477
values = quera_field.values
@@ -56,6 +89,12 @@ def to_braket_field(quera_field: Union[GlobalField, LocalField]) -> Field:
5689

5790

5891
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+
"""
5998
lattice = quera_task_ir.lattice
6099

61100
rabi_amplitude = (
@@ -90,18 +129,47 @@ def extract_braket_program(quera_task_ir: QuEraTaskSpecification):
90129
def to_braket_task(
91130
quera_task_ir: QuEraTaskSpecification,
92131
) -> 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+
"""
93141
braket_ahs_program = extract_braket_program(quera_task_ir)
94142
return quera_task_ir.nshots, braket_ahs_program
95143

96144

97145
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+
"""
98157
nshots, braket_ahs_program = to_braket_task(quera_task_ir)
99158
return BraketTaskSpecification(nshots=nshots, program=braket_ahs_program.to_ir())
100159

101160

102161
def from_braket_task_results(
103162
braket_task_results: AnalogHamiltonianSimulationTaskResult,
104163
) -> 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+
"""
105173
shot_outputs = []
106174
for measurement in braket_task_results.measurements:
107175
shot_outputs.append(
@@ -117,16 +185,34 @@ def from_braket_task_results(
117185
)
118186

119187

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"):
122202
return QuEraTaskStatusCode.Enqueued
123203
else:
124-
return QuEraTaskStatusCode(braket_message.lower().capitalize())
204+
return QuEraTaskStatusCode(braket_status.lower().capitalize())
205+
125206

207+
def to_quera_capabilities(paradigm) -> cp.QuEraCapabilities:
208+
"""Converts to `QuEraCapabilities` object supported by Braket.
126209
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
129212
213+
Returns:
214+
An object of the type `QuEraCapabilities` in Bloqade SDK.
215+
"""
130216
rydberg_global = paradigm.rydberg.rydbergGlobal
131217

132218
return cp.QuEraCapabilities(

0 commit comments

Comments
 (0)