Commit b5209d64 authored by Dmitry I. Lyakh's avatar Dmitry I. Lyakh

Fixed intermediate tensor naming: _xHASH:

TN output tensor: _zHASH;
TN intermediate tensor: _xHASH;
TN default output tensor: _smoky.
parent 92b3ea6e
Pipeline #92103 passed with stage
in 4 minutes and 37 seconds
/** ExaTN::Numerics: Tensor
REVISION: 2019/12/30
REVISION: 2020/03/03
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
#include "tensor.hpp"
#include "tensor_symbol.hpp"
......@@ -249,9 +249,10 @@ TensorHashType Tensor::getTensorHash() const
return reinterpret_cast<TensorHashType>(this);
}
std::string generateTensorName(const Tensor & tensor)
std::string generateTensorName(const Tensor & tensor,
const std::string & prefix)
{
return tensor_hex_name(tensor.getTensorHash());
return tensor_hex_name(prefix,tensor.getTensorHash());
}
} //namespace numerics
......
/** ExaTN::Numerics: Abstract Tensor
REVISION: 2019/12/11
REVISION: 2020/03/03
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
/** NOTES:
Tensor specification requires:
......@@ -190,7 +190,8 @@ private:
//FREE FUNCTIONS:
/** Generates a unique name for a given tensor. **/
std::string generateTensorName(const Tensor & tensor);
std::string generateTensorName(const Tensor & tensor, //in: tensor
const std::string & prefix); //in: name prefix
//TEMPLATES:
......
/** ExaTN::Numerics: Tensor connected to other tensors inside a tensor network
REVISION: 2020/01/24
REVISION: 2020/03/03
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -143,7 +143,7 @@ void TensorConn::replaceStoredTensor(const std::string & name)
const auto & old_tensor = *tensor_;
tensor_ = makeSharedTensor(old_tensor);
auto new_name(name);
if(new_name.empty()) new_name = tensor_hex_name(tensor_->getTensorHash());
if(new_name.empty()) new_name = tensor_hex_name("z",tensor_->getTensorHash());
tensor_->rename(new_name);
return;
}
......@@ -162,7 +162,7 @@ void TensorConn::replaceStoredTensor(const std::vector<unsigned int> & order,
for(unsigned int i = 0; i < rank; ++i) legs_[i] = old_legs[order[i]];
}
auto new_name(name);
if(new_name.empty()) new_name = tensor_hex_name(tensor_->getTensorHash());
if(new_name.empty()) new_name = tensor_hex_name("z",tensor_->getTensorHash());
tensor_->rename(new_name);
return;
}
......
/** ExaTN::Numerics: Tensor network
REVISION: 2020/01/24
REVISION: 2020/03/03
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -32,7 +32,7 @@ TensorNetwork::TensorNetwork():
{
auto res = emplaceTensorConnDirect(false,
0U, //output tensor (id = 0)
std::make_shared<Tensor>("_SMOKY_TENSOR_"),0U,std::vector<TensorLeg>{});
std::make_shared<Tensor>("_smoky"),0U,std::vector<TensorLeg>{});
if(!res){
std::cout << "#ERROR(exatn::numerics::TensorNetwork::TensorNetwork): Tensor id already in use!" << std::endl;
assert(false);
......@@ -187,7 +187,7 @@ TensorNetwork::TensorNetwork(const TensorNetwork & another)
auto output_tensor = another.getTensor(0);
const auto & output_legs = *(another.getTensorConnections(0));
auto new_output_tensor = makeSharedTensor(*output_tensor);
new_output_tensor->rename(generateTensorName(*new_output_tensor));
new_output_tensor->rename(generateTensorName(*new_output_tensor,"z"));
auto res = emplaceTensorConnDirect(false,
0U, //output tensor (id = 0)
new_output_tensor,0U,output_legs);
......@@ -212,7 +212,7 @@ TensorNetwork & TensorNetwork::operator=(const TensorNetwork & another)
auto output_tensor = another.getTensor(0);
const auto & output_legs = *(another.getTensorConnections(0));
auto new_output_tensor = makeSharedTensor(*output_tensor);
new_output_tensor->rename(generateTensorName(*new_output_tensor));
new_output_tensor->rename(generateTensorName(*new_output_tensor,"z"));
auto res = emplaceTensorConnDirect(false,
0U, //output tensor (id = 0)
new_output_tensor,0U,output_legs);
......@@ -1159,17 +1159,17 @@ bool TensorNetwork::mergeTensors(unsigned int left_id, unsigned int right_id, un
assert(generated);
}
//Append the tensor result:
auto res = emplaceTensorConnDirect(true,
auto res = emplaceTensorConnDirect(true,true,
result_id,
std::make_shared<Tensor>(
"_y" + std::to_string(result_id),
"_y" + std::to_string(result_id), //this is temporary name, will change to _xHASH
*(left_tensor->getTensor()),
*(right_tensor->getTensor()),
pattern
),
result_id,result_legs);
if(!res){
std::cout << "#ERROR(exatn::numerics::TensorNetwork::mergeTensors): Tensor id already in use!" << std::endl;
std::cout << "#ERROR(exatn::numerics::TensorNetwork::mergeTensors): Unable to append the tensor-result!" << std::endl;
return false;
}
//Delete two original tensors:
......@@ -1491,7 +1491,7 @@ std::list<std::shared_ptr<TensorOperation>> & TensorNetwork::getOperationList(co
auto tensor2 = net.getTensor(contr->right_id,&conj2);
std::string contr_pattern;
if(num_contractions > 1){ //intermediate contraction
auto merged = net.mergeTensors(contr->left_id,contr->right_id,contr->result_id,&contr_pattern);
auto merged = net.mergeTensors(contr->left_id,contr->right_id,contr->result_id,&contr_pattern); //append intermediate _xHASH
assert(merged);
}else{ //last contraction
assert(contr->result_id == 0); //last tensor contraction accumulates into the output tensor of the tensor network
......
/** ExaTN::Numerics: Tensor network
REVISION: 2020/01/24
REVISION: 2020/03/03
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -76,7 +76,7 @@ public:
using Iterator = typename std::unordered_map<unsigned int, TensorConn>::iterator; //iterator
using ConstIterator = typename std::unordered_map<unsigned int, TensorConn>::const_iterator; //constant iterator
/** Creates an unnamed empty tensor network with a single scalar output tensor named "_SMOKY_TENSOR_" **/
/** Creates an unnamed empty tensor network with a single scalar output tensor named "_smoky" **/
TensorNetwork();
/** Creates a named empty tensor network with a single scalar output tensor named with the same name. **/
TensorNetwork(const std::string & name);
......@@ -308,6 +308,11 @@ protected:
inline bool emplaceTensorConnDirect(bool dynamic_id_enabled,
unsigned int tensor_id,
Args&&... args); //arguments for TensorConn ctor
template <typename... Args>
inline bool emplaceTensorConnDirect(bool dynamic_name_enabled,
bool dynamic_id_enabled,
unsigned int tensor_id,
Args&&... args); //arguments for TensorConn ctor
/** Erases a connected tensor from the tensor network. **/
inline bool eraseTensorConn(unsigned int tensor_id);
......@@ -427,6 +432,30 @@ inline bool TensorNetwork::emplaceTensorConnDirect(bool dynamic_id_enabled,
}
template <typename... Args>
inline bool TensorNetwork::emplaceTensorConnDirect(bool dynamic_name_enabled,
bool dynamic_id_enabled,
unsigned int tensor_id,
Args&&... args)
{
auto res = tensors_.emplace(tensor_id,TensorConn(std::forward<Args>(args)...));
if(!(res.second) && dynamic_id_enabled){
tensor_id = getMaxTensorId() + 1;
assert(tensor_id != 0); //unsigned int overflow
res = tensors_.emplace(tensor_id,TensorConn(std::forward<Args>(args)...));
}
if(res.second){
res.first->second.resetTensorId(tensor_id);
updateMaxTensorIdOnAppend(tensor_id);
if(dynamic_name_enabled){
auto & stored_tensor = *(res.first->second.getTensor());
stored_tensor.rename(generateTensorName(stored_tensor,"x")); //intermediate tensor prefix "x": _xHASH
}
}
return res.second;
}
inline bool TensorNetwork::eraseTensorConn(unsigned int tensor_id)
{
auto num_deleted = tensors_.erase(tensor_id);
......
/** ExaTN: Numerics: Symbolic tensor processing
REVISION: 2019/12/31
REVISION: 2020/03/03
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle)
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle)
Rationale:
(a) Valid symbolic tensor formats are (angle brackets mark placeholders for tokens):
......@@ -38,6 +38,7 @@ Rationale:
#include <string>
#include <vector>
#include <cassert>
namespace exatn{
......@@ -115,12 +116,14 @@ inline std::pair<int,int> trim_spaces_off(const std::string & str, //in: full st
/** Generates a hexadecimal name for a tensor from an integer. **/
template <typename Integer>
std::string tensor_hex_name(Integer hash)
std::string tensor_hex_name(const std::string & symb_part, //symbolic part of the name
Integer hash) //hexadecimal part of the name
{
static_assert(std::is_integral<Integer>::value,"#FATAL(tensor_hex_name): Non-integer type passed!");
static const char digit[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
assert(symb_part.length() > 0);
auto n = hash; if(n < 0) n = -n;
std::string name("_z");
std::string name("_"+symb_part);
while(n > 0){
auto m = n%16;
name += digit[m];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment