Skip to content

types

FilledGrid dataclass

FilledGrid(
    x_spacing: tuple[float, ...],
    y_spacing: tuple[float, ...],
    x_init: float | None,
    y_init: float | None,
    parent: Grid[NumX, NumY],
    vacancies: frozenset[tuple[int, int]],
)

Bases: Grid[NumX, NumY]


              flowchart TD
              bloqade.geometry.dialects.filled.types.FilledGrid[FilledGrid]
              bloqade.geometry.dialects.grid.types.Grid[Grid]

                              bloqade.geometry.dialects.grid.types.Grid --> bloqade.geometry.dialects.filled.types.FilledGrid
                


              click bloqade.geometry.dialects.filled.types.FilledGrid href "" "bloqade.geometry.dialects.filled.types.FilledGrid"
              click bloqade.geometry.dialects.grid.types.Grid href "" "bloqade.geometry.dialects.grid.types.Grid"
            

positions cached property

positions: IList[tuple[float, float], Any]

All positions in the grid as a list of tuples (x, y) in lexicographic order.

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.

col_y_pos

col_y_pos(column_index: int)

Get the y positions of a specific column in the grid.

Parameters:

Name Type Description Default
column_index int

The index of the column.

required

Returns:

Type Description
IList[float, NumY]

IList[float, NumY]: The y positions of the specified column.

Source code in src/bloqade/geometry/dialects/filled/types.py
136
137
138
139
140
def col_y_pos(self, column_index: int):
    y_vacancies = {y for x, y in self.vacancies if x == column_index}
    return ilist.IList(
        [y for i, y in enumerate(self.y_positions) if i not in y_vacancies]
    )

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 Sequence[int]

The x indices to include in the sub-grid.

required
y_indices Sequence[int]

The y indices to include in the sub-grid.

required

Returns:

Name Type Description
Grid Grid

The sub-grid view.

Source code in src/bloqade/geometry/dialects/filled/types.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
def get_view(  # type: ignore
    self, x_indices: ilist.IList[int, Any], y_indices: ilist.IList[int, Any]
):
    remapping_x = {ix: i for i, ix in enumerate(x_indices)}
    remapping_y = {iy: i for i, iy in enumerate(y_indices)}
    return FilledGrid(
        parent=self.parent.get_view(x_indices, y_indices),
        vacancies=frozenset(
            (remapping_x[x], remapping_y[y])
            for x, y in self.vacancies
            if x in remapping_x and y in remapping_y
        ),
    )

is_equal

is_equal(other: Any) -> bool

Check if two grid geometry are equal.

Source code in src/bloqade/geometry/dialects/filled/types.py
47
48
def is_equal(self, other: Any) -> bool:
    return self == other

repeat

repeat(
    x_times: int, y_times: int, x_gap: float, y_gap: float
)

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/filled/types.py
121
122
123
124
125
126
127
128
def repeat(self, x_times: int, y_times: int, x_gap: float, y_gap: float):
    new_parent = self.parent.repeat(x_times, y_times, x_gap, y_gap)
    x_dim, y_dim = self.shape
    vacancies = frozenset(
        (x + x_dim * i, y + y_dim * j)
        for i, j, (x, y) in product(range(x_times), range(y_times), self.vacancies)
    )
    return FilledGrid.vacate(new_parent, vacancies)

row_x_pos

row_x_pos(row_index: int)

Get the x positions of a specific row in the grid.

Parameters:

Name Type Description Default
row_index int

The index of the row.

required

Returns:

Type Description
IList[float, NumX]

IList[float, NumX]: The x positions of the specified row.

Source code in src/bloqade/geometry/dialects/filled/types.py
130
131
132
133
134
def row_x_pos(self, row_index: int):
    x_vacancies = {x for x, y in self.vacancies if y == row_index}
    return ilist.IList(
        [x for i, x in enumerate(self.parent.x_positions) if i not in x_vacancies]
    )

scale

scale(x_scale: float, y_scale: float)

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/filled/types.py
115
116
117
118
119
def scale(self, x_scale: float, y_scale: float):
    return FilledGrid(
        parent=self.parent.scale(x_scale, y_scale),
        vacancies=self.vacancies,
    )

shift

shift(x_shift: float, y_shift: float)

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/filled/types.py
109
110
111
112
113
def shift(self, x_shift: float, y_shift: float):
    return FilledGrid(
        parent=self.parent.shift(x_shift, y_shift),
        vacancies=self.vacancies,
    )