Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional lattice models #6237

Merged
merged 16 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
91 changes: 89 additions & 2 deletions pennylane/spin/lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,73 @@ def _kagome(n_cells, boundary_condition=False, neighbour_order=1):
return lattice_kagome


def _lieb(n_cells, boundary_condition=False, neighbour_order=1):
r"""Generates a lieb lattice"""
vectors = [[0, 1], [1, 0]]
positions = [[0, 0], [0.5, 0], [0, 0.5]]

n_cells = n_cells[0:2]
lattice_lieb = Lattice(
n_cells=n_cells,
vectors=vectors,
positions=positions,
neighbour_order=neighbour_order,
boundary_condition=boundary_condition,
)

return lattice_lieb


def _cubic(n_cells, boundary_condition=False, neighbour_order=1):
r"""Generates a cubic lattice"""
vectors = math.eye(3)

n_cells = n_cells[0:3]
lattice_cubic = Lattice(
n_cells=n_cells,
vectors=vectors,
neighbour_order=neighbour_order,
boundary_condition=boundary_condition,
)

return lattice_cubic


def _bcc(n_cells, boundary_condition=False, neighbour_order=1):
r"""Generates a body centered cubic lattice"""
vectors = math.eye(3)
positions = [[0, 0, 0], [0.5, 0.5, 0.5]]

n_cells = n_cells[0:3]
ddhawan11 marked this conversation as resolved.
Show resolved Hide resolved
lattice_bcc = Lattice(
n_cells=n_cells,
vectors=vectors,
positions=positions,
neighbour_order=neighbour_order,
boundary_condition=boundary_condition,
)
print(lattice_bcc.edges)

return lattice_bcc


def _fcc(n_cells, boundary_condition=False, neighbour_order=1):
r"""Generates a face centered cubic lattice"""
vectors = math.eye(3)
positions = [[0, 0, 0], [0.5, 0.5, 0.0], [0.5, 0, 0.5], [0.0, 0.5, 0.5]]

n_cells = n_cells[0:3]
lattice_fcc = Lattice(
n_cells=n_cells,
vectors=vectors,
positions=positions,
neighbour_order=neighbour_order,
boundary_condition=boundary_condition,
)

return lattice_fcc


