quimb.tensor.tensor_2d ====================== .. py:module:: quimb.tensor.tensor_2d .. autoapi-nested-parse:: Classes and algorithms related to 2D tensor networks. Attributes ---------- .. autoapisummary:: quimb.tensor.tensor_2d.BOUNDARY_SEQUENCE_VALID quimb.tensor.tensor_2d.BOUNDARY_SEQUENCE_MAP Classes ------- .. autoapisummary:: quimb.tensor.tensor_2d.Rotator2D quimb.tensor.tensor_2d.TensorNetwork2D quimb.tensor.tensor_2d.TensorNetwork2DVector quimb.tensor.tensor_2d.TensorNetwork2DOperator quimb.tensor.tensor_2d.TensorNetwork2DFlat quimb.tensor.tensor_2d.PEPS quimb.tensor.tensor_2d.PEPO Functions --------- .. autoapisummary:: quimb.tensor.tensor_2d.manhattan_distance quimb.tensor.tensor_2d.nearest_neighbors quimb.tensor.tensor_2d.gen_2d_bonds quimb.tensor.tensor_2d.gen_2d_plaquette quimb.tensor.tensor_2d.gen_2d_plaquettes quimb.tensor.tensor_2d.gen_2d_strings quimb.tensor.tensor_2d.parse_boundary_sequence quimb.tensor.tensor_2d.is_lone_coo quimb.tensor.tensor_2d.gate_string_split_ quimb.tensor.tensor_2d.gate_string_reduce_split_ quimb.tensor.tensor_2d.gate_2d_long_range quimb.tensor.tensor_2d.show_2d quimb.tensor.tensor_2d.calc_plaquette_sizes quimb.tensor.tensor_2d.plaquette_to_sites quimb.tensor.tensor_2d.calc_plaquette_map quimb.tensor.tensor_2d.gen_long_range_path quimb.tensor.tensor_2d.gen_long_range_swap_path quimb.tensor.tensor_2d.swap_path_to_long_range_path quimb.tensor.tensor_2d.get_swap Module Contents --------------- .. py:function:: manhattan_distance(coo_a, coo_b) .. py:function:: nearest_neighbors(coo) .. py:function:: gen_2d_bonds(Lx, Ly, steppers=None, coo_filter=None, cyclic=False) Convenience function for tiling pairs of bond coordinates on a 2D lattice given a function like ``lambda i, j: (i + 1, j + 1)``. :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param steppers: Function(s) that take args ``(i, j)`` and generate another coordinate, thus defining a bond. Only valid steps are taken. If not given, defaults to nearest neighbor bonds. :type steppers: callable or sequence of callable, optional :param coo_filter: Function that takes args ``(i, j)`` and only returns ``True`` if this is to be a valid starting coordinate. :type coo_filter: callable :Yields: **bond** (*tuple[tuple[int, int], tuple[int, int]]*) -- A pair of coordinates. .. rubric:: Examples Generate nearest neighbor bonds: >>> for bond in gen_2d_bonds(2, 2, [lambda i, j: (i, j + 1), >>> lambda i, j: (i + 1, j)]): >>> print(bond) ((0, 0), (0, 1)) ((0, 0), (1, 0)) ((0, 1), (1, 1)) ((1, 0), (1, 1)) Generate next nearest neighbor digonal bonds: >>> for bond in gen_2d_bonds(2, 2, [lambda i, j: (i + 1, j + 1), >>> lambda i, j: (i + 1, j - 1)]): >>> print(bond) ((0, 0), (1, 1)) ((0, 1), (1, 0)) .. py:function:: gen_2d_plaquette(coo0, steps) Generate a plaquette at site ``coo0`` by stepping first in ``steps`` and then the reverse steps. :param coo0: The coordinate of the first site in the plaquette. :type coo0: tuple :param steps: The steps to take to generate the plaquette. Each element should be one of ``('x+', 'x-', 'y+', 'y-')``. :type steps: tuple :Yields: **coo** (*tuple*) -- The coordinates of the sites in the plaquette, including the last site which will be the same as the first. .. py:function:: gen_2d_plaquettes(Lx, Ly, tiling) Generate a tiling of plaquettes in a square 2D lattice. :param Lx: The length of the lattice in the x direction. :type Lx: int :param Ly: The length of the lattice in the y direction. :type Ly: int :param tiling: The tiling to use: - '1': plaquettes in a checkerboard pattern, such that each edge is covered by a maximum of one plaquette. - '2' or 'full': dense tiling of plaquettes. All bulk edges will be covered twice. :type tiling: {'1', '2', 'full'} :Yields: **plaquette** (*tuple[tuple[int]]*) -- The coordinates of the sites in each plaquette, including the last site which will be the same as the first. .. py:function:: gen_2d_strings(Lx, Ly) Generate all length-wise strings in a square 2D lattice. .. py:class:: Rotator2D(tn, xrange, yrange, from_which, stepsize=1) Object for rotating coordinates and various contraction functions so that the core algorithms only have to written once, but nor does the actual TN have to be modified. :param tn: The tensor network to rotate coordinates for. :type tn: TensorNetwork2D :param xrange: The range of x-coordinates to range over. :type xrange: tuple[int, int] :param yrange: The range of y-coordinates to range over. :type yrange: tuple[int, int] :param from_which: The direction to sweep from. :type from_which: {'xmin', 'xmax', 'ymin', 'ymax'} :param stepsize: The step size to use when sweeping. :type stepsize: int, optional .. py:attribute:: tn .. py:attribute:: xrange .. py:attribute:: yrange .. py:attribute:: from_which .. py:attribute:: plane .. py:method:: sweep_other() .. py:method:: cyclic_x() .. py:method:: cyclic_y() .. py:method:: get_jnext(j) .. py:method:: get_opposite_env_fn() Get the function and location label for contracting boundaries in the opposite direction to main sweep. .. py:data:: BOUNDARY_SEQUENCE_VALID .. py:data:: BOUNDARY_SEQUENCE_MAP .. py:function:: parse_boundary_sequence(sequence) Ensure ``sequence`` is a tuple of boundary sequence strings from ``{'xmin', 'xmax', 'ymin', 'ymax'}`` .. py:class:: TensorNetwork2D(ts=(), *, virtual=False, check_collisions=True) Bases: :py:obj:`quimb.tensor.tensor_arbgeom.TensorNetworkGen` Mixin class for tensor networks with a square lattice two-dimensional structure, indexed by ``[{row},{column}]`` so that:: 'Y{j}' v i=Lx-1 ●──●──●──●──●──●── ──● | | | | | | | ... | | | | | | 'I{i},{j}' = 'I3,5' e.g. i=3 ●──●──●──●──●──●── | | | | | | | i=2 ●──●──●──●──●──●── ──● <== 'X{i}' | | | | | | ... | i=1 ●──●──●──●──●──●── ──● | | | | | | | i=0 ●──●──●──●──●──●── ──● j=0, 1, 2, 3, 4, 5 j=Ly-1 This implies the following conventions: * the 'up' bond is coordinates ``(i, j), (i + 1, j)`` * the 'down' bond is coordinates ``(i, j), (i - 1, j)`` * the 'right' bond is coordinates ``(i, j), (i, j + 1)`` * the 'left' bond is coordinates ``(i, j), (i, j - 1)`` .. py:attribute:: _NDIMS :value: 2 .. py:attribute:: _EXTRA_PROPS :value: ('_site_tag_id', '_x_tag_id', '_y_tag_id', '_Lx', '_Ly') .. py:method:: _compatible_2d(other) Check whether ``self`` and ``other`` are compatible 2D tensor networks such that they can remain a 2D tensor network when combined. .. py:method:: combine(other, *, virtual=False, check_collisions=True) Combine this tensor network with another, returning a new tensor network. If the two are compatible, cast the resulting tensor network to a :class:`TensorNetwork2D` instance. :param other: The other tensor network to combine with. :type other: TensorNetwork2D or TensorNetwork :param virtual: Whether the new tensor network should copy all the incoming tensors (``False``, the default), or view them as virtual (``True``). :type virtual: bool, optional :param check_collisions: Whether to check for index collisions between the two tensor networks before combining them. If ``True`` (the default), any inner indices that clash will be mangled. :type check_collisions: bool, optional :rtype: TensorNetwork2D or TensorNetwork .. py:property:: Lx The number of rows. .. py:property:: Ly The number of columns. .. py:property:: nsites The total number of sites. .. py:method:: site_tag(i, j=None) The name of the tag specifiying the tensor at site ``(i, j)``. .. py:property:: x_tag_id The string specifier for tagging each row of this 2D TN. .. py:method:: x_tag(i) .. py:property:: x_tags A tuple of all of the ``Lx`` different row tags. .. py:attribute:: row_tag .. py:attribute:: row_tags .. py:property:: y_tag_id The string specifier for tagging each column of this 2D TN. .. py:method:: y_tag(j) .. py:property:: y_tags A tuple of all of the ``Ly`` different column tags. .. py:attribute:: col_tag .. py:attribute:: col_tags .. py:method:: maybe_convert_coo(x) Check if ``x`` is a tuple of two ints and convert to the corresponding site tag if so. .. py:method:: _get_tids_from_tags(tags, which='all') This is the function that lets coordinates such as ``(i, j)`` be used for many 'tag' based functions. .. py:method:: gen_site_coos() Generate coordinates for all the sites in this 2D TN. .. py:method:: gen_bond_coos() Generate pairs of coordinates for all the bonds in this 2D TN. .. py:method:: gen_horizontal_bond_coos() Generate all coordinate pairs like ``(i, j), (i, j + 1)``. .. py:method:: gen_horizontal_even_bond_coos() Generate all coordinate pairs like ``(i, j), (i, j + 1)`` where ``j`` is even, which thus don't overlap at all. .. py:method:: gen_horizontal_odd_bond_coos() Generate all coordinate pairs like ``(i, j), (i, j + 1)`` where ``j`` is odd, which thus don't overlap at all. .. py:method:: gen_vertical_bond_coos() Generate all coordinate pairs like ``(i, j), (i + 1, j)``. .. py:method:: gen_vertical_even_bond_coos() Generate all coordinate pairs like ``(i, j), (i + 1, j)`` where ``i`` is even, which thus don't overlap at all. .. py:method:: gen_vertical_odd_bond_coos() Generate all coordinate pairs like ``(i, j), (i + 1, j)`` where ``i`` is odd, which thus don't overlap at all. .. py:method:: gen_diagonal_left_bond_coos() Generate all coordinate pairs like ``(i, j), (i + 1, j - 1)``. .. py:method:: gen_diagonal_left_even_bond_coos() Generate all coordinate pairs like ``(i, j), (i + 1, j - 1)`` where ``j`` is even, which thus don't overlap at all. .. py:method:: gen_diagonal_left_odd_bond_coos() Generate all coordinate pairs like ``(i, j), (i + 1, j - 1)`` where ``j`` is odd, which thus don't overlap at all. .. py:method:: gen_diagonal_right_bond_coos() Generate all coordinate pairs like ``(i, j), (i + 1, j + 1)``. .. py:method:: gen_diagonal_right_even_bond_coos() Generate all coordinate pairs like ``(i, j), (i + 1, j + 1)`` where ``i`` is even, which thus don't overlap at all. .. py:method:: gen_diagonal_right_odd_bond_coos() Generate all coordinate pairs like ``(i, j), (i + 1, j + 1)`` where ``i`` is odd, which thus don't overlap at all. .. py:method:: gen_diagonal_bond_coos() Generate all next nearest neighbor diagonal coordinate pairs. .. py:method:: valid_coo(coo, xrange=None, yrange=None) Check whether ``coo`` is in-bounds. :param coo: The coordinates to check. :type coo: (int, int, int), optional :param xrange: The range of allowed values for the x and y coordinates. :type xrange: (int, int), optional :param yrange: The range of allowed values for the x and y coordinates. :type yrange: (int, int), optional :rtype: bool .. py:method:: get_ranges_present() Return the range of site coordinates present in this TN. :returns: **xrange, yrange** -- The minimum and maximum site coordinates present in each direction. :rtype: tuple[tuple[int, int]] .. py:method:: is_cyclic_x(j=None, imin=None, imax=None) Check if the x dimension is cyclic (periodic), specifically whether a bond exists between ``(imin, j)`` and ``(imax, j)``, with default values of ``imin = 0`` and ``imax = Lx - 1``, and ``j`` at the center of the lattice. If ``imin`` and ``imax`` are adjacent then this is considered False, since there is no 'extra' connectivity. .. py:method:: is_cyclic_y(i=None, jmin=None, jmax=None) Check if the y dimension is cyclic (periodic), specifically whether a bond exists between ``(i, jmin)`` and ``(i, jmax)``, with default values of ``jmin = 0`` and ``jmax = Ly - 1``, and ``i`` at the center of the lattice. If ``jmin`` and ``jmax`` are adjacent then this is considered False, since there is no 'extra' connectivity. .. py:method:: __getitem__(key) Key based tensor selection, checking for integer based shortcut. .. py:method:: show() Print a unicode schematic of this 2D TN and its bond dimensions. .. py:method:: _repr_info() General info to show in various reprs. Sublasses can add more relevant info to this dict. .. py:method:: flatten(fuse_multibonds=True, inplace=False) Contract all tensors corresponding to each site into one. .. py:attribute:: flatten_ .. py:method:: gen_pairs(xrange=None, yrange=None, xreverse=False, yreverse=False, coordinate_order='xy', xstep=None, ystep=None, stepping_order='xy', step_only=None) Helper function for generating pairs of cooordinates for all bonds within a certain range, optionally specifying an order. :param xrange: The range of allowed values for the x and y coordinates. :type xrange: (int, int), optional :param yrange: The range of allowed values for the x and y coordinates. :type yrange: (int, int), optional :param xreverse: Whether to reverse the order of the x and y sweeps. :type xreverse: bool, optional :param yreverse: Whether to reverse the order of the x and y sweeps. :type yreverse: bool, optional :param coordinate_order: The order in which to sweep the x and y coordinates. Earlier dimensions will change slower. If the corresponding range has size 1 then that dimension doesn't need to be specified. :type coordinate_order: str, optional :param xstep: When generating a bond, step in this direction to yield the neighboring coordinate. By default, these follow ``xreverse`` and ``yreverse`` respectively. :type xstep: int, optional :param ystep: When generating a bond, step in this direction to yield the neighboring coordinate. By default, these follow ``xreverse`` and ``yreverse`` respectively. :type ystep: int, optional :param stepping_order: The order in which to step the x and y coordinates to generate bonds. Does not need to include all dimensions. :type stepping_order: str, optional :param step_only: Only perform the ith steps in ``stepping_order``, used to interleave canonizing and compressing for example. :type step_only: int, optional :Yields: **coo_a, coo_b** (*((int, int), (int, int))*) .. py:method:: canonize_plane(xrange, yrange, equalize_norms=False, canonize_opts=None, **gen_pair_opts) Canonize every pair of tensors within a subrange, optionally specifying a order to visit those pairs in. .. py:method:: canonize_row(i, sweep, yrange=None, **canonize_opts) Canonize all or part of a row. If ``sweep == 'right'`` then:: | | | | | | | | | | | | | | ─●──●──●──●──●──●──●─ ─●──●──●──●──●──●──●─ | | | | | | | | | | | | | | ─●──●──●──●──●──●──●─ ==> ─●──>──>──>──>──o──●─ row=i | | | | | | | | | | | | | | ─●──●──●──●──●──●──●─ ─●──●──●──●──●──●──●─ | | | | | | | | | | | | | | . . . . jstart jstop jstart jstop If ``sweep == 'left'`` then:: | | | | | | | | | | | | | | ─●──●──●──●──●──●──●─ ─●──●──●──●──●──●──●─ | | | | | | | | | | | | | | ─●──●──●──●──●──●──●─ ==> ─●──o──<──<──<──<──●─ row=i | | | | | | | | | | | | | | ─●──●──●──●──●──●──●─ ─●──●──●──●──●──●──●─ | | | | | | | | | | | | | | . . . . jstop jstart jstop jstart Does not yield an orthogonal form in the same way as in 1D. :param i: Which row to canonize. :type i: int :param sweep: Which direction to sweep in. :type sweep: {'right', 'left'} :param jstart: Starting column, defaults to whole row. :type jstart: int or None :param jstop: Stopping column, defaults to whole row. :type jstop: int or None :param canonize_opts: Supplied to ``canonize_between``. .. py:method:: canonize_column(j, sweep, xrange=None, **canonize_opts) Canonize all or part of a column. If ``sweep='up'`` then:: | | | | | | ─●──●──●─ ─●──●──●─ | | | | | | ─●──●──●─ ─●──o──●─ istop | | | ==> | | | ─●──●──●─ ─●──^──●─ | | | | | | ─●──●──●─ ─●──^──●─ istart | | | | | | ─●──●──●─ ─●──●──●─ | | | | | | . . j j If ``sweep='down'`` then:: | | | | | | ─●──●──●─ ─●──●──●─ | | | | | | ─●──●──●─ ─●──v──●─ istart | | | ==> | | | ─●──●──●─ ─●──v──●─ | | | | | | ─●──●──●─ ─●──o──●─ istop | | | | | | ─●──●──●─ ─●──●──●─ | | | | | | . . j j Does not yield an orthogonal form in the same way as in 1D. :param j: Which column to canonize. :type j: int :param sweep: Which direction to sweep in. :type sweep: {'up', 'down'} :param xrange: The range of columns to canonize. :type xrange: None or (int, int), optional :param canonize_opts: Supplied to ``canonize_between``. .. py:method:: canonize_row_around(i, around=(0, 1)) .. py:method:: compress_plane(xrange, yrange, max_bond=None, cutoff=1e-10, equalize_norms=False, compress_opts=None, **gen_pair_opts) Compress every pair of tensors within a subrange, optionally specifying a order to visit those pairs in. .. py:method:: compress_row(i, sweep, yrange=None, max_bond=None, cutoff=1e-10, equalize_norms=False, compress_opts=None) Compress all or part of a row. If ``sweep == 'right'`` then:: | | | | | | | | | | | | | | ━●━━●━━●━━●━━●━━●━━●━ ━●━━●━━●━━●━━●━━●━━●━ | | | | | | | | | | | | | | ━●━━●━━●━━●━━●━━●━━●━ ━━> ━●━━>──>──>──>──o━━●━ row=i | | | | | | | | | | | | | | ━●━━●━━●━━●━━●━━●━━●━ ━●━━●━━●━━●━━●━━●━━●━ | | | | | | | | | | | | | | . . . . jstart jstop jstart jstop If ``sweep == 'left'`` then:: | | | | | | | | | | | | | | ━●━━●━━●━━●━━●━━●━━●━ ━●━━●━━●━━●━━●━━●━━●━ | | | | | | | | | | | | | | ━●━━●━━●━━●━━●━━●━━●━ ━━> ━●━━o──<──<──<──<━━●━ row=i | | | | | | | | | | | | | | ━●━━●━━●━━●━━●━━●━━●━ ━●━━●━━●━━●━━●━━●━━●━ | | | | | | | | | | | | | | . . . . jstop jstart jstop jstart Does not yield an orthogonal form in the same way as in 1D. :param i: Which row to compress. :type i: int :param sweep: Which direction to sweep in. :type sweep: {'right', 'left'} :param yrange: The range of columns to compress. :type yrange: tuple[int, int] or None :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param compress_opts: Supplied to :meth:`compress_between`. :type compress_opts: None or dict, optional .. py:method:: compress_column(j, sweep, xrange=None, max_bond=None, cutoff=1e-10, equalize_norms=False, compress_opts=None) Compress all or part of a column. If ``sweep='up'`` then:: ┃ ┃ ┃ ┃ ┃ ┃ ─●──●──●─ ─●──●──●─ ┃ ┃ ┃ ┃ ┃ ┃ ─●──●──●─ ─●──o──●─ . ┃ ┃ ┃ ==> ┃ | ┃ . ─●──●──●─ ─●──^──●─ . xrange ┃ ┃ ┃ ┃ | ┃ . ─●──●──●─ ─●──^──●─ . ┃ ┃ ┃ ┃ ┃ ┃ ─●──●──●─ ─●──●──●─ ┃ ┃ ┃ ┃ ┃ ┃ . . j j If ``sweep='down'`` then:: ┃ ┃ ┃ ┃ ┃ ┃ ─●──●──●─ ─●──●──●─ ┃ ┃ ┃ ┃ ┃ ┃ ─●──●──●─ ─●──v──●─ . ┃ ┃ ┃ ==> ┃ | ┃ . ─●──●──●─ ─●──v──●─ . xrange ┃ ┃ ┃ ┃ | ┃ . ─●──●──●─ ─●──o──●─ . ┃ ┃ ┃ ┃ ┃ ┃ ─●──●──●─ ─●──●──●─ ┃ ┃ ┃ ┃ ┃ ┃ . . j j Does not yield an orthogonal form in the same way as in 1D. :param j: Which column to compress. :type j: int :param sweep: Which direction to sweep in. :type sweep: {'up', 'down'} :param xrange: The range of rows to compress. :type xrange: None or (int, int), optional :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param compress_opts: Supplied to :meth:`compress_between`. :type compress_opts: None or dict, optional .. py:method:: _contract_boundary_core_via_1d(xrange, yrange, from_which, max_bond, cutoff=1e-10, method='dm', layer_tags=None, **compress_opts) .. py:method:: _contract_boundary_core(xrange, yrange, from_which, max_bond, cutoff=1e-10, canonize=True, layer_tags=None, compress_late=True, sweep_reverse=False, equalize_norms=False, compress_opts=None, canonize_opts=None) .. py:method:: _contract_boundary_full_bond(xrange, yrange, from_which, max_bond, cutoff=0.0, method='eigh', renorm=False, optimize='auto-hq', opposite_envs=None, equalize_norms=False, contract_boundary_opts=None) Contract the boundary of this 2D TN using the 'full bond' environment information obtained from a boundary contraction in the opposite direction. :param xrange: The range of rows to contract and compress. :type xrange: (int, int) or None, optional :param yrange: The range of columns to contract and compress. :type yrange: (int, int) :param from_which: Which direction to contract the rectangular patch from. :type from_which: {'xmin', 'ymin', 'xmax', 'ymax'} :param max_bond: The maximum boundary dimension, AKA 'chi'. By default used for the opposite direction environment contraction as well. :type max_bond: int :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction - only for the opposite direction environment contraction. :type cutoff: float, optional :param method: Which similarity decomposition method to use to compress the full bond environment. :type method: {'eigh', 'eig', 'svd', 'biorthog'}, optional :param renorm: Whether to renormalize the isometric projection or not. :type renorm: bool, optional :param optimize: Contraction optimizer to use for the exact contractions. :type optimize: str or PathOptimize, optimize :param opposite_envs: If supplied, the opposite environments will be fetched or lazily computed into this dict depending on whether they are missing. :type opposite_envs: dict, optional :param contract_boundary_opts: Other options given to the opposite direction environment contraction. .. py:method:: _contract_boundary_projector(xrange, yrange, from_which, max_bond=None, cutoff=1e-10, lazy=False, equalize_norms=False, optimize='auto-hq', compress_opts=None) Contract the boundary of this 2D tensor network by explicitly computing and inserting explicit local projector tensors, which can optionally be left uncontracted. Multilayer networks are naturally supported. :param xrange: The range of x indices to contract. :type xrange: tuple :param yrange: The range of y indices to contract. :type yrange: tuple :param from_which: From which boundary to contract. :type from_which: {'xmin', 'xmax', 'ymin', 'ymax'} :param max_bond: The maximum bond dimension to contract to. If ``None`` (default), compression is left to ``cutoff``. :type max_bond: int, optional :param cutoff: The cutoff to use for boundary compression. :type cutoff: float, optional :param lazy: Whether to leave the boundary tensors uncontracted. If ``False`` (the default), the boundary tensors are contracted and the resulting boundary has a single tensor per site. :type lazy: bool, optional :param equalize_norms: Whether to actively absorb the norm of modified tensors into ``self.exponent``. :type equalize_norms: bool, optional :param optimize: The contract path optimization to use when forming the projector tensors. :type optimize: str or PathOptimizer, optional :param compress_opts: Other options to pass to :func:`~quimb.tensor.decomp.svd_truncated`. :type compress_opts: dict, optional .. seealso:: :obj:`TensorNetwork.insert_compressor_between_regions` .. py:method:: contract_boundary_from(xrange, yrange, from_which, max_bond=None, *, cutoff=1e-10, canonize=True, mode='mps', layer_tags=None, sweep_reverse=False, compress_opts=None, inplace=False, **contract_boundary_opts) Unified entrypoint for contracting any rectangular patch of tensors from any direction, with any boundary method. .. py:attribute:: contract_boundary_from_ .. py:method:: contract_boundary_from_xmin(xrange, yrange=None, max_bond=None, *, cutoff=1e-10, canonize=True, mode='mps', layer_tags=None, sweep_reverse=False, compress_opts=None, inplace=False, **contract_boundary_opts) Contract a 2D tensor network inwards from the bottom, canonizing and compressing (left to right) along the way. If ``layer_tags is None`` this looks like:: a) contract │ │ │ │ │ ●──●──●──●──● │ │ │ │ │ │ │ │ │ │ --> ●══●══●══●══● ●──●──●──●──● b) optionally canonicalize │ │ │ │ │ ●══●══<══<══< c) compress in opposite direction │ │ │ │ │ --> │ │ │ │ │ --> │ │ │ │ │ >──●══●══●══● --> >──>──●══●══● --> >──>──>──●══● . . --> . . --> . . If ``layer_tags`` is specified, each then each layer is contracted in and compressed separately, resulting generally in a lower memory scaling. For two layer tags this looks like:: a) first flatten the outer boundary only │ ││ ││ ││ ││ │ │ ││ ││ ││ ││ │ ●─○●─○●─○●─○●─○ ●─○●─○●─○●─○●─○ │ ││ ││ ││ ││ │ ==> ╲│ ╲│ ╲│ ╲│ ╲│ ●─○●─○●─○●─○●─○ ●══●══●══●══● b) contract and compress a single layer only │ ││ ││ ││ ││ │ │ ○──○──○──○──○ │╱ │╱ │╱ │╱ │╱ ●══<══<══<══< c) contract and compress the next layer ╲│ ╲│ ╲│ ╲│ ╲│ >══>══>══>══● :param xrange: The range of rows to compress (inclusive). :type xrange: (int, int) :param yrange: The range of columns to compress (inclusive), sweeping along with canonization and compression. Defaults to all columns. :type yrange: (int, int) or None, optional :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param canonize: Whether to sweep one way with canonization before compressing. :type canonize: bool, optional :param mode: How to perform the compression on the boundary. :type mode: {'mps', 'full-bond'}, optional :param layer_tags: If ``None``, all tensors at each coordinate pair ``[(i, j), (i + 1, j)]`` will be first contracted. If specified, then the outer tensor at ``(i, j)`` will be contracted with the tensor specified by ``[(i + 1, j), layer_tag]``, for each ``layer_tag`` in ``layer_tags``. :type layer_tags: None or sequence[str], optional :param sweep_reverse: Which way to perform the compression sweep, which has an effect on which tensors end up being canonized. Setting this to true sweeps the compression from largest to smallest coordinates. :type sweep_reverse: bool, optional :param compress_opts: Supplied to :meth:`compress_between`. :type compress_opts: None or dict, optional :param inplace: Whether to perform the contraction inplace or not. :type inplace: bool, optional .. seealso:: :obj:`contract_boundary_from_xmax`, :obj:`contract_boundary_from_ymin`, :obj:`contract_boundary_from_ymax` .. py:attribute:: contract_boundary_from_xmin_ .. py:method:: contract_boundary_from_xmax(xrange, yrange=None, max_bond=None, *, cutoff=1e-10, canonize=True, mode='mps', layer_tags=None, inplace=False, sweep_reverse=False, compress_opts=None, **contract_boundary_opts) Contract a 2D tensor network inwards from the top, canonizing and compressing (right to left) along the way. If ``layer_tags is None`` this looks like:: a) contract ●──●──●──●──● | | | | | --> ●══●══●══●══● ●──●──●──●──● | | | | | | | | | | b) optionally canonicalize ●══●══<══<══< | | | | | c) compress in opposite direction >──●══●══●══● --> >──>──●══●══● --> >──>──>──●══● | | | | | --> | | | | | --> | | | | | . . --> . . --> . . If ``layer_tags`` is specified, each then each layer is contracted in and compressed separately, resulting generally in a lower memory scaling. For two layer tags this looks like:: a) first flatten the outer boundary only ●─○●─○●─○●─○●─○ ●══●══●══●══● │ ││ ││ ││ ││ │ ==> ╱│ ╱│ ╱│ ╱│ ╱│ ●─○●─○●─○●─○●─○ ●─○●─○●─○●─○●─○ │ ││ ││ ││ ││ │ │ ││ ││ ││ ││ │ b) contract and compress a single layer only ●══<══<══<══< │╲ │╲ │╲ │╲ │╲ │ ○──○──○──○──○ │ ││ ││ ││ ││ │ c) contract and compress the next layer ●══●══●══●══● ╱│ ╱│ ╱│ ╱│ ╱│ :param xrange: The range of rows to compress (inclusive). :type xrange: (int, int) :param yrange: The range of columns to compress (inclusive), sweeping along with canonization and compression. Defaults to all columns. :type yrange: (int, int) or None, optional :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param canonize: Whether to sweep one way with canonization before compressing. :type canonize: bool, optional :param mode: How to perform the compression on the boundary. :type mode: {'mps', 'full-bond'}, optional :param layer_tags: If ``None``, all tensors at each coordinate pair ``[(i, j), (i - 1, j)]`` will be first contracted. If specified, then the outer tensor at ``(i, j)`` will be contracted with the tensor specified by ``[(i - 1, j), layer_tag]``, for each ``layer_tag`` in ``layer_tags``. :type layer_tags: None or str, optional :param sweep_reverse: Which way to perform the compression sweep, which has an effect on which tensors end up being canonized. Setting this to true sweeps the compression from largest to smallest coordinates. :type sweep_reverse: bool, optional :param compress_opts: Supplied to :meth:`compress_between`. :type compress_opts: None or dict, optional :param inplace: Whether to perform the contraction inplace or not. :type inplace: bool, optional .. seealso:: :obj:`contract_boundary_from_xmin`, :obj:`contract_boundary_from_ymin`, :obj:`contract_boundary_from_ymax` .. py:attribute:: contract_boundary_from_xmax_ .. py:method:: contract_boundary_from_ymin(yrange, xrange=None, max_bond=None, *, cutoff=1e-10, canonize=True, mode='mps', layer_tags=None, sweep_reverse=False, compress_opts=None, inplace=False, **contract_boundary_opts) Contract a 2D tensor network inwards from the left, canonizing and compressing (bottom to top) along the way. If ``layer_tags is None`` this looks like:: a) contract ●──●── ●── │ │ ║ ●──●── ==> ●── │ │ ║ ●──●── ●── b) optionally canonicalize ●── v── ║ ║ ●── ==> v── ║ ║ ●── ●── c) compress in opposite direction v── ●── ║ │ v── ==> ^── ║ │ ●── ^── If ``layer_tags`` is specified, each then each layer is contracted in and compressed separately, resulting generally in a lower memory scaling. For two layer tags this looks like:: a) first flatten the outer boundary only ○──○── ●──○── │╲ │╲ │╲ │╲ ●─○──○── ╰─●──○── ╲│╲╲│╲ ==> │╲╲│╲ ●─○──○── ╰─●──○── ╲│ ╲│ │ ╲│ ●──●── ╰──●── b) contract and compress a single layer only ○── ╱╱ ╲ ●─── ○── ╲ ╱╱ ╲ ^─── ○── ╲ ╱╱ ^───── c) contract and compress the next layer ●── │╲ ╰─●── │╲ ╰─●── │ ╰── :param yrange: The range of columns to compress (inclusive). :type yrange: (int, int) :param xrange: The range of rows to compress (inclusive), sweeping along with canonization and compression. Defaults to all rows. :type xrange: (int, int) or None, optional :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param canonize: Whether to sweep one way with canonization before compressing. :type canonize: bool, optional :param mode: How to perform the compression on the boundary. :type mode: {'mps', 'full-bond'}, optional :param layer_tags: If ``None``, all tensors at each coordinate pair ``[(i, j), (i, j + 1)]`` will be first contracted. If specified, then the outer tensor at ``(i, j)`` will be contracted with the tensor specified by ``[(i + 1, j), layer_tag]``, for each ``layer_tag`` in ``layer_tags``. :type layer_tags: None or str, optional :param sweep_reverse: Which way to perform the compression sweep, which has an effect on which tensors end up being canonized. Setting this to true sweeps the compression from largest to smallest coordinates. :type sweep_reverse: bool, optional :param compress_opts: Supplied to :meth:`compress_between`. :type compress_opts: None or dict, optional :param inplace: Whether to perform the contraction inplace or not. :type inplace: bool, optional .. seealso:: :obj:`contract_boundary_from_xmin`, :obj:`contract_boundary_from_xmax`, :obj:`contract_boundary_from_ymax` .. py:attribute:: contract_boundary_from_ymin_ .. py:method:: contract_boundary_from_ymax(yrange, xrange=None, max_bond=None, *, cutoff=1e-10, canonize=True, mode='mps', layer_tags=None, sweep_reverse=False, compress_opts=None, inplace=False, **contract_boundary_opts) Contract a 2D tensor network inwards from the left, canonizing and compressing (top to bottom) along the way. If ``layer_tags is None`` this looks like:: a) contract ──●──● ──● │ │ ║ ──●──● ==> ──● │ │ ║ ──●──● ──● b) optionally canonicalize ──● ──v ║ ║ ──● ==> ──v ║ ║ ──● ──● c) compress in opposite direction ──v ──● ║ │ ──v ==> ──^ ║ │ ──● ──^ If ``layer_tags`` is specified, each then each layer is contracted in and compressed separately, resulting generally in a lower memory scaling. For two layer tags this looks like:: a) first flatten the outer boundary only ──○──○ ──○──● ╱│ ╱│ ╱│ ╱│ ──○──○─● ──○──●─╯ ╱│╱╱│╱ ==> ╱│╱╱│ ──○──○─● ──○──●─╯ │╱ │╱ │╱ │ ──●──● ──●──╯ b) contract and compress a single layer only ──○ ╱ ╲╲ ──○────v ╱ ╲╲ ╱ ──○────v ╲╲ ╱ ─────● c) contract and compress the next layer ╲ ────v ╲ ╱ ────v ╲ ╱ ────● :param yrange: The range of columns to compress (inclusive). :type yrange: (int, int) :param xrange: The range of rows to compress (inclusive), sweeping along with canonization and compression. Defaults to all rows. :type xrange: (int, int) or None, optional :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param canonize: Whether to sweep one way with canonization before compressing. :type canonize: bool, optional :param mode: How to perform the compression on the boundary. :type mode: {'mps', 'full-bond'}, optional :param layer_tags: If ``None``, all tensors at each coordinate pair ``[(i, j), (i, j - 1)]`` will be first contracted. If specified, then the outer tensor at ``(i, j)`` will be contracted with the tensor specified by ``[(i + 1, j), layer_tag]``, for each ``layer_tag`` in ``layer_tags``. :type layer_tags: None or str, optional :param sweep_reverse: Which way to perform the compression sweep, which has an effect on which tensors end up being canonized. Setting this to true sweeps the compression from largest to smallest coordinates. :type sweep_reverse: bool, optional :param compress_opts: Supplied to :meth:`compress_between`. :type compress_opts: None or dict, optional :param inplace: Whether to perform the contraction inplace or not. :type inplace: bool, optional .. seealso:: :obj:`contract_boundary_from_xmin`, :obj:`contract_boundary_from_xmax`, :obj:`contract_boundary_from_ymin` .. py:attribute:: contract_boundary_from_ymax_ .. py:method:: _contract_interleaved_boundary_sequence(*, contract_boundary_opts=None, sequence=None, xmin=None, xmax=None, ymin=None, ymax=None, max_separation=1, max_unfinished=1, around=None, equalize_norms=False, canonize=False, canonize_opts=None, final_contract=True, final_contract_opts=None, progbar=False, inplace=False) Unified handler for performing iterleaved contractions in a sequence of inwards boundary directions. .. py:method:: contract_boundary(max_bond=None, *, cutoff=1e-10, canonize=True, mode='mps', layer_tags=None, compress_opts=None, sequence=None, xmin=None, xmax=None, ymin=None, ymax=None, max_separation=1, max_unfinished=1, around=None, equalize_norms=False, final_contract=True, final_contract_opts=None, progbar=None, inplace=False, **contract_boundary_opts) Contract the boundary of this 2D tensor network inwards:: ●──●──●──● ●──●──●──● ●──●──● │ │ │ │ │ │ │ │ ║ │ │ ●──●──●──● ●──●──●──● ^──●──● >══>══● >──v │ │ij│ │ ==> │ │ij│ │ ==> ║ij│ │ ==> │ij│ │ ==> │ij║ ●──●──●──● ●══<══<══< ^──<──< ^──<──< ^──< │ │ │ │ ●──●──●──● Optionally from any or all of the boundary, in multiple layers, and stopping around a region. The default is to contract the boundary from the two shortest opposing sides. :param around: If given, don't contract the square of sites bounding these coordinates. :type around: None or sequence of (int, int), optional :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param canonize: Whether to sweep one way with canonization before compressing. :type canonize: bool, optional :param mode: How to perform the compression on the boundary, can also be any of the generic 1D or arbgeom methods. :type mode: {'mps', 'full-bond', ...}, optional :param layer_tags: If given, perform a multilayer contraction, contracting the inner sites in each layer into the boundary individually. :type layer_tags: None or sequence of str, optional :param compress_opts: Other low level options to pass to :meth:`~quimb.tensor.tensor_core.TensorNetwork.compress_between`. :type compress_opts: None or dict, optional :param sequence: Which directions to cycle throught when performing the inwards contractions, i.e. *from* that direction. If ``around`` is specified you will likely need all of these! Default is to contract from the two shortest opposing sides. :type sequence: sequence of {'xmin', 'xmax', 'ymin', 'ymax'}, optional :param xmin: The initial bottom boundary row, defaults to 0. :type xmin: int, optional :param xmax: The initial top boundary row, defaults to ``Lx - 1``. :type xmax: int, optional :param ymin: The initial left boundary column, defaults to 0. :type ymin: int, optional :param ymax: The initial right boundary column, defaults to ``Ly - 1``.. :type ymax: int, optional :param max_separation: If ``around is None``, when any two sides become this far apart simply contract the remaining tensor network. :type max_separation: int, optional :param max_unfinished: If ``around is None``, when this many sides are still not within ``max_separation`` simply contract the remaining tensor network. :type max_unfinished: int, optional :param around: If given, don't contract the square of sites bounding these coordinates. :type around: None or sequence of (int, int), optional :param equalize_norms: Whether to equalize the norms of the boundary tensors after each contraction, gathering the overall scaling coefficient, log10, in ``tn.exponent``. :type equalize_norms: bool or float, optional :param final_contract: Whether to exactly contract the remaining tensor network after the boundary contraction. :type final_contract: bool, optional :param final_contract_opts: Options to pass to :meth:`~quimb.tensor.tensor_core.TensorNetwork.contract`, ``optimize`` defaults to ``'auto-hq'``. :type final_contract_opts: None or dict, optional :param progbar: Whether to show a progress bar. :type progbar: bool, optional :param inplace: Whether to perform the contraction in place or not. :type inplace: bool, optional :param contract_boundary_opts: Supplied to :meth:`contract_boundary_from`, including compression and canonization options. .. py:attribute:: contract_boundary_ .. py:method:: contract_mps_sweep(max_bond=None, *, cutoff=1e-10, canonize=True, direction=None, **contract_boundary_opts) Contract this 2D tensor network by sweeping an MPS across from one side to the other. :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param canonize: Whether to sweep one way with canonization before compressing. :type canonize: bool, optional :param direction: Which direction to sweep from. If ``None`` (default) then the shortest boundary is chosen. :type direction: {'xmin', 'xmax', 'ymin', 'ymax'}, optional :param contract_boundary_opts: Supplied to :meth:`contract_boundary_from`, including compression and canonization options. .. py:attribute:: contract_mps_sweep_ .. py:method:: contract_full_bootstrap(n, *, optimize='auto-hq', **kwargs) .. py:method:: compute_environments(from_which, xrange=None, yrange=None, max_bond=None, *, cutoff=1e-10, canonize=True, mode='mps', layer_tags=None, dense=False, compress_opts=None, envs=None, **contract_boundary_opts) Compute the 1D boundary tensor networks describing the environments of rows and columns. :param from_which: Which boundary to compute the environments from. :type from_which: {'xmin', 'xmax', 'ymin', 'ymax'} :param xrange: The range of rows to compute the environments for. :type xrange: tuple[int], optional :param yrange: The range of columns to compute the environments for. :type yrange: tuple[int], optional :param max_bond: The maximum bond dimension of the environments. :type max_bond: int, optional :param cutoff: The cutoff for the singular values of the environments. :type cutoff: float, optional :param canonize: Whether to canonicalize along each MPS environment before compressing. :type canonize: bool, optional :param mode: Which contraction method to use for the environments. :type mode: {'mps', 'projector', 'full-bond'}, optional :param layer_tags: If this 2D TN is multi-layered (e.g. a bra and a ket), and ``mode == 'mps'``, contract and compress each specified layer separately, for a cheaper contraction. :type layer_tags: str or iterable[str], optional :param dense: Whether to use dense tensors for the environments. :type dense: bool, optional :param compress_opts: Other options to pass to :func:`~quimb.tensor.tensor_core.tensor_compress_bond`. :type compress_opts: dict, optional :param envs: An existing dictionary to store the environments in. :type envs: dict, optional :param contract_boundary_opts: Other options to pass to :meth:`~quimb.tensor.tensor_2d.TensorNetwork2D.contract_boundary_from`. :returns: **envs** -- A dictionary of the environments, with keys of the form ``(from_which, row_or_col_index)``. :rtype: dict .. py:attribute:: compute_xmin_environments Compute the ``self.Lx`` 1D boundary tensor networks describing the lower environments of each row in this 2D tensor network. See :meth:`~quimb.tensor.tensor_2d.TensorNetwork2D.compute_x_environments` for full details. .. py:attribute:: compute_xmax_environments Compute the ``self.Lx`` 1D boundary tensor networks describing the upper environments of each row in this 2D tensor network. See :meth:`~quimb.tensor.tensor_2d.TensorNetwork2D.compute_x_environments` for full details. .. py:attribute:: compute_ymin_environments Compute the ``self.Ly`` 1D boundary tensor networks describing the left environments of each column in this 2D tensor network. See :meth:`~quimb.tensor.tensor_2d.TensorNetwork2D.compute_y_environments` for full details. .. py:attribute:: compute_ymax_environments Compute the ``self.Ly`` 1D boundary tensor networks describing the right environments of each column in this 2D tensor network. See :meth:`~quimb.tensor.tensor_2d.TensorNetwork2D.compute_y_environments` for full details. .. py:method:: compute_x_environments(max_bond=None, *, cutoff=1e-10, canonize=True, dense=False, mode='mps', layer_tags=None, compress_opts=None, envs=None, **contract_boundary_opts) Compute the ``2 * self.Lx`` 1D boundary tensor networks describing the lower and upper environments of each row in this 2D tensor network, *assumed to represent the norm*. The top or 'xmax' environment for row ``i`` will be a contraction of all rows ``i + 1, i + 2, ...`` etc:: ●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━● ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ The bottom or 'xmin' environment for row ``i`` will be a contraction of all rows ``i - 1, i - 2, ...`` etc:: ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━● Such that ``envs['xmax', i] & self.select(self.x_tag(i)) & envs['xmin', i]`` would look like:: ●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━● ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ o─o─o─o─o─o─o─o─o─o─o─o─o─o─o─o─o─o─o─o ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ ●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━● And be (an approximation of) the norm centered around row ``i`` :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param canonize: Whether to sweep one way with canonization before compressing. :type canonize: bool, optional :param dense: If true, contract the boundary in as a single dense tensor. :type dense: bool, optional :param mode: How to perform the boundary compression. :type mode: {'mps', 'full-bond'}, optional :param layer_tags: If ``None``, all tensors at each coordinate pair ``[(i, j), (i + 1, j)]`` will be first contracted. If specified, then the outer tensor at ``(i, j)`` will be contracted with the tensor specified by ``[(i + 1, j), layer_tag]``, for each ``layer_tag`` in ``layer_tags``. :type layer_tags: None or sequence[str], optional :param compress_opts: Supplied to :meth:`compress_between`. :type compress_opts: None or dict, optional :param envs: Supply an existing dictionary to store the environments in. :type envs: dict, optional :param contract_boundary_opts: Supplied to :meth:`~quimb.tensor.tensor_2d.TensorNetwork2D.contract_boundary_from_xmin` and :meth:`~quimb.tensor.tensor_2d.TensorNetwork2D.contract_boundary_from_xmax` . :returns: **x_envs** -- The two environment tensor networks of row ``i`` will be stored in ``x_envs['xmin', i]`` and ``x_envs['xmax', i]``. :rtype: dict[(str, int), TensorNetwork] .. py:method:: compute_y_environments(max_bond=None, *, cutoff=1e-10, canonize=True, dense=False, mode='mps', layer_tags=None, compress_opts=None, envs=None, **contract_boundary_opts) Compute the ``2 * self.Ly`` 1D boundary tensor networks describing the left ('ymin') and right ('ymax') environments of each column in this 2D tensor network, assumed to represent the norm. The left or 'ymin' environment for column ``j`` will be a contraction of all columns ``j - 1, j - 2, ...`` etc:: ●< ┃ ●< ┃ ●< ┃ ●< The right or 'ymax' environment for row ``j`` will be a contraction of all rows ``j + 1, j + 2, ...`` etc:: >● ┃ >● ┃ >● ┃ >● Such that ``envs['ymin', j] & self.select(self.y_tag(j)) & envs['ymax', j]`` would look like:: ╱o ●< o| >● ┃ |o ┃ ●< o| >● ┃ |o ┃ ●< o| >● ┃ |o ┃ ●< o╱ >● And be (an approximation of) the norm centered around column ``j`` :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param canonize: Whether to sweep one way with canonization before compressing. :type canonize: bool, optional :param dense: If true, contract the boundary in as a single dense tensor. :type dense: bool, optional :param mode: How to perform the boundary compression. :type mode: {'mps', 'full-bond'}, optional :param layer_tags: If ``None``, all tensors at each coordinate pair ``[(i, j), (i + 1, j)]`` will be first contracted. If specified, then the outer tensor at ``(i, j)`` will be contracted with the tensor specified by ``[(i + 1, j), layer_tag]``, for each ``layer_tag`` in ``layer_tags``. :type layer_tags: None or sequence[str], optional :param compress_opts: Supplied to :meth:`compress_between`. :type compress_opts: None or dict, optional :param contract_boundary_opts: Supplied to :meth:`~quimb.tensor.tensor_2d.TensorNetwork2D.contract_boundary_from_ymin` and :meth:`~quimb.tensor.tensor_2d.TensorNetwork2D.contract_boundary_from_ymax` . :returns: **y_envs** -- The two environment tensor networks of column ``j`` will be stored in ``y_envs['ymin', j]`` and ``y_envs['ymax', j]``. :rtype: dict[(str, int), TensorNetwork] .. py:method:: _compute_plaquette_environments_x_first(x_bsz, y_bsz, max_bond=None, cutoff=1e-10, canonize=True, layer_tags=None, second_dense=None, x_envs=None, **compute_environment_opts) .. py:method:: _compute_plaquette_environments_y_first(x_bsz, y_bsz, max_bond=None, cutoff=1e-10, canonize=True, layer_tags=None, second_dense=None, y_envs=None, **compute_environment_opts) .. py:method:: compute_plaquette_environments(x_bsz=2, y_bsz=2, max_bond=None, *, cutoff=1e-10, canonize=True, mode='mps', layer_tags=None, first_contract=None, second_dense=None, compress_opts=None, **compute_environment_opts) Compute all environments like:: second_dense=False second_dense=True (& first_contract='columns') ●──● ╭───●───╮ ╱│ │╲ │ ╱ ╲ │ ●─. .─● ┬ ●─ . . ─● ┬ │ │ ┊ x_bsz │ │ ┊ x_bsz ●─. .─● ┴ ●─ . . ─● ┴ ╲│ │╱ │ ╲ ╱ │ ●──● ╰───●───╯ <--> <-> y_bsz y_bsz Use two boundary contractions sweeps. :param x_bsz: The size of the plaquettes in the x-direction (number of rows). :type x_bsz: int, optional :param y_bsz: The size of the plaquettes in the y-direction (number of columns). :type y_bsz: int, optional :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param canonize: Whether to sweep one way with canonization before compressing. :type canonize: bool, optional :param mode: How to perform the boundary compression. :type mode: {'mps', 'full-bond'}, optional :param layer_tags: If ``None``, all tensors at each coordinate pair ``[(i, j), (i + 1, j)]`` will be first contracted. If specified, then the outer tensor at ``(i, j)`` will be contracted with the tensor specified by ``[(i + 1, j), layer_tag]``, for each ``layer_tag`` in ``layer_tags``. :type layer_tags: None or sequence[str], optional :param first_contract: The environments can either be generated with initial sweeps in the row ('x') or column ('y') direction. Generally it makes sense to perform this approximate step in whichever is smaller (the default). :type first_contract: {None, 'x', 'y'}, optional :param second_dense: Whether to perform the second set of contraction sweeps (in the rotated direction from whichever ``first_contract`` is) using a dense tensor or boundary method. By default this is only turned on if the ``bsz`` in the corresponding direction is 1. :type second_dense: None or bool, optional :param compress_opts: Supplied to :meth:`compress_between`. :type compress_opts: None or dict, optional :param compute_environment_opts: Supplied to :meth:`~quimb.tensor.tensor_2d.TensorNetwork2D.compute_y_environments` or :meth:`~quimb.tensor.tensor_2d.TensorNetwork2D.compute_x_environments` . :returns: The plaquette environments. The key is two tuples of ints, the startings coordinate of the plaquette being the first and the size of the plaquette being the second pair. :rtype: dict[((int, int), (int, int)), TensorNetwork] .. py:method:: coarse_grain_hotrg(direction, max_bond=None, cutoff=1e-10, lazy=False, equalize_norms=False, optimize='auto-hq', compress_opts=None, inplace=False) Coarse grain this tensor network in ``direction`` using HOTRG. This inserts oblique projectors between tensor pairs and then optionally contracts them into new sites for form a lattice half the size. :param direction: The direction to coarse grain in. :type direction: {'x', 'y'} :param max_bond: The maximum bond dimension of the projector pairs inserted. :type max_bond: int, optional :param cutoff: The cutoff for the singular values of the projector pairs. :type cutoff: float, optional :param lazy: Whether to contract the coarse graining projectors or leave them in the tensor network lazily. Default is to contract them. :type lazy: bool, optional :param equalize_norms: Whether to equalize the norms of the tensors in the coarse grained lattice. :type equalize_norms: bool, optional :param optimize: The optimization method to use when contracting the coarse grained lattice, if ``lazy=False``. :type optimize: str, optional :param compress_opts: Supplied to :meth:`~quimb.tensor.tensor_core.TensorNetwork.insert_compressor_between_regions`. :type compress_opts: None or dict, optional :param inplace: Whether to perform the coarse graining in place. :type inplace: bool, optional :returns: The coarse grained tensor network, with size halved in ``direction``. :rtype: TensorNetwork2D .. seealso:: :obj:`contract_hotrg`, :obj:`TensorNetwork.insert_compressor_between_regions` .. py:attribute:: coarse_grain_hotrg_ .. py:method:: contract_hotrg(max_bond=None, *, cutoff=1e-10, canonize=False, canonize_opts=None, sequence=('x', 'y'), max_separation=1, max_unfinished=1, lazy=False, equalize_norms=False, final_contract=True, final_contract_opts=None, progbar=False, inplace=False, **coarse_grain_opts) Contract this tensor network using the finite version of HOTRG. See https://arxiv.org/abs/1201.1144v4 and https://arxiv.org/abs/1905.02351 for the more optimal computaton of the projectors used here. The TN is contracted sequentially in ``sequence`` directions by inserting oblique projectors between plaquettes, and then optionally contracting these new effective sites. The algorithm stops when only one direction has a length larger than 2, and thus exact contraction can be used. :param max_bond: The maximum bond dimension of the projector pairs inserted. :type max_bond: int, optional :param cutoff: The cutoff for the singular values of the projector pairs. :type cutoff: float, optional :param canonize: Whether to canonize all tensors before each contraction, via :meth:`gauge_all`. :type canonize: bool, optional :param canonize_opts: Additional options to pass to :meth:`gauge_all`. :type canonize_opts: None or dict, optional :param sequence: The directions to contract in. Default is to contract in all directions. :type sequence: tuple of str, optional :param max_separation: The maximum distance between sides (i.e. length - 1) of the tensor network before that direction is considered finished. :type max_separation: int, optional :param max_unfinished: The maximum number of directions that can be unfinished (i.e. are still longer than max_separation + 1) before the coarse graining terminates. :type max_unfinished: int, optional :param lazy: Whether to contract the coarse graining projectors or leave them in the tensor network lazily. Default is to contract them. :type lazy: bool, optional :param equalize_norms: Whether to equalize the norms of all tensors after each contraction, gathering the overall scaling coefficient, log10, in ``tn.exponent``. :type equalize_norms: bool or float, optional :param final_contract: Whether to exactly contract the remaining tensor network after the coarse graining contractions. :type final_contract: bool, optional :param final_contract_opts: Options to pass to :meth:`contract`, ``optimize`` defaults to ``'auto-hq'``. :type final_contract_opts: None or dict, optional :param progbar: Whether to show a progress bar. :type progbar: bool, optional :param inplace: Whether to perform the coarse graining in place. :type inplace: bool, optional :param coarse_grain_opts: Additional options to pass to :meth:`coarse_grain_hotrg`. :returns: The contracted tensor network, which will have no more than one direction of length > 2. :rtype: TensorNetwork2D .. seealso:: :obj:`coarse_grain_hotrg`, :obj:`contract_ctmrg`, :obj:`TensorNetwork.insert_compressor_between_regions` .. py:attribute:: contract_hotrg_ .. py:method:: contract_ctmrg(max_bond=None, *, cutoff=1e-10, canonize=False, canonize_opts=None, lazy=False, mode='projector', compress_opts=None, sequence=None, xmin=None, xmax=None, ymin=None, ymax=None, max_separation=1, around=None, equalize_norms=False, final_contract=True, final_contract_opts=None, progbar=False, inplace=False, **contract_boundary_opts) Contract this 2D tensor network using the finite analog of the CTMRG algorithm - https://arxiv.org/abs/cond-mat/9507087. The TN is contracted sequentially in ``sequence`` directions by inserting oblique projectors between boundary pairs, and then optionally contracting these new effective sites. The algorithm stops when only one direction has a length larger than 2, and thus exact contraction can be used. :param max_bond: The maximum bond dimension of the projector pairs inserted. :type max_bond: int, optional :param cutoff: The cutoff for the singular values of the projector pairs. :type cutoff: float, optional :param canonize: Whether to canonize the boundary tensors before each contraction, via :meth:`gauge_all`. :type canonize: bool, optional :param canonize_opts: Additional options to pass to :meth:`gauge_all`. :type canonize_opts: None or dict, optional :param lazy: Whether to contract the coarse graining projectors or leave them in the tensor network lazily. Default is to contract them. :type lazy: bool, optional :param mode: The method to perform the boundary contraction. Defaults to ``'projector'``. :type mode: str, optional :param compress_opts: Other low level options to pass to :meth:`insert_compressor_between_regions`. :type compress_opts: None or dict, optional :param sequence: Which directions to cycle throught when performing the inwards contractions, i.e. *from* that direction. If ``around`` is specified you will likely need all of these! Default is to contract in all directions. :type sequence: sequence of {'xmin', 'xmax', 'ymin', 'ymax'}, optional :param xmin: The initial bottom boundary row, defaults to 0. :type xmin: int, optional :param xmax: The initial top boundary row, defaults to ``Lx - 1``. :type xmax: int, optional :param ymin: The initial left boundary column, defaults to 0. :type ymin: int, optional :param ymax: The initial right boundary column, defaults to ``Ly - 1``.. :type ymax: int, optional :param max_separation: If ``around is None``, when any two sides become this far apart simply contract the remaining tensor network. :type max_separation: int, optional :param around: If given, don't contract the square of sites bounding these coordinates. :type around: None or sequence of (int, int), optional :param equalize_norms: Whether to equalize the norms of the boundary tensors after each contraction, gathering the overall scaling coefficient, log10, in ``tn.exponent``. :type equalize_norms: bool or float, optional :param final_contract: Whether to exactly contract the remaining tensor network after the boundary contraction. :type final_contract: bool, optional :param final_contract_opts: Options to pass to :meth:`contract`, ``optimize`` defaults to ``'auto-hq'``. :type final_contract_opts: None or dict, optional :param progbar: Whether to show a progress bar. :type progbar: bool, optional :param inplace: Whether to perform the boundary contraction in place. :type inplace: bool, optional :param contract_boundary_opts: Additional options to pass to :meth:`contract_boundary_from`. :returns: Either the fully contracted scalar (if ``final_contract=True`` and ``around=None``) or the partially contracted tensor network. :rtype: scalar or TensorNetwork2D .. seealso:: :obj:`contract_boundary_from`, :obj:`contract_hotrg`, :obj:`TensorNetwork.insert_compressor_between_regions` .. py:attribute:: contract_ctmrg_ .. py:function:: is_lone_coo(where) Check if ``where`` has been specified as a single coordinate pair. .. py:function:: gate_string_split_(TG, where, string, original_ts, bonds_along, reindex_map, site_ix, info, **compress_opts) .. py:function:: gate_string_reduce_split_(TG, where, string, original_ts, bonds_along, reindex_map, site_ix, info, **compress_opts) .. py:function:: gate_2d_long_range(self, G, where, contract=False, tags=None, inplace=False, info=None, long_range_use_swaps=False, long_range_path_sequence=None, **compress_opts) .. py:class:: TensorNetwork2DVector(ts=(), *, virtual=False, check_collisions=True) Bases: :py:obj:`TensorNetwork2D`, :py:obj:`quimb.tensor.tensor_arbgeom.TensorNetworkGenVector` Mixin class for a 2D square lattice vector TN, i.e. one with a single physical index per site. .. py:attribute:: _EXTRA_PROPS :value: ('_site_tag_id', '_x_tag_id', '_y_tag_id', '_Lx', '_Ly', '_site_ind_id') .. py:method:: site_ind(i, j=None) Return the physical index of site ``(i, j)``. .. py:method:: reindex_sites(new_id, where=None, inplace=False) Modify the site indices for all or some tensors in this vector tensor network (without changing the ``site_ind_id``). :param new_id: A string with a format placeholder to accept a site, e.g. "ket{}". :type new_id: str :param where: Which sites to update the index labels on. If ``None`` (default) all sites. :type where: None or sequence :param inplace: Whether to reindex in place. :type inplace: bool .. py:attribute:: reindex_sites_ .. py:method:: phys_dim(i=None, j=None) Get the size of the physical indices / a specific physical index. .. py:method:: gate(G, where, contract=False, tags=None, propagate_tags='sites', inplace=False, info=None, long_range_use_swaps=False, long_range_path_sequence=None, **compress_opts) Apply the dense gate ``G``, maintaining the physical indices of this 2D vector tensor network. :param G: The gate array to apply, should match or be factorable into the shape ``(phys_dim,) * (2 * len(where))``. :type G: array_like :param where: Which site coordinates to apply the gate to. :type where: sequence of tuple[int, int] or tuple[int, int] :param contract: How to contract the gate into the 2D tensor network: - False: gate is added to network and nothing is contracted, tensor network structure is thus not maintained. - True: gate is contracted with all tensors involved, tensor network structure is thus only maintained if gate acts on a single site only. - 'split': contract all involved tensors then split the result back into two. - 'reduce-split': factor the two physical indices into 'R-factors' using QR decompositions on the original site tensors, then contract the gate, split it and reabsorb each side. Much cheaper than ``'split'``. The final two methods are relevant for two site gates only, for single site gates they use the ``contract=True`` option which also maintains the structure of the TN. See below for a pictorial description of each method. :type contract: {'reduce-split', 'split', False, True}, optional :param tags: Tags to add to the new gate tensor. :type tags: str or sequence of str, optional :param propagate_tags: If ``contract==False``, which tags to propagate to the new gate tensor from the tensors it was applied to: - If ``'sites'``, then only propagate tags matching e.g. 'I{},{}' and ignore all others. I.e. assuming unitary gates just propagate the causal lightcone. - If ``'register'``, then only propagate tags matching the sites of where this gate was actually applied. I.e. ignore the lightcone, just keep track of which 'registers' the gate was applied to. - If ``False``, propagate nothing. - If ``True``, propagate all tags. :type propagate_tags: {'sites', 'register', True, False}, optional :param inplace: Whether to perform the gate operation inplace on the tensor network or not. :type inplace: bool, optional :param info: Used to store extra optional information such as the singular values if not absorbed. :type info: None or dict, optional :param compress_opts: Supplied to :func:`~quimb.tensor.tensor_core.tensor_split` for any ``contract`` methods that involve splitting. Ignored otherwise. :returns: **G_psi** -- The new 2D vector TN like ``IIIGII @ psi`` etc. :rtype: TensorNetwork2DVector .. rubric:: Notes The ``contract`` options look like the following (for two site gates). ``contract=False``:: │ │ GGGGG │╱ │╱ ──●───●── ╱ ╱ ``contract=True``:: │╱ │╱ ──GGGGG── ╱ ╱ ``contract='split'``:: │╱ │╱ │╱ │╱ ──GGGGG── ==> ──G┄┄┄G── ╱ ╱ ╱ ╱ ``contract='reduce-split'``:: │ │ │ │ GGGGG GGG │ │ │╱ │╱ ==> ╱│ │ ╱ ==> ╱│ │ ╱ │╱ │╱ ──●───●── ──>─●─●─<── ──>─GGG─<── ==> ──G┄┄┄G── ╱ ╱ ╱ ╱ ╱ ╱ ╱ ╱ For one site gates when one of the 'split' methods is supplied ``contract=True`` is assumed. .. py:attribute:: gate_ .. py:method:: compute_norm(max_bond=None, *, cutoff=1e-10, canonize=True, mode='mps', layer_tags=('KET', 'BRA'), compress_opts=None, sequence=None, equalize_norms=False, progbar=None, **contract_opts) Compute the norm of this vector via boundary contraction. :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param canonize: Whether to sweep one way with canonization before compressing. :type canonize: bool, optional :param mode: How to perform the compression on the boundary, can also be any of the generic 1D or arbgeom methods. :type mode: {'mps', 'full-bond', ...}, optional :param layer_tags: If given, perform a multilayer contraction, contracting the inner sites in each layer into the boundary individually. :type layer_tags: None or sequence of str, optional :param compress_opts: Other low level options to pass to :meth:`~quimb.tensor.tensor_core.TensorNetwork.compress_between`. :type compress_opts: None or dict, optional :param sequence: Which directions to cycle throught when performing the inwards contractions, i.e. *from* that direction. If ``around`` is specified you will likely need all of these! Default is to contract from the two shortest opposing sides. :type sequence: sequence of {'xmin', 'xmax', 'ymin', 'ymax'}, optional :param equalize_norms: Whether to equalize the norms of the boundary tensors after each contraction, gathering the overall scaling coefficient, log10, in ``tn.exponent``. :type equalize_norms: bool or float, optional :param progbar: Whether to show a progress bar. :type progbar: bool, optional :param contract_opts: Additional options to pass to :meth:`contract_boundary`. :rtype: scalar .. py:method:: compute_local_expectation(terms, max_bond=None, *, cutoff=1e-10, canonize=True, mode='mps', layer_tags=('KET', 'BRA'), normalized=False, autogroup=True, contract_optimize='auto-hq', return_all=False, plaquette_envs=None, plaquette_map=None, **plaquette_env_options) Compute the sum of many local expecations by essentially forming the reduced density matrix of all required plaquettes. If you supply ``normalized=True`` each expecation is locally normalized, which a) is usually more accurate and b) doesn't require a separate normalization boundary contraction. :param terms: A dictionary mapping site coordinates to raw operators, which will be supplied to :meth:`~quimb.tensor.tensor_2d.TensorNetwork2DVector.gate`. The keys should either be a single coordinate - ``(i, j)`` - describing a single site operator, or a pair of coordinates - ``((i_a, j_a), (i_b, j_b))`` describing a two site operator. :type terms: dict[tuple[tuple[int], array] :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param canonize: Whether to sweep one way with canonization before compressing. :type canonize: bool, optional :param mode: How to perform the compression on the boundary. :type mode: {'mps', 'full-bond'}, optional :param layer_tags: If given, perform a multilayer contraction, contracting the inner sites in each layer into the boundary individually. :type layer_tags: None or sequence of str, optional :param normalized: If True, normalize the value of each local expectation by the local norm: $\langle O_i \rangle = Tr[\rho_p O_i] / Tr[\rho_p]$. :type normalized: bool, optional :param autogroup: If ``True`` (the default), group terms into horizontal and vertical sets to be computed separately (usually more efficient) if possible. :type autogroup: bool, optional :param contract_optimize: Contraction path finder to use for contracting the local plaquette expectation (and optionally normalization). :type contract_optimize: str, optional :param return_all: Whether to the return all the values individually as a dictionary of coordinates to tuple[local_expectation, local_norm]. :type return_all: bool, optional :param plaquette_envs: Supply precomputed plaquette environments. :type plaquette_envs: None or dict, optional :param plaquette_map: Supply the mapping of which plaquettes (denoted by ``((x0, y0), (dx, dy))``) to use for which coordinates, it will be calculated automatically otherwise. :type plaquette_map: None, dict, optional :param plaquette_env_options: Supplied to :meth:`compute_plaquette_environments` to generate the plaquette environments, equivalent to approximately performing the partial trace. :rtype: scalar or dict .. py:method:: normalize(max_bond=None, *, cutoff=1e-10, canonize=True, mode='mps', layer_tags=('KET', 'BRA'), balance_bonds=False, equalize_norms=False, inplace=False, **contract_boundary_opts) Normalize this PEPS. :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param canonize: Whether to sweep one way with canonization before compressing. :type canonize: bool, optional :param mode: How to perform the compression on the boundary. :type mode: {'mps', 'full-bond'}, optional :param layer_tags: If given, perform a multilayer contraction, contracting the inner sites in each layer into the boundary individually. :type layer_tags: None or sequence of str, optional :param balance_bonds: Whether to balance the bonds after normalization, a form of conditioning. :type balance_bonds: bool, optional :param equalize_norms: Whether to set all the tensor norms to the same value after normalization, another form of conditioning. :type equalize_norms: bool, optional :param inplace: Whether to perform the normalization inplace or not. :type inplace: bool, optional :param contract_boundary_opts: Supplied to :meth:`contract_boundary`, by default, two layer contraction will be used. .. py:attribute:: normalize_ .. py:class:: TensorNetwork2DOperator(ts=(), *, virtual=False, check_collisions=True) Bases: :py:obj:`TensorNetwork2D`, :py:obj:`quimb.tensor.tensor_arbgeom.TensorNetworkGenOperator` Mixin class for a 2D square lattice TN operator, i.e. one with both 'upper' and 'lower' site (physical) indices. .. py:attribute:: _EXTRA_PROPS :value: ('_site_tag_id', '_x_tag_id', '_y_tag_id', '_Lx', '_Ly', '_upper_ind_id', '_lower_ind_id') .. py:method:: reindex_lower_sites(new_id, where=None, inplace=False) Update the lower site index labels to a new string specifier. :param new_id: A string with a format placeholder to accept an int, e.g. ``"ket{},{}"``. :type new_id: str :param where: Which sites to update the index labels on. If ``None`` (default) all sites. :type where: None or slice :param inplace: Whether to reindex in place. :type inplace: bool .. py:attribute:: reindex_lower_sites_ .. py:method:: reindex_upper_sites(new_id, where=None, inplace=False) Update the upper site index labels to a new string specifier. :param new_id: A string with a format placeholder to accept an int, e.g. ``"ket{},{}"``. :type new_id: str :param where: Which sites to update the index labels on. If ``None`` (default) all sites. :type where: None or slice :param inplace: Whether to reindex in place. :type inplace: bool .. py:attribute:: reindex_upper_sites_ .. py:method:: lower_ind(i, j=None) Get the lower index for a given site. .. py:method:: upper_ind(i, j=None) Get the upper index for a given site. .. py:method:: phys_dim(i=0, j=0, which='upper') Get a physical index size of this 2D operator. .. py:class:: TensorNetwork2DFlat(ts=(), *, virtual=False, check_collisions=True) Bases: :py:obj:`TensorNetwork2D` Mixin class for a 2D square lattice tensor network with a single tensor per site, for example, both PEPS and PEPOs. .. py:attribute:: _EXTRA_PROPS :value: ('_site_tag_id', '_x_tag_id', '_y_tag_id', '_Lx', '_Ly') .. py:method:: expand_bond_dimension(new_bond_dim, inplace=True, bra=None, rand_strength=0.0) Increase the bond dimension of this flat, 2D, tensor network, padding the tensor data with either zeros or random entries. :param new_bond_dim: The new dimension. If smaller or equal to the current bond dimension nothing will happend. :type new_bond_dim: int :param inplace: Whether to expand in place (the default), or return a new TN. :type inplace: bool, optional :param bra: Expand this TN with the same data also, assuming it to be the conjugate, bra, TN. :type bra: TensorNetwork2DFlat, optional :param rand_strength: If greater than zero, pad the data arrays with gaussian noise of this strength. :type rand_strength: float, optional :returns: **tn** :rtype: TensorNetwork2DFlat .. py:method:: compress(max_bond=None, cutoff=1e-10, equalize_norms=False, row_sweep='right', col_sweep='up', **compress_opts) Compress all bonds in this flat 2D tensor network. :param max_bond: The maximum boundary dimension, AKA 'chi'. The default of ``None`` means truncation is left purely to ``cutoff`` and is not recommended in 2D. :type max_bond: int, optional :param cutoff: Cut-off value to used to truncate singular values in the boundary contraction. :type cutoff: float, optional :param compress_opts: Supplied to :meth:`compress_between`. :type compress_opts: None or dict, optional .. py:class:: PEPS(arrays, *, shape='urdlp', tags=None, site_ind_id='k{},{}', site_tag_id='I{},{}', x_tag_id='X{}', y_tag_id='Y{}', **tn_opts) Bases: :py:obj:`TensorNetwork2DVector`, :py:obj:`TensorNetwork2DFlat` Projected Entangled Pair States object (2D):: ... │ │ │ │ │ │ ●────●────●────●────●────●── ╱│ ╱│ ╱│ ╱│ ╱│ ╱│ │ │ │ │ │ │ ●────●────●────●────●────●── ╱│ ╱│ ╱│ ╱│ ╱│ ╱│ │ │ │ │ │ │ ... ●────●────●────●────●────●── ╱│ ╱│ ╱│ ╱│ ╱│ ╱│ │ │ │ │ │ │ ●────●────●────●────●────●── ╱ ╱ ╱ ╱ ╱ ╱ :param arrays: The core tensor data arrays. :type arrays: sequence of sequence of array_like :param shape: Which order the dimensions of the arrays are stored in, the default ``'urdlp'`` stands for ('up', 'right', 'down', 'left', 'physical'). Arrays on the edge of lattice are assumed to be missing the corresponding dimension. :type shape: str, optional :param tags: Extra global tags to add to the tensor network. :type tags: set[str], optional :param site_ind_id: String specifier for naming convention of site indices. :type site_ind_id: str, optional :param site_tag_id: String specifier for naming convention of site tags. :type site_tag_id: str, optional :param x_tag_id: String specifier for naming convention of row ('x') tags. :type x_tag_id: str, optional :param y_tag_id: String specifier for naming convention of column ('y') tags. :type y_tag_id: str, optional .. py:attribute:: _EXTRA_PROPS :value: ('_site_tag_id', '_x_tag_id', '_y_tag_id', '_Lx', '_Ly', '_site_ind_id') .. py:attribute:: _site_ind_id :value: 'k{},{}' .. py:attribute:: _site_tag_id :value: 'I{},{}' .. py:attribute:: _x_tag_id :value: 'X{}' .. py:attribute:: _y_tag_id :value: 'Y{}' .. py:attribute:: _Lx .. py:attribute:: _Ly .. py:method:: from_fill_fn(fill_fn, Lx, Ly, bond_dim, phys_dim=2, cyclic=False, shape='urdlp', **peps_opts) :classmethod: Create a 2D PEPS from a filling function with signature ``fill_fn(shape)``. :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param bond_dim: The bond dimension. :type bond_dim: int :param phys_dim: The physical index dimension. :type phys_dim: int, optional :param cyclic: Whether the lattice is cyclic in the x and y directions. :type cyclic: bool or tuple[bool, bool], optional :param shape: How to layout the indices of the tensors, the default is ``(up, right, down, left, phys) == 'urdlbk'``. This is the order of the shape supplied to the filling function. :type shape: str, optional :param peps_opts: Supplied to :class:`~quimb.tensor.tensor_2d.PEPS`. :returns: **psi** :rtype: PEPS .. py:method:: empty(Lx, Ly, bond_dim, phys_dim=2, like='numpy', **peps_opts) :classmethod: Create an empty 2D PEPS. :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param bond_dim: The bond dimension. :type bond_dim: int :param physical: The physical index dimension. :type physical: int, optional :param peps_opts: Supplied to :class:`~quimb.tensor.tensor_2d.PEPS`. :returns: **psi** :rtype: PEPS .. seealso:: :obj:`PEPS.from_fill_fn` .. py:method:: ones(Lx, Ly, bond_dim, phys_dim=2, like='numpy', **peps_opts) :classmethod: Create a 2D PEPS whose tensors are filled with ones. :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param bond_dim: The bond dimension. :type bond_dim: int :param physical: The physical index dimension. :type physical: int, optional :param peps_opts: Supplied to :class:`~quimb.tensor.tensor_2d.PEPS`. :returns: **psi** :rtype: PEPS .. seealso:: :obj:`PEPS.from_fill_fn` .. py:method:: zeros(Lx, Ly, bond_dim, phys_dim=2, like='numpy', **peps_opts) :classmethod: Create a 2D PEPS whose tensors are filled with zeros. :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param bond_dim: The bond dimension. :type bond_dim: int :param physical: The physical index dimension. :type physical: int, optional :param peps_opts: Supplied to :class:`~quimb.tensor.tensor_2d.PEPS`. :returns: **psi** :rtype: PEPS .. seealso:: :obj:`PEPS.from_fill_fn` .. py:method:: rand(Lx, Ly, bond_dim, phys_dim=2, dist='normal', loc=0.0, scale=1.0, dtype='float64', seed=None, **peps_opts) :classmethod: Create a random (un-normalized) PEPS. :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param bond_dim: The bond dimension. :type bond_dim: int :param physical: The physical index dimension. :type physical: int, optional :param dist: Type of random number to generate, defaults to 'normal'. :type dist: {'normal', 'uniform', 'rademacher', 'exp'}, optional :param loc: An additive offset to add to the random numbers. :type loc: float, optional :param dtype: The dtype to create the arrays with, default is real double. :type dtype: dtype, optional :param seed: A random seed. :type seed: int, optional :param peps_opts: Supplied to :class:`~quimb.tensor.tensor_2d.PEPS`. :returns: **psi** :rtype: PEPS .. seealso:: :obj:`PEPS.from_fill_fn` .. py:method:: product_state(site_map, cyclic=False, **peps_opts) :classmethod: Create a PEPS representing a product state, with explicit bonds of dimension 1 between sites. :param site_map: A mapping of site coordinates to physical vectors, or a 2D array of physical vectors. Each vector being a single site state. :type site_map: dict[tuple[int, int], array] or Sequence[Sequence[array]] :param cyclic: Whether the lattice is cyclic in the x and y directions. :type cyclic: bool or tuple[bool, bool], optional :param peps_opts: Supplied to :class:`~quimb.tensor.tensor_2d.PEPS`. :rtype: PEPS .. py:method:: vacuum(Lx, Ly, phys_dim=2, **peps_opts) :classmethod: Create the 'vaccum' state PEPS, i.e. |00...0>. :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param phys_dim: The physical index dimension. :type phys_dim: int, optional :param peps_opts: Supplied to :class:`~quimb.tensor.tensor_2d.PEPS.product_state`. .. py:method:: add_PEPS(other, inplace=False) .. py:attribute:: add_PEPS_ .. py:method:: show() Print a unicode schematic of this PEPS and its bond dimensions. .. py:class:: PEPO(arrays, *, shape='urdlbk', tags=None, upper_ind_id='k{},{}', lower_ind_id='b{},{}', site_tag_id='I{},{}', x_tag_id='X{}', y_tag_id='Y{}', **tn_opts) Bases: :py:obj:`TensorNetwork2DOperator`, :py:obj:`TensorNetwork2DFlat` Projected Entangled Pair Operator object:: ... │╱ │╱ │╱ │╱ │╱ │╱ ●────●────●────●────●────●── ╱│ ╱│ ╱│ ╱│ ╱│ ╱│ │╱ │╱ │╱ │╱ │╱ │╱ ●────●────●────●────●────●── ╱│ ╱│ ╱│ ╱│ ╱│ ╱│ │╱ │╱ │╱ │╱ │╱ │╱ ... ●────●────●────●────●────●── ╱│ ╱│ ╱│ ╱│ ╱│ ╱│ │╱ │╱ │╱ │╱ │╱ │╱ ●────●────●────●────●────●── ╱ ╱ ╱ ╱ ╱ ╱ :param arrays: The core tensor data arrays. :type arrays: sequence of sequence of array :param shape: Which order the dimensions of the arrays are stored in, the default ``'urdlbk'`` stands for ('up', 'right', 'down', 'left', 'bra', 'ket'). Arrays on the edge of lattice are assumed to be missing the corresponding dimension. :type shape: str, optional :param tags: Extra global tags to add to the tensor network. :type tags: set[str], optional :param upper_ind_id: String specifier for naming convention of upper site indices. :type upper_ind_id: str, optional :param lower_ind_id: String specifier for naming convention of lower site indices. :type lower_ind_id: str, optional :param site_tag_id: String specifier for naming convention of site tags. :type site_tag_id: str, optional :param x_tag_id: String specifier for naming convention of row ('x') tags. :type x_tag_id: str, optional :param y_tag_id: String specifier for naming convention of column ('y') tags. :type y_tag_id: str, optional .. py:attribute:: _EXTRA_PROPS :value: ('_site_tag_id', '_x_tag_id', '_y_tag_id', '_Lx', '_Ly', '_upper_ind_id', '_lower_ind_id') .. py:attribute:: _upper_ind_id :value: 'k{},{}' .. py:attribute:: _lower_ind_id :value: 'b{},{}' .. py:attribute:: _site_tag_id :value: 'I{},{}' .. py:attribute:: _x_tag_id :value: 'X{}' .. py:attribute:: _y_tag_id :value: 'Y{}' .. py:attribute:: _Lx .. py:attribute:: _Ly .. py:method:: from_fill_fn(fill_fn, Lx, Ly, bond_dim, phys_dim=2, cyclic=False, shape='urdlbk', **pepo_opts) :classmethod: Create a PEPO and fill the tensor entries with a supplied function matching signature ``fill_fn(shape) -> array``. :param fill_fn: A function that takes a shape tuple and returns a data array. :type fill_fn: callable :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param bond_dim: The bond dimension. :type bond_dim: int :param phys_dim: The physical indices dimension. :type phys_dim: int, optional :param cyclic: Whether the lattice is cyclic in the x and y directions. :type cyclic: bool or tuple[bool, bool], optional :param shape: How to layout the indices of the tensors, the default is ``(up, right, down, left bra, ket) == 'urdlbk'``. :type shape: str, optional :param pepo_opts: Supplied to :class:`~quimb.tensor.tensor_2d.PEPO`. .. py:method:: rand(Lx, Ly, bond_dim, phys_dim=2, herm=False, dist='normal', loc=0.0, scale=1.0, dtype='float64', seed=None, **pepo_opts) :classmethod: Create a random PEPO. :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param bond_dim: The bond dimension. :type bond_dim: int :param physical: The physical index dimension. :type physical: int, optional :param herm: Whether to symmetrize the tensors across the physical bonds to make the overall operator hermitian. :type herm: bool, optional :param dtype: The dtype to create the arrays with, default is real double. :type dtype: dtype, optional :param seed: A random seed. :type seed: int, optional :param pepo_opts: Supplied to :class:`~quimb.tensor.tensor_2d.PEPO`. :returns: **X** :rtype: PEPO .. py:attribute:: rand_herm .. py:method:: zeros(Lx, Ly, bond_dim, phys_dim=2, dtype='float64', backend='numpy', **pepo_opts) :classmethod: Create a PEPO with all zero entries. :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param bond_dim: The bond dimension. :type bond_dim: int :param physical: The physical index dimension. :type physical: int, optional :param dtype: The dtype to create the arrays with, default is real double. :type dtype: dtype, optional :param backend: Which backend to use, default is ``'numpy'``. :type backend: str, optional :param pepo_opts: Supplied to :class:`~quimb.tensor.tensor_2d.PEPO`. .. py:method:: add_PEPO(other, inplace=False) .. py:attribute:: add_PEPO_ .. py:method:: _apply_peps(other, compress=False, contract=True, **compress_opts) .. py:method:: apply(other, compress=False, **compress_opts) Act with this PEPO on ``other``, returning a new TN like ``other`` with the same outer indices. :param other: The TN to act on. :type other: PEPS :param compress: Whether to compress the resulting TN. :type compress: bool, optional :param compress_opts: Supplied to :meth:`~quimb.tensor.tensor_2d.TensorNetwork2DFlat.compress`. :rtype: TensorNetwork2DFlat .. py:method:: show() Print a unicode schematic of this PEPO and its bond dimensions. .. py:function:: show_2d(tn_2d, show_lower=False, show_upper=False) Base function for printing a unicode schematic of flat 2D TNs. .. py:function:: calc_plaquette_sizes(coo_groups, autogroup=True) Find a sequence of plaquette blocksizes that will cover all the terms (coordinate pairs) in ``pairs``. :param coo_groups: The sequence of 2D coordinates pairs describing terms. Each should either be a single 2D coordinate or a sequence of 2D coordinates. :type coo_groups: sequence of tuple[tuple[int]] or tuple[int] :param autogroup: Whether to return the minimal sequence of blocksizes that will cover all terms or merge them into a single ``((x_bsz, y_bsz),)``. :type autogroup: bool, optional :returns: **bszs** -- Pairs of blocksizes. :rtype: tuple[tuple[int]] .. rubric:: Examples Some nearest neighbour interactions: >>> H2 = {None: qu.ham_heis(2)} >>> ham = qtn.LocalHam2D(10, 10, H2) >>> calc_plaquette_sizes(ham.terms.keys()) ((1, 2), (2, 1)) >>> calc_plaquette_sizes(ham.terms.keys(), autogroup=False) ((2, 2),) If we add any next nearest neighbour interaction then we are going to need the (2, 2) blocksize in any case: >>> H2[(1, 1), (2, 2)] = 0.5 * qu.ham_heis(2) >>> ham = qtn.LocalHam2D(10, 10, H2) >>> calc_plaquette_sizes(ham.terms.keys()) ((2, 2),) If we add longer range interactions (non-diagonal next nearest) we again can benefit from multiple plaquette blocksizes: >>> H2[(1, 1), (1, 3)] = 0.25 * qu.ham_heis(2) >>> H2[(1, 1), (3, 1)] = 0.25 * qu.ham_heis(2) >>> ham = qtn.LocalHam2D(10, 10, H2) >>> calc_plaquette_sizes(ham.terms.keys()) ((1, 3), (2, 2), (3, 1)) Or choose the plaquette blocksize that covers all terms: >>> calc_plaquette_sizes(ham.terms.keys(), autogroup=False) ((3, 3),) .. py:function:: plaquette_to_sites(p) Turn a plaquette ``((i0, j0), (di, dj))`` into the sites it contains. .. rubric:: Examples >>> plaquette_to_sites([(3, 4), (2, 2)]) ((3, 4), (3, 5), (4, 4), (4, 5)) .. py:function:: calc_plaquette_map(plaquettes) Generate a dictionary of all the coordinate pairs in ``plaquettes`` mapped to the 'best' (smallest) rectangular plaquette that contains them. .. rubric:: Examples Consider 4 sites, with one 2x2 plaquette and two vertical (2x1) and horizontal (1x2) plaquettes each: >>> plaquettes = [ ... # 2x2 plaquette covering all sites ... ((0, 0), (2, 2)), ... # horizontal plaquettes ... ((0, 0), (1, 2)), ... ((1, 0), (1, 2)), ... # vertical plaquettes ... ((0, 0), (2, 1)), ... ((0, 1), (2, 1)), ... ] >>> calc_plaquette_map(plaquettes) {((0, 0), (0, 1)): ((0, 0), (1, 2)), ((0, 0), (1, 0)): ((0, 0), (2, 1)), ((0, 0), (1, 1)): ((0, 0), (2, 2)), ((0, 1), (1, 0)): ((0, 0), (2, 2)), ((0, 1), (1, 1)): ((0, 1), (2, 1)), ((1, 0), (1, 1)): ((1, 0), (1, 2))} Now every of the size coordinate pairs is mapped to one of the plaquettes, but to the smallest one that contains it. So the 2x2 plaquette (specified by ``((0, 0), (2, 2))``) would only used for diagonal terms here. .. py:function:: gen_long_range_path(ij_a, ij_b, sequence=None) Generate a string of coordinates, in order, from ``ij_a`` to ``ij_b``. :param ij_a: Coordinate of site 'a'. :type ij_a: (int, int) :param ij_b: Coordinate of site 'b'. :type ij_b: (int, int) :param sequence: What order to cycle through and try and perform moves in, 'v', 'h' standing for move vertically and horizontally respectively. The default is ``('v', 'h')``. :type sequence: None, iterable of {'v', 'h'}, or 'random', optional :returns: The path, each element is a single coordinate. :rtype: generator[tuple[int]] .. py:function:: gen_long_range_swap_path(ij_a, ij_b, sequence=None) Generate the coordinates or a series of swaps that would bring ``ij_a`` and ``ij_b`` together. :param ij_a: Coordinate of site 'a'. :type ij_a: (int, int) :param ij_b: Coordinate of site 'b'. :type ij_b: (int, int) :param sequence: What order to cycle through and try and perform moves in, 'av', 'bv', 'ah', 'bh' standing for move 'a' vertically, 'b' vertically, 'a' horizontally', and 'b' horizontally respectively. The default is ``('av', 'bv', 'ah', 'bh')``. :type sequence: None, it of {'av', 'bv', 'ah', 'bh'}, or 'random', optional :returns: The path, each element is two coordinates to swap. :rtype: generator[tuple[tuple[int]]] .. py:function:: swap_path_to_long_range_path(swap_path, ij_a) Generates the ordered long-range path - a sequence of coordinates - from a (long-range) swap path - a sequence of coordinate pairs. .. py:function:: get_swap(dp, dtype, backend)