From 5797c1e724c9e19e6a8725658c167ddf71b5cb55 Mon Sep 17 00:00:00 2001 From: Alessandro Santini Date: Wed, 12 Aug 2026 15:22:11 +0200 Subject: [PATCH 1/3] Naming of DataGraph consistent with Register --- qoolqit/graphs/data_graph.py | 23 +++++++++++++++++++---- tests/test_graphs/test_data_graph.py | 4 ++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/qoolqit/graphs/data_graph.py b/qoolqit/graphs/data_graph.py index 86e247f7c..4641172ac 100644 --- a/qoolqit/graphs/data_graph.py +++ b/qoolqit/graphs/data_graph.py @@ -216,18 +216,18 @@ def heavy_hexagonal( return graph @classmethod - def square( + def rectangular( cls, m: int, n: int, spacing: float = 1.0, ) -> DataGraph: """ - Constructs a square lattice graph, with respective coordinates. + Constructs a rectangular lattice graph, with respective coordinates. Arguments: - m: Number of rows of square. - n: Number of columns of square. + m: Number of rows of rectangle. + n: Number of columns of rectangle. spacing: The distance between adjacent nodes on the final lattice. """ G = nx.grid_2d_graph(m, n) @@ -239,6 +239,21 @@ def square( graph._reset_dicts() return graph + @classmethod + def square( + cls, + m: int, + spacing: float = 1.0, + ) -> DataGraph: + """ + Constructs a square lattice graph, with respective coordinates. + + Arguments: + m: Number of rows of the square. + spacing: The distance between adjacent nodes on the final lattice. + """ + return cls.rectangular(m, m, spacing=spacing) + @classmethod def random_ud( cls, diff --git a/tests/test_graphs/test_data_graph.py b/tests/test_graphs/test_data_graph.py index f89f4c815..aff1b1497 100644 --- a/tests/test_graphs/test_data_graph.py +++ b/tests/test_graphs/test_data_graph.py @@ -136,8 +136,8 @@ def test_hexagonal() -> None: assert edges == expected_edges -def test_square() -> None: - graph = DataGraph.square(4, 4, spacing=2.71) +def test_rectangular() -> None: + graph = DataGraph.rectangular(4, 4, spacing=2.71) expected_coords = { 0: (0.0, 0.0), From dc8bce9fa5ea7d96e00fda3c966be9ec248a1af3 Mon Sep 17 00:00:00 2001 From: Alessandro Santini Date: Wed, 12 Aug 2026 15:27:47 +0200 Subject: [PATCH 2/3] Added different spacing for row and col --- qoolqit/graphs/data_graph.py | 10 ++++++---- tests/test_graphs/test_data_graph.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/qoolqit/graphs/data_graph.py b/qoolqit/graphs/data_graph.py index 4641172ac..90583f191 100644 --- a/qoolqit/graphs/data_graph.py +++ b/qoolqit/graphs/data_graph.py @@ -220,7 +220,8 @@ def rectangular( cls, m: int, n: int, - spacing: float = 1.0, + row_spacing: float = 1.0, + col_spacing: float = 1.0, ) -> DataGraph: """ Constructs a rectangular lattice graph, with respective coordinates. @@ -228,10 +229,11 @@ def rectangular( Arguments: m: Number of rows of rectangle. n: Number of columns of rectangle. - spacing: The distance between adjacent nodes on the final lattice. + row_spacing: distance between adjacent qubits in the row direction. Defaults to 1.0. + col_spacing: distance between adjacent qubits in the column direction. Defaults to 1.0. """ G = nx.grid_2d_graph(m, n) - final_coords = [(x * spacing, y * spacing) for (x, y) in list(G.nodes)] + final_coords = [(x * row_spacing, y * col_spacing) for (x, y) in list(G.nodes)] G = nx.convert_node_labels_to_integers(G) graph = DataGraph.from_coordinates(final_coords) @@ -252,7 +254,7 @@ def square( m: Number of rows of the square. spacing: The distance between adjacent nodes on the final lattice. """ - return cls.rectangular(m, m, spacing=spacing) + return cls.rectangular(m, m, row_spacing=spacing, col_spacing=spacing) @classmethod def random_ud( diff --git a/tests/test_graphs/test_data_graph.py b/tests/test_graphs/test_data_graph.py index aff1b1497..a3eb1a1d6 100644 --- a/tests/test_graphs/test_data_graph.py +++ b/tests/test_graphs/test_data_graph.py @@ -137,7 +137,7 @@ def test_hexagonal() -> None: def test_rectangular() -> None: - graph = DataGraph.rectangular(4, 4, spacing=2.71) + graph = DataGraph.rectangular(4, 4, row_spacing=2.71, col_spacing=2.71) expected_coords = { 0: (0.0, 0.0), From f7b655e248d075c486dcf98cbdbe0a6999d0d067 Mon Sep 17 00:00:00 2001 From: Alessandro Santini Date: Wed, 12 Aug 2026 15:39:04 +0200 Subject: [PATCH 3/3] Fix Fundamentals Notebook --- docs/fundamentals/graphs.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/fundamentals/graphs.ipynb b/docs/fundamentals/graphs.ipynb index 7bf995ab0..140487014 100644 --- a/docs/fundamentals/graphs.ipynb +++ b/docs/fundamentals/graphs.ipynb @@ -388,7 +388,7 @@ "metadata": {}, "source": [ "### Square\n", - "A square lattice graph with m rows and n columns of square." + "A square lattice graph with m rows and m columns." ] }, { @@ -398,7 +398,7 @@ "metadata": {}, "outputs": [], "source": [ - "graph = DataGraph.square(m = 2, n = 2, spacing = 1.0)\n", + "graph = DataGraph.square(m = 2, spacing = 1.0)\n", "graph.draw()" ] }, @@ -551,7 +551,7 @@ ], "metadata": { "kernelspec": { - "display_name": "qoolqit", + "display_name": "devqoolqit (3.14.6)", "language": "python", "name": "python3" }, @@ -565,7 +565,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.11" + "version": "3.14.6" } }, "nbformat": 4,