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 HexagonalLattice Class #1027

Merged
merged 21 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions qiskit_nature/second_q/hamiltonians/lattices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
SquareLattice
TriangularLattice
HyperCubicLattice
HexagonalLattice

"""

Expand All @@ -33,6 +34,7 @@
from .line_lattice import LineLattice
from .square_lattice import SquareLattice
from .triangular_lattice import TriangularLattice
from .hexagonal_lattice import HexagonalLattice

__all__ = [
"BoundaryCondition",
Expand All @@ -42,4 +44,5 @@
"SquareLattice",
"TriangularLattice",
"HyperCubicLattice",
"HexagonalLattice",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""The hexagonal lattice"""
from rustworkx import generators

from .lattice import Lattice


class HexagonalLattice(Lattice):
"""Hexagonal lattice."""

def __init__(
self,
rows: int,
cols: int,
edge_parameter: complex = 1.0,
onsite_parameter: complex = 0.0,
) -> None:
"""
Args:
rows: Length of the x direction.
cols: Length of the y direction.
edge_parameter: Weight on all the edges, specified as a single value.
Defaults to 1.0.
onsite_parameter: Weight on the self-loops, which are edges connecting a node to itself.
Defaults to 0.0.
"""
self._rows = rows
self._cols = cols
self._edge_parameter = edge_parameter
self._onsite_parameter = onsite_parameter

graph = generators.hexagonal_lattice_graph(rows, cols, multigraph=False)

edges = graph.weighted_edge_list()

# Add edge weights
for idx, _ in enumerate(edges):
graph.update_edge_by_index(idx, self._edge_parameter)

# Add self loops
for node in graph.node_indices():
graph.add_edges_from([(node, node, self._onsite_parameter)])

super().__init__(graph)

@property
def edge_parameter(self) -> complex:
"""Weights on all edges.

Returns:
the parameter for the edges.
"""
return self._edge_parameter

@property
def onsite_parameter(self) -> complex:
"""Weight on the self-loops (edges connecting a node to itself).

Returns:
the parameter for the self-loops.
"""
return self._onsite_parameter