types
Grid dataclass
Grid(
x_spacing: tuple[float, ...],
y_spacing: tuple[float, ...],
x_init: float | None,
y_init: float | None,
)
Bases: Data['Grid']
, Generic[NumX, NumY]
height cached
property
height
Height of the grid, which is the sum of y_spacing
.
positions cached
property
positions: IList[tuple[float, float], Any]
All positions in the grid as a list of tuples (x, y) in lexicographic order.
shape cached
property
shape: tuple[int, int]
Shape of the grid, which is (num_x, num_y).
Note
if x_init or y_init is None, num_x or num_y will be 0 respectively.
width cached
property
width
Width of the grid, which is the sum of x_spacing
.
x_init instance-attribute
x_init: float | None
The initial x position of the grid, or None if not set.
x_positions cached
property
x_positions: tuple[float, ...]
X positions of the grid.
Note
If x_init
is None, returns an empty tuple.
x_spacing instance-attribute
x_spacing: tuple[float, ...]
A tuple of x spacings between grid points.
y_init instance-attribute
y_init: float | None
The initial y position of the grid, or None if not set.
y_positions cached
property
y_positions: tuple[float, ...]
Y positions of the grid.
Note
If y_init
is None, returns an empty tuple.
y_spacing instance-attribute
y_spacing: tuple[float, ...]
A tuple of y spacings between grid points.
from_positions classmethod
from_positions(
x_positions: Sequence[float],
y_positions: Sequence[float],
)
Create a grid from sequence of x and y positions.
Args:
x_positions (Sequence[float]): The x positions.
y_positions (Sequence[float]): The y positions.
Returns:
Name | Type | Description |
---|---|---|
Grid | A grid object with the specified x and y positions. |
Source code in src/bloqade/geometry/dialects/grid/types.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
get
get(idx: tuple[int, int]) -> tuple[float, float]
Get the (x, y) position at the specified grid index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx | tuple[int, int] | The (x, y) index in the grid. | required |
Returns:
Type | Description |
---|---|
tuple[float, float] | tuple[float, float]: The (x, y) position in the grid. |
Source code in src/bloqade/geometry/dialects/grid/types.py
194 195 196 197 198 199 200 201 202 203 |
|
get_view
get_view(
x_indices: IList[int, Nx], y_indices: IList[int, Ny]
) -> Grid[Nx, Ny]
Get a sub-grid view based on the specified x and y indices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_indices | IList[int, Nx] | The x indices to include in the sub-grid. | required |
y_indices | IList[int, Ny] | The y indices to include in the sub-grid. | required |
Returns:
Type | Description |
---|---|
Grid[Nx, Ny] | Grid[Nx, Ny]: The sub-grid view. |
Source code in src/bloqade/geometry/dialects/grid/types.py
208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
is_equal
is_equal(other: Any) -> bool
Check if two grid geometry are equal.
Source code in src/bloqade/geometry/dialects/grid/types.py
62 63 64 65 66 67 68 69 70 71 |
|
repeat
repeat(
x_times: int, y_times: int, x_gap: float, y_gap: float
) -> Grid[NumX, NumY]
Repeat the grid in both x and y directions with specified gaps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_times | int | The number of times to repeat the grid in the x direction. | required |
y_times | int | The number of times to repeat the grid in the y direction. | required |
x_gap | float | The gap between repeated grids in the x direction. | required |
y_gap | float | The gap between repeated grids in the y direction. | required |
Returns:
Type | Description |
---|---|
Grid[NumX, NumY] | Grid[NumX, NumY]: A new grid with the specified repetitions and gaps. |
Source code in src/bloqade/geometry/dialects/grid/types.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
scale
scale(x_scale: float, y_scale: float) -> Grid[NumX, NumY]
Scale the grid spacings by the specified x and y factors with fixed x and y initial positions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_scale | float | The scaling factor for the x spacings. | required |
y_scale | float | The scaling factor for the y spacings. | required |
Returns:
Type | Description |
---|---|
Grid[NumX, NumY] | Grid[NumX, NumY]: A new grid with scaled x and y spacings |
Source code in src/bloqade/geometry/dialects/grid/types.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
set_init
set_init(
x_init: float | None, y_init: float | None
) -> Grid[NumX, NumY]
Set the initial positions of the grid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_init | float | None | The new initial x position. If None, the grid will not have an initial x position. | required |
y_init | float | None | The new initial y position. If None, the grid will not have an initial y position. | required |
Returns:
Type | Description |
---|---|
Grid[NumX, NumY] | Grid[NumX, NumY]: A new grid with the specified initial positions. |
Source code in src/bloqade/geometry/dialects/grid/types.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
|
shift
shift(x_shift: float, y_shift: float) -> Grid[NumX, NumY]
Shift the grid by the specified x and y amounts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_shift | float | The amount to shift the grid in the x direction. | required |
y_shift | float | The amount to shift the grid in the y direction. | required |
Returns:
Type | Description |
---|---|
Grid[NumX, NumY] | Grid[NumX, NumY]: A new grid with the specified shifts applied to the initial positions. |
Source code in src/bloqade/geometry/dialects/grid/types.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
x_bounds
x_bounds()
X bounds of the grid, which is (x_init, x_init + width)
.
Raises:
Type | Description |
---|---|
ValueError | If x_init is None, cannot compute bounds. |
Source code in src/bloqade/geometry/dialects/grid/types.py
130 131 132 133 134 135 136 137 138 139 140 |
|
y_bounds
y_bounds()
Y bounds of the grid, which is (y_init, y_init + height)
.
Raises:
Type | Description |
---|---|
ValueError | If y_init is None, cannot compute bounds. |
Source code in src/bloqade/geometry/dialects/grid/types.py
142 143 144 145 146 147 148 149 150 151 152 |
|
SubGrid dataclass
SubGrid(
x_spacing: tuple[float, ...],
y_spacing: tuple[float, ...],
x_init: float | None,
y_init: float | None,
parent: Grid[Any, Any],
x_indices: IList[int, NumX],
y_indices: IList[int, NumY],
)
Bases: Grid[NumX, NumY]
A sub-grid view of a parent grid with specified x and y indices.
For API documentation see the Grid
class.
x_init class-attribute
instance-attribute
x_init: float | None = field(init=False)
The initial x position of the grid, or None if not set.
x_spacing class-attribute
instance-attribute
x_spacing: tuple[float, ...] = field(init=False)
A tuple of x spacings between grid points.
y_init class-attribute
instance-attribute
y_init: float | None = field(init=False)
The initial y position of the grid, or None if not set.
y_spacing class-attribute
instance-attribute
y_spacing: tuple[float, ...] = field(init=False)
A tuple of y spacings between grid points.
get_view
get_view(
x_indices: IList[int, Any], y_indices: IList[int, Any]
)
Get a sub-grid view based on the specified x and y indices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_indices | IList[int, Nx] | The x indices to include in the sub-grid. | required |
y_indices | IList[int, Ny] | The y indices to include in the sub-grid. | required |
Returns:
Type | Description |
---|---|
Grid[Nx, Ny] | Grid[Nx, Ny]: The sub-grid view. |
Source code in src/bloqade/geometry/dialects/grid/types.py
431 432 433 434 435 436 437 |
|