ExaTN
Public Types | Public Member Functions | Protected Member Functions | List of all members
exatn::numerics::TensorNetwork Class Reference

Public Types

using Iterator = typename std::unordered_map< unsigned int, TensorConn >::iterator
 
using ConstIterator = typename std::unordered_map< unsigned int, TensorConn >::const_iterator
 

Public Member Functions

 TensorNetwork ()
 
 TensorNetwork (const std::string &name)
 
 TensorNetwork (const std::string &name, std::shared_ptr< Tensor > output_tensor, const std::vector< TensorLeg > &output_legs)
 
 TensorNetwork (const std::string &name, const std::string &tensor_network, const std::map< std::string, std::shared_ptr< Tensor >> &tensors)
 
 TensorNetwork (const std::string &name, std::shared_ptr< Tensor > output_tensor, NetworkBuilder &builder)
 
 TensorNetwork (const TensorNetwork &)=default
 
TensorNetworkoperator= (const TensorNetwork &)=default
 
 TensorNetwork (TensorNetwork &&) noexcept=default
 
TensorNetworkoperator= (TensorNetwork &&) noexcept=default
 
void printIt () const
 
bool isEmpty () const
 
bool isExplicit () const
 
bool isFinalized () const
 
unsigned int getRank () const
 
unsigned int getNumTensors () const
 
unsigned int getMaxTensorId () const
 
const std::string & getName () const
 
void rename (const std::string &name)
 
std::shared_ptr< TensorgetTensor (unsigned int tensor_id, bool *conjugated=nullptr)
 
const std::vector< TensorLeg > * getTensorConnections (unsigned int tensor_id)
 
Iterator begin ()
 
Iterator end ()
 
ConstIterator cbegin () const
 
ConstIterator cend () const
 
bool finalize (bool check_validity=false)
 
bool appendTensor (unsigned int tensor_id, std::shared_ptr< Tensor > tensor, const std::vector< TensorLeg > &connections, bool conjugated=false, bool leg_matching_check=true)
 
bool appendTensor (unsigned int tensor_id, std::shared_ptr< Tensor > tensor, const std::vector< std::pair< unsigned int, unsigned int >> &pairing, const std::vector< LegDirection > &leg_dir=std::vector< LegDirection >{}, bool conjugated=false)
 
bool appendTensorGate (unsigned int tensor_id, std::shared_ptr< Tensor > tensor, const std::vector< unsigned int > &pairing, bool conjugated=false)
 
bool appendTensorNetwork (TensorNetwork &&network, const std::vector< std::pair< unsigned int, unsigned int >> &pairing)
 
bool appendTensorNetworkGate (TensorNetwork &&network, const std::vector< unsigned int > &pairing)
 
bool reorderOutputModes (const std::vector< unsigned int > &order)
 
bool deleteTensor (unsigned int tensor_id)
 
bool mergeTensors (unsigned int left_id, unsigned int right_id, unsigned int result_id, std::string *contr_pattern=nullptr)
 
bool splitTensor (unsigned int tensor_id, unsigned int left_tensor_id, const std::string &left_tensor_name, unsigned int right_tensor_id, const std::string &right_tensor_name, const TensorShape &contracted_dims, const std::vector< int > &right_dims)
 
void conjugate ()
 
double getContractionCost (unsigned int left_id, unsigned int right_id, double *arithm_intensity=nullptr, bool adjust_cost=false)
 
std::list< std::shared_ptr< TensorOperation > > & getOperationList (const std::string &contr_seq_opt_name="dummy")
 

Protected Member Functions

TensorConngetTensorConn (unsigned int tensor_id)
 
std::vector< TensorConn * > getTensorConnAll ()
 
bool checkConnections (unsigned int tensor_id)
 
bool checkConnections ()
 
void updateConnections (unsigned int tensor_id)
 
void updateConnectionsFromInputTensors ()
 
void invalidateContractionSequence ()
 
double determineContractionSequence (ContractionSeqOptimizer &contr_seq_optimizer)
 

