Skip to content

Commit

Permalink
setup isort
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger-luo committed Feb 20, 2025
1 parent e6235e7 commit 134ea7e
Show file tree
Hide file tree
Showing 166 changed files with 1,369 additions and 1,321 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black
rev: 24.10.0
rev: 25.1.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ packages = ["src/bloqade"]
[tool.black]
line-length = 88

[tool.isort]
profile = "black"
combine_as_imports = true
multi_line_output = 3
length_sort = true
src_paths = ["src/bloqade"]

[tool.ruff]
exclude = [
".bzr",
Expand Down
67 changes: 67 additions & 0 deletions src/bloqade-analog/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
try:
__import__("pkg_resources").declare_namespace(__name__)
except ImportError:
__path__ = __import__("pkgutil").extend_path(__path__, __name__)

import importlib.metadata

import bloqade.analog.ir as _ir
from bloqade.analog.ir import (
Literal,
Variable,
var,
cast,
start,
to_waveform as waveform,
)
from bloqade.analog.factory import (
linear,
constant,
rydberg_h,
get_capabilities,
piecewise_linear,
piecewise_constant,
)
from bloqade.analog.constants import RB_C6
from bloqade.analog.serialize import load, save, dumps, loads

__version__ = importlib.metadata.version("bloqade")


def tree_depth(depth: int | None = None):
"""Setting globally maximum depth for tree printing
If `depth=None`, return current depth.
If `depth` is provided, setting current depth to `depth`
Args:
depth (int, optional): the user specified depth. Defaults to None.
Returns:
int: current updated depth
"""
if depth is not None:
_ir.tree_print.MAX_TREE_DEPTH = depth
return _ir.tree_print.MAX_TREE_DEPTH


__all__ = [
"RB_C6",
"start",
"var",
"cast",
"Variable",
"Literal",
"piecewise_linear",
"piecewise_constant",
"linear",
"constant",
"set_print_depth",
"load",
"save",
"loads",
"dumps",
"rydberg_h",
"waveform",
"get_capabilities",
]
27 changes: 16 additions & 11 deletions src/bloqade/__init__.py → src/bloqade/analog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@
except ImportError:
__path__ = __import__("pkgutil").extend_path(__path__, __name__)

from bloqade.ir import var, cast, Variable, Literal, start
from bloqade.ir import to_waveform as waveform
from bloqade.serialize import load, save, loads, dumps
import importlib.metadata

from bloqade.factory import (
get_capabilities,
piecewise_linear,
piecewise_constant,
import bloqade.analog.ir as _ir
from bloqade.analog.ir import (
Literal,
Variable,
var,
cast,
start,
to_waveform as waveform,
)
from bloqade.analog.factory import (
linear,
constant,
rydberg_h,
get_capabilities,
piecewise_linear,
piecewise_constant,
)
import bloqade.ir as _ir
from bloqade.constants import RB_C6

import importlib.metadata
from bloqade.analog.constants import RB_C6
from bloqade.analog.serialize import load, save, dumps, loads

__version__ = importlib.metadata.version("bloqade")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from bloqade.ir.location import (
AtomArrangement,
from bloqade.analog.ir.location import (
Lieb,
Chain,
Kagome,
Square,
Rectangular,
Honeycomb,
Triangular,
Lieb,
Kagome,
Rectangular,
AtomArrangement,
ListOfLocations,
)


__all__ = [
"AtomArrangement",
"Chain",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from beartype import beartype
from beartype.typing import List, Optional, Union
from bloqade.ir.scalar import Variable
from bloqade.builder.base import Builder
from bloqade.builder.pragmas import Parallelizable
from bloqade.builder.backend import BackendRoute
from beartype.typing import List, Union, Optional

from bloqade.analog.ir.scalar import Variable
from bloqade.analog.builder.base import Builder
from bloqade.analog.builder.backend import BackendRoute
from bloqade.analog.builder.pragmas import Parallelizable


class Args(Parallelizable, BackendRoute, Builder):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from itertools import repeat
from beartype.typing import Optional, List, Dict, Set, Sequence, Union
from bloqade.builder.typing import ParamType
from bloqade.builder.base import Builder
from bloqade.builder.pragmas import Parallelizable, AddArgs, BatchAssignable
from bloqade.builder.backend import BackendRoute
from numbers import Real
from decimal import Decimal
from numbers import Real
from itertools import repeat

import numpy as np
from beartype.typing import Set, Dict, List, Union, Optional, Sequence

from bloqade.analog.builder.base import Builder
from bloqade.analog.builder.typing import ParamType
from bloqade.analog.builder.backend import BackendRoute
from bloqade.analog.builder.pragmas import AddArgs, Parallelizable, BatchAssignable


class CastParams:
Expand Down Expand Up @@ -69,7 +71,7 @@ class Assign(BatchAssignable, AddArgs, Parallelizable, BackendRoute, AssignBase)
def __init__(
self, assignments: Dict[str, ParamType], parent: Optional[Builder] = None
) -> None:
from bloqade.compiler.analysis.common.scan_variables import ScanVariables
from bloqade.analog.compiler.analysis.common.scan_variables import ScanVariables

super().__init__(parent)

Expand All @@ -85,7 +87,7 @@ class BatchAssign(AddArgs, Parallelizable, BackendRoute, AssignBase):
def __init__(
self, assignments: Dict[str, List[ParamType]], parent: Optional[Builder] = None
) -> None:
from bloqade.compiler.analysis.common.scan_variables import ScanVariables
from bloqade.analog.compiler.analysis.common.scan_variables import ScanVariables

super().__init__(parent)

Expand Down Expand Up @@ -120,7 +122,7 @@ def __init__(
batch_params: Sequence[Dict[str, ParamType]],
parent: Optional[Builder] = None,
) -> None:
from bloqade.compiler.analysis.common.scan_variables import ScanVariables
from bloqade.analog.compiler.analysis.common.scan_variables import ScanVariables

super().__init__(parent)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from bloqade.builder.backend.quera import QuEraService
from bloqade.builder.backend.braket import BraketService
from bloqade.builder.backend.bloqade import BloqadeService
from bloqade.analog.builder.backend.quera import QuEraService
from bloqade.analog.builder.backend.braket import BraketService
from bloqade.analog.builder.backend.bloqade import BloqadeService


class BackendRoute(QuEraService, BraketService, BloqadeService):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from bloqade.builder.base import Builder
from bloqade.analog.builder.base import Builder


class BloqadeService(Builder):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from beartype.typing import TYPE_CHECKING
from bloqade.builder.base import Builder

from bloqade.analog.builder.base import Builder

if TYPE_CHECKING:
from bloqade.ir.routine.braket import (
from bloqade.analog.ir.routine.braket import (
BraketHardwareRoutine,
BraketLocalEmulatorRoutine,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Optional
from bloqade.builder.base import Builder

from bloqade.analog.builder.base import Builder


class QuEraService(Builder):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional, Union, List
from typing import List, Union, Optional
from numbers import Real

from bloqade.builder.parse.trait import Parse, Show
from bloqade.analog.builder.parse.trait import Show, Parse

ParamType = Union[Real, List[Real]]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from bloqade.builder.base import Builder
from bloqade.builder.field import Rabi, Detuning
from bloqade.analog.builder.base import Builder
from bloqade.analog.builder.field import Rabi, Detuning


class LevelCoupling(Builder):
@property
def detuning(self) -> Detuning:
"""
Specify the [`Detuning`][bloqade.builder.field.Detuning] [`Field`][bloqade.builder.field.Field] of your program.
Specify the [`Detuning`][bloqade.analog.builder.field.Detuning] [`Field`][bloqade.analog.builder.field.Field] of your program.
You will be able to specify the spatial modulation afterwards.
Args:
None
Returns:
[`Detuning`][bloqade.builder.field.Detuning]: A program node representing the detuning field.
[`Detuning`][bloqade.analog.builder.field.Detuning]: A program node representing the detuning field.
Note:
The detuning specifies how off-resonant the laser being applied to the atoms is from the atomic energy transition, driven by the Rabi frequency.
Expand All @@ -28,18 +28,18 @@ def detuning(self) -> Detuning:
- Next Possible Steps
You may continue building your program via:
- [`uniform`][bloqade.builder.field.Detuning.uniform]: To address all atoms in the field
- [`location(locations, scales)`][bloqade.builder.field.Detuning.location]: To address atoms at specific
- [`uniform`][bloqade.analog.builder.field.Detuning.uniform]: To address all atoms in the field
- [`location(locations, scales)`][bloqade.analog.builder.field.Detuning.location]: To address atoms at specific
locations via indices
- [`scale(coeffs)`][bloqade.builder.field.Detuning.scale]: To address all atoms with an individual scale factor
- [`scale(coeffs)`][bloqade.analog.builder.field.Detuning.scale]: To address all atoms with an individual scale factor
"""

return Detuning(self)

@property
def rabi(self) -> Rabi:
"""
Specify the complex-valued [`Rabi`][bloqade.builder.field.Rabi]
Specify the complex-valued [`Rabi`][bloqade.analog.builder.field.Rabi]
field of your program.
The Rabi field is composed of a real-valued Amplitude and Phase field.
Expand Down Expand Up @@ -68,18 +68,18 @@ class Rydberg(LevelCoupling):
Examples:
- To reach the node from the start node:
>>> node = bloqade.start.rydberg
>>> from bloqade.analog import start
>>> node = start.rydberg
>>> type(node)
<class 'bloqade.builder.coupling.Rydberg'>
<class 'bloqade.analog.builder.coupling.Rydberg'>
- Rydberg level coupling has two reachable field nodes:
- detuning term (See also [`Detuning`][bloqade.builder.field.Detuning])
- rabi term (See also [`Rabi`][bloqade.builder.field.Rabi])
- detuning term (See also [`Detuning`][bloqade.analog.builder.field.Detuning])
- rabi term (See also [`Rabi`][bloqade.analog.builder.field.Rabi])
>>> ryd_detune = bloqade.start.rydberg.detuning
>>> ryd_rabi = bloqade.start.rydberg.rabi
>>> ryd_detune = start.rydberg.detuning
>>> ryd_rabi = start.rydberg.rabi
"""

def __bloqade_ir__(self):
Expand All @@ -98,7 +98,7 @@ def __bloqade_ir__(self):
Note:
This method is used internally by the Bloqade framework.
"""
from bloqade.ir.control.sequence import rydberg
from bloqade.analog.ir.control.sequence import rydberg

return rydberg

Expand All @@ -110,18 +110,18 @@ class Hyperfine(LevelCoupling):
Examples:
- To reach the node from the start node:
>>> node = bloqade.start.hyperfine
>>> from bloqade.analog import start
>>> node = start.hyperfine
>>> type(node)
<class 'bloqade.builder.coupling.Hyperfine'>
<class 'bloqade.analog.builder.coupling.Hyperfine'>
- Hyperfine level coupling has two reachable field nodes:
- detuning term (See also [`Detuning`][bloqade.builder.field.Detuning])
- rabi term (See also [`Rabi`][bloqade.builder.field.Rabi])
- detuning term (See also [`Detuning`][bloqade.analog.builder.field.Detuning])
- rabi term (See also [`Rabi`][bloqade.analog.builder.field.Rabi])
>>> hyp_detune = bloqade.start.hyperfine.detuning
>>> hyp_rabi = bloqade.start.hyperfine.rabi
>>> hyp_detune = start.hyperfine.detuning
>>> hyp_rabi = start.hyperfine.rabi
"""

def __bloqade_ir__(self):
Expand All @@ -140,6 +140,6 @@ def __bloqade_ir__(self):
Note:
This method is used internally by the Bloqade framework.
"""
from bloqade.ir.control.sequence import hyperfine
from bloqade.analog.ir.control.sequence import hyperfine

return hyperfine
Loading

0 comments on commit 134ea7e

Please sign in to comment.