8#include <initializer_list>
26 class NetworkType_class{
33 std::string getname(
const int &nwrktype_id);
35 extern NetworkType_class
NtType;
39 class Network_base:
public intrusive_ptr_base<Network_base>{
44 std::vector<UniTensor> tensors;
45 std::vector<cytnx_int64> TOUT_labels;
51 ContractionTree CtTree;
52 std::vector<std::string> ORDER_tokens;
55 std::vector< std::vector<cytnx_int64> > label_arr;
56 std::vector< cytnx_int64 > iBondNums;
60 std::vector< std::string > names;
61 std::map<std::string,cytnx_uint64> name2pos;
65 friend class FermionNetwork;
66 friend class RegularNetwork;
68 Network_base():nwrktype_id(
NtType.Void){};
71 bool HasPutAllUniTensor(){
72 for(cytnx_uint64 i=0;i<this->tensors.size();i++){
73 if(this->tensors[i].uten_type()==
UTenType.Void)
return false;
89 virtual void PutUniTensor(
const std::string &name,
const UniTensor &utensor,
const bool &is_clone);
90 virtual void PutUniTensor(
const cytnx_uint64 &idx,
const UniTensor &utensor,
const bool &is_clone);
91 virtual void PutUniTensors(
const std::vector<std::string> &name,
const std::vector<UniTensor> &utensors,
const bool &is_clone);
92 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);
94 virtual void Fromfile(
const std::string& fname);
96 virtual UniTensor Launch(
const bool &optimal=
false);
97 virtual void PrintNet(std::ostream &os);
98 virtual boost::intrusive_ptr<Network_base> clone();
99 virtual void Savefile(
const std::string &fname);
100 virtual ~Network_base(){};
105 class RegularNetwork :
public Network_base{
108 RegularNetwork(){this->nwrktype_id =
NtType.Regular;};
109 void Fromfile(
const std::string &fname);
110 void PutUniTensor(
const std::string &name,
const UniTensor &utensor,
const bool &is_clone=
true);
111 void PutUniTensor(
const cytnx_uint64 &idx,
const UniTensor &utensor,
const bool &is_clone=
true);
112 void PutUniTensors(
const std::vector<std::string> &name,
const std::vector<UniTensor> &utensors,
const bool &is_clone=
true);
113 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=
"");
115 this->name2pos.clear();
116 this->CtTree.clear();
118 this->iBondNums.clear();
119 this->label_arr.clear();
120 this->TOUT_labels.clear();
121 this->TOUT_iBondNum = 0;
122 this->ORDER_tokens.clear();
124 UniTensor Launch(
const bool &optimal=
false);
125 boost::intrusive_ptr<Network_base> clone(){
126 RegularNetwork *tmp =
new RegularNetwork();
127 tmp->name2pos = this->name2pos;
128 tmp->CtTree = this->CtTree;
129 tmp->names = this->names;
130 tmp->iBondNums = this->iBondNums;
131 tmp->label_arr = this->label_arr;
132 tmp->TOUT_labels = this->TOUT_labels;
133 tmp->TOUT_iBondNum = this->TOUT_iBondNum;
134 tmp->ORDER_tokens = this->ORDER_tokens;
135 boost::intrusive_ptr<Network_base> out(tmp);
138 void PrintNet(std::ostream& os);
139 void Savefile(
const std::string &fname);
145 class FermionNetwork :
public Network_base{
150 FermionNetwork(){this->nwrktype_id=
NtType.Fermion;};
151 void Fromfile(
const std::string &fname){};
152 void PutUniTensor(
const std::string &name,
const UniTensor &utensor,
const bool &is_clone=
true){};
153 void PutUniTensor(
const cytnx_uint64 &idx,
const UniTensor &utensor,
const bool &is_clone=
true){};
154 void PutUniTensors(
const std::vector<std::string> &name,
const std::vector<UniTensor> &utensors,
const bool &is_clone=
true){};
155 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=
""){};
157 this->name2pos.clear();
158 this->CtTree.clear();
160 this->iBondNums.clear();
161 this->label_arr.clear();
162 this->TOUT_labels.clear();
163 this->TOUT_iBondNum = 0;
164 this->ORDER_tokens.clear();
166 UniTensor Launch(
const bool &optimal=
false){
return UniTensor();};
167 boost::intrusive_ptr<Network_base> clone(){
168 FermionNetwork *tmp =
new FermionNetwork();
169 tmp->name2pos = this->name2pos;
170 tmp->CtTree = this->CtTree;
171 tmp->names = this->names;
172 tmp->iBondNums = this->iBondNums;
173 tmp->label_arr = this->label_arr;
174 tmp->TOUT_labels = this->TOUT_labels;
175 tmp->TOUT_iBondNum = this->TOUT_iBondNum;
176 tmp->ORDER_tokens = this->ORDER_tokens;
177 boost::intrusive_ptr<Network_base> out(tmp);
180 void PrintNet(std::ostream &os){};
181 void Savefile(
const std::string &fname){};
194 boost::intrusive_ptr<Network_base> _impl;
195 Network(): _impl(
new Network_base()){};
197 Network& operator=(
const Network &rhs){this->_impl = rhs._impl;
return *
this;}
249 if(network_type==
NtType.Regular){
250 boost::intrusive_ptr<Network_base> tmp(
new RegularNetwork());
253 cytnx_error_msg(
true,
"[Developing] currently only support regular type network.%s",
"\n");
255 this->_impl->Fromfile(fname);
262 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=
""){
263 boost::intrusive_ptr<Network_base> tmp(
new RegularNetwork());
266 out._impl->Contract_plan(tensors,Tout,is_clone,alias,contract_order);
276 this->_impl->PutUniTensor(name,utensor,is_clone);
279 this->_impl->PutUniTensor(idx,utensor,is_clone);
281 void PutUniTensors(
const std::vector<std::string> &name,
const std::vector<UniTensor> &utensors,
const bool &is_clone=
true){
282 this->_impl->PutUniTensors(name,utensors,is_clone);
285 return this->_impl->Launch(optimal);
289 this->_impl->clear();
294 out._impl = this->_impl->
clone();
298 this->_impl->PrintNet(std::cout);
302 this->_impl->Savefile(fname);
308 std::ostream&
operator<<(std::ostream &os,
const Network &bin);
Definition Network.hpp:191
void Fromfile(const std::string &fname, const int &network_type=NtType.Regular)
Construct Network from network file.
Definition Network.hpp:248
Network(const std::string &fname, const int &network_type=NtType.Regular)
Definition Network.hpp:271
Network clone()
Definition Network.hpp:292
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:262
void PrintNet()
Definition Network.hpp:297
UniTensor Launch(const bool &optimal=false)
Definition Network.hpp:284
void PutUniTensor(const std::string &name, const UniTensor &utensor, const bool &is_clone=true)
Definition Network.hpp:275
void clear()
Definition Network.hpp:287
void PutUniTensors(const std::vector< std::string > &name, const std::vector< UniTensor > &utensors, const bool &is_clone=true)
Definition Network.hpp:281
void PutUniTensor(const cytnx_uint64 &idx, const UniTensor &utensor, const bool &is_clone=true)
Definition Network.hpp:278
void Savefile(const std::string &fname)
Definition Network.hpp:301
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:1072
#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