netket.graph.Lattice#

class netket.graph.Lattice#

Bases: netket.graph.Graph

A lattice built by periodic arrangement of a given unit cell.

The lattice is represented as a Bravais lattice with (basis_vectors) \(\{a_d\}_{d=1}^D\) (where \(D = \mathtt{ndim}\) is the dimension of the lattice) and a unit cell consisting of one or more sites, The positions of those sites within the unit cell can be specified by the site_offsets parameter. The extent is a array where extent[d] specifies the number of times each unit cell is translated along direction \(d\). The full lattice is then generated by placing a site at each of the points

\[R_{rq} = \sum_{d=1}^D r_d a_d + b_q \in \mathbb R^D\]

where \(r_d \in \{1, \ldots, \mathtt{extent}[d]\}\) and \(b_q = \mathtt{site\_offsets}[q]\). We also refer to \(q\) as the label of the site within the unit cell.

The lattice class supports three ways of addressing a specific lattice site:

id

An integer index that is used to identify the site in self.edges() and also corresponds to the index of the corresponding site in sequences like self.nodes(), self.positions or self.basis_coords.

positions

Real-space position vector \(R_{rq}\) as defined above, which is available from positions() and can be resolved into an id via id_from_position().

basis coordinates

where each site is specified by a vector [r1, ..., rD, q] with \(r\) being the integer vector of length ndim specifying the cell position as multiples of the primitive vectors and the site label \(q\) giving the number of the site within the unit cell. Basis coordinates are available from basis_coords() and can be resolved into an id via id_from_basis_coords().

Inheritance
Inheritance diagram of netket.graph.Lattice
__init__(basis_vectors, extent, *, pbc=True, site_offsets=None, atoms_coord=None, distance_atol=1e-05, point_group=None, max_neighbor_order=None, custom_edges=None)[source]#

Constructs a new Lattice given its side length and the features of the unit cell.

Parameters
  • basis_vectors (ndarray) – The basis vectors of the lattice. Should be an array of shape (ndim, ndim) where each row is a basis vector.

  • extent (ndarray) – The number of copies of the unit cell; needs to be an array of length ndim.

  • pbc (Union[bool, Sequence[bool]]) – If True then the constructed lattice will have periodic boundary conditions, otherwise open boundary conditions are imposed. Can also be an boolean sequence of length ndim, indicating either open or closed boundary conditions separately for each direction.

  • site_offsets (Optional[ndarray]) – The position offsets of sites in the unit cell (one site at the origin by default).

  • distance_atol (float) – Distance below which spatial points are considered equal for the purpose of identifying nearest neighbors.

  • point_group (Optional[PointGroup]) – Default PointGroup object for constructing space groups

  • max_neighbor_order (Optional[int]) – For max_neighbor_order == k, edges between up to \(k\)-nearest neighbor sites (measured by their Euclidean distance) are included in the graph. The edges can be distinguished by their color, which is set to \(k - 1\) (so nearest-neighbor edges have color 0). By default, nearest neighbours (max_neighbor_order=1) are autogenerated unless custom_edges is passed.

  • custom_edges (Optional[Sequence[Union[Tuple[int, int, Union[ndarray, DeviceArray, Tracer]], Tuple[int, int, Union[ndarray, DeviceArray, Tracer], int]]]]) – (Optional) Lists all edges starting in one unit cell, which are repeated in every unit cell of the constructed lattice. Should be a list of tuples; each tuple should contain the following: * index of the starting point in the unit cell * index of the endpoint in the unit cell * vector pointing from the former to the latter * color of the edge (optional) If colors are not supplied, they are assigned sequentially starting from 0. Cannot be used together with max_neighbor_order.

  • atoms_coord (Optional[numpy.ndarray]) –

Examples

Constructs a Kagome lattice with 3 Γ— 3 unit cells:

>>> import numpy as np
>>> from netket.graph import Lattice
>>> # Hexagonal lattice basis
>>> sqrt3 = np.sqrt(3.0)
>>> basis = np.array([
...     [1.0, 0.0],
...     [0.5, sqrt3 / 2.0],
... ])
>>> # Kagome unit cell
>>> cell = np.array([
...     basis[0] / 2.0,
...     basis[1] / 2.0,
...     (basis[0]+basis[1])/2.0
... ])
>>> g = Lattice(basis_vectors=basis, site_offsets=cell, extent=[3, 3])
>>> print(g.n_nodes)
27
>>> print(g.basis_coords[:6])
[[0 0 0]
 [0 0 1]
 [0 0 2]
 [0 1 0]
 [0 1 1]
 [0 1 2]]
 >>> print(g.positions[:6])
 [[0.5        0.        ]
  [0.25       0.4330127 ]
  [0.75       0.4330127 ]
  [1.         0.8660254 ]
  [0.75       1.29903811]
  [1.25       1.29903811]]

Constructs a rectangular lattice with distinct horizontal and vertical edges:

>>> import numpy as np
>>> from netket.graph import Lattice
>>> basis = np.array([
...     [1.0,0.0],
...     [0.0,0.5],
... ])
>>> custom_edges = [
...     (0, 0, [1.0,0.0], 0),
...     (0, 0, [0.0,0.5], 1),
... ]
>>> g = Lattice(basis_vectors=basis, pbc=False, extent=[4,6],
...     custom_edges=custom_edges)
>>> print(g.n_nodes)
24
>>> print(len(g.edges(filter_color=0)))
18
>>> print(len(g.edges(filter_color=1)))
20
Attributes
atoms_coord#

Deprecated. please use site_offsets instead.

Return type

ndarray

basis_coords#

basis coordinates of all lattice sites

Return type

ndarray

basis_vectors#

Basis vectors of the lattice

coordinates#

Deprecated. please use positions instead.

Return type

ndarray

edge_colors#

Sequence of edge colors, in the order of the edges returned by self.edges.

Return type

Sequence[int]

extent#

Extent of the lattice

n_edges#

The number of edges in the graph.

n_nodes#

The number of nodes (or vertices) in the graph

Return type

int

ndim#

Dimension of the lattice

pbc#

Array of bools such that pbc[d] indicates whether dimension d has periodic boundaries.

positions#

Real-space positions of all lattice sites

Return type

ndarray

site_offsets#

Position offsets of sites in the unit cell

sites#

Sequence of lattice site objects

Return type

Sequence[LatticeSite]

Methods
adjacency_list()#

List containing the adjacency list of the graph where each node is represented by an integer in [0, n_nodes)

Return type

List[List]

atom_label(site_id)[source]#

Deprecated. please use basis_coords[site_id, -1] instead.

Return type

int

Parameters

site_id (int) –

automorphisms()#

Symmetry group containing the automorphisms of the graph

Return type

PermutationGroup

distances()#

List containing the distances between the nodes. The distance between unconnected nodes (no path exists between them) is set to -1

Return type

List[List]

draw(ax=None, figsize=None, node_color='#1f78b4', node_size=300, edge_color='k', curvature=0.2, font_size=12, font_color='k')[source]#

Draws the Lattice graph

Parameters
  • ax – Matplotlib axis object.

  • figsize (Optional[Tuple[Union[int, float]]]) – (width, height) tuple of the generated figure.

  • node_color (str) – String with the colour of the nodes.

  • node_size (int) – Area of the nodes (as in matplotlib.pyplot.scatter).

  • edge_color (str) – String with the colour of the edges.

  • curvature (float) – A Bezier curve is fit, where the β€œheight” of the curve is curvature times the β€œlength” of the curvature.

  • font_size (int) – fontsize of the labels for each node.

  • font_color (str) – Colour of the font used to label nodes.

Returns

Matplotlib axis object containing the graph’s drawing.

edges(color=None, *, return_color=False, filter_color=None)#

Returns the sequence of edges of the graph.

Parameters
  • return_color (bool) – If True, return edges with added color information.

  • filter_color (Optional[int]) – If set, return only edges of the given color.

Return type

Union[Sequence[Tuple[int, int]], Sequence[Tuple[int, int, int]]]

Returns

A sequence of edges as tuples (i, j) or, if return_color is passed, a sequence of tuples (i, j, c) with c indicating the color of the respective edge.

classmethod from_igraph(graph)#

Creates a new Graph instance from an igraph.Graph instance.

Return type

Graph

Parameters

graph (igraph.Graph) –

classmethod from_networkx(graph)#

Creates a new Graph instance from a networkx graph.

Return type

Graph

id_from_basis_coords(basis_coords)[source]#

