Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
two_site_split.hpp
Go to the documentation of this file.
1
7#pragma once
8
15
16#include <concepts>
17#include <cstddef>
18#include <stdexcept>
19#include <type_traits>
20#include <utility>
21#include <vector>
22
24{
25
32
38template <class FirstSite, class SecondSite, class SingularValues, class Truncation> struct TwoSiteMpsSplit
39{
41 FirstSite first_site;
43 SecondSite second_site;
45 SingularValues singular_values;
47 Truncation truncation;
50};
51
55template <class SingularValues, class Truncation> struct InstalledMpsBond
56{
58 SingularValues singular_values;
60 Truncation truncation;
63};
64
65namespace detail
66{
67
68template <class Space>
69concept SplitBondSpace =
72
73template <class Space>
74concept SplitPhysicalSpace =
77
78template <class Storage, class Scalar>
82
83template <class Tensor, std::size_t Index>
84using split_domain_space_t = typename block_tensor_domain_t<Tensor>::template space_type<Index>;
85
86template <class Tensor, std::size_t Index>
87using split_codomain_space_t = typename block_tensor_codomain_t<Tensor>::template space_type<Index>;
88
89template <class Tensor>
90concept TwoSiteSvdCenter =
93 (block_tensor_type_t<Tensor>::dense_block_order() == 2) && SplitBondSpace<split_domain_space_t<Tensor, 0>> &&
94 SplitPhysicalSpace<split_domain_space_t<Tensor, 1>> && SplitPhysicalSpace<split_domain_space_t<Tensor, 2>> &&
95 SplitBondSpace<split_codomain_space_t<Tensor, 0>>;
96
97template <SparseBlockStorage OutputStorage, BlockTensorView Source>
98auto materialize_block_tensor_copy(Source const& source)
99{
101 block_tensor_codomain_t<Source>, OutputStorage>;
102 using key_type = typename output_type::key_type;
103 std::vector<key_type> keys(source.stored_keys().begin(), source.stored_keys().end());
104 auto result = [&] {
105 if constexpr (requires {
106 output_type(uninitialized, source.symmetry(), source.domain(), source.codomain(), keys,
107 source.allocation_context());
108 })
109 return output_type(uninitialized, source.symmetry(), source.domain(), source.codomain(), std::move(keys),
110 source.allocation_context());
111 else
112 return output_type(uninitialized, source.symmetry(), source.domain(), source.codomain(), std::move(keys));
113 }();
114 for (std::size_t ordinal = 0; ordinal < result.stored_block_count(); ++ordinal)
115 {
116 auto output_block = result.block_by_ordinal(ordinal);
117 auto input_block = source.block_by_ordinal(ordinal);
118 uni20::copy(output_block, input_block);
119 }
120 return result;
121}
122
123} // namespace detail
124
136template <detail::TwoSiteSvdCenter Center, class Measurements, class Event>
137 requires uni20::LapackScalar<block_tensor_value_t<Center>> && performance::BatchMeasurementPolicy<Measurements, Event>
138[[nodiscard]] auto decompose_two_site_center(Center const& center, linalg::SvdOptions options,
139 Measurements& measurements, Event batch_event)
140{
141 auto matrix = repartition<MorphismSide::Domain, BoundaryEnd::Right>(center);
142 return block_svd(matrix, options, measurements, batch_event);
143}
144
150template <detail::TwoSiteSvdCenter Center>
152[[nodiscard]] auto decompose_two_site_center(Center const& center, linalg::SvdOptions options = {})
153{
154 performance::NoMeasurements measurements;
155 return decompose_two_site_center(center, options, measurements, nullptr);
156}
157
171template <SparseBlockStorage OutputStorage = SeparateSparseBlockStorage<>, class Decomposition>
172 requires detail::MpsSiteStorage<OutputStorage, typename Decomposition::scalar_type>
173[[nodiscard]] auto materialize_two_site_mps_split(Decomposition const& decomposition,
175 MpsSweepDirection direction,
177{
178 static_assert(Decomposition::domain_type::size() == 2, "two-site MPS decomposition requires a two-factor domain");
179 static_assert(Decomposition::codomain_type::size() == 2, "two-site MPS decomposition requires a two-factor codomain");
180 if (selection.state_ids().empty()) throw std::invalid_argument("two-site MPS split requires a retained state");
182 throw std::invalid_argument("two-site MPS split has an invalid sweep direction");
183
184 bool const absorb_left = direction == MpsSweepDirection::left_to_right;
185 bool const absorb_right = direction == MpsSweepDirection::right_to_left;
186 auto factors = uni20::detail::materialize_svd_with_absorption(decomposition, selection, std::move(options),
187 absorb_left, absorb_right);
188 if (direction == MpsSweepDirection::left_to_right)
189 {
190 auto first_site = detail::materialize_block_tensor_copy<OutputStorage>(factors.right_singular_vectors_adjoint);
191 auto second_view = repartition<MorphismSide::Codomain, BoundaryEnd::Right>(factors.left_singular_vectors);
192 auto second_site = detail::materialize_block_tensor_copy<OutputStorage>(second_view);
193 return TwoSiteMpsSplit{.first_site = std::move(first_site),
194 .second_site = std::move(second_site),
195 .singular_values = std::move(factors.singular_values),
196 .truncation = std::move(factors.truncation),
197 .direction = direction};
198 }
199
200 auto first_site = detail::materialize_block_tensor_copy<OutputStorage>(factors.right_singular_vectors_adjoint);
201 auto second_view = repartition<MorphismSide::Codomain, BoundaryEnd::Right>(factors.left_singular_vectors);
202 auto second_site = detail::materialize_block_tensor_copy<OutputStorage>(second_view);
203 return TwoSiteMpsSplit{.first_site = std::move(first_site),
204 .second_site = std::move(second_site),
205 .singular_values = std::move(factors.singular_values),
206 .truncation = std::move(factors.truncation),
207 .direction = direction};
208}
209
222template <typename Scalar, Space Bond, Space Physical, BlockTensorStorage SiteStorage, class Decomposition>
223 requires std::same_as<Bond, BlockSpace> && detail::MpsSiteStorage<SiteStorage, Scalar>
225 std::size_t first_index, Decomposition const& decomposition,
228{
229 auto split = materialize_two_site_mps_split<SiteStorage>(decomposition, selection, direction, std::move(options));
230 mps.replace_pair(first_index, std::move(split.first_site), std::move(split.second_site));
231 return InstalledMpsBond{.singular_values = std::move(split.singular_values),
232 .truncation = std::move(split.truncation),
233 .direction = direction};
234}
235
236} // namespace uni20::tensor_network
Defines local pairwise BlockTensor contraction.
Defines structure-preserving linear operations on BlockTensor values.
Defines zero-copy bosonic edge repartition views.
Classifies tensor spaces for block-key and dense-block storage.
Staged host singular value decompositions of bosonic Abelian BlockTensor values.
Arbitrary paired-state selection from a block-SVD spectrum.
Definition block_tensor_svd.hpp:92
auto state_ids() const noexcept -> std::span< BlockSvdStateId const >
Return selected state identities in global spectrum order.
Definition block_tensor_svd.hpp:95
Fixed-order tensor whose blocks obey a bosonic abelian selection rule.
Definition block_tensor.hpp:161
Homogeneous finite MPS owner with exact bond connectivity.
Definition finite_chain.hpp:32
void replace_pair(std::size_t first_index, site_type first, site_type second)
Replace adjacent sites while permitting their shared bond to change.
Definition finite_chain.hpp:97
Local BlockTensor storage with one independently scheduled async value per block.
Definition block_tensor_storage.hpp:142
Tensor space with an explicit block-coordinate/dense-axis classification.
Definition block_tensor_space_traits.hpp:71
Tensor-level view of a symmetry-preserving collection of dense blocks.
Definition block_tensor_concepts.hpp:52
BlockTensor storage whose stored numerical blocks are generalized diagonals.
Definition block_tensor_storage.hpp:71
Concept for scalar types with a configured dense LAPACK backend.
Definition scalar_concepts.hpp:147
BlockTensor storage whose blocks reside within one local process.
Definition block_tensor_storage.hpp:118
BlockTensor storage whose stored key set may omit legal blocks.
Definition block_tensor_storage.hpp:58
Owns validated finite MPS and MPO chains.
Definition right_first_rabc.hpp:34
auto materialize_two_site_mps_split(Decomposition const &decomposition, BlockSvdSelection< typename Decomposition::real_type > const &selection, MpsSweepDirection direction, BlockSvdMaterializationOptions options={})
Materialize selected SVD states as a directional pair of owning MPS sites.
Definition two_site_split.hpp:173
auto replace_two_site_from_svd(FiniteMps< Scalar, Bond, Physical, SiteStorage > &mps, std::size_t first_index, Decomposition const &decomposition, BlockSvdSelection< typename Decomposition::real_type > const &selection, MpsSweepDirection direction, BlockSvdMaterializationOptions options={})
Materialize and install a selected two-site split in a finite MPS.
Definition two_site_split.hpp:224
MpsSweepDirection
Direction in which a two-site split moves the MPS canonical center.
Definition two_site_split.hpp:28
@ left_to_right
Absorb singular values into the right site.
@ right_to_left
Absorb singular values into the left site.
auto decompose_two_site_center(Center const &center, linalg::SvdOptions options, Measurements &measurements, Event batch_event)
Factorize a canonical two-site MPS center by its internal cut with performance measurements.
Definition two_site_split.hpp:138
constexpr uninitialized_t uninitialized
Explicit allocation tag for overwrite outputs and scratch space.
Definition common/initialization.hpp:22
std::remove_cvref_t< Tensor > block_tensor_type_t
Cvref-stripped BlockTensor-level object type.
Definition block_tensor_concepts.hpp:22
typename block_tensor_type_t< Tensor >::domain_type block_tensor_domain_t
Ordered domain type exposed by a BlockTensor-level object.
Definition block_tensor_concepts.hpp:31
void copy(BackendSelector selector, async::Async< OutputTensor > &output, async::Async< InputTensor > const &input)
Schedule a Tensor copy through an explicit backend selector.
Definition linalg/async/copy.hpp:174
typename block_tensor_type_t< Tensor >::codomain_type block_tensor_codomain_t
Ordered codomain type exposed by a BlockTensor-level object.
Definition block_tensor_concepts.hpp:34
Options controlling one selected block-SVD materialization.
Definition block_tensor_svd.hpp:132
Compile-time storage properties of one BlockTensor boundary space.
Definition block_tensor_space_traits.hpp:27
Output-shape options for an exact singular value decomposition.
Definition operation_tags.hpp:255
Explicit disabled measurement policy used by ordinary operation overloads.
Definition performance_measurements.hpp:39
Bond data retained after installing a two-site MPS split.
Definition two_site_split.hpp:56
Truncation truncation
Statistics for the selected and discarded singular states.
Definition two_site_split.hpp:60
SingularValues singular_values
Selected singular values over the installed internal bond.
Definition two_site_split.hpp:58
MpsSweepDirection direction
Direction used to absorb the singular values.
Definition two_site_split.hpp:62
Directionally absorbed two-site MPS factors and retained bond data.
Definition two_site_split.hpp:39
SecondSite second_site
Owning right MPS site.
Definition two_site_split.hpp:43
SingularValues singular_values
Selected singular values over the new internal bond.
Definition two_site_split.hpp:45
MpsSweepDirection direction
Direction used to absorb the singular values.
Definition two_site_split.hpp:49
Truncation truncation
Statistics for the selected and discarded singular states.
Definition two_site_split.hpp:47
FirstSite first_site
Owning left MPS site.
Definition two_site_split.hpp:41