quimb.tensor.tn2dinf.geometry¶
Geometry of infinite, translation-invariant 2D lattices: the unit cell of
sites and bonds, with a GeometryInfinite2D.square builder for square
lattices. See the subpackage __init__ for some shared definition.
Classes¶
Helper class to represent the geometry of an infinite 2D lattice. |
Functions¶
|
Check if site is a valid 2d infinite site specifier, that is, it is |
|
Ensure |
|
Given a bond between two sites, simply return the sorted order of the |
|
Given a bond between two sites, get its bond type: the canonical |
|
Return the average position of a sequence of 2d positions. |
|
Get all positive displacements ( |
|
Calculate possible long range bonds on a square lattice, producing a |
|
Edges of an |
Module Contents¶
- quimb.tensor.tn2dinf.geometry.is_inf_2d_site(site)[source]¶
Check if site is a valid 2d infinite site specifier, that is, it is tuple (cell, site_type) where cell is a tuple (x : int, y : int).
- quimb.tensor.tn2dinf.geometry.ensure_inf_2d_sites(where)[source]¶
Ensure
where(a single site or a sequence of sites) is a tuple of sites.
- quimb.tensor.tn2dinf.geometry.get_bond_sorted(sitea, siteb)[source]¶
Given a bond between two sites, simply return the sorted order of the two, which is the canonical way to refer to it / use it as a key etc.
- quimb.tensor.tn2dinf.geometry.get_bond_type(sitea, siteb)[source]¶
Given a bond between two sites, get its bond type: the canonical representative of the bond’s translation class. The first endpoint is translated to cell (0, 0) and the orientation chosen so the two endpoints are in sorted order, i.e.
cella < cellb, or (within-cell)site_type_a < site_type_b. Thus cells compare dx-first.
- quimb.tensor.tn2dinf.geometry._average_position(positions)[source]¶
Return the average position of a sequence of 2d positions.
- class quimb.tensor.tn2dinf.geometry.GeometryInfinite2D(edges, basis=None, positions=None)[source]¶
Helper class to represent the geometry of an infinite 2D lattice.
- Parameters:
edges (sequence[(((int, int), hashable), ((int, int), hashable)), ...]) – A sequence of edges, where each edge is a pair of sites. Each site is represented as a tuple of (cell, site_type), where cell is a tuple of integers representing the cell coordinates, and site_type is a hashable representing the type of site (e.g., an integer or string). Equivalent edges are automatically deduplicated and normalized to a canonical
bond_type: the first endpoint translated to cell (0, 0) and the two endpoints in sorted order, i.e.cella < cellb, or (within-cell)site_type_a < site_type_b(cells compare dx-first).basis ((float, float), optional) – A pair of 2D vectors representing the lattice basis vectors. If not provided, the default basis is the standard square lattice basis.
positions (dict, optional) – A dictionary mapping site types to their fractional positions within the unit cell. If not provided, the default position for each site type is (0.0, 0.0). Currently only used for drawing.
- site_types¶
- bond_types¶
- site_type_neighbors¶
- covering_sites¶
- covering_bonds¶
- basis¶
- positions¶
- classmethod square(Lx=2, Ly=None, *, couplings=None, radius=None, basis=None, **kwargs)[source]¶
Build a square-lattice geometry on an
LxbyLyunit cell, withsite_type = (subx, suby)sitting at the 0-based lattice points. By default builds the minimal 2x2 cell with nearest-neighbor bonds. Longer range bonds can be included by specifyingcouplingsorradius.- Parameters:
Lx (int) – The number of sites in the x-direction in the unit cell, default 2.
Ly (int, optional) – The number of sites in the y-direction in the unit cell, default
Lx.couplings (int or sequence[tuple[int, int]], optional) – Which neighbor shells to bond, in square-lattice distance: an int
kfor the firstkshells (1nearest-neighbor,2also diagonal next-nearest, …), or an explicit sequence of(dx, dy)site-step displacements. Mutually exclusive withradius, defaults to nearest-neighbor.radius (float, optional) – Alternatively, bond every neighbor within this square-lattice distance.
basis (tuple[tuple[float, float], tuple[float, float]], optional) – Lattice vectors for the spatial embedding (drawing only), defaults to the unit square.
kwargs – Passed to the
GeometryInfinite2Dconstructor.
- Return type:
- coordinate(site)[source]¶
Map a site
(cell, site_type)to its cartesian position:(cell + fractional_offset) @ basis, defining a spatial embedding.
- get_graph_distance(sitea, siteb, max_hops=None)[source]¶
Calculate the graph distance (number of hops) between two sites, found by BFS over the site graph.
max_hopscaps the search, guarding against an unreachable siteb (any connected pair terminates without it).
- get_sites_within_radius(site, radius)[source]¶
All sites within
radiusgraph distance ofsite, inclusive.
- get_cell_size()[source]¶
Return (dx, dy), the ‘width’ and ‘height’ of the unit cell in terms of the minimum number of bond hops for any site_type to reach the same site_type in the neighboring cell in the x and y directions, respectively. Useful for computing necessary tiling sizes.
- get_tiling_for_radius(radius)[source]¶
Number of cells to tile out from the origin in each direction so that every site within
radiusbond-hops of the origin cell is contained. Returns(nx, ny), i.e. tile cells-nx..nxby-ny..ny. Explores the graph directly, so the tiling never undershoots (note an oversized fragment is usually harmless, the region of interest is generally subselected from it).
- is_canonical_bond(sitea, siteb)[source]¶
Whether the bond between
siteaandsitebis already in canonicalbond_typeform, i.e. sorted with its first endpoint in the origin cell (0, 0).
- get_auto_ordering(order='sort', group=False, interchange=True)[source]¶
An ordering of the
bond_typessuch that consecutive entries act on disjointsite_typeswhere possible, i.e. grouped into commuting layers. Used to sequence gates in e.g. a simple-update sweep.- Parameters:
order ({'sort', None, 'random', 'random-ungrouped', str}, optional) –
How to order the
bond_typesbefore greedily grouping them into commuting (non site_type-overlapping) layers:'sort'sorts thebond_typesfirst.Noneuses their current order.'random'randomly shuffles them before grouping.'random-ungrouped'randomly shuffles them and does not group them at all. Withgroup=Truethe shuffledbond_typesare aggregated only with commuting neighbors.
Any other value is passed as a strategy to
networkx.coloring.greedy_color(), coloring the graph whose nodes arebond_types, linked when they share asite_type, so each color is a commuting layer.group (bool, optional) – If
True, return a list of layers (tuples ofbond_types), otherwise return a flat list ofbond_types.interchange (bool, optional) – For the networkx coloring strategies, whether to use the interchange heuristic (usually better colorings, but slower).
- Return type:
- draw(order=None, pos=None)[source]¶
Draw the covering sites and bonds of the unit cell, with the cell boundary marked.
- Parameters:
order (str, optional) – If given, color the bonds by the commuting layer they fall into, as computed by
get_auto_ordering()with thisorderstrategy (e.g."sort"). IfNone, eachbond_typeis colored by its own hash instead.pos (dict, optional) – A mapping of
site_typeto fractional position within the unit cell. If not given, the geometry’s owncoordinateis used.
- quimb.tensor.tn2dinf.geometry._half_grid(rmax)[source]¶
Get all positive displacements (
(dx, dy) > (0, 0)) withdx <= rmaxanddy <= rmax.
- quimb.tensor.tn2dinf.geometry._square_displacements(couplings=None, radius=None)[source]¶
Calculate possible long range bonds on a square lattice, producing a sorted list of
(dx, dy)site-step displacements, one per +/- pair, measured in square-lattice distance (independent of the drawing basis). At most one ofcouplings/radiusmay be given, defaulting to nearest-neighbor.- Parameters:
- Return type:
- quimb.tensor.tn2dinf.geometry.make_edges_inf_2d_square(Lx=2, Ly=None, couplings=None, radius=None)[source]¶
Edges of an
LxbyLysquare-lattice unit cell, withsite_type = (subx, suby). By default nearest-neighbor bonds only, with longer range bonds included by specifyingcouplingsorradius.Each bond must reach a different sublattice in a neighboring cell, else a
ValueErrorasks to expand the cell (e.g. 3rd-NN(2, 0)invalidly links sites to themselves in only a 2x2 cell).- Parameters:
Lx (int) – The number of sites in the x-direction in the unit cell, default 2.
Ly (int, optional) – The number of sites in the y-direction in the unit cell, default
Lx.couplings (int or sequence[tuple[int, int]], optional) – The neighbor shells to bond (see
_square_displacements()).radius (float, optional) – A square-lattice distance cutoff, as an alternative to
couplings.
- Return type: