Template Class TensorNetwork¶
Defined in File TensorNetwork.hpp
Class Documentation¶
-
template<class
Tensor
>
classJet
::
TensorNetwork
¶ TensorNetwork
represents a tensor network.Internally, the nodes (tensors) of the network are stored in
nodes_
and the tags are stored intag_to_node_ids_map
. Furthermore, when a contraction path is not specified, the edges (contractions) are stored inindex_to_edge_map_
. The contraction path followed by a call to Contract() is stored in thepath_
member.- tparam Tensor
Type of the tensor in the tensor network. The only requirement for this type is that the following member functions exist:
std::vector<std::string> GetIndices(); std::vector<std::size_t> GetShape(); void InitIndicesAndShape(const std::vector<std::string>&, const std::vector<std::size_t>&); static Tensor Reshape(const Tensor&, const std::vector<std::string>&); static Tensor SliceIndex(const Tensor&, const std::string&, size_t); static Tensor ContractTensors(const Tensor&, const Tensor&);
Public Types
-
using
NodeID_t
= size_t¶ Type of a node ID.
Public Functions
-
inline const Nodes &
GetNodes
() const noexcept¶ Returns the nodes in this
TensorNetwork
.- Returns
Collection of nodes.
-
inline const IndexToEdgeMap &
GetIndexToEdgeMap
() const noexcept¶ Returns the index-to-edge map of this
TensorNetwork
.- Returns
Map which associates indices with edges.
-
inline const TagToNodeIdsMap &
GetTagToNodesMap
() const noexcept¶ Returns the tag-to-node-IDs map of this
TensorNetwork
.- Returns
Map which associates tags with node IDs.
-
inline const Path &
GetPath
() noexcept¶ Returns the contaction path of this
TensorNetwork
.Note
The contraction path is always empty before Contract() is called.
- Returns
Pairs of node IDs representing the contraction path.
-
inline size_t
NumIndices
() const noexcept¶ Returns the number of indices in this
TensorNetwork
.- Returns
Number of indices.
-
inline size_t
NumTensors
() const noexcept¶ Returns the number of tensors in this
TensorNetwork
.- Returns
Number of tensors.
-
inline NodeID_t
AddTensor
(const Tensor &tensor, const std::vector<std::string> &tags) noexcept¶ Adds a tensor with the specified tags and returns its assigned ID.
Warning
This function is not safe for concurrent execution.
-
inline void
SliceIndices
(const std::vector<std::string> &indices, unsigned long long value)¶ Slices a set of indices.
The value taken along each axis is derived from the provided linear index.
Example: Suppose this tensor network contains an index “A0” of dimension 2 and another index “B1” of dimension 3. To slice these indices at values 0 and 1 respectively, use
tensor_network.SliceIndices({"A0", "B1"}, 0 + 1 * 2);
- See
Jet::Utilities::UnravelIndex()
Warning
The program is aborted if a sliced index does not exist in this tensor network.
- Parameters
indices – Indices to be sliced.
value – Raveled value representing the element to take along each of the given indices. See
UnravelIndex()
for details on how raveled values are interpreted.
-
inline const Tensor &
Contract
(const Path &path = {})¶ Contracts this tensor network.
If the given contraction path is empty, the first two nodes belonging to each edge of the tensor network are contracted. Otherwise, the specified contraction path is used to guide the contraction of nodes.
Note
After this function is invoked, the
path_
member of this tensor network will reflect the contractions performed in this function.Warning
The program is aborted if the tensor network is empty.
- Parameters
path – Contraction path specified as a list of node ID pairs.
- Returns
Tensor associated with the result of the final contraction.
-
struct
Edge
¶ Edge
is a POD which connectsNodes
in aTensorNetwork
.Public Functions
-
struct
Node
¶ Node
is a POD which wraps tensors in aTensorNetwork
.