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

Added a test for tensor operator to tensor expansion conversion


Signed-off-by: default avatarDmitry I. Lyakh <quant4me@gmail.com>
parent f1ce5c88
......@@ -29,9 +29,9 @@
#define EXATN_TEST8
#define EXATN_TEST9
#define EXATN_TEST10
#define EXATN_TEST11
#define EXATN_TEST11*/
#define EXATN_TEST12
#define EXATN_TEST13
/*#define EXATN_TEST13
#define EXATN_TEST14
//#define EXATN_TEST15 //buggy (parsed named spaces/subspaces)
#define EXATN_TEST16
......@@ -47,7 +47,7 @@
#define EXATN_TEST26*/
//#define EXATN_TEST27 //requires input file from source
//#define EXATN_TEST28 //requires input file from source
#define EXATN_TEST29
//#define EXATN_TEST29
//#define EXATN_TEST30
......@@ -1530,7 +1530,7 @@ TEST(NumServerTester, HamiltonianNumServer)
#endif
#ifdef EXATN_TEST12
TEST(NumServerTester, EigenNumServer)
TEST(NumServerTester, IsingTNO)
{
using exatn::Tensor;
using exatn::TensorShape;
......@@ -1540,7 +1540,16 @@ TEST(NumServerTester, EigenNumServer)
using exatn::TensorExpansion;
using exatn::TensorElementType;
//exatn::resetLoggingLevel(1,2); //debug
const auto TENS_ELEM_TYPE = TensorElementType::COMPLEX64;
const int num_sites = 4;
const int bond_dim_lim = 4;
const int max_bond_dim = std::min(static_cast<int>(std::pow(2,num_sites/2)),bond_dim_lim);
const int arity = 2;
const std::string tn_type = "TTN"; //MPS or TTN
bool success = true;
//exatn::resetLoggingLevel(2,2); //debug
//Define Ising Hamiltonian constants:
constexpr std::complex<double> ZERO{0.0,0.0};
......@@ -1570,52 +1579,79 @@ TEST(NumServerTester, EigenNumServer)
//Declare the Ising Hamiltonian operator:
TensorOperator ham("Hamiltonian");
auto appended = false;
appended = ham.appendComponent(t01,{{0,0},{1,1}},{{0,2},{1,3}},{1.0,0.0}); assert(appended);
appended = ham.appendComponent(t12,{{1,0},{2,1}},{{1,2},{2,3}},{1.0,0.0}); assert(appended);
appended = ham.appendComponent(t23,{{2,0},{3,1}},{{2,2},{3,3}},{1.0,0.0}); assert(appended);
appended = ham.appendComponent(u00,{{0,0}},{{0,1}},{1.0,0.0}); assert(appended);
appended = ham.appendComponent(u11,{{1,0}},{{1,1}},{1.0,0.0}); assert(appended);
appended = ham.appendComponent(u22,{{2,0}},{{2,1}},{1.0,0.0}); assert(appended);
appended = ham.appendComponent(u33,{{3,0}},{{3,1}},{1.0,0.0}); assert(appended);
success = ham.appendComponent(t01,{{0,0},{1,1}},{{0,2},{1,3}},{1.0,0.0}); assert(success);
success = ham.appendComponent(t12,{{1,0},{2,1}},{{1,2},{2,3}},{1.0,0.0}); assert(success);
success = ham.appendComponent(t23,{{2,0},{3,1}},{{2,2},{3,3}},{1.0,0.0}); assert(success);
success = ham.appendComponent(u00,{{0,0}},{{0,1}},{1.0,0.0}); assert(success);
success = ham.appendComponent(u11,{{1,0}},{{1,1}},{1.0,0.0}); assert(success);
success = ham.appendComponent(u22,{{2,0}},{{2,1}},{1.0,0.0}); assert(success);
success = ham.appendComponent(u33,{{3,0}},{{3,1}},{1.0,0.0}); assert(success);
ham.printIt(); //debug
//Configure the tensor network builder:
auto tn_builder = exatn::getTensorNetworkBuilder(tn_type);
if(tn_type == "MPS"){
success = tn_builder->setParameter("max_bond_dim",max_bond_dim); assert(success);
}else if(tn_type == "TTN"){
success = tn_builder->setParameter("max_bond_dim",max_bond_dim); assert(success);
success = tn_builder->setParameter("arity",arity); assert(success);
}else{
assert(false);
}
//Build a tensor network operator:
auto ket_tensor = exatn::makeSharedTensor("TensorSpace",std::vector<int>(num_sites,2));
auto vec_net = exatn::makeSharedTensorNetwork("VectorNet",ket_tensor,*tn_builder,false);
vec_net->printIt(); //debug
auto space_tensor = exatn::makeSharedTensor("TensorSpaceMap",std::vector<int>(num_sites*2,2));
auto ham_net = exatn::makeSharedTensorNetwork("HamiltonianNet",space_tensor,*tn_builder,true);
ham_net->printIt(); //debug
TensorOperator ham_tno("HamiltonianTNO");
success = ham_tno.appendComponent(ham_net,{{0,0},{1,1},{2,2},{3,3}},{{0,4},{1,5},{2,6},{3,7}},{1.0,0.0});
{//Numerical evaluation:
//Create Hamiltonian tensors:
auto created = false;
created = exatn::createTensorSync(t01,TensorElementType::COMPLEX64); assert(created);
created = exatn::createTensorSync(t12,TensorElementType::COMPLEX64); assert(created);
created = exatn::createTensorSync(t23,TensorElementType::COMPLEX64); assert(created);
created = exatn::createTensorSync(u00,TensorElementType::COMPLEX64); assert(created);
created = exatn::createTensorSync(u11,TensorElementType::COMPLEX64); assert(created);
created = exatn::createTensorSync(u22,TensorElementType::COMPLEX64); assert(created);
created = exatn::createTensorSync(u33,TensorElementType::COMPLEX64); assert(created);
success = exatn::createTensorSync(t01,TENS_ELEM_TYPE); assert(success);
success = exatn::createTensorSync(t12,TENS_ELEM_TYPE); assert(success);
success = exatn::createTensorSync(t23,TENS_ELEM_TYPE); assert(success);
success = exatn::createTensorSync(u00,TENS_ELEM_TYPE); assert(success);
success = exatn::createTensorSync(u11,TENS_ELEM_TYPE); assert(success);
success = exatn::createTensorSync(u22,TENS_ELEM_TYPE); assert(success);
success = exatn::createTensorSync(u33,TENS_ELEM_TYPE); assert(success);
//Initialize Hamiltonian tensors:
auto initialized = false;
initialized = exatn::initTensorDataSync("T01",hamt); assert(initialized);
initialized = exatn::initTensorDataSync("T12",hamt); assert(initialized);
initialized = exatn::initTensorDataSync("T23",hamt); assert(initialized);
initialized = exatn::initTensorDataSync("U00",hamu); assert(initialized);
initialized = exatn::initTensorDataSync("U11",hamu); assert(initialized);
initialized = exatn::initTensorDataSync("U22",hamu); assert(initialized);
initialized = exatn::initTensorDataSync("U33",hamu); assert(initialized);
success = exatn::initTensorDataSync("T01",hamt); assert(success);
success = exatn::initTensorDataSync("T12",hamt); assert(success);
success = exatn::initTensorDataSync("T23",hamt); assert(success);
success = exatn::initTensorDataSync("U00",hamu); assert(success);
success = exatn::initTensorDataSync("U11",hamu); assert(success);
success = exatn::initTensorDataSync("U22",hamu); assert(success);
success = exatn::initTensorDataSync("U33",hamu); assert(success);
//Remap the Ising Hamiltonian as a tensor network operator:
auto ham_expansion = makeSharedTensorExpansion(ham,*ket_tensor);
ham_expansion->printIt(); //debug
auto ham_tno_expansion = makeSharedTensorExpansion(ham_tno,*ket_tensor);
ham_tno_expansion->printIt(); //debug
//Reconstruct the Ising Hamiltonian as a tensor network operator:
//`Finish
success = exatn::sync(); assert(success);
//Destroy all tensors:
auto destroyed = false;
destroyed = exatn::destroyTensorSync("U33"); assert(destroyed);
destroyed = exatn::destroyTensorSync("U22"); assert(destroyed);
destroyed = exatn::destroyTensorSync("U11"); assert(destroyed);
destroyed = exatn::destroyTensorSync("U00"); assert(destroyed);
destroyed = exatn::destroyTensorSync("T23"); assert(destroyed);
destroyed = exatn::destroyTensorSync("T12"); assert(destroyed);
destroyed = exatn::destroyTensorSync("T01"); assert(destroyed);
success = exatn::destroyTensorSync("U33"); assert(success);
success = exatn::destroyTensorSync("U22"); assert(success);
success = exatn::destroyTensorSync("U11"); assert(success);
success = exatn::destroyTensorSync("U00"); assert(success);
success = exatn::destroyTensorSync("T23"); assert(success);
success = exatn::destroyTensorSync("T12"); assert(success);
success = exatn::destroyTensorSync("T01"); assert(success);
//Synchronize:
exatn::sync();
success = exatn::sync(); assert(success);
}
exatn::resetLoggingLevel(0,0);
}
#endif
......@@ -3230,9 +3266,9 @@ TEST(NumServerTester, TensorOperatorReconstruction) {
}
//Build a tensor network operator:
auto ansatz_tensor = exatn::makeSharedTensor("TensorSpaceMap",std::vector<int>(num_sites*2,2));
auto ansatz_net = exatn::makeSharedTensorNetwork("Ansatz",ansatz_tensor,*tn_builder,true);
ansatz_net->printIt(); //debug
auto space_tensor = exatn::makeSharedTensor("TensorSpaceMap",std::vector<int>(num_sites*2,2));
auto ham_net = exatn::makeSharedTensorNetwork("HamiltonianNet",space_tensor,*tn_builder,true);
ham_net->printIt(); //debug
//Synchronize:
success = exatn::sync(); assert(success);
......
/** ExaTN::Numerics: Tensor network builder: MPS: Matrix Product State
REVISION: 2021/06/25
REVISION: 2021/10/14
Copyright (C) 2018-2021 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2021 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -8,6 +8,23 @@ Copyright (C) 2018-2021 Oak Ridge National Laboratory (UT-Battelle) **/
(a) Builds a matrix product state tensor network:
Parameters:
* max_bond_dim: Maximal internal bond dimension;
(b) Leg numeration (tensor network vector):
[0] [1] [2] [n-2] [n-1]
0 1 1 1 1
| | | | |
X-1--0-X-2--0-X-2-- .. --0-X-2--0-X
(c) Leg numeration (tensor network operator):
[0] [1] [2] [n-2] [n-1]
0 1 1 1 1
| | | | |
X-1--0-X-2--0-X-2-- .. --0-X-2--0-X
| | | | |
2 3 3 3 2
[n] [n+1] [n+2] [n*2-2][n*2-1]
**/
#ifndef EXATN_NUMERICS_NETWORK_BUILDER_MPS_HPP_
......
/** ExaTN::Numerics: Tensor network builder: Tree: Tree Tensor Network
REVISION: 2021/06/25
REVISION: 2021/10/14
Copyright (C) 2018-2021 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2021 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -9,6 +9,29 @@ Copyright (C) 2018-2021 Oak Ridge National Laboratory (UT-Battelle) **/
Parameters:
* max_bond_dim: Maximal internal bond dimension;
* arity: Tree arity;
(b) Leg numeration (tensor network vector):
[0] [1] [2] [3] ...
0 1 0 1
\ / \ /
X X
\ /
2 2
\ /
\ /
0 1
\ /
X
\
2
\
...
(c) Leg numeration (tensor network operator): Each tensor X in the layer
of tree leaves gets two more legs (#3,#4) for the bra space (that is,
legs #0 and #1 are mapped to legs #3 and #4). The bra legs will be
appended to the end of the output tensor of the tensor network.
**/
#ifndef EXATN_NUMERICS_NETWORK_BUILDER_TTN_HPP_
......
/** ExaTN::Numerics: Tensor network expansion
REVISION: 2021/10/13
REVISION: 2021/10/14
Copyright (C) 2018-2021 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2021 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -166,7 +166,7 @@ TensorExpansion::TensorExpansion(const TensorOperator & tensor_operator,
auto identity_tensor = makeSharedTensor("_d",
std::initializer_list<DimExtent>{ket_subspace.getDimExtent(ki),bra_subspace.getDimExtent(bi)},
std::initializer_list<std::pair<SpaceId,SubspaceId>>{ket_subspace.getDimSpaceAttr(ki),bra_subspace.getDimSpaceAttr(bi)});
identity_tensor->rename(tensor_hex_name("_d",identity_tensor->getTensorHash()));
identity_tensor->rename(tensor_hex_name("d",identity_tensor->getTensorHash()));
auto success = network->appendTensor(identity_tensor,{}); assert(success);
++ki; ++bi;
}
......@@ -190,6 +190,13 @@ TensorExpansion::TensorExpansion(const TensorOperator & tensor_operator,
}
TensorExpansion::TensorExpansion(const TensorOperator & tensor_operator,
const Tensor & ket_subspace):
TensorExpansion(tensor_operator,ket_subspace,ket_subspace)
{
}
TensorExpansion TensorExpansion::clone(bool reset_output_tensors,
const std::string & new_name) const
{
......
/** ExaTN::Numerics: Tensor network expansion
REVISION: 2021/10/13
REVISION: 2021/10/14
Copyright (C) 2018-2021 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2021 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -139,6 +139,8 @@ public:
TensorExpansion(const TensorOperator & tensor_operator, //in: tensor network operator
const Tensor & ket_subspace, //in: tensor defining the ket subspace from the tensor operator map
const Tensor & bra_subspace); //in: tensor defining the bra subspace from the tensor operator map
TensorExpansion(const TensorOperator & tensor_operator, //in: tensor network operator
const Tensor & ket_subspace); //in: tensor defining the ket and bra subspace from the tensor operator map
TensorExpansion(const TensorExpansion &) = default;
TensorExpansion & operator=(const TensorExpansion &) = default;
......
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