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);
95 virtual void FromString(
const std::vector<std::string> &content);
97 virtual UniTensor Launch(
const bool &optimal=
false);
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 UniTensor Launch(
const bool &optimal=
false);
127 boost::intrusive_ptr<Network_base> clone(){
128 RegularNetwork *tmp =
new RegularNetwork();
129 tmp->name2pos = this->name2pos;
130 tmp->CtTree = this->CtTree;
131 tmp->names = this->names;
132 tmp->iBondNums = this->iBondNums;
133 tmp->label_arr = this->label_arr;
134 tmp->TOUT_labels = this->TOUT_labels;
135 tmp->TOUT_iBondNum = this->TOUT_iBondNum;
136 tmp->ORDER_tokens = this->ORDER_tokens;
137 boost::intrusive_ptr<Network_base> out(tmp);
140 void PrintNet(std::ostream& os);
141 void Savefile(
const std::string &fname);
147 class FermionNetwork :
public Network_base{
152 FermionNetwork(){this->nwrktype_id=
NtType.Fermion;};
153 void Fromfile(
const std::string &fname){};
154 void FromString(
const std::vector<std::string> &contents){};
155 void PutUniTensor(
const std::string &name,
const UniTensor &utensor,
const bool &is_clone=
true){};
156 void PutUniTensor(
const cytnx_uint64 &idx,
const UniTensor &utensor,
const bool &is_clone=
true){};
157 void PutUniTensors(
const std::vector<std::string> &name,
const std::vector<UniTensor> &utensors,
const bool &is_clone=
true){};
158 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=
""){};
160 this->name2pos.clear();
161 this->CtTree.clear();
163 this->iBondNums.clear();
164 this->label_arr.clear();
165 this->TOUT_labels.clear();
166 this->TOUT_iBondNum = 0;
167 this->ORDER_tokens.clear();
169 UniTensor Launch(
const bool &optimal=
false){
return UniTensor();};
170 boost::intrusive_ptr<Network_base> clone(){
171 FermionNetwork *tmp =
new FermionNetwork();
172 tmp->name2pos = this->name2pos;
173 tmp->CtTree = this->CtTree;
174 tmp->names = this->names;
175 tmp->iBondNums = this->iBondNums;
176 tmp->label_arr = this->label_arr;
177 tmp->TOUT_labels = this->TOUT_labels;
178 tmp->TOUT_iBondNum = this->TOUT_iBondNum;
179 tmp->ORDER_tokens = this->ORDER_tokens;
180 boost::intrusive_ptr<Network_base> out(tmp);
183 void PrintNet(std::ostream &os){};
184 void Savefile(
const std::string &fname){};
197 boost::intrusive_ptr<Network_base> _impl;
198 Network(): _impl(
new Network_base()){};
200 Network& operator=(
const Network &rhs){this->_impl = rhs._impl;
return *
this;}
252 if(network_type==
NtType.Regular){
253 boost::intrusive_ptr<Network_base> tmp(
new RegularNetwork());
256 cytnx_error_msg(
true,
"[Developing] currently only support regular type network.%s",
"\n");
258 this->_impl->Fromfile(fname);
287 void FromString(
const std::vector<std::string> &contents,
const int &network_type=
NtType.Regular){
288 if(network_type==
NtType.Regular){
289 boost::intrusive_ptr<Network_base> tmp(
new RegularNetwork());
292 cytnx_error_msg(
true,
"[Developing] currently only support regular type network.%s",
"\n");
294 this->_impl->FromString(contents);
300 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=
""){
301 boost::intrusive_ptr<Network_base> tmp(
new RegularNetwork());
304 out._impl->Contract_plan(tensors,Tout,is_clone,alias,contract_order);
315 this->_impl->PutUniTensor(name,utensor,is_clone);
318 this->_impl->PutUniTensor(idx,utensor,is_clone);
320 void PutUniTensors(
const std::vector<std::string> &name,
const std::vector<UniTensor> &utensors,
const bool &is_clone=
true){
321 this->_impl->PutUniTensors(name,utensors,is_clone);
324 return this->_impl->Launch(optimal);
328 this->_impl->clear();
333 out._impl = this->_impl->
clone();
337 this->_impl->PrintNet(std::cout);
341 this->_impl->Savefile(fname);
347 std::ostream&
operator<<(std::ostream &os,
const Network &bin);
Definition Network.hpp:194
void Fromfile(const std::string &fname, const int &network_type=NtType.Regular)
Construct Network from network file.
Definition Network.hpp:251
Network(const std::string &fname, const int &network_type=NtType.Regular)
Definition Network.hpp:310
Network clone()
Definition Network.hpp:331
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:300
void PrintNet()
Definition Network.hpp:336
UniTensor Launch(const bool &optimal=false)
Definition Network.hpp:323
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:287
void PutUniTensor(const std::string &name, const UniTensor &utensor, const bool &is_clone=true)
Definition Network.hpp:314
void clear()
Definition Network.hpp:326
void PutUniTensors(const std::vector< std::string > &name, const std::vector< UniTensor > &utensors, const bool &is_clone=true)
Definition Network.hpp:320
void PutUniTensor(const cytnx_uint64 &idx, const UniTensor &utensor, const bool &is_clone=true)
Definition Network.hpp:317
void Savefile(const std::string &fname)
Definition Network.hpp:340
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:1123
#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