quimb.tensor.tn1d.compress ========================== .. py:module:: quimb.tensor.tn1d.compress .. autoapi-nested-parse:: Generic methods for compressing 1D-like tensor networks, where the tensor network can locally have arbitrary structure and outer indices. - [x] the direct method - [x] the density matrix method - [x] successive randomized compression (SRC) method - [x] src-oversampled - [x] the zip-up method - [x] the zip-up first / oversampled method - [x] the 1-site variational fit method, including sums of tensor networks - [x] the 2-site variational fit method, including sums of tensor networks Attributes ---------- .. autoapisummary:: quimb.tensor.tn1d.compress.tensor_network_1d_compress_fit_zipup quimb.tensor.tn1d.compress.tensor_network_1d_compress_fit_projector quimb.tensor.tn1d.compress._TN1D_COMPRESS_METHODS Functions --------- .. autoapisummary:: quimb.tensor.tn1d.compress.enforce_1d_like quimb.tensor.tn1d.compress.possibly_permute_ quimb.tensor.tn1d.compress.tensor_network_1d_compress_direct quimb.tensor.tn1d.compress._form_final_tn_from_tensor_sequence quimb.tensor.tn1d.compress.tensor_network_1d_compress_dm quimb.tensor.tn1d.compress.tensor_network_1d_compress_zipup quimb.tensor.tn1d.compress._do_direct_sweep quimb.tensor.tn1d.compress.tensor_network_1d_compress_zipup_oversample quimb.tensor.tn1d.compress._do_sweep_compress_from_low_rank_left_envs quimb.tensor.tn1d.compress._src_get_local_noise_tensors quimb.tensor.tn1d.compress.tensor_network_1d_compress_src quimb.tensor.tn1d.compress.tensor_network_1d_compress_src_oversample quimb.tensor.tn1d.compress.tensor_network_1d_compress_srcmps quimb.tensor.tn1d.compress.tensor_network_1d_compress_srcmps_oversample quimb.tensor.tn1d.compress._tn1d_fit_sum_sweep_1site quimb.tensor.tn1d.compress._tn1d_fit_sum_sweep_2site quimb.tensor.tn1d.compress.tensor_network_1d_compress_fit quimb.tensor.tn1d.compress.tensor_network_1d_compress_fit_guess quimb.tensor.tn1d.compress.tensor_network_1d_compress_fit_oversample quimb.tensor.tn1d.compress.tensor_network_1d_compress quimb.tensor.tn1d.compress.mps_gate_with_mpo_lazy quimb.tensor.tn1d.compress.mps_gate_with_mpo_direct quimb.tensor.tn1d.compress.mps_gate_with_mpo_dm quimb.tensor.tn1d.compress.mps_gate_with_mpo_zipup quimb.tensor.tn1d.compress.mps_gate_with_mpo_zipup_first quimb.tensor.tn1d.compress.mps_gate_with_mpo_fit quimb.tensor.tn1d.compress.mps_gate_with_mpo_autofit quimb.tensor.tn1d.compress.mps_gate_with_mpo_projector Module Contents --------------- .. py:function:: enforce_1d_like(tn, site_tags=None, fix_bonds=True, inplace=False) Check that ``tn`` is 1D-like with OBC, i.e. 1) that each tensor has exactly one of the given ``site_tags``. If not, raise a ValueError. 2) That there are no hyper indices. And 3) that there are only bonds within sites or between nearest neighbor sites. This issue can be optionally automatically fixed by inserting a string of identity tensors. :param tn: The tensor network to check. :type tn: TensorNetwork :param site_tags: The tags to use to group and order the tensors from ``tn``. If not given, uses ``tn.site_tags``. :type site_tags: sequence of str, optional :param fix_bonds: Whether to fix the bond structure by inserting identity tensors. :type fix_bonds: bool, optional :param inplace: Whether to perform the fix inplace or not. :type inplace: bool, optional :raises ValueError: If the tensor network is not 1D-like. .. py:function:: possibly_permute_(tn: quimb.tensor.tensor_core.TensorNetwork, permute_arrays: bool | str) .. py:function:: tensor_network_1d_compress_direct(tn: quimb.tensor.tensor_core.TensorNetwork, max_bond=None, cutoff=1e-10, site_tags=None, normalize=False, canonize=True, cutoff_mode='rsum2', permute_arrays=True, optimize='auto-hq', sweep_reverse=False, equalize_norms=False, contract_opts=None, canonize_opts=None, compress_opts=None, inplace=False, **kwargs) Compress a 1D-like tensor network using the 'direct' or 'naive' method, that is, explicitly contracting site-wise to form a MPS-like TN, canonicalizing in one direction, then compressing in the other. This has the same scaling as the density matrix (dm) method, but a larger prefactor. It can still be faster for small bond dimensions however, and is potentially higher precision since it works in the space of singular values directly rather than singular values squared. It is not quite optimal in terms of error due to the compounding errors of the SVDs. :param tn: The tensor network to compress. Every tensor should have exactly one of the site tags. Each site can have multiple tensors and output indices. :type tn: TensorNetwork :param max_bond: The maximum bond dimension to compress to. :type max_bond: int :param cutoff: A dynamic threshold for discarding singular values when compressing. :type cutoff: float, optional :param site_tags: The tags to use to group and order the tensors from ``tn``. If not given, uses ``tn.site_tags``. The tensor network built will have one tensor per site, in the order given by ``site_tags``. :type site_tags: sequence of str, optional :param normalize: Whether to normalize the final tensor network, making use of the fact that the output tensor network is in right canonical form. :type normalize: bool, optional :param canonize: Whether to canonicalize the network in one direction before compressing in the other. :type canonize: bool, optional :param cutoff_mode: The mode to use when truncating the singular values of the decomposed tensors. See :func:`~quimb.tensor.tensor_split`. :type cutoff_mode: {"rsum2", "rel", ...}, optional :param permute_arrays: Whether to permute the array indices of the final tensor network into canonical order. If ``True`` will use the default order, otherwise if a string this specifies a custom order. :type permute_arrays: bool or str, optional :param optimize: The contraction path optimizer to use. :type optimize: str, optional :param sweep_reverse: Whether to sweep in the reverse direction, resulting in a left canonical form instead of right canonical. :type sweep_reverse: bool, optional :param equalize_norms: Whether to renormalize the tensors during the compression procedure. If ``True`` the gathered exponent will be redistributed equally among the tensors. If a float, all tensors will be renormalized to this value, and the gathered exponent is tracked in ``tn.exponent`` of the returned tensor network. :type equalize_norms: bool, optional :param inplace: Whether to perform the compression inplace or not. :type inplace: bool, optional :param contract_opts: Supplied to :func:`~quimb.tensor.tensor_contract`. Values set here take precedence over any defaults. :type contract_opts: dict, optional :param canonize_opts: Supplied to :func:`~quimb.tensor.TensorNetwork.canonize_between` when canonizing between sites. Values set here take precedence over any defaults. :type canonize_opts: dict, optional :param compress_opts: Supplied to :func:`~quimb.tensor.TensorNetwork.compress_between` when compressing between sites. Values set here take precedence over any defaults. :type compress_opts: dict, optional :param kwargs: Extra keyword arguments are combined into `compress_opts`, though existing items in `compress_opts` take precedence over `kwargs`. :returns: The compressed tensor network, with canonical center at ``site_tags[0]`` ('right canonical' form) or ``site_tags[-1]`` ('left canonical' form) if ``sweep_reverse``. :rtype: TensorNetwork .. py:function:: _form_final_tn_from_tensor_sequence(tn: quimb.tensor.tensor_core.TensorNetwork, ts: list[quimb.tensor.tensor_core.Tensor], normalize: bool, sweep_reverse: bool, permute_arrays: bool | str, equalize_norms: bool | float, exponent=0.0, inplace=False) -> quimb.tensor.tensor_core.TensorNetwork Form the final, compressed tensor network given the the original target (uncompressed) tensor network and the new sequence of tensors, e.g. sequence of unitaries from the dm method. :param tn: The original target tensor network. :type tn: TensorNetwork :param ts: The sequence of tensors describing the compressed tensor network, assumed to be in 'right canonical' form. :type ts: list of Tensor :param normalize: Whether to normalize the final tensor network, making use of the fact that the output tensor network is in right canonical form. :type normalize: bool :param sweep_reverse: Whether to reverse the order the tensors are inserted, e.g. if `site_tags` have been reversed, purely for cosmetic ordering of the resulting `tensor_map`. :type sweep_reverse: bool :param permute_arrays: Whether to permute the array indices of the final tensor network into canonical order. If ``True`` will use the default order, if any (e.g. MatrixProductState), otherwise if a string this specifies a custom order. :type permute_arrays: bool or str :param equalize_norms: Whether to equalize the norms of the tensors after compression. If an explicit value is given, then the norms will be set to that value, and the overall scaling factor will be accumulated into `.exponent`. If ``True``, whatever current `.exponent` will be distributed equally among the tensors. :type equalize_norms: bool or float :param exponent: An exponent value to add to the final tensor network's existing exponent, e.g. generated during the compression procedure. :type exponent: float :param inplace: Whether to perform the compression inplace or not. :type inplace: bool .. py:function:: tensor_network_1d_compress_dm(tn: quimb.tensor.tensor_core.TensorNetwork, max_bond=None, cutoff=1e-10, site_tags=None, normalize=False, cutoff_mode='rsum1', permute_arrays=True, optimize='auto-hq', sweep_reverse=False, canonize=True, equalize_norms=False, contract_opts=None, compress_opts=None, inplace=False, **kwargs) Compress any 1D-like tensor network using the 'density matrix' method (https://tensornetwork.org/mps/algorithms/denmat_mpo_mps/). While this has the same scaling as the direct method, in practice it can often be faster, especially at large bond dimensions. Potentially there are some situations where the direct method is more stable with regard to precision, since the density matrix method works in the 'squared' picture. :param tn: The tensor network to compress. Every tensor should have exactly one of the site tags. Each site can have multiple tensors and output indices. :type tn: TensorNetwork :param max_bond: The maximum bond dimension to compress to. :type max_bond: int :param cutoff: The truncation error to use when compressing the double layer tensor network. :type cutoff: float, optional :param site_tags: The tags to use to group and order the tensors from ``tn``. If not given, uses ``tn.site_tags``. The tensor network built will have one tensor per site, in the order given by ``site_tags``. :type site_tags: sequence of str, optional :param normalize: Whether to normalize the final tensor network, making use of the fact that the output tensor network is in right canonical form. :type normalize: bool, optional :param cutoff_mode: The mode to use when truncating the singular values of the decomposed tensors. See :func:`~quimb.tensor.tensor_split`. Note for the density matrix method the default 'rsum1' mode acts like 'rsum2' for the direct method due to truncating in the squared space. :type cutoff_mode: {"rsum1", "rel", ...}, optional :param permute_arrays: Whether to permute the array indices of the final tensor network into canonical order. If ``True`` will use the default order, otherwise if a string this specifies a custom order. :type permute_arrays: bool or str, optional :param optimize: The contraction path optimizer to use. :type optimize: str, optional :param sweep_reverse: Whether to sweep in the reverse direction, resulting in a left canonical form instead of right canonical. :type sweep_reverse: bool, optional :param canonize: Dummy argument to match the signature of other compression methods. :type canonize: bool, optional :param equalize_norms: Whether to equalize the norms of the tensors after compression. If an explicit value is given, then the norms will be set to that value, and the overall scaling factor will be accumulated into `.exponent`. :type equalize_norms: bool or float, optional :param inplace: Whether to perform the compression inplace or not. :type inplace: bool, optional :param contract_opts: Supplied to :func:`~quimb.tensor.tensor_contract`. Values set here take precedence over any defaults. :type contract_opts: dict, optional :param compress_opts: Supplied to :func:`~quimb.tensor.tensor_core.tensor_split`. Values set here take precedence over any defaults. :type compress_opts: dict, optional :param kwargs: Extra keyword arguments are combined into `compress_opts`, though existing items in `compress_opts` take precedence over `kwargs`. :returns: The compressed tensor network, with canonical center at ``site_tags[0]`` ('right canonical' form) or ``site_tags[-1]`` ('left canonical' form) if ``sweep_reverse``. :rtype: TensorNetwork .. py:function:: tensor_network_1d_compress_zipup(tn: quimb.tensor.tensor_core.TensorNetwork, max_bond=None, cutoff=1e-10, site_tags=None, canonize=True, normalize=False, cutoff_mode='rsum2', permute_arrays=True, optimize='auto-hq', sweep_reverse=False, equalize_norms=False, contract_opts=None, canonize_opts=None, compress_opts=None, inplace=False, **kwargs) Compress a 1D-like tensor network using the 'zip-up' algorithm due to 'Minimally Entangled Typical Thermal State Algorithms', E.M. Stoudenmire & Steven R. White (https://arxiv.org/abs/1002.1305). The returned tensor network will have one tensor per site, in the order given by ``site_tags``, with canonical center at ``site_tags[0]`` ('right' canonical form). The zipup algorithm scales better than the direct and density matrix methods when multiple tensors are present at each site (such as MPO-MPS multiplication), but is less accurate due to the compressions taking place in an only pseudo-canonical gauge. It generally also only makes sense in the fixed bond dimension case, as opposed to relying on a specific `cutoff` only. :param tn: The tensor network to compress. Every tensor should have exactly one of the site tags. Each site can have multiple tensors and output indices. :type tn: TensorNetwork :param max_bond: The maximum bond dimension to compress to. :type max_bond: int :param cutoff: A dynamic threshold for discarding singular values when compressing. :type cutoff: float, optional :param site_tags: The tags to use to group and order the tensors from ``tn``. If not given, uses ``tn.site_tags``. The tensor network built will have one tensor per site, in the order given by ``site_tags``. :type site_tags: sequence of str, optional :param canonize: Whether to pseudo canonicalize the initial tensor network. :type canonize: bool, optional :param normalize: Whether to normalize the final tensor network, making use of the fact that the output tensor network is in right canonical form. :type normalize: bool, optional :param cutoff_mode: The mode to use when truncating the singular values of the decomposed tensors. See :func:`~quimb.tensor.tensor_split`. :type cutoff_mode: {"rsum2", "rel", ...}, optional :param permute_arrays: Whether to permute the array indices of the final tensor network into canonical order. If ``True`` will use the default order, otherwise if a string this specifies a custom order. :type permute_arrays: bool or str, optional :param optimize: The contraction path optimizer to use. :type optimize: str, optional :param sweep_reverse: Whether to sweep in the reverse direction, resulting in a left canonical form instead of right canonical. :type sweep_reverse: bool, optional :param equalize_norms: Whether to equalize the norms of the tensors after compression. If an explicit value is given, then the norms will be set to that value, and the overall scaling factor will be accumulated into `.exponent`. :type equalize_norms: bool or float, optional :param contract_opts: Supplied to :func:`~quimb.tensor.tensor_contract`. Values set here take precedence over any defaults. :type contract_opts: dict, optional :param canonize_opts: Supplied to :func:`~quimb.tensor.TensorNetwork.canonize_around_` when pseudo-canonicalizing. Values set here take precedence over defaults. :type canonize_opts: dict, optional :param inplace: Whether to perform the compression inplace or not. :type inplace: bool, optional :param compress_opts: Supplied to :func:`~quimb.tensor.tensor_split`. Values set here take precedence over defaults. :type compress_opts: dict, optional :param kwargs: Extra keyword arguments are combined into `compress_opts`, though existing items in `compress_opts` take precedence over `kwargs`. :returns: The compressed tensor network, with canonical center at ``site_tags[0]`` ('right canonical' form) or ``site_tags[-1]`` ('left canonical' form) if ``sweep_reverse``. :rtype: TensorNetwork .. py:function:: _do_direct_sweep(tn: quimb.tensor.tensor_core.TensorNetwork, site_tags, max_bond, cutoff, cutoff_mode, equalize_norms, normalize, permute_arrays, compress_opts=None, **kwargs) .. py:function:: tensor_network_1d_compress_zipup_oversample(tn: quimb.tensor.tensor_core.TensorNetwork, max_bond=None, max_bond_oversample=None, cutoff=1e-10, cutoff_oversample=None, site_tags=None, canonize=True, normalize=False, cutoff_mode='rsum2', permute_arrays=True, optimize='auto-hq', sweep_reverse=False, equalize_norms=False, contract_opts=None, canonize_opts=None, compress_opts=None, inplace=False, **kwargs) Compress this 1D-like tensor network using the 'zip-up first' algorithm, that is, first compressing the tensor network to a larger bond dimension using the 'zip-up' algorithm, then compressing to the desired bond dimension using a direct sweep. Depending on the value of ``max_bond`` and ``max_bond_oversample``, this can be scale better than the direct and density matrix methods, but reach close to the same accuracy. As with the 'zip-up' method, there is no advantage unless there are multiple tensors per site, and it generally only makes sense in the fixed bond dimension case, as opposed to relying on a specific `cutoff` only. :param tn: The tensor network to compress. Every tensor should have exactly one of the site tags. Each site can have multiple tensors and output indices. :type tn: TensorNetwork :param max_bond: The final maximum bond dimension to compress to. :type max_bond: int :param max_bond_oversample: The intermediate maximum bond dimension to compress to using the 'zip-up' algorithm. If not given and `max_bond` is, this is set as twice the target bond dimension, ``2 * max_bond``. :type max_bond_oversample: int, optional :param cutoff: A dynamic threshold for discarding singular values when compressing. :type cutoff: float, optional :param cutoff_oversample: A dynamic threshold for discarding singular values when compressing to the intermediate bond dimension using the 'zip-up' algorithm. If not given, this is set to the same as ``cutoff`` if a maximum bond is given, else ``cutoff / 10``. :type cutoff_oversample: float, optional :param site_tags: The tags to use to group and order the tensors from ``tn``. If not given, uses ``tn.site_tags``. The tensor network built will have one tensor per site, in the order given by ``site_tags``. :type site_tags: sequence of str, optional :param canonize: Whether to pseudo canonicalize the initial tensor network. :type canonize: bool, optional :param normalize: Whether to normalize the final tensor network, making use of the fact that the output tensor network is in right canonical form. :type normalize: bool, optional :param cutoff_mode: The mode to use when truncating the singular values of the decomposed tensors. See :func:`~quimb.tensor.tensor_split`. :type cutoff_mode: {"rsum2", "rel", ...}, optional :param permute_arrays: Whether to permute the array indices of the final tensor network into canonical order. If ``True`` will use the default order, otherwise if a string this specifies a custom order. :type permute_arrays: bool or str, optional :param optimize: The contraction path optimizer to use. :type optimize: str, optional :param sweep_reverse: Whether to sweep in the reverse direction, resulting in a left canonical form instead of right canonical. :type sweep_reverse: bool, optional :param equalize_norms: Whether to equalize the norms of the tensors after compression. If an explicit value is given, then the norms will be set to that value, and the overall scaling factor will be accumulated into `.exponent`. :type equalize_norms: bool or float, optional :param contract_opts: Supplied to :func:`~quimb.tensor.tensor_contract`. Values set here take precedence over any defaults. :type contract_opts: dict, optional :param canonize_opts: Supplied to :func:`tensor_network_1d_compress_zipup` when pseudo-canonicalizing in the oversampling step. :type canonize_opts: dict, optional :param inplace: Whether to perform the compression inplace or not. :type inplace: bool, optional :param compress_opts: Supplied to :func:`~quimb.tensor.tensor_split` in the oversampling step and to :func:`~quimb.tensor.TensorNetwork.compress_between` in the final direct sweep. Values set here take precedence over defaults. :type compress_opts: dict, optional :param kwargs: Extra keyword arguments are combined into `compress_opts`, though existing items in `compress_opts` take precedence over `kwargs`. :returns: The compressed tensor network, with canonical center at ``site_tags[0]`` ('right canonical' form) or ``site_tags[-1]`` ('left canonical' form) if ``sweep_reverse``. :rtype: TensorNetwork .. py:function:: _do_sweep_compress_from_low_rank_left_envs(tn: quimb.tensor.tensor_core.TensorNetwork, local_tns: list[quimb.tensor.tensor_core.TensorNetwork], left_envs: dict[int, quimb.tensor.tensor_core.Tensor], left_env_inds: dict[int, list[str]], contract_opts: dict, project_opts: dict, equalize_norms: bool | float, normalize: bool, sweep_reverse: bool, permute_arrays: bool | str, inplace: bool) -> quimb.tensor.tensor_core.TensorNetwork Form a compressed MPS for any method that produces a sequence of low-rank 'left environments' such as SRC. :param tn: The original target tensor network. :type tn: TensorNetwork :param local_tns: The tensor network partitioned into each local site. :type local_tns: list[TensorNetwork, ...] :param left_envs: The left environment tensors, keyed by the site they are the environment for. :type left_envs: sequence[int, Tensor] :param left_env_inds: The 'left' indices of each left environment, typically only one. :type left_env_inds: dict[int, sequence[str]] :param contract_opts: Supplied to :func:`~quimb.tensor.tensor_contract` when contracting tensors during the sweep. Values set here take precedence over defaults. :type contract_opts: dict :param project_opts: Supplied to :func:`~quimb.tensor.tensor_split` when forming the orthogonal projectors. The method should produce a left isometry, for example ``method="svd:eig"``. Values set here take precedence over defaults. :type project_opts: dict :param equalize_norms: Whether to equalize the norms of the tensors after compression. If an explicit value is given, then the norms will be set to that value, and the overall scaling factor will be accumulated into `.exponent`. :type equalize_norms: bool or float :param normalize: Whether to normalize the final tensor network, making use of the fact that the output tensor network is in right canonical form. :type normalize: bool :param sweep_reverse: Whether to reverse the order the tensors are inserted, e.g. if `site_tags` have been reversed, purely for cosmetic ordering of the resulting `tensor_map`. :type sweep_reverse: bool :param permute_arrays: Whether to permute the array indices of the final tensor network into canonical order. If ``True`` will use the default order, if any (e.g. MatrixProductState), otherwise if a string this specifies a custom order. :type permute_arrays: bool or str :param inplace: Whether to perform the compression inplace or not. :type inplace: bool :rtype: TensorNetwork .. py:function:: _src_get_local_noise_tensors(noise_mode, noise_dist, max_bond, Bix, inds, ind_sizes, site_tag) .. py:function:: tensor_network_1d_compress_src(tn: quimb.tensor.tensor_core.TensorNetwork, max_bond: int, cutoff=0.0, site_tags=None, normalize=False, noise_mode='joint', noise_dist='normal', permute_arrays=True, sweep_reverse=False, canonize=True, equalize_norms=False, contract_opts=None, project_opts=None, compress_opts=None, inplace=False, **kwargs) Compress any 1D-like tensor network using 'Successive Randomized Compression' (SRC) https://arxiv.org/abs/2504.06475. :param tn: The tensor network to compress. Every tensor should have exactly one of the site tags. Each site can have multiple tensors and output indices. :type tn: TensorNetwork :param max_bond: The maximum bond dimension to compress to. :type max_bond: int :param cutoff: Unused for SRC, use ``max_bond``. :type cutoff: float, optional :param site_tags: The tags to use to group and order the tensors from ``tn``. If not given, uses ``tn.site_tags``. The tensor network built will have one tensor per site, in the order given by ``site_tags``. :type site_tags: sequence of str, optional :param normalize: Whether to normalize the final tensor network, making use of the fact that the output tensor network is in right canonical form. :type normalize: bool, optional :param noise_mode: How to generate the random noise tensors. 'joint' generates a single random tensor for all outer indices on a site. 'separable' generates a random vector for each outer index. 'symmetric' reuses the same random vector for all outer indices on a site. :type noise_mode: {'joint', 'separable', 'symmetric'}, optional :param noise_dist: The distribution to use when generating the random noise tensors. See :func:`~quimb.tensor.rand_tensor` for options. :type noise_dist: {"normal", "rademacher", ...}, optional :param permute_arrays: Whether to permute the array indices of the final tensor network into canonical order. If ``True`` will use the default order, otherwise if a string this specifies a custom order. :type permute_arrays: bool or str, optional :param sweep_reverse: Whether to sweep in the reverse direction, resulting in a left canonical form instead of right canonical. :type sweep_reverse: bool, optional :param canonize: Whether to pseudo canonicalize the initial tensor network. :type canonize: bool, optional :param equalize_norms: Whether to equalize the norms of the tensors after compression. If an explicit value is given, then the norms will be set to that value, and the overall scaling factor will be accumulated into `.exponent`. :type equalize_norms: bool or float, optional :param contract_opts: Supplied to :func:`~quimb.tensor.tensor_contract`. Values set here take precedence over any defaults. :type contract_opts: dict, optional :param project_opts: Supplied to :func:`~quimb.tensor.tensor_split` when forming the orthogonal projectors. The method should product a left isometry, for example ``method="svd:eig"``. Values set here take precedence over defaults. :type project_opts: dict, optional :param inplace: Whether to perform the compression inplace or not. :type inplace: bool, optional :param kwargs: Extra keyword arguments are combined into `contract_opts`, though existing items in `contract_opts` take precedence over `kwargs`. :returns: The compressed tensor network, with canonical center at ``site_tags[0]`` ('right canonical' form) or ``site_tags[-1]`` ('left canonical' form) if ``sweep_reverse``. :rtype: TensorNetwork .. py:function:: tensor_network_1d_compress_src_oversample(tn: quimb.tensor.tensor_core.TensorNetwork, max_bond: int, max_bond_oversample=None, cutoff=1e-10, cutoff_oversample=0.0, noise_mode='joint', site_tags=None, canonize=True, normalize=False, cutoff_mode='rsum2', permute_arrays=True, optimize='auto-hq', sweep_reverse=False, equalize_norms=False, contract_opts=None, project_opts=None, compress_opts=None, inplace=False, **kwargs) Compress this 1D-like tensor network using the 'src first' algorithm, i.e. src with oversampling, that is, first compressing the tensor network to a larger bond dimension using the 'src' (successive randomized compression, https://arxiv.org/abs/2504.06475) algorithm, then compressing to the desired bond dimension using a direct sweep. :param tn: The tensor network to compress. Every tensor should have exactly one of the site tags. Each site can have multiple tensors and output indices. :type tn: TensorNetwork :param max_bond: The final maximum bond dimension to compress to. :type max_bond: int :param max_bond_oversample: The intermediate maximum bond dimension to compress to using the 'src' algorithm. If not given and `max_bond` is, this is set as ``max(round(1.5 * max_bond), max_bond + 10)``. If given as a float, this is assumed to be a multiplier of `max_bond`. :type max_bond_oversample: int, optional :param cutoff: A dynamic threshold for discarding singular values when compressing during the final direct sweep. :type cutoff: float, optional :param cutoff_oversample: Unused for SRC. :type cutoff_oversample: float, optional :param noise_mode: How to generate the random noise tensors for the SRC step. :type noise_mode: {'separable', 'symmetric', 'joint'}, optional :param site_tags: The tags to use to group and order the tensors from ``tn``. If not given, uses ``tn.site_tags``. The tensor network built will have one tensor per site, in the order given by ``site_tags``. :type site_tags: sequence of str, optional :param canonize: Whether to pseudo canonicalize the initial tensor network. :type canonize: bool, optional :param normalize: Whether to normalize the final tensor network, making use of the fact that the output tensor network is in right canonical form. :type normalize: bool, optional :param cutoff_mode: The mode to use when truncating the singular values of the decomposed tensors during the final direct sweep. :type cutoff_mode: {"rsum2", "rel", ...}, optional :param permute_arrays: Whether to permute the array indices of the final tensor network into canonical order. If ``True`` will use the default order, otherwise if a string this specifies a custom order. :type permute_arrays: bool or str, optional :param optimize: The contraction path optimizer to use. :type optimize: str, optional :param sweep_reverse: Whether to sweep in the reverse direction, resulting in a left canonical form instead of right canonical. :type sweep_reverse: bool, optional :param equalize_norms: Whether to equalize the norms of the tensors after compression. If an explicit value is given, then the norms will be set to that value, and the overall scaling factor will be accumulated into `.exponent`. :type equalize_norms: bool or float, optional :param contract_opts: Supplied to :func:`~quimb.tensor.tensor_contract`. Values set here take precedence over any defaults. :type contract_opts: dict, optional :param project_opts: Supplied to :func:`~quimb.tensor.tensor_split` when forming the orthogonal projectors in the SRC step. The method should product a left isometry, for example ``method="svd:eig"``. Values set here take precedence over defaults. :type project_opts: dict, optional :param inplace: Whether to perform the compression inplace or not. :type inplace: bool, optional :param compress_opts: Supplied to :func:`~quimb.tensor.tensor_split` during the final direct sweep. Values set here take precedence over defaults. :type compress_opts: dict, optional :param kwargs: Extra keyword arguments are combined into `compress_opts`, though existing items in `compress_opts` take precedence over `kwargs`. :returns: The compressed tensor network. :rtype: TensorNetwork .. py:function:: tensor_network_1d_compress_srcmps(tn: quimb.tensor.tensor_core.TensorNetwork, max_bond: int, cutoff=0.0, tn_fit=None, site_tags=None, normalize=False, permute_arrays=True, sweep_reverse=False, canonize=True, equalize_norms=False, contract_opts=None, project_opts=None, compress_opts=None, inplace=False, **kwargs) Compress any 1D-like tensor network using 'Successive Randomized Compression' (SRC) https://arxiv.org/abs/2504.06475 but using a random or a supplied MPS as the 'sampling noise'. :param tn: The tensor network to compress. Every tensor should have exactly one of the site tags. Each site can have multiple tensors and output indices. :type tn: TensorNetwork :param max_bond: The maximum bond dimension to compress to. :type max_bond: int :param cutoff: Unused for SRC, use ``max_bond``. :type cutoff: float, optional :param tn_fit: The MPS specificing the sampling noise (its bond dimension effectively sets the compression rank). If not given, a random MPS with bond dimension ``max_bond`` is used. If a string or dict, this is used to construct the MPS from ``tn``. :type tn_fit: TensorNetwork, dict, or str, optional :param site_tags: The tags to use to group and order the tensors from ``tn``. If not given, uses ``tn.site_tags``. The tensor network built will have one tensor per site, in the order given by ``site_tags``. :type site_tags: sequence of str, optional :param normalize: Whether to normalize the final tensor network, making use of the fact that the output tensor network is in right canonical form. :type normalize: bool, optional :param permute_arrays: Whether to permute the array indices of the final tensor network into canonical order. If ``True`` will use the default order, otherwise if a string this specifies a custom order. :type permute_arrays: bool or str, optional :param canonize: Whether to pseudo canonicalize the initial tensor network. :type canonize: bool, optional :param sweep_reverse: Whether to sweep in the reverse direction, resulting in a left canonical form instead of right canonical. :type sweep_reverse: bool, optional :param equalize_norms: Whether to equalize the norms of the tensors after compression. If an explicit value is given, then the norms will be set to that value, and the overall scaling factor will be accumulated into `.exponent`. :type equalize_norms: bool or float, optional :param contract_opts: Supplied to :func:`~quimb.tensor.tensor_contract`. Values set here take precedence over any defaults. :type contract_opts: dict, optional :param project_opts: Supplied to :func:`~quimb.tensor.tensor_split` when forming the orthogonal projectors. The method should product a left isometry, for example ``method="svd:eig"``. Values set here take precedence over defaults. :type project_opts: dict, optional :param inplace: Whether to perform the compression inplace or not. :type inplace: bool, optional :param kwargs: Extra keyword arguments are combined into `contract_opts`, though existing items in `contract_opts` take precedence over `kwargs`. :returns: The compressed tensor network. :rtype: TensorNetwork .. py:function:: tensor_network_1d_compress_srcmps_oversample(tn: quimb.tensor.tensor_core.TensorNetwork, max_bond: int, max_bond_oversample=None, cutoff=1e-10, cutoff_oversample=0.0, tn_fit=None, site_tags=None, canonize=True, normalize=False, cutoff_mode='rsum2', permute_arrays=True, optimize='auto-hq', sweep_reverse=False, equalize_norms=False, contract_opts=None, project_opts=None, compress_opts=None, inplace=False, **kwargs) Compress this 1D-like tensor network using the 'srcmps-oversample' algorithm, i.e. src with oversampling and matrix product state noise, that is, first compressing the tensor network to a larger bond dimension using the 'src' (successive randomized compression, https://arxiv.org/abs/2504.06475) algorithm, then compressing to the desired bond dimension using a direct sweep. :param tn: The tensor network to compress. Every tensor should have exactly one of the site tags. Each site can have multiple tensors and output indices. :type tn: TensorNetwork :param max_bond: The final maximum bond dimension to compress to. :type max_bond: int :param max_bond_oversample: The intermediate maximum bond dimension to compress to using the 'srcmps' algorithm. If not given and `max_bond` is, this is set as ``max(round(1.5 * max_bond), max_bond + 10)``. If given as a float, this is assumed to be a multiplier of `max_bond`. :type max_bond_oversample: int, optional :param cutoff: A dynamic threshold for discarding singular values when compressing during the final direct sweep. :type cutoff: float, optional :param cutoff_oversample: Unused for SRC. :type cutoff_oversample: float, optional :param tn_fit: The MPS specificing the sampling noise (its bond dimension effectively sets the compression rank). :type tn_fit: TensorNetwork, optional :param site_tags: The tags to use to group and order the tensors from ``tn``. If not given, uses ``tn.site_tags``. The tensor network built will have one tensor per site, in the order given by ``site_tags``. :type site_tags: sequence of str, optional :param canonize: Whether to pseudo canonicalize the initial tensor network. :type canonize: bool, optional :param normalize: Whether to normalize the final tensor network, making use of the fact that the output tensor network is in right canonical form. :type normalize: bool, optional :param cutoff_mode: The mode to use when truncating the singular values of the decomposed tensors during the final direct sweep. :type cutoff_mode: {"rsum2", "rel", ...}, optional :param permute_arrays: Whether to permute the array indices of the final tensor network into canonical order. If ``True`` will use the default order, otherwise if a string this specifies a custom order. :type permute_arrays: bool or str, optional :param optimize: The contraction path optimizer to use. :type optimize: str, optional :param sweep_reverse: Whether to sweep in the reverse direction, resulting in a left canonical form instead of right canonical. :type sweep_reverse: bool, optional :param equalize_norms: Whether to equalize the norms of the tensors after compression. If an explicit value is given, then the norms will be set to that value, and the overall scaling factor will be accumulated into `.exponent`. :type equalize_norms: bool or float, optional :param contract_opts: Supplied to :func:`~quimb.tensor.tensor_contract`. Values set here take precedence over any defaults. :type contract_opts: dict, optional :param project_opts: Supplied to :func:`~quimb.tensor.tensor_split` when forming the orthogonal projectors in the SRC step. The method should product a left isometry, for example ``method="svd:eig"``. Values set here take precedence over defaults. :type project_opts: dict, optional :param compress_opts: Supplied to :func:`~quimb.tensor.tensor_split` during the final direct sweep. Values set here take precedence over defaults. :type compress_opts: dict, optional :param inplace: Whether to perform the compression inplace or not. :type inplace: bool, optional :param kwargs: Extra keyword arguments are combined into `compress_opts`, though existing items in `compress_opts` take precedence over `kwargs`. :returns: The compressed tensor network. :rtype: TensorNetwork .. py:function:: _tn1d_fit_sum_sweep_1site(tn_fit: quimb.tensor.tensor_core.TensorNetwork, tn_overlaps: list[quimb.tensor.tensor_core.TensorNetwork], site_tags: list[str], max_bond=None, cutoff=0.0, envs=None, prepare=True, reverse=False, compute_tdiff=True, optimize='auto-hq') Core sweep of the 1-site 1D fit algorithm. .. py:function:: _tn1d_fit_sum_sweep_2site(tn_fit: quimb.tensor.tensor_core.TensorNetwork, tn_overlaps: list[quimb.tensor.tensor_core.TensorNetwork], site_tags: list[str], max_bond=None, cutoff=1e-10, envs=None, prepare=True, reverse=False, optimize='auto-hq', compute_tdiff=True, **compress_opts) Core sweep of the 2-site 1D fit algorithm. .. py:function:: tensor_network_1d_compress_fit(tns: quimb.tensor.tensor_core.TensorNetwork | list[quimb.tensor.tensor_core.TensorNetwork], max_bond=None, cutoff=None, tn_fit=None, bsz='auto', initial_bond_dim=8, max_iterations=10, tol=0.0, site_tags=None, cutoff_mode='rsum2', sweep_sequence='RL', normalize=False, permute_arrays=True, optimize='auto-hq', canonize=True, sweep_reverse=False, equalize_norms=False, compress_opts=None, inplace_fit=False, inplace=False, progbar=False, **kwargs) Compress any 1D-like (can have multiple tensors per site) tensor network or sum of tensor networks to an exactly 1D (one tensor per site) tensor network of bond dimension `max_bond` using the 1-site or 2-site variational fitting (or 'DMRG-style') method. The tensor network(s) can have arbitrary inner and outer structure. This method has the lowest scaling of the standard 1D compression methods and can also provide the most accurate compression, but the actual speed and accuracy depend on the number of iterations required and initial guess, making it a more 'hands-on' method. It's also the only method to support fitting to a sum of tensor networks directly, rather than having to forming the explicitly summed TN first. :param tns: The tensor network or tensor networks to compress. Each tensor network should have the same outer index structure, and within each tensor network every tensor should have exactly one of the site tags. :type tns: TensorNetwork or Sequence[TensorNetwork] :param max_bond: The maximum bond dimension to compress to. If not given, this is set as the maximum bond dimension of the initial guess tensor network, if any, else infinite for ``bsz=2``. :type max_bond: int :param cutoff: A dynamic threshold for discarding singular values when compressing. This is only relevant for the 2-site sweeping algorithm (``bsz=2``), where it defaults to 1e-10. :type cutoff: float, optional :param tn_fit: An initial guess for the compressed tensor network. It should matching outer indices and site tags with ``tn``. If a `dict`, this is assumed to be options to supply to `tensor_network_1d_compress` to construct the initial guess, inheriting various defaults like `initial_bond_dim`. If a string, e.g. ``"zipup"``, this is shorthand for that compression method with default settings. If not given, a random 1D tensor network will be used. :type tn_fit: TensorNetwork, dict, or str, optional :param bsz: The size of the block to optimize while sweeping. If ``"auto"``, this will be inferred from the value of ``max_bond`` and ``cutoff``. :type bsz: {"auto", 1, 2}, optional :param initial_bond_dim: The initial bond dimension to use when creating the initial guess. This is only relevant if ``tn_fit`` is not given. For each sweep the allowed bond dimension is doubled, up to ``max_bond``. For 1-site this occurs via explicit bond expansion, while for 2-site it occurs during the 2-site tensor decomposition. :type initial_bond_dim: int, optional :param max_iterations: The maximum number of variational sweeps to perform. :type max_iterations: int, optional :param tol: The convergence tolerance, in terms of local tensor distance normalized. If zero, there will be exactly ``max_iterations`` sweeps. :type tol: float, optional :param site_tags: The tags to use to group and order the tensors from ``tn``. If not given, uses ``tn.site_tags``. The tensor network built will have one tensor per site, in the order given by ``site_tags``. :type site_tags: sequence of str, optional :param cutoff_mode: The mode to use when truncating the singular values of the decomposed tensors. See :func:`~quimb.tensor.tensor_split`, if using the 2-site sweeping algorithm. :type cutoff_mode: {"rsum2", "rel", ...}, optional :param sweep_sequence: The sequence of sweeps to perform, e.g. ``"LR"`` means first sweep left to right, then right to left. The sequence is cycled. The final canonical form of the output tensor network depends on the last sweep direction and ``sweep_reverse``. :type sweep_sequence: str, optional :param normalize: Whether to normalize the final tensor network, making use of the fact that the output tensor network is in left or right canonical form. :type normalize: bool, optional :param permute_arrays: Whether to permute the array indices of the final tensor network into canonical order. If ``True`` will use the default order, otherwise if a string this specifies a custom order. :type permute_arrays: bool or str, optional :param optimize: The contraction path optimizer to use. :type optimize: str, optional :param canonize: Dummy argument to match the signature of other compression methods. :type canonize: bool, optional :param sweep_reverse: Whether to sweep in the reverse direction, swapping whether the final tensor network is in right or left canonical form, which also depends on the last sweep direction. :type sweep_reverse: bool, optional :param equalize_norms: Whether to equalize the norms of the tensors after compression. If an explicit value is given, then the norms will be set to that value, and the overall scaling factor will be accumulated into `.exponent`. :type equalize_norms: bool or float, optional :param compress_opts: Supplied to :func:`~quimb.tensor.tensor_split`, if using the 2-site sweeping algorithm. Values set here take precedence over defaults. :type compress_opts: dict, optional :param inplace_fit: Whether to perform the compression inplace on the initial guess tensor network, ``tn_fit``, if supplied. :type inplace_fit: bool, optional :param inplace: Whether to perform the compression inplace on the target tensor network supplied, or ``tns[0]`` if a sequence to sum is supplied. :type inplace: bool, optional :param progbar: Whether to show a progress bar. Note the progress bar shows the maximum change of any single tensor norm, *not* the global change in norm or truncation error. :type progbar: bool, optional :param kwargs: Extra keyword arguments are combined into `compress_opts`, though existing items in `compress_opts` take precedence over `kwargs`. :returns: The compressed tensor network. Depending on ``sweep_reverse`` and the last sweep direction, the canonical center will be at either L: ``site_tags[0]`` or R: ``site_tags[-1]``, or the opposite if ``sweep_reverse``. :rtype: TensorNetwork .. py:function:: tensor_network_1d_compress_fit_guess(tn: quimb.tensor.tensor_core.TensorNetwork | list[quimb.tensor.tensor_core.TensorNetwork], guess: str, max_bond=None, cutoff=1e-10, cutoff_fit=0.0, bsz=1, max_iterations=8, canonize=True, **kwargs) Compress any 1D-like (can have multiple tensors per site) tensor network to an exactly 1D (one tensor per site) tensor network of bond dimension `max_bond` using by default 1-site variational fitting (or 'DMRG-style') method starting with a non-random guess tensor network, e.g. from the cheap zip-up or projector methods. :param tn: The tensor network to compress. Every tensor should have exactly one of the site tags. Each site can have multiple tensors and output indices. :type tn: TensorNetwork :param guess: The method to use to generate the initial guess. :type guess: str :param max_bond: The maximum bond dimension to compress to. :type max_bond: int :param cutoff: The cutoff used for the *guess* compression method. :type cutoff: float, optional :param cutoff_fit: The cutoff used for the *fit* compression method. :type cutoff_fit: float, optional :param bsz: The block size to use for the variational fitting sweep. :type bsz: int, optional :param max_iterations: The maximum number of variational sweeps to perform. :type max_iterations: int, optional :param canonize: Whether to canonicalize the guess tensor network. :type canonize: bool, optional :param kwargs: Supplied to :func:`tensor_network_1d_compress_fit`. :returns: The compressed tensor network. :rtype: TensorNetwork .. py:data:: tensor_network_1d_compress_fit_zipup .. py:data:: tensor_network_1d_compress_fit_projector .. py:function:: tensor_network_1d_compress_fit_oversample(tn: quimb.tensor.tensor_core.TensorNetwork | list[quimb.tensor.tensor_core.TensorNetwork], max_bond=None, max_bond_oversample=None, cutoff=1e-10, cutoff_fit=0.0, bsz=1, site_tags=None, canonize=True, normalize=False, cutoff_mode='rsum2', permute_arrays=True, optimize='auto-hq', sweep_reverse=False, equalize_norms=False, compress_opts=None, inplace=False, **kwargs) Compress this 1D-like tensor network using the 'fit-oversample' algorithm, that is, first compressing the tensor network to a larger bond dimension using the variational 'fit' algorithm, then compressing to the desired bond dimension using a direct sweep. :param tn: The tensor network to compress. Every tensor should have exactly one of the site tags. Each site can have multiple tensors and output indices. :type tn: TensorNetwork :param max_bond: The final maximum bond dimension to compress to. :type max_bond: int :param max_bond_oversample: The intermediate maximum bond dimension to compress to using the 'fit' algorithm. If not given and `max_bond` is, this is set as ``max(round(1.5 * max_bond), max_bond + 10)``. If given as a float, this is assumed to be a multiplier of `max_bond`. :type max_bond_oversample: int, optional :param cutoff: A dynamic threshold for discarding singular values when compressing during the final direct sweep. :type cutoff: float, optional :param cutoff_fit: A dynamic threshold for discarding singular values when compressing to the intermediate bond dimension using the 'fit' algorithm (only relevant if ``bsz=2``). :type cutoff_fit: float, optional :param bsz: The block size to use for the variational fitting sweep. :type bsz: {1, 2}, optional :param site_tags: The tags to use to group and order the tensors from ``tn``. If not given, uses ``tn.site_tags``. The tensor network built will have one tensor per site, in the order given by ``site_tags``. :type site_tags: sequence of str, optional :param canonize: Whether to pseudo canonicalize the initial tensor network. :type canonize: bool, optional :param normalize: Whether to normalize the final tensor network, making use of the fact that the output tensor network is in right canonical form. :type normalize: bool, optional :param cutoff_mode: The mode to use when truncating the singular values of the decomposed tensors. See :func:`~quimb.tensor.tensor_split`. :type cutoff_mode: {"rsum2", "rel", ...}, optional :param permute_arrays: Whether to permute the array indices of the final tensor network into canonical order. If ``True`` will use the default order, otherwise if a string this specifies a custom order. :type permute_arrays: bool or str, optional :param optimize: The contraction path optimizer to use. :type optimize: str, optional :param sweep_reverse: Whether to sweep in the reverse direction, resulting in a left canonical form instead of right canonical. :type sweep_reverse: bool, optional :param equalize_norms: Whether to equalize the norms of the tensors after compression. If an explicit value is given, then the norms will be set to that value, and the overall scaling factor will be accumulated into `.exponent`. :type equalize_norms: bool or float, optional :param inplace: Whether to perform the compression inplace or not. :type inplace: bool, optional :param compress_opts: Supplied to :func:`~quimb.tensor.tensor_split` during the final direct sweep. Values set here take precedence over defaults. :type compress_opts: dict, optional :param kwargs: Extra keyword arguments are combined into `compress_opts`, though existing items in `compress_opts` take precedence over `kwargs`. :returns: The compressed tensor network, with canonical center at ``site_tags[0]`` ('right canonical' form) or ``site_tags[-1]`` ('left canonical' form) if ``sweep_reverse``. :rtype: TensorNetwork .. py:data:: _TN1D_COMPRESS_METHODS .. py:function:: tensor_network_1d_compress(tn: quimb.tensor.tensor_core.TensorNetwork | list[quimb.tensor.tensor_core.TensorNetwork], max_bond=None, cutoff=1e-10, method='dm', site_tags=None, canonize=True, permute_arrays=True, optimize='auto-hq', sweep_reverse=False, equalize_norms=False, inplace=False, **kwargs) -> quimb.tensor.tensor_core.TensorNetwork Compress a 1D-like tensor network, or sequence of such networks representing a sum, using the specified method, into an exactly 1D tensor network of bond dimension `max_bond`. The only requirement is that each tensor has exactly one of the site tags, which determines which site it will be grouped and compressed into. Each such 'site' can have multiple tensors and output indices. Long range bonds are handled automatically by inserting identities, but note that this function is intended for 1D-like *open boundary* tensor networks and always produces an open boundary compressed tensor network. See :func:`tensor_network_ag_compress` for arbitrary geometry tensor network compression methods for non 1D-like TNs. :param tn: The tensor network(s) to compress. Every tensor should have exactly one of the site tags. Each site can have multiple tensors and output indices. If a sequence is given, these tensor networks will be compressed as their sum (only supported by the 'fit' method). :type tn: TensorNetwork or sequence of TensorNetwork :param max_bond: The maximum bond dimension to compress to. :type max_bond: int :param cutoff: A dynamic threshold for discarding singular values when compressing. :type cutoff: float, optional :param method: The compression method to use. The options are: - ``"direct"`` : direct SVD sweep. - ``"dm"`` : density matrix method. - ``"zipup"`` : zip-up method. - ``"zipup-first"`` or ``"zipup-oversample"`` : zip-up with oversampling. - ``"src"``: successive randomized compression method. - ``"src-first"`` or ``"src-oversample"`` : successive randomized compression with oversampling. - ``"srcmps"``: successive randomized compression method using an MPS as the sampling noise. - ``"srcmps-first"`` or ``"srcmps-oversample"`` : successive randomized compression using an MPS as the sampling noise with oversampling. - ``"fit"`` : variational fitting (DMRG-style) method. - ``"fit-{method}"`` : variational fitting starting from a guess generated using `{method}`, e.g. ``"fit-zipup"``. - ``"fit-oversample"`` : variational fitting with oversampling. - any other method supported by :func:`tensor_network_ag_compress`. Oversampling methods first compress to `max_bond_oversample` (typically chosen as 1.5 or 2x `max_bond`) using the specified method, then compress to `max_bond` using a direct sweep. :type method: str, optional :param site_tags: The tags to use to group and order the tensors from ``tn``. If not given, uses ``tn.site_tags``. The tensor network built will have one tensor per site, in the order given by ``site_tags``. :type site_tags: sequence of str, optional :param canonize: Whether to perform canonicalization, pseudo or otherwise depending on the method, before compressing. Ignored for ``method='dm'`` and ``method='fit'``. :type canonize: bool, optional :param permute_arrays: Whether to permute the array indices of the final tensor network into canonical order. If ``True`` will use the default order, otherwise if a string this specifies a custom order. :type permute_arrays: bool or str, optional :param optimize: The contraction path optimizer to use. :type optimize: str, optional :param sweep_reverse: Whether to sweep in the reverse direction, resulting in a left canonical form instead of right canonical (for the fit method, this also depends on the last sweep direction). :type sweep_reverse: bool, optional :param equalize_norms: Whether to equalize the norms of the tensors after compression. If an explicit value is given, then the norms will be set to that value, and the overall scaling factor will be accumulated into `.exponent`. :type equalize_norms: bool or float, optional :param inplace: Whether to perform the compression inplace. :type inplace: bool, optional :param kwargs: Supplied to the chosen compression method. :rtype: TensorNetwork .. py:function:: mps_gate_with_mpo_lazy(mps, mpo, inplace=False) Apply an MPO to an MPS lazily, i.e. nothing is contracted, but the new TN object has the same outer indices as the original MPS. .. py:function:: mps_gate_with_mpo_direct(mps, mpo, max_bond=None, cutoff=1e-10, inplace=False, **compress_opts) Apply an MPO to an MPS using the boundary compression method, that is, explicitly contracting site-wise to form a MPS-like TN, canonicalizing in one direction, then compressing in the other. This has the same scaling as the density matrix (dm) method, but a larger prefactor. It can still be faster for small bond dimensions however, and is potentially higher precision since it works in the space of singular values directly rather than singular values squared. It is not quite optimal in terms of error due to the compounding errors of the SVDs. :param mps: The MPS to gate. :type mps: MatrixProductState :param mpo: The MPO to gate with. :type mpo: MatrixProductOperator :param max_bond: The maximum bond dimension to compress to. :type max_bond: int :param cutoff: A dynamic threshold for discarding singular values when compressing. :type cutoff: float, optional :param compress_opts: Supplied to :func:`~quimb.tensor.tensor_split`. .. py:function:: mps_gate_with_mpo_dm(mps, mpo, max_bond=None, cutoff=1e-10, inplace=False, **compress_opts) Gate this MPS with an MPO, using the density matrix compression method. :param mps: The MPS to gate. :type mps: MatrixProductState :param mpo: The MPO to gate with. :type mpo: MatrixProductOperator :param max_bond: The maximum bond dimension to keep when compressing the double layer tensor network, if any. :type max_bond: int, optional :param cutoff: The truncation error to use when compressing the double layer tensor network, if any. :type cutoff: float, optional :param compress_opts: Supplied to :func:`~quimb.tensor.tensor_split`. .. py:function:: mps_gate_with_mpo_zipup(mps, mpo, max_bond=None, cutoff=1e-10, canonize=True, optimize='auto-hq', **compress_opts) Apply an MPO to an MPS using the 'zip-up' algorithm due to 'Minimally Entangled Typical Thermal State Algorithms', E.M. Stoudenmire & Steven R. White (https://arxiv.org/abs/1002.1305). :param mps: The MPS to gate. :type mps: MatrixProductState :param mpo: The MPO to gate with. :type mpo: MatrixProductOperator :param max_bond: The maximum bond dimension to compress to. :type max_bond: int :param cutoff: A dynamic threshold for discarding singular values when compressing. :type cutoff: float, optional :param site_tags: The tags to use to group and order the tensors from ``tn``. If not given, uses ``tn.site_tags``. The tensor network built will have one tensor per site, in the order given by ``site_tags``. :type site_tags: sequence of str, optional :param canonize: Whether to pseudo canonicalize the initial tensor network. :type canonize: bool, optional :param normalize: Whether to normalize the final tensor network, making use of the fact that the output tensor network is in right canonical form. :type normalize: bool, optional :param permute_arrays: Whether to permute the array indices of the final tensor network into canonical order. If ``True`` will use the default order, otherwise if a string this specifies a custom order. :type permute_arrays: bool or str, optional :param optimize: The contraction path optimizer to use. :type optimize: str, optional :param compress_opts: Supplied to :func:`~quimb.tensor.tensor_split`. :returns: The compressed MPS, in right canonical form. :rtype: MatrixProductState .. py:function:: mps_gate_with_mpo_zipup_first(mps, mpo, max_bond=None, max_bond_oversample=None, cutoff=1e-10, cutoff_oversample=None, canonize=True, optimize='auto-hq', **compress_opts) Apply an MPO to an MPS by first using the zip-up method with a larger bond dimension, then doing a regular compression sweep to the target final bond dimension. This avoids forming an intermediate MPS with bond dimension ``mps.max_bond() * mpo.max_bond()``. :param mps: The MPS to gate. :type mps: MatrixProductState :param mpo: The MPO to gate with. :type mpo: MatrixProductOperator :param max_bond: The target final bond dimension. :type max_bond: int :param max_bond_oversample: The maximum bond dimension to use when zip-up compressing the double layer tensor network. If not given, defaults to ``2 * max_bond``. Needs to be smaller than ``mpo.max_bond()`` for any savings. :type max_bond_oversample: int, optional :param cutoff: The truncation error to use when performing the final regular compression sweep. :type cutoff: float, optional :param cutoff_oversample: The truncation error to use when performing the zip-up compression. :type cutoff_oversample: float, optional :param canonize: Whether to pseudo canonicalize the initial tensor network. :type canonize: bool, optional :param optimize: The contraction path optimizer to use. :type optimize: str, optional :param compress_opts: Supplied to :func:`~quimb.tensor.tensor_split` (both the zip-up and final sweep). :returns: The compressed MPS, in right canonical form. :rtype: MatrixProductState .. py:function:: mps_gate_with_mpo_fit(mps, mpo, max_bond, **kwargs) Gate an MPS with an MPO using the variational fitting or DMRG-style method. :param mps: The MPS to gate. :type mps: MatrixProductState :param mpo: The MPO to gate with. :type mpo: MatrixProductOperator :param max_bond: The maximum bond dimension to compress to. :type max_bond: int :returns: The gated MPS. :rtype: MatrixProductState .. py:function:: mps_gate_with_mpo_autofit(self, mpo, max_bond, cutoff=0.0, init_guess=None, **fit_opts) Fit a MPS to a MPO applied to an MPS using geometry generic versions of either ALS or autodiff. This is usually much less efficient that using the 1D specific methods. Some nice alternatives to the default fit_opts: - method="autodiff" - method="als", solver="lstsq" .. py:function:: mps_gate_with_mpo_projector(self, mpo, max_bond, cutoff=1e-10, canonize=True, canonize_opts=None, inplace=False, **compress_opts) Apply an MPO to an MPS using local projectors, in the style of CTMRG or HOTRG, without using information beyond the neighboring 4 tensors.