Return the id for a site at the given basis coordinates. When passed a rank-2 array where each row is a coordinate vector, returns an array of the corresponding ids. Throws an InvalidSiteError if any of the coords do not correspond to a site.

Return type

Union[int, ndarray, DeviceArray, Tracer]

Parameters

basis_coords (numpy.ndarray) –

id_from_position(position)[source]#

Returns the id for a site at the given position. When passed a rank-2 array where each row is a position, returns an array of the corresponding ids. Throws an InvalidSiteError if any of the positions do not correspond to a site.

Return type

Union[int, ndarray, DeviceArray, Tracer]

Parameters

position (numpy.ndarray) –

is_bipartite()#

True if the graph is bipartite

Return type

bool

is_connected()#

True if the graph is connected

Return type

bool

nodes()#

Iterator over the nodes of the graph

Return type

Sequence[int]

point_group(point_group=None)[source]#

Returns the action of point_group on the sites of self as a PermutationGroup. If no point_group is specified, uses the point group provided upon construction.

Return type

PermutationGroup

Parameters

point_group (Optional[netket.utils.group._point_group.PointGroup]) –

position_from_basis_coords(basis_coords)[source]#

Return the position of the site with given basis coordinates. When passed a rank-2 array where each row is a coordinate vector, this method returns an array of the corresponding positions. Throws an InvalidSiteError if no site is found for any of the coordinates.

Return type

ndarray

Parameters

basis_coords (numpy.ndarray) –

rotation_group(point_group=None)[source]#

Returns the action of rotations (i.e. symmetries with determinant +1) in point_group on the sites of self as a PermutationGroup. If no point_group is specified, uses the point group provided upon construction.

Return type

PermutationGroup

Parameters

point_group (Optional[netket.utils.group._point_group.PointGroup]) –

site_to_coord(site_id)[source]#

Deprecated. please use positions[site_id] instead.

Return type

ndarray

Parameters

site_id (int) –

site_to_vector(site_id)[source]#

Deprecated. please use basis_coords[site_id, :-1] instead.

Return type

ndarray

Parameters

site_id (int) –

space_group(point_group=None)[source]#

Returns the space group generated by the translation symmetries of self and the elements of point_group as a PermutationGroup acting on the sites of self. If no point_group is specified, uses the point group provided upon construction.

Return type

PermutationGroup

Parameters

point_group (Optional[netket.utils.group._point_group.PointGroup]) –

space_group_builder(point_group=None)[source]#

Returns a SpaceGroupBuilder object that represents the spatial symmetries of self.

Parameters

point_group (Optional[PointGroup]) – a PointGroup object describing the point-group symmetries of self. Optional, if not supplied, the PointGroup object provided at construction is used.

Return type

SpaceGroupBuilder

Returns

A SpaceGroupBuilder object that generates PermutationGroup`s encoding the action of `point_group, the translation group of self, and the space group obtained as their semidirect product as permutations of the sites of self. It also yields space group irreps for symmetrising wave functions.

to_igraph()#

Returns a copy of this graph as an igraph.Graph instance.

to_networkx()#

Returns a copy of this graph as an igraph.Graph instance. This method requires networkx to be installed.

to_reciprocal_lattice(ks)[source]#

Converts wave vectors from Cartesian axes to reciprocal lattice vectors.

Parameters

ks (Union[ndarray, DeviceArray, Tracer]) – wave vectors in Cartesian axes. Multidimensional arrays are accepted, the Cartesian coordinates must form the last dimension.

Return type

Union[ndarray, DeviceArray, Tracer]

Returns

The same wave vectors in the reciprocal basis of the simulation box. Valid wave vector components in this basis are integers in (periodic BCs) or zero (in open BCs).

Throws an InvalidWaveVectorError if any of the supplied wave vectors are not reciprocal lattice vectors of the simulation box.

translation_group(dim=None)[source]#

Returns the group of lattice translations of self as a PermutationGroup acting on the sites of self.

Return type

PermutationGroup

Parameters

dim (Optional[Union[int, Sequence[int]]]) –

vector_to_coord(vector, label)[source]#

Deprecated. please use position_from_basis_coords([*vector, label]).

Return type

ndarray

Parameters
vector_to_site(vector)[source]#

Deprecated. please use id_from_basis_coords([*vector, 0]) instead.

Return type

int

Parameters

vector (numpy.ndarray) –