Constructor & Destructor Documentation

◆ TensorNetwork() [1/5]

exatn::numerics::TensorNetwork::TensorNetwork ( )

Creates an unnamed empty tensor network with a single scalar output tensor named "_SMOKY_TENSOR_"

◆ TensorNetwork() [2/5]

exatn::numerics::TensorNetwork::TensorNetwork ( const std::string &  name)

Creates a named empty tensor network with a single scalar output tensor named with the same name.

◆ TensorNetwork() [3/5]

exatn::numerics::TensorNetwork::TensorNetwork ( const std::string &  name,
std::shared_ptr< Tensor output_tensor,
const std::vector< TensorLeg > &  output_legs 
)

Creates a named empty tensor network with an explicitly provided output tensor with the same name.

◆ TensorNetwork() [4/5]

exatn::numerics::TensorNetwork::TensorNetwork ( const std::string &  name,
const std::string &  tensor_network,
const std::map< std::string, std::shared_ptr< Tensor >> &  tensors 
)

Creates a named tensor network from a symbolic tensor network expression and a container of tensors.

◆ TensorNetwork() [5/5]

exatn::numerics::TensorNetwork::TensorNetwork ( const std::string &  name,
std::shared_ptr< Tensor output_tensor,
NetworkBuilder builder 
)

Builds a named tensor network from a template implemented by a custom tensor network builder.

Member Function Documentation

◆ appendTensor() [1/2]

bool exatn::numerics::TensorNetwork::appendTensor ( unsigned int  tensor_id,
std::shared_ptr< Tensor tensor,
const std::vector< std::pair< unsigned int, unsigned int >> &  pairing,
const std::vector< LegDirection > &  leg_dir = std::vector<LegDirection>{},
bool  conjugated = false 
)

Appends a new tensor to the tensor network by matching the tensor modes with the modes of the output tensor of the tensor network. The unmatched modes of the newly appended tensor will be appended to the existing modes of the output tensor of the tensor network (at the end). The optional argument leg_dir allows specification of the leg direction for all tensor modes. If provided, the direction of the paired legs of the appended tensor must anti-match the direction of the corresponding legs of existing tensors.

◆ appendTensor() [2/2]

bool exatn::numerics::TensorNetwork::appendTensor ( unsigned int  tensor_id,
std::shared_ptr< Tensor tensor,
const std::vector< TensorLeg > &  connections,
bool  conjugated = false,
bool  leg_matching_check = true 
)

Appends a new tensor to the tensor network by matching the tensor modes with the modes of other tensors present or to be present in the tensor network. The fully specified output tensor with all its legs has had to be provided in advance in the TensorNetwork ctor. This way requires the advance knowledge of the entire tensor network. Once all tensors have been appended, one needs to call .finalize() to complete the construction of the tensor network.

◆ appendTensorGate()

bool exatn::numerics::TensorNetwork::appendTensorGate ( unsigned int  tensor_id,
std::shared_ptr< Tensor tensor,
const std::vector< unsigned int > &  pairing,
bool  conjugated = false 
)

Appends a new even-rank tensor to the tensor network by matching the first half of the tensor legs with network's output legs provided in "pairing". The second half of the tensor legs will then replace the matched output legs in the output tensor.

◆ appendTensorNetwork()

bool exatn::numerics::TensorNetwork::appendTensorNetwork ( TensorNetwork &&  network,
const std::vector< std::pair< unsigned int, unsigned int >> &  pairing 
)

Appends a tensor network to the current (primary) tensor network by matching the modes of the output tensors of both tensor networks. The unmatched modes of the output tensor of the appended tensor network will be appended to the updated output tensor of the primary tensor network (at the end). The appended tensor network will cease to exist after being absorbed by the primary tensor network. If paired legs of either output tensor are directed, the directions must be respected. The tensors constituting the appended tensor network, except its output tensor, must have their unique ids be different from the ids of the tensors constituting the primary tensor network, otherwise the result is undefined and unrecoverable!

◆ appendTensorNetworkGate()

