Commit c04ee5cc authored by Dmitry I. Lyakh's avatar Dmitry I. Lyakh
Browse files

Merge branch 'devel_dil' of https://github.com/ORNL-QCI/exatn into gtc2021

parents 3b3b1a32 1b2d0614
......@@ -15,7 +15,7 @@
//Test activation:
#define EXATN_TEST0
/*#define EXATN_TEST1
#define EXATN_TEST1
#define EXATN_TEST2
#define EXATN_TEST3
#define EXATN_TEST4
......@@ -34,16 +34,16 @@
#define EXATN_TEST17
//#define EXATN_TEST18 //buggy (parsed named spaces/subspaces)
#define EXATN_TEST19
//#define EXATN_TEST20 //MKL only (tensor hyper-contraction)*/
//#define EXATN_TEST20 //MKL only (tensor hyper-contraction)
#define EXATN_TEST21
/*#define EXATN_TEST22
#define EXATN_TEST22
#define EXATN_TEST23
#define EXATN_TEST24
#define EXATN_TEST25
#define EXATN_TEST26
#define EXATN_TEST27
#define EXATN_TEST28
#define EXATN_TEST29*/
#define EXATN_TEST29
#ifdef EXATN_TEST0
......@@ -2283,7 +2283,7 @@ TEST(NumServerTester, neurIPS) {
const exatn::DimExtent chi1 = 4; //Laptop: 3; Summit (1 node): 4
const auto chi2 = std::min(chi1*chi1,512ULL);
const auto chi3 = std::min(chi2*chi2,1024ULL);
const auto chi4 = std::min(chi3*chi3,4096ULL);
const auto chi4 = std::min(chi3*chi3,2048ULL);
success = exatn::createTensor("Z",TENS_ELEM_TYPE,TensorShape{chi3,chi3,chi4}); assert(success);
success = exatn::createTensor("A",TENS_ELEM_TYPE,TensorShape{chi4,chi4}); assert(success);
success = exatn::createTensor("B",TENS_ELEM_TYPE,TensorShape{chi3,chi3,chi4}); assert(success);
......
......@@ -45,14 +45,14 @@ protected:
std::list<ContrTriple> & contr_seq,
std::function<unsigned int ()> intermediate_num_generator);
static constexpr const unsigned int NUM_WALKERS = 8;
static constexpr const unsigned int NUM_WALKERS = 16;
static constexpr const double ACCEPTANCE_TOLERANCE = 0.0;
static constexpr const std::size_t PARTITION_FACTOR = 2;
static constexpr const std::size_t PARTITION_MAX_SIZE = 3;
static constexpr const std::size_t PARTITION_IMBALANCE_DEPTH = 48;
static constexpr const std::size_t PARTITION_IMBALANCE_DEPTH = 32;
static constexpr const std::size_t PARTITION_GRANULARITY = PARTITION_IMBALANCE_DEPTH;
static constexpr const double PARTITION_IMBALANCE = 1.6;
static constexpr const double PARTITION_IMBALANCE = 1.3;
unsigned int num_walkers_;
double acceptance_tolerance_;
......
/** ExaTN::Numerics: Tensor network builder: Tree: Tree Tensor Network
REVISION: 2019/11/01
REVISION: 2021/04/10
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
Copyright (C) 2018-2021 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2021 Oak Ridge National Laboratory (UT-Battelle) **/
#include "network_builder_tree.hpp"
#include "tensor_network.hpp"
#include <initializer_list>
#include <vector>
namespace exatn{
namespace numerics{
......@@ -47,7 +50,70 @@ bool NetworkBuilderTree::setParameter(const std::string & name, long long value)
void NetworkBuilderTree::build(TensorNetwork & network)
{
//`Finish
//Inspect the output tensor:
auto output_tensor = network.getTensor(0);
const auto output_tensor_rank = output_tensor->getRank();
const auto & output_dim_extents = output_tensor->getDimExtents();
//Build tensor tree by layers:
std::vector<DimExtent> extents(output_dim_extents);
unsigned int num_dims = extents.size();
assert(num_dims > 0);
unsigned int tensor_id_base = 1, layer = 0;
//Loop over layers:
bool not_done = true;
while(not_done){
unsigned int num_tensors_in_layer = (num_dims - 1) / arity_ + 1;
//Loop over tensors within a layer:
unsigned int num_dims_new = 0;
for(unsigned int extent_id = 0; extent_id < num_dims; extent_id += arity_){
unsigned int tens_rank = std::min(static_cast<unsigned int>(arity_),(num_dims - extent_id));
unsigned int end_decr = 0;
if(num_dims > arity_){++tens_rank; ++end_decr;} //not root: additional output leg is needed
//Configure tensor dimension extents:
DimExtent out_dim_ext = 1;
std::vector<DimExtent> tens_dims(tens_rank);
for(unsigned int i = 0; i < (tens_rank - end_decr); ++i){ //input legs
tens_dims[i] = extents[extent_id + i];
out_dim_ext *= tens_dims[i];
}
if(end_decr){ //output leg
tens_dims[tens_rank - 1] = std::min(static_cast<DimExtent>(max_bond_dim_),out_dim_ext);
extents[num_dims_new] = tens_dims[tens_rank - 1];
}
//Configure tensor connectivity:
std::vector<TensorLeg> tens_legs(tens_rank);
if(layer == 0){
for(unsigned int i = 0; i < (tens_rank - end_decr); ++i) tens_legs[i] = TensorLeg(0,(extent_id + i));
if(end_decr){
tens_legs[tens_rank - 1] = TensorLeg(tensor_id_base + num_tensors_in_layer + (num_dims_new / arity_),
num_dims_new % arity_);
}
}else{
for(unsigned int i = 0; i < (tens_rank - end_decr); ++i){
unsigned int below_tensor_id = (tensor_id_base - num_dims + extent_id + i);
tens_legs[i] = TensorLeg(below_tensor_id,(network.getTensor(below_tensor_id)->getRank() - 1));
}
if(end_decr){
tens_legs[tens_rank - 1] = TensorLeg(tensor_id_base + num_tensors_in_layer + (num_dims_new / arity_),
num_dims_new % arity_);
}
}
bool appended = network.placeTensor(tensor_id_base + num_dims_new, //tensor id
std::make_shared<Tensor>("_T"+std::to_string(tensor_id_base + num_dims_new), //tensor name
tens_dims),
tens_legs,
false,false);
assert(appended);
network.getTensor(tensor_id_base + num_dims_new)->rename();
++num_dims_new; //next tensor within the layer (each tensor supplies one new dimension)
}
tensor_id_base += num_tensors_in_layer;
not_done = (num_dims_new > 1);
if(not_done){
num_dims = num_dims_new;
++layer;
}
}
return;
}
......
......@@ -130,6 +130,36 @@ TEST(NumericsTester, checkSharedTensorNetworkSymbolic)
}
TEST(NumericsTester, checkNetworkBuilders)
{
//Get tensor network builders:
auto & network_build_factory = *(numerics::NetworkBuildFactory::get());
auto builder_mps = network_build_factory.createNetworkBuilderShared("MPS");
auto builder_ttn = network_build_factory.createNetworkBuilderShared("Tree");
//Building an MPS tensor network with 8 sites and max bond dimension of 6:
// O-O-O-O-O-O-O-O
// | | | | | | | |
auto success = builder_mps->setParameter("max_bond_dim",6); assert(success);
auto output_tensor_mps = makeSharedTensor("Z_MPS",std::vector<DimExtent>{2,2,2,2,2,2,2,2});
auto network_mps = makeSharedTensorNetwork("TensorTrain",output_tensor_mps,*builder_mps);
network_mps->printIt();
//Building a 3:1 Tree tensor network with 11 sites and max bond dimension of 24:
// OOOOOOOOOOOO
// | |
// OOOOOOOOOOOOO O
// | | | |
// OOOOO OOOOO OOOOO OOO
// | | | | | | | | | | |
success = builder_ttn->setParameter("arity",3); assert(success);
success = builder_ttn->setParameter("max_bond_dim",24); assert(success);
auto output_tensor_ttn = makeSharedTensor("Z_TTN",std::vector<DimExtent>{2,2,2,2,2,2,2,2,2,2,2});
auto network_ttn = makeSharedTensorNetwork("TensorTree",output_tensor_ttn,*builder_ttn);
network_ttn->printIt();
}
TEST(NumericsTester, checkTensorExpansion)
{
//Building an MPS tensor network with 8 sites and max bond dimension of 6:
......
Subproject commit 01d9e85ec61134ad3d2828b22d18324145157d08
Subproject commit c3c16d0927fa405520b20aca8d30c520ab9c1ece
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