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

Still implementing tensor rank reduction for extent-1 dimensions,

TensorOpTransform/Slice/Insert need the original tensor shape ...
parent 988ed29a
/** ExaTN: Tensor basic types and parameters
REVISION: 2020/06/22
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......
/** ExaTN::Numerics: Tensor operation: Adds a tensor to another tensor
REVISION: 2020/06/06
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -15,7 +15,7 @@ namespace exatn{
namespace numerics{
TensorOpAdd::TensorOpAdd():
TensorOperation(TensorOpCode::ADD,2,1,1+0*2)
TensorOperation(TensorOpCode::ADD,2,1,1+0*2,{0,1})
{
this->setScalar(0,std::complex<double>{1.0,0.0}); //default alpha prefactor
}
......
/** ExaTN::Numerics: Tensor operation: All-reduces a tensor
REVISION: 2020/04/13
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -15,7 +15,7 @@ namespace exatn{
namespace numerics{
TensorOpAllreduce::TensorOpAllreduce():
TensorOperation(TensorOpCode::ALLREDUCE,1,0,1)
TensorOperation(TensorOpCode::ALLREDUCE,1,0,1,{0})
{
}
......
/** ExaTN::Numerics: Tensor operation: Broadcasts a tensor
REVISION: 2020/04/16
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -15,7 +15,7 @@ namespace exatn{
namespace numerics{
TensorOpBroadcast::TensorOpBroadcast():
TensorOperation(TensorOpCode::BROADCAST,1,0,1),
TensorOperation(TensorOpCode::BROADCAST,1,0,1,{0}),
root_rank_(0)
{
}
......
/** ExaTN::Numerics: Tensor operation: Contracts two tensors and accumulates the result into another tensor
REVISION: 2020/06/06
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -17,7 +17,7 @@ namespace exatn{
namespace numerics{
TensorOpContract::TensorOpContract():
TensorOperation(TensorOpCode::CONTRACT,3,2,1+0*2+0*4)
TensorOperation(TensorOpCode::CONTRACT,3,2,1+0*2+0*4,{0,1,2})
{
this->setScalar(0,std::complex<double>{1.0,0.0}); //default alpha prefactor
this->setScalar(1,std::complex<double>{1.0,0.0}); //default beta prefactor (accumulative)
......
/** ExaTN::Numerics: Tensor operation: Creates a tensor
REVISION: 2020/06/23
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -15,7 +15,7 @@ namespace exatn{
namespace numerics{
TensorOpCreate::TensorOpCreate():
TensorOperation(TensorOpCode::CREATE,1,0,1),
TensorOperation(TensorOpCode::CREATE,1,0,1,{0}),
element_type_(TensorElementType::REAL64)
{
}
......
/** ExaTN::Numerics: Tensor operation: Decomposes a tensor into two tensor factors via SVD
REVISION: 2020/04/07
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -15,7 +15,7 @@ namespace exatn{
namespace numerics{
TensorOpDecomposeSVD2::TensorOpDecomposeSVD2():
TensorOperation(TensorOpCode::DECOMPOSE_SVD2,3,0,1+1*2+0*4)
TensorOperation(TensorOpCode::DECOMPOSE_SVD2,3,0,1+1*2+0*4,{1,2,0})
{
}
......
/** ExaTN::Numerics: Tensor operation: Decomposes a tensor into three tensor factors via SVD
REVISION: 2020/04/13
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -15,7 +15,7 @@ namespace exatn{
namespace numerics{
TensorOpDecomposeSVD3::TensorOpDecomposeSVD3():
TensorOperation(TensorOpCode::DECOMPOSE_SVD3,4,0,1+1*2+1*4+0*8),
TensorOperation(TensorOpCode::DECOMPOSE_SVD3,4,0,1+1*2+1*4+0*8,{1,2,-1,0}),
absorb_singular_values_('N')
{
}
......
/** ExaTN::Numerics: Tensor operation: Destroys a tensor
REVISION: 2020/04/07
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -15,7 +15,7 @@ namespace exatn{
namespace numerics{
TensorOpDestroy::TensorOpDestroy():
TensorOperation(TensorOpCode::DESTROY,1,0,1)
TensorOperation(TensorOpCode::DESTROY,1,0,1,{0})
{
}
......
/** ExaTN::Numerics: Tensor operation: Inserts a slice into a tensor
REVISION: 2020/04/07
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -15,7 +15,7 @@ namespace exatn{
namespace numerics{
TensorOpInsert::TensorOpInsert():
TensorOperation(TensorOpCode::INSERT,2,0,1+0*2)
TensorOperation(TensorOpCode::INSERT,2,0,1+0*2,{0,1})
{
}
......
/** ExaTN::Numerics: Tensor operation: Orthogonalizes a tensor via MGS
REVISION: 2020/04/07
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -15,7 +15,7 @@ namespace exatn{
namespace numerics{
TensorOpOrthogonalizeMGS::TensorOpOrthogonalizeMGS():
TensorOperation(TensorOpCode::ORTHOGONALIZE_MGS,1,0,1)
TensorOperation(TensorOpCode::ORTHOGONALIZE_MGS,1,0,1,{0})
{
}
......
/** ExaTN::Numerics: Tensor operation: Orthogonalizes a tensor via SVD
REVISION: 2020/04/07
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -15,7 +15,7 @@ namespace exatn{
namespace numerics{
TensorOpOrthogonalizeSVD::TensorOpOrthogonalizeSVD():
TensorOperation(TensorOpCode::ORTHOGONALIZE_SVD,1,0,1)
TensorOperation(TensorOpCode::ORTHOGONALIZE_SVD,1,0,1,{0})
{
}
......
/** ExaTN::Numerics: Tensor operation: Extracts a slice from a tensor
REVISION: 2020/04/07
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -15,7 +15,7 @@ namespace exatn{
namespace numerics{
TensorOpSlice::TensorOpSlice():
TensorOperation(TensorOpCode::SLICE,2,0,1+0*2)
TensorOperation(TensorOpCode::SLICE,2,0,1+0*2,{0,1})
{
}
......
/** ExaTN::Numerics: Tensor operation: Transforms/initializes a tensor
REVISION: 2020/04/07
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -15,7 +15,7 @@ namespace exatn{
namespace numerics{
TensorOpTransform::TensorOpTransform():
TensorOperation(TensorOpCode::TRANSFORM,1,1,1)
TensorOperation(TensorOpCode::TRANSFORM,1,1,1,{0})
{
this->setScalar(0,std::complex<double>{0.0,0.0}); //default numerical initialization value
}
......
......@@ -17,8 +17,9 @@ namespace numerics{
TensorOperation::TensorOperation(TensorOpCode opcode,
unsigned int num_operands,
unsigned int num_scalars,
std::size_t mutability):
num_operands_(num_operands), num_scalars_(num_scalars),
std::size_t mutability,
std::initializer_list<int> symbolic_positions):
symb_pos_(symbolic_positions), num_operands_(num_operands), num_scalars_(num_scalars),
mutation_(mutability), opcode_(opcode), id_(0),
scalars_(num_scalars,std::complex<double>{0.0,0.0})
{
......@@ -200,29 +201,32 @@ std::string TensorOperation::getIndexPatternReduced() const
const auto num_tensors = tensors.size();
assert(num_tensors == num_operands);
for(unsigned int oprnd = 0; oprnd < num_operands; ++oprnd){
std::string tensor_name;
std::vector<IndexLabel> indices;
bool conj;
parsed = parse_tensor(tensors[oprnd],tensor_name,indices,conj);
if(parsed){
const auto & tensor = *(this->getTensorOperand(oprnd));
unsigned int i = 0;
auto iter = indices.begin();
while(iter != indices.end()){
if(tensor.getDimExtent(i++) > 1){
++iter;
}else{
iter = indices.erase(iter);
const auto & tensor = *(this->getTensorOperand(oprnd));
if(symb_pos_[oprnd] >= 0){ //tensor operand is present in the symbolic index pattern
std::string tensor_name;
std::vector<IndexLabel> indices;
bool conj;
parsed = parse_tensor(tensors[symb_pos_[oprnd]],tensor_name,indices,conj);
if(parsed){
unsigned int i = 0;
auto iter = indices.begin();
while(iter != indices.end()){
if(tensor.getDimExtent(i++) > 1){
++iter;
}else{
iter = indices.erase(iter);
}
}
tensors[symb_pos_[oprnd]] = assemble_symbolic_tensor(tensor_name,indices,conj);
}else{
std::cout << "#ERROR(exatn::numerics::TensorOperation::getIndexPatternReduced): "
<< "Unable to parse tensor operand " << symb_pos_[oprnd]
<< " in symbolic tensor operation specification: " << pattern_ << std::endl;
assert(false);
}
//`Finish
}else{
std::cout << "#ERROR(exatn::numerics::TensorOperation::getIndexPatternReduced): "
<< "Unable to parse tensor operand " << oprnd << " in symbolic tensor operation specification: "
<< pattern_ << std::endl;
assert(false);
}
}
reduced = assemble_symbolic_tensor_network(tensors);
}else{
std::cout << "#ERROR(exatn::numerics::TensorOperation::getIndexPatternReduced): "
<< "Unable to parse the symbolic tensor operation specification: "
......
......@@ -17,6 +17,7 @@ Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
#include "tensor.hpp"
#include "timers.hpp"
#include <initializer_list>
#include <tuple>
#include <memory>
#include <string>
......@@ -45,7 +46,8 @@ public:
TensorOperation(TensorOpCode opcode, //in: tensor operation code
unsigned int num_operands, //in: required number of tensor operands
unsigned int num_scalars, //in: required number of scalar operands
std::size_t mutability); //in: bit-mask for operand mutability
std::size_t mutability, //in: bit-mask for operand mutability (bit X --> operand X)
std::initializer_list<int> symbolic_positions); //positions of the tensor operands in the symbolic index pattern
TensorOperation(const TensorOperation &) = default;
TensorOperation & operator=(const TensorOperation &) = default;
......@@ -181,6 +183,7 @@ private:
protected:
std::string pattern_; //symbolic index pattern
const std::vector<int> symb_pos_; //symb_pos_[operand_position] --> operand position in the symbolic index pattern;
std::vector<std::tuple<std::shared_ptr<Tensor>,bool,bool>> operands_; //tensor operands <operand,conjugation,mutation>
std::vector<std::complex<double>> scalars_; //additional scalars (prefactors)
unsigned int num_operands_; //number of required tensor operands
......
/** ExaTN: Numerics: Symbolic tensor processing
REVISION: 2020/05/26
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -155,6 +155,17 @@ std::string assemble_symbolic_tensor(const std::string & tensor_name, //
}
std::string assemble_symbolic_tensor_network(const std::vector<std::string> & tensors)
{
std::string tensor_network;
const unsigned int num_tensors = tensors.size();
assert(num_tensors >= 2);
tensor_network = (tensors[0] + "+=" + tensors[1]);
for(unsigned int i = 2; i < num_tensors; ++i) tensor_network += ("*" + tensors[i]);
return std::move(tensor_network);
}
bool generate_contraction_pattern(const std::vector<numerics::TensorLeg> & pattern,
unsigned int left_tensor_rank,
unsigned int right_tensor_rank,
......
/** ExaTN: Numerics: Symbolic tensor processing
REVISION: 2020/05/16
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle)
......@@ -144,11 +144,14 @@ bool parse_tensor(const std::string & tensor, //in: tensor as a string
bool parse_tensor_network(const std::string & network, //in: tensor network as a string
std::vector<std::string> & tensors); //out: parsed (symbolic) tensors
/** Assembles the symbolic indexed tensor specification from its parts. **/
/** Assembles a symbolic indexed tensor specification from its parts. **/
std::string assemble_symbolic_tensor(const std::string & tensor_name, //in: tensor name
const std::vector<IndexLabel> & indices, //in: tensor indices
bool conjugated = false); //in: tensor conjugation status
/** Assembles a symbolic tensor network specification from symbolic tensors. **/
std::string assemble_symbolic_tensor_network(const std::vector<std::string> & tensors);
/** Generates symbolic tensor contraction pattern from the digital tensor
contraction pattern used by the contraction-based Tensor constructor:
pattern[0..m-1] describes connectivity of dimensions of the left contracted tensor,
......
/** ExaTN:: Tensor Runtime: Tensor graph node executor: Talsh
REVISION: 2020/06/23
REVISION: 2020/06/25
Copyright (C) 2018-2020 Dmitry Lyakh, Tiffany Mintz, Alex McCaskey
Copyright (C) 2018-2020 Oak Ridge National Laboratory (UT-Battelle)
......@@ -107,11 +107,22 @@ int TalshNodeExecutor::execute(numerics::TensorOpCreate & op,
assert(op.isSet());
const auto & tensor = *(op.getTensorOperand(0));
const auto tensor_rank = tensor.getRank();
auto tensor_rank = tensor.getRank();
const auto tensor_hash = tensor.getTensorHash();
const auto & dim_extents = tensor.getDimExtents();
std::vector<int> extents(tensor_rank);
for(int i = 0; i < tensor_rank; ++i) extents[i] = static_cast<int>(dim_extents[i]);
#if 0
auto iter = extents.begin();
while(iter != extents.end()){
if(*iter > 1){
++iter;
}else{
iter = extents.erase(iter);
}
}
tensor_rank = extents.size();
#endif
auto data_kind = get_talsh_tensor_element_kind(op.getTensorElementType());
auto res = tensors_.emplace(std::make_pair(tensor_hash,
std::make_shared<talsh::Tensor>(extents,data_kind,talsh_tens_no_init)));
......
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