8#include <initializer_list>
25 class NetworkType_class{
32 std::string getname(
const int &nwrktype_id);
34 extern NetworkType_class
NtType;
38 class Network_base:
public intrusive_ptr_base<Network_base>{
43 std::vector<UniTensor> tensors;
44 std::vector<cytnx_int64> TOUT_labels;
50 ContractionTree CtTree;
51 std::vector<std::string> ORDER_tokens;
54 std::vector< std::vector<cytnx_int64> > label_arr;
55 std::vector< cytnx_int64 > iBondNums;
59 std::vector< std::string > names;
60 std::map<std::string,cytnx_uint64> name2pos;
64 friend class FermionNetwork;
65 friend class RegularNetwork;
67 Network_base():nwrktype_id(
NtType.Void){};
70 bool HasPutAllUniTensor(){
71 for(cytnx_uint64 i=0;i<this->tensors.size();i++){
72 if(this->tensors[i].uten_type()==
UTenType.Void)
return false;
88 virtual void PutUniTensor(
const std::string &name,
const UniTensor &utensor,
const bool &is_clone);
89 virtual void PutUniTensor(
const cytnx_uint64 &idx,
const UniTensor &utensor,
const bool &is_clone);
90 virtual void PutUniTensors(
const std::vector<std::string> &name,
const std::vector<UniTensor> &utensors,
const bool &is_clone);
91 virtual void Contract_plan(
const std::vector<UniTensor> &utensors,
const std::string &Tout,
const std::vector<bool> &is_clone,
const std::vector<std::string> &alias,
const std::string &contract_order);
93 virtual void Fromfile(
const std::string& fname);
94 virtual void FromString(
const std::vector<std::string> &content);
96 virtual std::string getOptimalOrder();
97 virtual UniTensor Launch(
const bool &optimal=
false,
const std::string& contract_order=
"");
98 virtual void PrintNet(std::ostream &os);
99 virtual boost::intrusive_ptr<Network_base> clone();
100 virtual void Savefile(
const std::string &fname);
101 virtual ~Network_base(){};
106 class RegularNetwork :
public Network_base{
109 RegularNetwork(){this->nwrktype_id =
NtType.Regular;};
110 void Fromfile(
const std::string &fname);
111 void FromString(
const std::vector<std::string> &contents);
112 void PutUniTensor(
const std::string &name,
const UniTensor &utensor,
const bool &is_clone=
true);
113 void PutUniTensor(
const cytnx_uint64 &idx,
const UniTensor &utensor,
const bool &is_clone=
true);
114 void PutUniTensors(
const std::vector<std::string> &name,
const std::vector<UniTensor> &utensors,
const bool &is_clone=
true);
115 void Contract_plan(
const std::vector<UniTensor> &utensors,
const std::string &Tout,
const std::vector<bool> &is_clone={},
const std::vector<std::string> &alias={},
const std::string &contract_order=
"");
117 this->name2pos.clear();
118 this->CtTree.clear();
120 this->iBondNums.clear();
121 this->label_arr.clear();
122 this->TOUT_labels.clear();
123 this->TOUT_iBondNum = 0;
124 this->ORDER_tokens.clear();
126 std::string getOptimalOrder();
127 UniTensor Launch(
const bool &optimal=
false,
const std::string& contract_order=
"");
128 boost::intrusive_ptr<Network_base> clone(){
129 RegularNetwork *tmp =
new RegularNetwork();
130 tmp->name2pos = this->name2pos;
131 tmp->CtTree = this->CtTree;
132 tmp->names = this->names;
133 tmp->iBondNums = this->iBondNums;
134 tmp->label_arr = this->label_arr;
135 tmp->TOUT_labels = this->TOUT_labels;
136 tmp->TOUT_iBondNum = this->TOUT_iBondNum;
137 tmp->ORDER_tokens = this->ORDER_tokens;
138 boost::intrusive_ptr<Network_base> out(tmp);
141 void PrintNet(std::ostream& os);
142 void Savefile(
const std::string &fname);
148 class FermionNetwork :
public Network_base{
153 FermionNetwork(){this->nwrktype_id=
NtType.Fermion;};
154 void Fromfile(
const std::string &fname){};
155 void FromString(
const std::vector<std::string> &contents){};
156 void PutUniTensor(
const std::string &name,
const UniTensor &utensor,
const bool &is_clone=
true){};
157 void PutUniTensor(
const cytnx_uint64 &idx,
const UniTensor &utensor,
const bool &is_clone=
true){};
158 void PutUniTensors(
const std::vector<std::string> &name,
const std::vector<UniTensor> &utensors,
const bool &is_clone=
true){};
159 void Contract_plan(
const std::vector<UniTensor> &utensors,
const std::string &Tout,
const std::vector<bool> &is_clone={},
const std::vector<std::string> &alias={},
const std::string &contract_order=
""){};
161 this->name2pos.clear();
162 this->CtTree.clear();
164 this->iBondNums.clear();
165 this->label_arr.clear();
166 this->TOUT_labels.clear();
167 this->TOUT_iBondNum = 0;
168 this->ORDER_tokens.clear();
170 UniTensor Launch(
const bool &optimal=
false){
return UniTensor();};
171 boost::intrusive_ptr<Network_base> clone(){
172 FermionNetwork *tmp =
new FermionNetwork();
173 tmp->name2pos = this->name2pos;
174 tmp->CtTree = this->CtTree;
175 tmp->names = this->names;
176 tmp->iBondNums = this->iBondNums;
177 tmp->label_arr = this->label_arr;
178 tmp->TOUT_labels = this->TOUT_labels;
179 tmp->TOUT_iBondNum = this->TOUT_iBondNum;
180 tmp->ORDER_tokens = this->ORDER_tokens;
181 boost::intrusive_ptr<Network_base> out(tmp);
184 void PrintNet(std::ostream &os){};
185 void Savefile(
const std::string &fname){};
198 boost::intrusive_ptr<Network_base> _impl;
199 Network(): _impl(
new Network_base()){};
201 Network& operator=(
const Network &rhs){this->_impl = rhs._impl;
return *
this;}
253 if(network_type==
NtType.Regular){
254 boost::intrusive_ptr<Network_base> tmp(
new RegularNetwork());
257 cytnx_error_msg(
true,
"[Developing] currently only support regular type network.%s",
"\n");
259 this->_impl->Fromfile(fname);
288 void FromString(
const std::vector<std::string> &contents,
const int &network_type=
NtType.Regular){
289 if(network_type==
NtType.Regular){
290 boost::intrusive_ptr<Network_base> tmp(
new RegularNetwork());
293 cytnx_error_msg(
true,
"[Developing] currently only support regular type network.%s",
"\n");
295 this->_impl->FromString(contents);
301 static Network Contract(
const std::vector<UniTensor> &tensors,
const std::string &Tout,
const std::vector<bool> &is_clone={},
const std::vector<std::string> &alias={},
const std::string &contract_order=
""){
302 boost::intrusive_ptr<Network_base> tmp(
new RegularNetwork());
305 out._impl->Contract_plan(tensors,Tout,is_clone,alias,contract_order);
316 this->_impl->PutUniTensor(name,utensor,is_clone);
319 this->_impl->PutUniTensor(idx,utensor,is_clone);
321 void PutUniTensors(
const std::vector<std::string> &name,
const std::vector<UniTensor> &utensors,
const bool &is_clone=
true){
322 this->_impl->PutUniTensors(name,utensors,is_clone);
325 return this->_impl->Launch(optimal);
329 this->_impl->clear();
334 out._impl = this->_impl->
clone();
338 this->_impl->PrintNet(std::cout);
342 this->_impl->Savefile(fname);
348 std::ostream&
operator<<(std::ostream &os,
const Network &bin);
Definition Network.hpp:195
void Fromfile(const std::string &fname, const int &network_type=NtType.Regular)
Construct Network from network file.
Definition Network.hpp:252
Network(const std::string &fname, const int &network_type=NtType.Regular)
Definition Network.hpp:311
Network clone()
Definition Network.hpp:332
static Network Contract(const std::vector< UniTensor > &tensors, const std::string &Tout, const std::vector< bool > &is_clone={}, const std::vector< std::string > &alias={}, const std::string &contract_order="")
Definition Network.hpp:301
void PrintNet()
Definition Network.hpp:337
UniTensor Launch(const bool &optimal=false)
Definition Network.hpp:324
void FromString(const std::vector< std::string > &contents, const int &network_type=NtType.Regular)
Construct Network from a list of strings, where each string is the same as each line in network file.
Definition Network.hpp:288
void PutUniTensor(const std::string &name, const UniTensor &utensor, const bool &is_clone=true)
Definition Network.hpp:315
void clear()
Definition Network.hpp:327
void PutUniTensors(const std::vector< std::string > &name, const std::vector< UniTensor > &utensors, const bool &is_clone=true)
Definition Network.hpp:321
void PutUniTensor(const cytnx_uint64 &idx, const UniTensor &utensor, const bool &is_clone=true)
Definition Network.hpp:318
void Savefile(const std::string &fname)
Definition Network.hpp:341
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:1122
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:18
Definition Accessor.hpp:12
UniTensorType_class UTenType
Definition UniTensor_base.cpp:21
std::ostream & operator<<(std::ostream &os, const Scalar &in)
Definition Scalar.cpp:14
NetworkType_class NtType
Definition Network.cpp:21
uint64_t cytnx_uint64
Definition Type.hpp:22