Class TensorNetworkV2¶
Defined in File tensor_network_v2.hpp
Nested Relationships¶
Nested Types¶
Class Documentation¶
-
class TensorNetworkV2¶
A (non-directed) graph view of a sequence of AbstractTensor objects.
Note
The main role of this is to canonize itself. Since Tensor objects can be connected by multiple Index’es (thus edges are colored), what is canonized is actually the graph of indices (roughly the dual of the tensor graph), with Tensor objects represented by one or more vertices.
Public Types
-
using NamedIndexSet = container::set<Index, Index::FullLabelCompare>¶
Public Functions
-
template<typename ExprPtrRange, typename = std::enable_if_t<!std::is_base_of_v<ExprPtr, ExprPtrRange> && !std::is_base_of_v<Expr, ExprPtrRange>>>
inline TensorNetworkV2(const ExprPtrRange &exprptr_range)¶
-
inline const auto &tensors() const¶
Note
after invoking TensorNetwork::canonicalize() the order of tensors may be different from that provided as input; use tensor_input_ordinals() to obtain the input ordinals of the tensors in the result
- Returns:
const reference to the sequence of tensors
-
inline const auto &tensor_input_ordinals() const¶
-
ExprPtr canonicalize(const container::vector<std::wstring> &cardinal_tensor_labels = {}, bool fast = true, const NamedIndexSet *named_indices = nullptr)¶
- Parameters:
cardinal_tensor_labels – move all tensors with these labels to the front before canonicalizing indices
fast – if true (default), does fast canonicalization that is only optimal if all tensors are distinct; set to false to perform complete canonicalization
named_indices – specifies the indices that cannot be renamed, i.e. their labels are meaningful; default is nullptr, which results in external indices treated as named indices
- Returns:
byproduct of canonicalization (e.g. phase); if none, returns nullptr
-
SlotCanonicalizationMetadata canonicalize_slots(const container::vector<std::wstring> &cardinal_tensor_labels = {}, const NamedIndexSet *named_indices = nullptr, SlotCanonicalizationMetadata::named_index_compare_t named_index_compare = default_idxptr_slottype_lesscompare{})¶
Like canonicalize(), but only use graph-based canonicalization to produce canonical list of slots occupied by named indices. This is sufficient to be able to match 2 tensor networks that differ in anonymous and named indices.
- Parameters:
cardinal_tensor_labels – move all tensors with these labels to the front before canonicalizing indices
named_indices – specifies the indices that cannot be renamed, i.e. their labels are meaningful; default is nullptr, which results in external indices treated as named indices
named_index_compare – less-than comparison function for named indices, used for coarse-grained sorting of named indices, before sorting to canonical order; the default is to sort by Index::space()
- Returns:
the computed canonicalization metadata
-
container::svector<std::pair<long, long>> factorize()¶
Factorizes tensor network
- Returns:
sequence of binary products; each element encodes the tensors to be multiplied (values >0 refer to the tensors in tensors(), values <0 refer to the elements of this sequence. E.g. sequences
{{0
,1},{-1,2},{-2,3}} ,{{0
,2},{1,3},{-1,-2}} ,{{3
,1},{2,-1},{0,-2}} encode the following respective factorizations(((T0*T1)*T2)*T3) ,
((T0*T2)*(T1*T3)) , and
(((T3*T1)*T2)*T0) .
-
inline const auto &ext_indices() const¶
Returns a range of external indices, i.e. those indices that do not connect tensors.
-
Graph create_graph(const NamedIndexSet *named_indices = nullptr, bool distinct_named_indices = true, container::map<Index, std::size_t> *idx_to_vertex = nullptr) const¶
converts the network into a Bliss graph whose vertices are indices and tensor vertex representations
Note
Rules for constructing the graph:
Indices with protoindices are connected to their protoindices, either directly or (if protoindices are symmetric) via a protoindex vertex.
Indices are colored by their space, which in general encodes also the space of the protoindices.
An anti/symmetric n-body tensor has 2 terminals, each connected to each other + to n index vertices.
A nonsymmetric n-body tensor has n terminals, each connected to 2 indices and 1 tensor vertex which is connected to all n terminal indices.
tensor vertices are colored by the label+rank+symmetry of the tensor; terminal vertices are colored by the color of its tensor, with the color of symm/antisymm terminals augmented by the terminal’s type (bra/ket).
- Parameters:
named_indices – [in] pointer to the set of named indices (ordinarily, this includes all external indices); default is nullptr, which means use all external indices for named indices
distinct_named_indices – [in] if false, will use same color for all named indices that have same Index::color(), else will use distinct color for each
idx_to_vertex – [out] A map of indices to the corresponding vertices in the graph representation. If this is not nullptr, the pointed-to map gets overwritten with the one containing the relevant information.
- Returns:
The created Graph object
Friends
- friend class TensorNetworkV2Accessor
-
class Edge¶
Edge in a TensorNetworkV2 = the Index annotating it + a pair of indices to identify which Tensor terminals it’s connected to.
Note
tensor terminals in a sequence of tensors are indexed as follows:
>0 for bra terminals (i.e. “+7” indicated connection to a bra terminal of 7th tensor object in the sequence)
<0 for ket terminals
0 if free (not attached to any tensor objects)
position records the terminal’s location in the sequence of bra/ket terminals (always 0 for symmetric/antisymmetric tensors) Terminal indices are sorted by the tensor index (i.e. by the absolute value of the terminal index), followed by position
-
struct Graph¶
Public Types
-
using VertexColor = std::uint32_t¶
The type used to encode the color of a vertex. The restriction of this being as 32-bit integer comes from how BLISS is trying to convert these into RGB values.
Public Functions
-
Graph() = default¶
-
std::size_t vertex_to_index_idx(std::size_t vertex) const¶
-
std::size_t vertex_to_tensor_idx(std::size_t vertex) const¶
Public Members
-
std::unique_ptr<bliss::Graph> bliss_graph¶
-
std::vector<std::wstring> vertex_labels¶
-
std::vector<std::optional<std::wstring>> vertex_texlabels¶
-
std::vector<VertexColor> vertex_colors¶
-
std::vector<VertexType> vertex_types¶
-
using VertexColor = std::uint32_t¶
-
struct SlotCanonicalizationMetadata¶
metadata produced by canonicalize_slots()
Public Types
-
using named_index_compare_t = std::function<bool(const std::pair<const Index*, IndexSlotType>&, const std::pair<const Index*, IndexSlotType>&)>¶
type of less-than comparison function for named indices, receives {Index ptr, its slot type}
Public Functions
-
size_t hash_value() const¶
-
inline auto get_index_view() const¶
-
template<typename Cont>
inline auto get_indices() const¶
Public Members
-
NamedIndexSet named_indices¶
list of named indices
-
named_index_compare_t named_index_compare¶
less-than comparison function for named indices, used for coarse-grained sorting of named indices, before sorting to canonical order
-
container::svector<NamedIndexSet::const_iterator> named_indices_canonical¶
list of named indices, sorted first by named_index_compare, then by canonical order; iterators point to named_indices
-
std::shared_ptr<bliss::Graph> graph¶
canonicalized colored graph, use graph->cmp to compare against another to detect equivalence
-
std::int8_t phase = +1¶
if tensor network contains tensors with antisymmetric bra/ket this reports the phase change due to permutation of slots relative to their input order
-
using named_index_compare_t = std::function<bool(const std::pair<const Index*, IndexSlotType>&, const std::pair<const Index*, IndexSlotType>&)>¶
-
class Vertex¶
-
using NamedIndexSet = container::set<Index, Index::FullLabelCompare>¶