diff --git a/pulser-core/pulser/json/supported.py b/pulser-core/pulser/json/supported.py index 597fbcb26..e00ba8597 100644 --- a/pulser-core/pulser/json/supported.py +++ b/pulser-core/pulser/json/supported.py @@ -69,6 +69,7 @@ "RectangularLatticeLayout", "SquareLatticeLayout", "TriangularLatticeLayout", + # "RectangularLatticeLayout", ), "pulser.register.mappable_reg": ("MappableRegister",), "pulser.register.weight_maps": ("DetuningMap",), diff --git a/pulser-core/pulser/register/__init__.py b/pulser-core/pulser/register/__init__.py index 3dca1234a..5eb20397b 100644 --- a/pulser-core/pulser/register/__init__.py +++ b/pulser-core/pulser/register/__init__.py @@ -18,11 +18,9 @@ from pulser.register.register3d import Register3D from pulser.register.register_layout import RegisterLayout from pulser.register.special_layouts import ( - RectangularLatticeLayout, SquareLatticeLayout, TriangularLatticeLayout, - TriangularLatticeLayoutRectShape, - RandomLayout, + RectangularLatticeLayout, ) __all__ = [ @@ -32,6 +30,5 @@ "RegisterLayout", "SquareLatticeLayout", "TriangularLatticeLayout", - "TriangularLatticeLayoutRectShape", - "RandomLayout", + "RectangularLatticeLayout", ] diff --git a/pulser-core/pulser/register/register.py b/pulser-core/pulser/register/register.py index 16908d32d..260608e0b 100644 --- a/pulser-core/pulser/register/register.py +++ b/pulser-core/pulser/register/register.py @@ -89,7 +89,7 @@ def rectangle( spacing: float = 4.0, prefix: Optional[str] = None, ) -> Register: - """Initializes register, qubits in a rectangular array, square lattice. + """Creates a rectangular array of qubits on a square lattice. Args: rows: Number of rows. @@ -102,33 +102,10 @@ def rectangle( Returns: A register with qubits placed in a rectangular array. """ - # Check rows - if rows < 1: - raise ValueError( - f"The number of rows (`rows` = {rows})" - " must be greater than or equal to 1." - ) - - # Check columns - if columns < 1: - raise ValueError( - f"The number of columns (`columns` = {columns})" - " must be greater than or equal to 1." - ) - - # Check spacing - if spacing <= 0.0: - raise ValueError( - f"Spacing between atoms (`spacing` = {spacing})" - " must be greater than 0." - ) - - coords = patterns.square_rect(rows, columns) * spacing - - return cls.from_coordinates(coords, center=True, prefix=prefix) + return cls.rectangular_lattice(rows, columns, spacing, spacing, prefix) @classmethod - def rectangle_rect_lattice( + def rectangular_lattice( cls, rows: int, columns: int, @@ -136,7 +113,7 @@ def rectangle_rect_lattice( col_spacing: float = 2.0, prefix: Optional[str] = None, ) -> Register: - """Initializes register, qubits in rectangle array, rectangle lattice. + """Creates a rectangular array of qubits on a rectangular lattice. Args: rows: Number of rows. @@ -148,7 +125,8 @@ def rectangle_rect_lattice( (e.g. prefix='q' -> IDs: 'q0', 'q1', 'q2', ...) Returns: - Register, qubits placed in a rectangular array, rectangle lattice. + Register with qubits placed in a rectangular array on a + rectangular lattice. """ # Check rows if rows < 1: @@ -166,13 +144,11 @@ def rectangle_rect_lattice( # Check spacing if row_spacing <= 0.0 or col_spacing <= 0.0: - raise ValueError( - "Spacing between atoms must be greater than 0." - ) + raise ValueError("Spacing between atoms must be greater than 0.") coords = patterns.square_rect(rows, columns) - coords[:, 0] = coords[:, 0]*col_spacing - coords[:, 1] = coords[:, 1]*row_spacing + coords[:, 0] = coords[:, 0] * col_spacing + coords[:, 1] = coords[:, 1] * row_spacing return cls.from_coordinates(coords, center=True, prefix=prefix) diff --git a/pulser-core/pulser/register/special_layouts.py b/pulser-core/pulser/register/special_layouts.py index fe79884fc..d285f3286 100644 --- a/pulser-core/pulser/register/special_layouts.py +++ b/pulser-core/pulser/register/special_layouts.py @@ -25,9 +25,6 @@ if TYPE_CHECKING: from pulser.register import Register -import numpy as np -from scipy.spatial.distance import cdist - class RectangularLatticeLayout(RegisterLayout): """RegisterLayout with rectangular lattice pattern in a rectangular shape. @@ -108,8 +105,11 @@ def rectangular_register( def _to_dict(self) -> dict[str, Any]: return obj_to_dict( - self, self._rows, self._columns, self._col_spacing, - self._row_spacing + self, + self._rows, + self._columns, + self._col_spacing, + self._row_spacing, ) @@ -215,75 +215,3 @@ def rectangular_register( def _to_dict(self) -> dict[str, Any]: return obj_to_dict(self, self.number_of_traps, self._spacing) - - -class TriangularLatticeLayoutRectShape(RegisterLayout): - """RegisterLayout with a triangular lattice pattern in a rectangular shape. - - Args: - n_traps: The number of traps in the layout. - spacing: The distance between neighbouring traps (in µm). - """ - - def __init__(self, columns: int, rows: int, spacing: float = 5): - """Initializes a TriangularLatticeLayout.""" - self._spacing = float(spacing) - self._columns = int(columns) - self._rows = int(rows) - slug = ( - f"TriangularLatticeLayoutRectshape({self._rows}x{self._columns}, " - f"{self._spacing}µm)" - ) - super().__init__( - patterns.triangular_rect(self._rows, self._columns) - * self._spacing, - slug=slug, - ) - - -class RandomLayout(RegisterLayout): - """A RegisterLayout generated randomly. - - Args : - n_traps : the number of traps in the layout - radius : radius defining the working area - min_dist : minimum distance between traps - max_iter = maximum number of iterations to compute the random layout - """ - - def __init__( - self, - n_traps: int, - radius: float = 35, - min_spacing: float = 5, - max_iter: int = 1000, - ): - """Initializes a random layout.""" - self._pts : np.ndarray = [] - self._n_traps = int(n_traps) - self._min_spacing = float(min_spacing) - i = 0 - while len(self._pts) < n_traps and i < max_iter: - pt_x = np.random.uniform(low=-radius, high=radius, size=1) - pt_y = np.random.uniform(low=-radius, high=radius, size=1) - pt = np.stack([pt_x, pt_y], axis=1) - if not self._pts and pt_x**2 + pt_y**2 <= radius**2: - self._pts.append(pt) - continue - if len(self._pts) == 0: - continue - dist = cdist(np.concatenate(self._pts), pt) - if pt_x**2 + pt_y**2 <= radius**2 and np.all( - dist > self._min_spacing - ): - self._pts.append(pt) - i += 1 - if len(self._pts) < n_traps: - raise ValueError( - "Could not compute random traps in max iterations" - ) - slug = ( - f"RandomLayout({self._n_traps} traps, " - f"min spacing {self._min_spacing}µm)" - ) - super().__init__(trap_coordinates=np.concatenate(self._pts), slug=slug) diff --git a/tests/test_register_layout.py b/tests/test_register_layout.py index 7ed3fd2ee..5909fe278 100644 --- a/tests/test_register_layout.py +++ b/tests/test_register_layout.py @@ -22,11 +22,9 @@ from pulser.register import Register, Register3D from pulser.register.register_layout import RegisterLayout from pulser.register.special_layouts import ( - RandomLayout, RectangularLatticeLayout, SquareLatticeLayout, TriangularLatticeLayout, - TriangularLatticeLayoutRectShape, ) @@ -195,15 +193,12 @@ def test_square_lattice_layout(): def test_rectangular_lattice_layout(): rectangle = RectangularLatticeLayout(9, 7, 2, 4) - assert ( - str(rectangle) - == "RectangularLatticeLayout(9x7, 2.0x4.0µm)" - ) - assert rectangle.square_register(3) == Register.rectangle_rect_lattice( + assert str(rectangle) == "RectangularLatticeLayout(9x7, 2.0x4.0µm)" + assert rectangle.square_register(3) == Register.rectangular_lattice( 3, 3, col_spacing=2, row_spacing=4, prefix="q" ) # An even number of atoms on the side won't align the center with an atom - assert rectangle.square_register(4) != Register.rectangle_rect_lattice( + assert rectangle.square_register(4) != Register.rectangular_lattice( 4, 4, col_spacing=2, row_spacing=4, prefix="q" ) with pytest.raises(ValueError, match="'8x8' array doesn't fit"): @@ -243,16 +238,6 @@ def test_triangular_lattice_layout(): ) -def test_triangular_lattice_layout_rect_shape(): - tri = TriangularLatticeLayoutRectShape(10, 4, 5) - assert str(tri) == "TriangularLatticeLayoutRectshape(4x10, 5.0µm)" - - -def test_random_layout(): - rand = RandomLayout(50, max_iter=10000, min_spacing=4) - assert str(rand) == "RandomLayout(50 traps, min spacing 4.0µm)" - - def test_mappable_register_creation(): tri = TriangularLatticeLayout(50, 5) with pytest.raises(ValueError, match="greater than the number of traps"):