Class TensorNetwork

Nested Relationships

Nested Types

Class Documentation

class TensorNetwork

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

enum class VertexType

Values:

enumerator Index
enumerator SPBundle
enumerator TensorBra
enumerator TensorKet
enumerator TensorBraKet
enumerator TensorCore
using named_indices_t = container::set<Index, Index::LabelCompare>

Public Functions

template<typename ExprPtrRange>
inline TensorNetwork(ExprPtrRange &exprptr_range)

Note

uses RTTI

Throws:

std::logic_error – if exprptr_range contains a non-tensor

inline const auto &tensors() const

Note

the order of tensors may be different from that provided as input

Returns:

const reference to the sequence of tensors

ExprPtr canonicalize(const container::vector<std::wstring> &cardinal_tensor_labels = {}, bool fast = true, const named_indices_t *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:

biproduct of canonicalization (e.g. phase); if none, returns nullptr

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 &edges() const

accessor for the Edge object sequence

See also

Edge

Returns:

const reference to the sequence container of Edge objects, sorted by their Index’s full label

inline const auto &ext_indices() const

Returns a range of external indices, i.e. those indices that do not connect tensors.

Note

The external indices are sorted by label (not full label) of the corresponding value (Index)

inline const auto &idxrepl() const

accessor for the list of anonymous index replacements performed by the last call to canonicalize()

Returns:

replacements of anonymous indices performed by the last call to canonicalize()

std::tuple<std::shared_ptr<bliss::Graph>, std::vector<std::wstring>, std::vector<std::size_t>, std::vector<VertexType>> make_bliss_graph(const named_indices_t *named_indices = 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

Returns:

{shared_ptr to Graph, vector of vertex labels, vector of vertex colors, vector of vertex types}

Public Static Attributes

static constexpr size_t max_rank = 256
class Edge

Edge in a TensorNetwork = 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

Public Functions

Edge() = default
inline explicit Edge(int terminal_idx, int position = 0)
inline Edge(int terminal_idx, const Index *idxptr, int position = 0)
inline Edge &connect_to(int terminal_idx, int position = 0)
inline bool operator<(const Edge &other) const
inline bool operator==(const Edge &other) const
inline auto first() const
inline auto second() const
inline auto first_position() const
inline auto second_position() const
inline auto size() const
Returns:

the number of attached terminals (0, 1, or 2)

inline const Index &idx() const