# TODO Check the efficiency of this function with a dictionary instead.
def _generate_lattice(lattice, n_cells, boundary_condition=False, neighbour_order=1):
r"""Generates the lattice object for a given shape and n_cells.
Expand All @@ -333,10 +400,22 @@ def _generate_lattice(lattice, n_cells, boundary_condition=False, neighbour_orde

lattice_shape = lattice.strip().lower()

if lattice_shape not in ["chain", "square", "rectangle", "honeycomb", "triangle", "kagome"]:
ddhawan11 marked this conversation as resolved.
Show resolved Hide resolved
if lattice_shape not in [
"chain",
ddhawan11 marked this conversation as resolved.
Show resolved Hide resolved
"square",
"rectangle",
"honeycomb",
"triangle",
"kagome",
"lieb",
"cubic",
"bcc",
"fcc",
]:
raise ValueError(
f"Lattice shape, '{lattice}' is not supported."
f"Please set lattice to: chain, square, rectangle, honeycomb, triangle, or kagome"
f"Please set lattice to: chain, square, rectangle, honeycomb, triangle, kagome, lieb,"
ddhawan11 marked this conversation as resolved.
Show resolved Hide resolved
f"cubic, bcc or fcc."
)

if lattice_shape == "chain":
Expand All @@ -351,5 +430,13 @@ def _generate_lattice(lattice, n_cells, boundary_condition=False, neighbour_orde
lattice = _triangle(n_cells, boundary_condition, neighbour_order)
elif lattice_shape == "kagome":
lattice = _kagome(n_cells, boundary_condition, neighbour_order)
elif lattice_shape == "lieb":
lattice = _lieb(n_cells, boundary_condition, neighbour_order)
elif lattice_shape == "cubic":
lattice = _cubic(n_cells, boundary_condition, neighbour_order)
elif lattice_shape == "bcc":
lattice = _bcc(n_cells, boundary_condition, neighbour_order)
elif lattice_shape == "fcc":
lattice = _fcc(n_cells, boundary_condition, neighbour_order)

return lattice
225 changes: 225 additions & 0 deletions tests/spin/test_lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,231 @@ def test_add_edge():
(8, 9, 0),
],
),
(
"LIEB",
ddhawan11 marked this conversation as resolved.
Show resolved Hide resolved
[2, 2],
[
(0, 1, 0),
(0, 2, 0),
(1, 3, 0),
(2, 6, 0),
(3, 4, 0),
(3, 5, 0),
(5, 9, 0),
(6, 7, 0),
(6, 8, 0),
(7, 9, 0),
(9, 10, 0),
(9, 11, 0),
],
),
(
" cubic",
[3, 3, 3],
[
(0, 1, 0),
(0, 3, 0),
(0, 9, 0),
(1, 2, 0),
(1, 4, 0),
(1, 10, 0),
(2, 5, 0),
(2, 11, 0),
(3, 4, 0),
(3, 6, 0),
(3, 12, 0),
(4, 5, 0),
(4, 7, 0),
(4, 13, 0),
(5, 8, 0),
(5, 14, 0),
(6, 7, 0),
(6, 15, 0),
(7, 8, 0),
(7, 16, 0),
(8, 17, 0),
(9, 10, 0),
(9, 12, 0),
(9, 18, 0),
(10, 11, 0),
(10, 13, 0),
(10, 19, 0),
(11, 14, 0),
(11, 20, 0),
(12, 13, 0),
(12, 15, 0),
(12, 21, 0),
(13, 14, 0),
(13, 16, 0),
(13, 22, 0),
(14, 17, 0),
(14, 23, 0),
(15, 16, 0),
(15, 24, 0),
(16, 17, 0),
(16, 25, 0),
(17, 26, 0),
(18, 19, 0),
(18, 21, 0),
(19, 20, 0),
(19, 22, 0),
(20, 23, 0),
(21, 22, 0),
(21, 24, 0),
(22, 23, 0),
(22, 25, 0),
(23, 26, 0),
(24, 25, 0),
(25, 26, 0),
],
),
(
"BCC",
[2, 2, 2],
[
(0, 1, 0),
(1, 2, 0),
(1, 4, 0),
(1, 6, 0),
(1, 8, 0),
(1, 10, 0),
(1, 12, 0),
(1, 14, 0),
(2, 3, 0),
(3, 6, 0),
(3, 10, 0),
(3, 14, 0),
(4, 5, 0),
(5, 6, 0),
(5, 12, 0),
(5, 14, 0),
(6, 7, 0),
(7, 14, 0),
(8, 9, 0),
(9, 10, 0),
(9, 12, 0),
(9, 14, 0),
(10, 11, 0),
(11, 14, 0),
(12, 13, 0),
(13, 14, 0),
(14, 15, 0),
],
),
(
"FCC",
[2, 2, 2],
[
(0, 1, 0),
(0, 2, 0),
(0, 3, 0),
(1, 2, 0),
(1, 3, 0),
(1, 8, 0),
(1, 10, 0),
(1, 16, 0),
(1, 19, 0),
(1, 24, 0),
(2, 3, 0),
(2, 4, 0),
(2, 5, 0),
(2, 16, 0),
(2, 19, 0),
(2, 20, 0),
(3, 4, 0),
(3, 5, 0),
(3, 8, 0),
(3, 10, 0),
(3, 12, 0),
(4, 5, 0),
(4, 6, 0),
(4, 7, 0),
(5, 6, 0),
(5, 7, 0),
(5, 10, 0),
(5, 12, 0),
(5, 14, 0),
(5, 19, 0),
(5, 20, 0),
(5, 23, 0),
(5, 28, 0),
(6, 7, 0),
(6, 20, 0),
(6, 23, 0),
(7, 12, 0),
(7, 14, 0),
(8, 9, 0),
(8, 10, 0),
(8, 11, 0),
(9, 10, 0),
(9, 11, 0),
(9, 24, 0),
(9, 27, 0),
(10, 11, 0),
(10, 12, 0),
(10, 13, 0),
(10, 19, 0),
(10, 24, 0),
(10, 27, 0),
(10, 28, 0),
(11, 12, 0),
(11, 13, 0),
(12, 13, 0),
(12, 14, 0),
(12, 15, 0),
(13, 14, 0),
(13, 15, 0),
(13, 27, 0),
(13, 28, 0),
(13, 31, 0),
(14, 15, 0),
(14, 23, 0),
(14, 28, 0),
(14, 31, 0),
(16, 17, 0),
(16, 18, 0),
(16, 19, 0),
(17, 18, 0),
(17, 19, 0),
(17, 24, 0),
(17, 26, 0),
(18, 19, 0),
(18, 20, 0),
(18, 21, 0),
(19, 20, 0),
(19, 21, 0),
(19, 24, 0),
(19, 26, 0),
(19, 28, 0),
(20, 21, 0),
(20, 22, 0),
(20, 23, 0),
(21, 22, 0),
(21, 23, 0),
(21, 26, 0),
(21, 28, 0),
(21, 30, 0),
(22, 23, 0),
(23, 28, 0),
(23, 30, 0),
(24, 25, 0),
(24, 26, 0),
(24, 27, 0),
(25, 26, 0),
(25, 27, 0),
(26, 27, 0),
(26, 28, 0),
(26, 29, 0),
(27, 28, 0),
(27, 29, 0),
(28, 29, 0),
(28, 30, 0),
(28, 31, 0),
(29, 30, 0),
(29, 31, 0),
(30, 31, 0),
],
),
],
)
def test_edges_for_shapes(shape, n_cells, expected_edges):
Expand Down
Loading