11#include "utils/vec_clone.hpp"
16#include <initializer_list>
31 std::string getname(
const int &mps_type);
33 extern MPSType_class MPSType;
37 class MPS_impl:
public intrusive_ptr_base<MPS_impl>{
49 MPS_impl(): mps_type_id(MPSType.Void){}
53 std::vector<UniTensor> _TNs;
56 std::vector<UniTensor>& get_data(){
60 virtual Scalar norm()
const;
61 virtual boost::intrusive_ptr<MPS_impl> clone()
const;
62 virtual std::ostream& Print(std::ostream &os);
64 virtual void Init(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
const cytnx_uint64 &virt_dim,
const cytnx_int64 &dtype);
65 virtual void Init_Msector(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
const cytnx_uint64 &virt_dim,
const std::vector<cytnx_int64> &select,
const cytnx_int64 &dtype);
72 virtual void Into_Lortho();
73 virtual void S_mvleft();
74 virtual void S_mvright();
76 virtual void _save_dispatch(std::fstream &f);
77 virtual void _load_dispatch(std::fstream &f);
83 class RegularMPS:
public MPS_impl{
90 this->mps_type_id = MPSType.RegularMPS;
97 std::ostream& Print(std::ostream &os);
99 void Init(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
const cytnx_uint64 &virt_dim,
const cytnx_int64 &dtype);
100 void Init_Msector(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
const cytnx_uint64 &virt_dim,
const std::vector<cytnx_int64> &select,
const cytnx_int64 &dtype);
110 boost::intrusive_ptr<MPS_impl> clone()
const{
111 boost::intrusive_ptr<MPS_impl> out(
new RegularMPS());
112 out->S_loc = this->S_loc;
113 out->virt_dim = this->virt_dim;
114 out->_TNs = vec_clone(this->_TNs);
118 void _save_dispatch(std::fstream &f);
119 void _load_dispatch(std::fstream &f);
123 class iMPS:
public MPS_impl{
130 this->mps_type_id = MPSType.iMPS;
136 std::ostream& Print(std::ostream &os);
138 void Init(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
const cytnx_uint64 &virt_dim,
const cytnx_int64 &dtype);
139 void Init_Msector(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
const cytnx_uint64 &virt_dim,
const std::vector<cytnx_int64> &select,
const cytnx_int64 &dtype){
140 cytnx_error_msg(
true,
"[ERROR][MPS][type=iMPS] cannot call Init_Msector%s",
"\n");
146 cytnx_error_msg(
true,
"[ERROR][MPS][type=iMPS] cannot call Into_Lortho%s",
"\n");
149 cytnx_error_msg(
true,
"[ERROR][MPS][type=iMPS] cannot call S_mvleft%s",
"\n");
152 cytnx_error_msg(
true,
"[ERROR][MPS][type=iMPS] cannot call S_mvright%s",
"\n");
154 boost::intrusive_ptr<MPS_impl> clone()
const{
155 boost::intrusive_ptr<MPS_impl> out(
new RegularMPS());
156 out->S_loc = this->S_loc;
157 out->virt_dim = this->virt_dim;
158 out->_TNs = vec_clone(this->_TNs);
162 void _save_dispatch(std::fstream &f);
163 void _load_dispatch(std::fstream &f);
176 boost::intrusive_ptr<MPS_impl> _impl;
177 MPS(): _impl(
new MPS_impl()){
194 MPS& operator=(
const MPS &rhs){
208 this->_impl =boost::intrusive_ptr<MPS_impl>(
new RegularMPS());
210 this->_impl =boost::intrusive_ptr<MPS_impl>(
new iMPS());
214 this->_impl->Init(N, vphys_dim,
virt_dim,dtype);
219 std::vector<cytnx_uint64> vphys_dim(N,
phys_dim);
230 this->_impl =boost::intrusive_ptr<MPS_impl>(
new RegularMPS());
232 this->_impl =boost::intrusive_ptr<MPS_impl>(
new iMPS());
236 this->_impl->Init_Msector(N, vphys_dim,
virt_dim, select, dtype);
256 return this->_impl->size();
260 return this->_impl->mps_type_id;
263 return MPSType.getname(this->_impl->mps_type_id);
268 out._impl = this->_impl->
clone();
272 std::vector<UniTensor> &
data(){
return this->_impl->get_data();};
288 return this->_impl->norm();
292 return this->_impl->_TNs[idx].shape()[1];
296 return this->_impl->virt_dim;
300 return this->_impl->S_loc;
304 void _Save(std::fstream &f)
const;
305 void _Load(std::fstream &f);
308 void Save(
const std::string &fname)
const;
309 void Save(
const char* fname)
const;
Definition Scalar.hpp:1751
std::string mps_type_str() const
Definition MPS.hpp:262
cytnx_uint64 size()
Definition MPS.hpp:255
void Save(const std::string &fname) const
void Save(const char *fname) const
std::vector< UniTensor > & data()
Definition MPS.hpp:272
MPS & S_mvleft()
Definition MPS.hpp:278
cytnx_int64 phys_dim(const cytnx_int64 &idx)
Definition MPS.hpp:291
MPS & Init(const cytnx_uint64 &N, const cytnx_uint64 &phys_dim, const cytnx_uint64 &virt_dim, const cytnx_int64 &dtype=Type.Double, const cytnx_int64 &mps_type=0)
Definition MPS.hpp:217
int mps_type() const
Definition MPS.hpp:259
static MPS Load(const char *fname)
MPS & Init(const cytnx_uint64 &N, const std::vector< cytnx_uint64 > &vphys_dim, const cytnx_uint64 &virt_dim, const cytnx_int64 &dtype=Type.Double, const cytnx_int64 &mps_type=0)
Definition MPS.hpp:205
MPS clone() const
Definition MPS.hpp:266
MPS & Init_Msector(const cytnx_uint64 &N, const std::vector< cytnx_uint64 > &vphys_dim, const cytnx_uint64 &virt_dim, const std::vector< cytnx_int64 > &select, const cytnx_int64 &dtype=Type.Double, const cytnx_int64 &mps_type=0)
Definition MPS.hpp:227
MPS & S_mvright()
Definition MPS.hpp:282
Scalar norm() const
Definition MPS.hpp:287
cytnx_int64 & S_loc()
Definition MPS.hpp:299
cytnx_int64 & virt_dim()
Definition MPS.hpp:295
static MPS Load(const std::string &fname)
MPS & Into_Lortho()
Definition MPS.hpp:274
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:18
std::ostream & operator<<(std::ostream &os, const MPO &in)
Definition Accessor.hpp:12
uint64_t cytnx_uint64
Definition Type.hpp:22
int64_t cytnx_int64
Definition Type.hpp:25
Type_class Type
Definition Type.cpp:143