bool exatn::numerics::TensorNetwork::appendTensorNetworkGate ( TensorNetwork &&  network,
const std::vector< unsigned int > &  pairing 
)

Appends an even-rank tensor network to the current (primary) tensor network by matching the first half of the output modes of the appended tensor network with selected modes of the current (primary) tensor network, simultaneously replacing the matched output modes of the current (primary) tensor network by the second half of the modes of the appended tensor network, going in order. Matching will respect leg directions. The replacing output modes of the appended tensor network mush have same directions as the replaced modes of the current (primary) tensor network. The appended tensor network will cease to exist after being absorbed by the primary tensor network. The tensors constituting the appended tensor network, except its output tensor, must have their unique ids be different from the ids of the tensors constituting the primary tensor network, otherwise the result is undefined and unrecoverable!

◆ begin()

Iterator exatn::numerics::TensorNetwork::begin ( )
inline

Begin iterator

◆ cbegin()

ConstIterator exatn::numerics::TensorNetwork::cbegin ( ) const
inline

Begin constant iterator

◆ cend()

ConstIterator exatn::numerics::TensorNetwork::cend ( ) const
inline

End constant iterator

◆ checkConnections() [1/2]

bool exatn::numerics::TensorNetwork::checkConnections ( )
protected

Checks validity of connections in the enitre tensor network.

◆ checkConnections() [2/2]

bool exatn::numerics::TensorNetwork::checkConnections ( unsigned int  tensor_id)
protected

Checks validity of connections of a given tensor.

◆ conjugate()

void exatn::numerics::TensorNetwork::conjugate ( )

Conjugates the tensor network, which includes complex conjugation of all tensors as well as reversal of the direction of all tensor legs.

◆ deleteTensor()

bool exatn::numerics::TensorNetwork::deleteTensor ( unsigned int  tensor_id)

Deletes a tensor from a finalized tensor network (output tensor cannot be deleted). The released tensor legs will be joined at the end of the output tensor, unless a tensor leg was already connected to the output tensor, in which case it will be deleted completely, resulting in a reduced rank of the output tensor.

◆ determineContractionSequence()

double exatn::numerics::TensorNetwork::determineContractionSequence ( ContractionSeqOptimizer contr_seq_optimizer)
protected

Determines a pseudo-optimal tensor contraction sequence required for evaluating the tensor network. Returns an estimate of the total flop count required by the returned contraction sequence. The tensor network must contain at least two input tensors in order to generate a single contraction. No contraction sequence is generated for tensor networks consisting of a single input tensor.

◆ end()

Iterator exatn::numerics::TensorNetwork::end ( )
inline

End iterator

◆ finalize()

bool exatn::numerics::TensorNetwork::finalize ( bool  check_validity = false)

Finalizes the explicit construction of the tensor network (construction with advance knowledge). The tensor network cannot be empty.

◆ getContractionCost()

double exatn::numerics::TensorNetwork::getContractionCost ( unsigned int  left_id,
unsigned int  right_id,
double *  arithm_intensity = nullptr,
bool  adjust_cost = false 
)

Returns the FMA flop count for a given contraction of two tensors identified by their ids in the tensor network. Optionally returns the arithmetic intensity of the tensor contraction as well. Additionally, it also allows rescaling of the tensor contraction cost with the adjustment by the arithmetic intensity (lower arithmetic intensity will increase the cost).

◆ getMaxTensorId()

unsigned int exatn::numerics::TensorNetwork::getMaxTensorId ( ) const

Returns the maximal tensor id value used in the tensor network.

◆ getName()

const std::string & exatn::numerics::TensorNetwork::getName ( ) const

Returns the name of the tensor network.

◆ getNumTensors()

unsigned int exatn::numerics::TensorNetwork::getNumTensors ( ) const

Returns the number of input tensors in the tensor network. Note that the output tensor (tensor #0) is not counted here.

◆ getOperationList()

std::list< std::shared_ptr< TensorOperation > > & exatn::numerics::TensorNetwork::getOperationList ( const std::string &  contr_seq_opt_name = "dummy")

Returns the list of tensor operations required for evaluating the tensor network.

◆ getRank()

unsigned int exatn::numerics::TensorNetwork::getRank ( ) const

Returns the rank of the tensor network (rank of its output tensor).

◆ getTensor()

std::shared_ptr< Tensor > exatn::numerics::TensorNetwork::getTensor ( unsigned int  tensor_id,
bool *  conjugated = nullptr 
)

Returns a given tensor of the tensor network without its connections (legs). If not found, returns nullptr.

◆ getTensorConn()

TensorConn * exatn::numerics::TensorNetwork::getTensorConn ( unsigned int  tensor_id)
protected

Returns a non-owning pointer to a given tensor of the tensor network together with its connections (legs). If not found, returns nullptr.

◆ getTensorConnAll()

std::vector< TensorConn * > exatn::numerics::TensorNetwork::getTensorConnAll ( )
protected

Returns a vector of non-owning pointers to all tensors in the tensor network, except the output tensor.

◆ getTensorConnections()

const std::vector< TensorLeg > * exatn::numerics::TensorNetwork::getTensorConnections ( unsigned int  tensor_id)

Get tensor connections.

◆ invalidateContractionSequence()

void exatn::numerics::TensorNetwork::invalidateContractionSequence ( )
protected

Invalidates cached tensor contraction sequence.

◆ isEmpty()

bool exatn::numerics::TensorNetwork::isEmpty ( ) const

Returns TRUE if the tensor network is empty, FALSE otherwise.

◆ isExplicit()

bool exatn::numerics::TensorNetwork::isExplicit ( ) const

Returns TRUE if the tensor network is being built explicitly, FALSE otherwise.

◆ isFinalized()

bool exatn::numerics::TensorNetwork::isFinalized ( ) const

Returns TRUE if the tensor network is finalized, FALSE otherwise.

◆ mergeTensors()

bool exatn::numerics::TensorNetwork::mergeTensors ( unsigned int  left_id,
unsigned int  right_id,
unsigned int  result_id,
std::string *  contr_pattern = nullptr 
)

Merges two tensors in a finalized tensor network by replacing them by their contracted product: result = left * right: All participating tensor ids must be distinct and not equal to 0. The uncontracted modes of the left tensor will precede in-order the uncontracted modes of the right tensor in the tensor-result.

◆ printIt()

void exatn::numerics::TensorNetwork::printIt ( ) const

Prints

◆ rename()

void exatn::numerics::TensorNetwork::rename ( const std::string &  name)

Renames the tensor network.

◆ reorderOutputModes()

bool exatn::numerics::TensorNetwork::reorderOutputModes ( const std::vector< unsigned int > &  order)

Reorders the modes of the output tensor of the tensor network: order[x] = y: yth mode of the output tensor becomes its xth mode.

◆ splitTensor()

bool exatn::numerics::TensorNetwork::splitTensor ( unsigned int  tensor_id,
unsigned int  left_tensor_id,
const std::string &  left_tensor_name,
unsigned int  right_tensor_id,
const std::string &  right_tensor_name,
const TensorShape contracted_dims,
const std::vector< int > &  right_dims 
)

Splits a given tensor in a finalized tensor network into two tensors by introducing new dimensions across the cutting boundary. The original tensor dimensions are then assigned to either left or right tensor. The new dimensions are then appended to both tensors at the end. The two tensors obtained via such splitting must get unique ids, one of them may be the original tensor_id.

◆ updateConnections()

void exatn::numerics::TensorNetwork::updateConnections ( unsigned int  tensor_id)
protected

Updates tensor network linking when a tensor has its connections modified: tensor_id is the id of the tensor whose leg numeration was updated.

◆ updateConnectionsFromInputTensors()

void exatn::numerics::TensorNetwork::updateConnectionsFromInputTensors ( )
protected

Calls updateConnections() method for all input tensors. This is used for updating the output tensor legs.


The documentation for this class was generated from the following files: