Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/fundamentals/graphs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
},
{
Expand All @@ -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()"
]
},
Expand Down Expand Up @@ -551,7 +551,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "qoolqit",
"display_name": "devqoolqit (3.14.6)",
"language": "python",
"name": "python3"
},
Expand All @@ -565,7 +565,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.11"
"version": "3.14.6"
}
},
"nbformat": 4,
Expand Down
31 changes: 24 additions & 7 deletions qoolqit/graphs/data_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,29 +216,46 @@ def heavy_hexagonal(
return graph

@classmethod
def square(
def rectangular(
cls,
m: int,
n: int,
spacing: float = 1.0,
row_spacing: float = 1.0,
col_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.
spacing: The distance between adjacent nodes on the final lattice.
m: Number of rows of rectangle.
n: Number of columns of rectangle.
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)
graph.add_edges_from(G.edges)
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, row_spacing=spacing, col_spacing=spacing)

@classmethod
def random_ud(
cls,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_graphs/test_data_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, row_spacing=2.71, col_spacing=2.71)

expected_coords = {
0: (0.0, 0.0),
Expand Down
Loading