quimb.tensor.tn2dinf.core¶
Infinite, translation-invariant 2D tensor networks on a unit cell: the
flat single-tensor-per-site base and the PEPS wavefunction. See the
subpackage __init__ for the shared vocabulary.
Classes¶
Base class for an infinite, translation-invariant 2D tensor network with |
|
Infinite 2D PEPS: a translation-invariant wavefunction with one physical |
Module Contents¶
- class quimb.tensor.tn2dinf.core.TensorNetworkInfinite2DFlat(geometry_or_edges, site_tag_id='I{}', bond_ind_id='b{},{}', site_type_tag_id='SITE_TYPE_{}')[source]¶
Base class for an infinite, translation-invariant 2D tensor network with a single tensor per site (‘flat’), defined by a unit cell (
GeometryInfinite2D). It explicitly stores the[-1, 1]^2block of cells as afragmenttensor network and keeps two translation-invariance registers:shared_tensors[site_type]andshared_indices[bond_type]. Subclasses specialize the per-site legs and the fragment type viaget_site_inds(+get_site_shape/get_site_duals) and_new_fragment, e.g.PEPSInfinite2Dfor a wavefunction (physical index per site). On its own this base is a bare virtual-bond network, e.g. a classical network.- Parameters:
geometry_or_edges (GeometryInfinite2D or sequence of edges) – The unit-cell geometry, or a sequence of edges to build one from.
site_tag_id (str, optional) – Format string for a site’s tensor tag, formatted with the site.
bond_ind_id (str, optional) – Format string for a bond index, formatted with its two sorted sites.
site_type_tag_id (str, optional) – Format string for a
site_type’s shared tag.
- site_tag_id = 'I{}'¶
- bond_ind_id = 'b{},{}'¶
- site_type_tag_id = 'SITE_TYPE_{}'¶
- fragment¶
- _sites¶
- _new_fragment(sites)[source]¶
Build the empty
fragmenttensor network oversites. The base is a bareTensorNetworkGen(virtual bonds only); subclasses choose a richer type (and any physical ids).
- site_type_tag(site_type)[source]¶
The shared tag applied to every tensor of
site_typein the fragment tensor network.
- get_site_inds(site)[source]¶
Index names of
site’s tensor, one per bond inget_site_neighborsorder. Subclasses append extra legs (e.g. a physical index) viasuper().get_site_inds(site).
- get_site_shape(site, bond_dim)[source]¶
Leg sizes of
site’s tensor, inget_site_indsorder: onebond_dimper bond.
- get_site_duals(site)[source]¶
The symmray
dualflag per leg ofsite’s tensor, inget_site_indsorder. A bond leg isdual=Falsewhensiteis the first endpoint of the bond’s canonicalbond_typeandTruewhen it is the second, giving opposite duals on the two ends of every bond. For symmetric (symmray) builders.
- get_site_tags(site)[source]¶
The tags of the tensor at
sitein the fragment tensor network: the site tag and the site_type tag.
- _block_fill(fill_fn, shape_fn)[source]¶
Populate the whole
[-1, 1]^2block: the first tensor of each site_type getsfill_fn(shape_fn(site)), later translates reuse it.
- copy(deep=False)[source]¶
Copy this infinite tensor network. The
geometryis shared (it is static configuration), while the explicitfragmentand the shared-tensor and shared-index registers are copied so the two networks can be mutated independently.- Parameters:
deep (bool, optional) – If
False(the default), the underlying numeric data arrays are shared between the two networks, matchingTensorNetwork.copy. IfTrue, the data arrays are copied too.- Return type:
- property site_types¶
- property site_type_tags¶
- get_bond_ind(sitea, siteb)[source]¶
Get the name of the bond index between two sites, invariant to which order they are supplied.
- get_bond_type(sitea, siteb)[source]¶
Get the bond type between two sites, invariant to which order they are supplied.
- add_fragment_site(site, data=None)[source]¶
Add, if not already present,
siteto the explicit fragment tensor network. No-op ifsiteis already present. The bond and physical dimensions are defined bydata;datais required for the first site of each site_type and reused (shared) by all its translates, so it is ignored for later sites of the same type. Sites are normally added by a constructor (.rand/.from_fill_fn).- Parameters:
site (tuple[tuple[int, int], hashable]) – The site to add, as
(cell, site_type). Must lie within the[-1, 1]^2neighbor region of the unit cell.data (array_like, optional) – The tensor data for the first site of a new site_type (its legs are the bonds in
get_site_neighborsorder then any extra legs, seeget_site_shape). Reused for later translates.
- _sync_site(site, t=None)[source]¶
Broadcast the data from site to every site of that site_type.
The tensor is retrieved from the current fragment tensor network or you can explicitly supply it if you have it.
- _sync_bond(bond_type, bond_ind, gauges)[source]¶
Broadcast the gauge on
bond_indto every index of bond_type.
- gauge_all_simple(max_iterations=5, tol=0.0, smudge=1e-12, power=1.0, gauges=None, fuse_multibonds=False, info=None, progbar=False, inplace=False)[source]¶
Iterative gauge all the bonds in this tensor network with a ‘simple update’ like strategy. If gauges are not supplied they are initialized and then reabsorbed at the end, in which case this method acts as a kind of conditioning. More usefully, if you supply gauges then they will be updated inplace and not absorbed back into the tensor network, with the assumption that you are using/tracking them externally. As the tensors and bond weights are updated, changes are propagated to all globally shared bond and site types.
- Parameters:
max_iterations (int, optional) – The maximum number of gauging sweeps over all
bond_types.tol (float, optional) – The convergence tolerance on the singular values. Only enables early stopping if greater than 0.0.
smudge (float, optional) – A small value to add to the singular values when gauging.
power (float, optional) – A power to raise the singular values to when gauging.
gauges (dict, optional) – The store of bond gauges, keyed by bond index in the fragment. If supplied, it is updated inplace and the gauges are left on the bonds. If not, an internal store is used and reabsorbed into the tensors at the end.
fuse_multibonds (bool, optional) – Accepted for signature compatibility, only
Falseis supported (bonds are gauged onebond_typerepresentative at a time, never fused).info (dict, optional) –
Store extra information about the gauging process in this dict. The following keys are filled:
’iterations’: the number of sweeps performed.
’max_sdiff’: the maximum singular value difference of the final sweep (
-1.0if no diffs were computed).
progbar (bool, optional) – Whether to show a progress bar tracking the max singular value change per sweep.
inplace (bool, optional) – Whether to gauge this network inplace or return a gauged copy.
- Return type:
- gauge_simple_insert(gauges)[source]¶
Absorb the bond
gaugesinto the tensors, split half-half perbond_typerepresentative and synced to translates. Thegaugesdict is read but not modified (matchingTensorNetwork.gauge_simple_insert).
- normalize_simple(gauges)[source]¶
Normalize the state and bond
gaugesin place, translation invariantly: each gauge to unit 2-norm, and eachsite_typeto unit local norm. The local norm is computed on the cell(0, 0)representative (always fully interior, so all its bonds carry gauges) and the rescaled tensor synced to all translates.
- build_fragment(sites)[source]¶
Build a standalone fragment tensor network over an arbitrary set of
sites, filling each with itssite_type’s shared data so the patch is translation-consistent with this network. Unlike the mainfragment,sitesare not restricted to the[-1, 1]^2block; this is how the larger neighborhoods needed bymax_distance > 0clusters and generalized-loop expansions are materialized without growing the main fragment. Bonds to sites outsidesitesare left dangling. Usebuild_fragment_with_gaugesto also get a tiled gauge store for the environment.- Parameters:
sites (iterable[site]) – The sites to include in the fragment.
- Return type:
- build_fragment_with_gauges(sites, gauges)[source]¶
Build a fragment over
sites(seebuild_fragment) together with a copy ofgaugestiled onto every bond present, including the dangling boundary bonds, so it can serve as the environment.- Parameters:
sites (iterable[site]) – The sites to include in the fragment.
gauges (dict) – A bond-gauge store keyed by the main fragment’s bond indices. The tiled copy is keyed by this fragment’s own (translated) bond indices, each taking the value of its canonical
bond_typegauge (the cell (0, 0) representative, always present).
- Returns:
fragment (TensorNetworkGen)
fragment_gauges (dict)
- class quimb.tensor.tn2dinf.core.PEPSInfinite2D(geometry_or_edges, site_tag_id='I{}', site_ind_id='k{}', bond_ind_id='b{},{}', site_type_tag_id='SITE_TYPE_{}')[source]¶
Bases:
TensorNetworkInfinite2DFlatInfinite 2D PEPS: a translation-invariant wavefunction with one physical index per site, on a unit cell (
GeometryInfinite2D). Adds the physical leg, gates, and cluster expectations toTensorNetworkInfinite2DFlat.- Parameters:
geometry_or_edges (GeometryInfinite2D or sequence of edges) – The unit-cell geometry, or a sequence of edges to build one from.
site_tag_id (str, optional) – Format string for a site’s tensor tag, formatted with the site.
site_ind_id (str, optional) – Format string for a site’s physical index, formatted with the site.
bond_ind_id (str, optional) – Format string for a bond index, formatted with its two sorted sites.
site_type_tag_id (str, optional) – Format string for a
site_type’s shared tag.
- site_ind_id = 'k{}'¶
- classmethod from_fill_fn(fill_fn, geometry_or_edges, bond_dim, phys_dim=2, site_tag_id='I{}', site_ind_id='k{}', bond_ind_id='b{},{}', site_type_tag_id='SITE_TYPE_{}')[source]¶
Build a PEPS, filling each site_type’s tensor with
fill_fn(shape) -> array(fill_fnfirst, matchingquimb.tensor.tensor_builder.TN_from_edges_and_fill_fn).- Parameters:
fill_fn (callable) – Called as
fill_fn(shape) -> arrayonce persite_typeto generate its shared tensor data.geometry_or_edges (GeometryInfinite2D or sequence of edges) – The unit-cell geometry, or a sequence of edges to build one from.
bond_dim (int) – The virtual bond dimension.
phys_dim (int, optional) – The physical dimension.
site_tag_id (str, optional) – Format strings for tags and indices, see the class docstring.
site_ind_id (str, optional) – Format strings for tags and indices, see the class docstring.
bond_ind_id (str, optional) – Format strings for tags and indices, see the class docstring.
site_type_tag_id (str, optional) – Format strings for tags and indices, see the class docstring.
- Return type:
- classmethod rand(geometry_or_edges, bond_dim, phys_dim=2, *, seed=None, dtype='float64', site_tag_id='I{}', site_ind_id='k{}', bond_ind_id='b{},{}', site_type_tag_id='SITE_TYPE_{}', **randn_opts)[source]¶
Build a PEPS with random dense tensors.
- Parameters:
geometry_or_edges (GeometryInfinite2D or sequence of edges) – The unit-cell geometry, or a sequence of edges to build one from.
bond_dim (int) – The virtual bond dimension.
phys_dim (int, optional) – The physical dimension.
seed (int, optional) – Random seed for reproducibility.
dtype (str, optional) – The data type of the random entries.
site_tag_id (str, optional) – Format strings for tags and indices, see the class docstring.
site_ind_id (str, optional) – Format strings for tags and indices, see the class docstring.
bond_ind_id (str, optional) – Format strings for tags and indices, see the class docstring.
site_type_tag_id (str, optional) – Format strings for tags and indices, see the class docstring.
randn_opts – Supplied to the random fill function.
- Return type:
- _new_fragment(sites)[source]¶
Build the empty
fragmenttensor network oversites. The base is a bareTensorNetworkGen(virtual bonds only); subclasses choose a richer type (and any physical ids).
- get_site_inds(site)[source]¶
Index names of
site’s tensor, one per bond inget_site_neighborsorder. Subclasses append extra legs (e.g. a physical index) viasuper().get_site_inds(site).
- get_site_shape(site, bond_dim, phys_dim=2)[source]¶
Leg sizes of
site’s tensor, inget_site_indsorder: onebond_dimper bond.
- get_site_duals(site)[source]¶
The symmray
dualflag per leg ofsite’s tensor, inget_site_indsorder. A bond leg isdual=Falsewhensiteis the first endpoint of the bond’s canonicalbond_typeandTruewhen it is the second, giving opposite duals on the two ends of every bond. For symmetric (symmray) builders.
- copy(deep=False)[source]¶
Copy this infinite tensor network. The
geometryis shared (it is static configuration), while the explicitfragmentand the shared-tensor and shared-index registers are copied so the two networks can be mutated independently.- Parameters:
deep (bool, optional) – If
False(the default), the underlying numeric data arrays are shared between the two networks, matchingTensorNetwork.copy. IfTrue, the data arrays are copied too.- Return type:
- gate_simple(G, where, gauges, *, max_bond=None, cutoff=1e-10, renorm=True, smudge=1e-12, power=1.0, path=None, info=None, inplace=False, **gate_opts)[source]¶
Apply a gate
Gat siteswherewith local truncated gauging, then propagate the updated tensors and bond gauges to all translates.Supports one-site gates (
wherea single site), nearest-neighbor two-site gates, and long-range two-site gates. Long-range gates are applied as an MPO string along a path of sites between the two endpoints (the path must stay within the fragment), updating every tensor and bond gauge on the path. Delegates the actual gate to the fragmentTensorNetworkGenVector.- Parameters:
G (array_like) – The gate to apply (e.g. an exponentiated local Hamiltonian term).
where (site or sequence[site]) – The site(s) to gate, e.g.
(site,)or abond_type(site_a, site_b).gauges (dict) – Diagonal bond gauges (environments), keyed by bond index. Modified in place (the only way to access the updated bond gauges).
max_bond (int, optional) – The maximum bond dimension to keep.
cutoff (float, optional) – The singular value cutoff.
renorm (bool, optional) – Whether to renormalize the new bond gauges before storing them.
smudge (float, optional) – Numerical stabilization of the bond environments.
power (float, optional) – Numerical stabilization of the bond environments.
path (sequence[site], optional) – For long-range gates, the explicit path of sites to use. If None any shortest path will be used.
inplace (bool, optional) – Whether to gate this network inplace or a copy.
- Return type:
- get_cluster(where, gauges=None, max_distance=0, **kwargs)[source]¶
Get the local wavefunction cluster around
where, optionally inserting the bondgaugesas the environment. Delegates to a fragmentTensorNetworkGenVector.For
max_distance=0the main[-1, 1]^2fragment is used. Larger clusters are computed on a freshly built fragment tiled out to themax_distanceneighborhood ofwhere(seebuild_fragment).
- partial_trace_cluster(where, gauges=None, max_distance=0, normalized=True, **kwargs)[source]¶
Approximate reduced density matrix at sites
where, formed by partial-tracing amax_distance-cluster with the bondgaugesas the environment. Delegates to a fragmentTensorNetworkGenVector(get_clusterthenpartial_trace_exact).- Parameters:
where (sequence[site]) – The sites to keep.
gauges (dict, optional) – Diagonal bond gauges (environments), keyed by bond index.
max_distance (int, optional) – The graph distance neighborhood to include (
0uses the main fragment,> 0builds a tiled fragment).normalized (bool, optional) – Whether to normalize the reduced density matrix.
- Return type:
array_like
- local_expectation_cluster(G, where, gauges=None, max_distance=0, normalized=True, **kwargs)[source]¶
Approximate local expectation of gate
Gat siteswhere, using amax_distance-cluster with the bondgaugesas the environment. Delegates to a fragmentTensorNetworkGenVector.- Parameters:
G (array_like) – The gate to compute the expectation of.
where (sequence[site]) – The sites to compute the expectation at (e.g. a
bond_type).gauges (dict, optional) – Diagonal bond gauges (environments), keyed by bond index.
max_distance (int, optional) – The graph distance neighborhood to include (
0uses the main fragment,> 0builds a tiled fragment).normalized (bool, optional) – Whether to divide by the local norm (expectation of the identity).
- Return type:
- compute_local_expectation_cluster(terms, gauges=None, max_distance=0, normalized=True, return_all=False, **kwargs)[source]¶
Sum the local cluster expectations of
termsover the unit cell, e.g. to estimate the energy per unit cell from aLocalHamInfinite2D.- Parameters:
terms (LocalHamInfinite2D or dict[bond_type, array_like]) – Anything with an
.items()yielding(where, gate), wherewhereis abond_type.gauges (dict, optional) – Diagonal bond gauges (environments), keyed by bond index.
max_distance (int, optional) – The graph distance neighborhood to include (
0uses the main fragment,> 0builds a single tiled fragment covering all terms).normalized (bool, optional) – Whether to locally normalize each term.
return_all (bool, optional) – If
Truereturn the per-bond_typeexpectations instead of their sum.
- Return type:
- _gloop_region(where, gloops)[source]¶
The set of sites needed to evaluate a generalized-loop expansion of size
gloopsaroundwhere. An explicit set of loops contributes exactly its sites; an integer max-size orNone(smallest loop) is turned into a conservative graph-distance radius (a loop ofCsites reaches at most~C // 2hops out and back).
- local_expectation_gloop_expand(G, where, gloops=None, gauges=None, normalized=True, **kwargs)[source]¶
Approximate local expectation of gate
Gat siteswherevia a generalized-loop expansion with the bondgaugesas the environment. Computed on a freshly built fragment tiled out far enough to hold the loops (seebuild_fragment/_gloop_region); delegates to the fragmentTensorNetworkGenVector.- Parameters:
G (array_like) – The gate to compute the expectation of.
where (sequence[site]) – The sites to compute the expectation at (e.g. a
bond_type).gloops (None, int, or sequence[sequence[site]], optional) – The generalized loops to use, or an integer max loop size, or
Nonefor the smallest non-trivial loop.gauges (dict, optional) – Diagonal bond gauges (environments), keyed by bond index.
normalized (bool, optional) – Whether and how to normalize the result.
- Return type:
- compute_local_expectation_gloop_expand(terms, gloops=None, *, gauges=None, normalized=True, return_all=False, **kwargs)[source]¶
Sum the generalized-loop-expansion expectations of
termsover the unit cell, e.g. an energy per unit cell that is cheaper than (though less accurate than) the equivalent-size cluster estimate. Computed on a single fragment tiled out to hold the loops around every term; delegates to the fragmentTensorNetworkGenVector.- Parameters:
terms (LocalHamInfinite2D or dict[bond_type, array_like]) – Anything with an
.items()yielding(where, gate).gloops (None, int, or sequence[sequence[site]], optional) – The generalized loops to use, or an integer max loop size, or
Nonefor the smallest non-trivial loop.gauges (dict, optional) – Diagonal bond gauges (environments), keyed by bond index.
normalized (bool, optional) – Whether and how to normalize the result.
return_all (bool, optional) – If
Truereturn the per-bond_typeexpectations instead of their sum.
- Return type: