11#include "utils/vec_clone.hpp"
14#include <initializer_list>
20 #include "backend/Scalar.hpp"
33 std::string getname(
const int &mps_type);
35 extern MPSType_class MPSType;
37 class MPS_impl :
public intrusive_ptr_base<MPS_impl> {
48 MPS_impl() : mps_type_id(MPSType.Void) {}
51 std::vector<UniTensor> _TNs;
53 std::vector<UniTensor> &get_data() {
return this->_TNs; }
55 virtual Scalar norm()
const;
56 virtual boost::intrusive_ptr<MPS_impl> clone()
const;
57 virtual std::ostream &Print(std::ostream &os);
59 virtual void Init(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
60 const cytnx_uint64 &virt_dim,
const cytnx_int64 &dtype);
61 virtual void Init_Msector(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
62 const cytnx_uint64 &virt_dim,
63 const std::vector<cytnx_int64> &select,
const cytnx_int64 &dtype);
73 virtual void Into_Lortho();
74 virtual void S_mvleft();
75 virtual void S_mvright();
77 virtual void _save_dispatch(std::fstream &f);
78 virtual void _load_dispatch(std::fstream &f);
82 class RegularMPS :
public MPS_impl {
86 this->mps_type_id = MPSType.RegularMPS;
92 std::ostream &Print(std::ostream &os);
94 void Init(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
95 const cytnx_uint64 &virt_dim,
const cytnx_int64 &dtype);
96 void Init_Msector(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
97 const cytnx_uint64 &virt_dim,
const std::vector<cytnx_int64> &select,
98 const cytnx_int64 &dtype);
111 boost::intrusive_ptr<MPS_impl> clone()
const {
112 boost::intrusive_ptr<MPS_impl> out(
new RegularMPS());
113 out->S_loc = this->S_loc;
114 out->virt_dim = this->virt_dim;
115 out->_TNs = vec_clone(this->_TNs);
119 void _save_dispatch(std::fstream &f);
120 void _load_dispatch(std::fstream &f);
124 class iMPS :
public MPS_impl {
128 this->mps_type_id = MPSType.iMPS;
133 std::ostream &Print(std::ostream &os);
135 void Init(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
136 const cytnx_uint64 &virt_dim,
const cytnx_int64 &dtype);
137 void Init_Msector(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
138 const cytnx_uint64 &virt_dim,
const std::vector<cytnx_int64> &select,
139 const cytnx_int64 &dtype) {
140 cytnx_error_msg(
true,
"[ERROR][MPS][type=iMPS] cannot call Init_Msector%s",
"\n");
147 cytnx_error_msg(
true,
"[ERROR][MPS][type=iMPS] cannot call Into_Lortho%s",
"\n");
150 cytnx_error_msg(
true,
"[ERROR][MPS][type=iMPS] cannot call S_mvleft%s",
"\n");
153 cytnx_error_msg(
true,
"[ERROR][MPS][type=iMPS] cannot call S_mvright%s",
"\n");
155 boost::intrusive_ptr<MPS_impl> clone()
const {
156 boost::intrusive_ptr<MPS_impl> out(
new RegularMPS());
157 out->S_loc = this->S_loc;
158 out->virt_dim = this->virt_dim;
159 out->_TNs = vec_clone(this->_TNs);
163 void _save_dispatch(std::fstream &f);
164 void _load_dispatch(std::fstream &f);
173 boost::intrusive_ptr<MPS_impl> _impl;
175 : _impl(
new MPS_impl()){
181 : _impl(
new MPS_impl()) {
188 : _impl(
new MPS_impl()) {
192 MPS(
const MPS &rhs) { _impl = rhs._impl; }
194 MPS &operator=(
const MPS &rhs) {
206 this->_impl = boost::intrusive_ptr<MPS_impl>(
new RegularMPS());
208 this->_impl = boost::intrusive_ptr<MPS_impl>(
new iMPS());
212 this->_impl->Init(N, vphys_dim,
virt_dim, dtype);
217 std::vector<cytnx_uint64> vphys_dim(N,
phys_dim);
229 this->_impl = boost::intrusive_ptr<MPS_impl>(
new RegularMPS());
231 this->_impl = boost::intrusive_ptr<MPS_impl>(
new iMPS());
235 this->_impl->Init_Msector(N, vphys_dim,
virt_dim, select, dtype);
257 int mps_type()
const {
return this->_impl->mps_type_id; }
258 std::string
mps_type_str()
const {
return MPSType.getname(this->_impl->mps_type_id); }
262 out._impl = this->_impl->
clone();
266 std::vector<UniTensor> &
data() {
return this->_impl->get_data(); };
281 Scalar
norm()
const {
return this->_impl->norm(); }
290 void _Save(std::fstream &f)
const;
291 void _Load(std::fstream &f);
294 void Save(
const std::string &fname)
const;
295 void Save(
const char *fname)
const;
std::string mps_type_str() const
Definition MPS.hpp:258
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:266
MPS & S_mvleft()
Definition MPS.hpp:272
cytnx_int64 phys_dim(const cytnx_int64 &idx)
Definition MPS.hpp:283
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:215
int mps_type() const
Definition MPS.hpp:257
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:202
MPS clone() const
Definition MPS.hpp:260
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:224
MPS & S_mvright()
Definition MPS.hpp:276
Scalar norm() const
Definition MPS.hpp:281
cytnx_int64 & S_loc()
Definition MPS.hpp:287
cytnx_int64 & virt_dim()
Definition MPS.hpp:285
static MPS Load(const std::string &fname)
MPS & Into_Lortho()
Definition MPS.hpp:268
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:16
std::ostream & operator<<(std::ostream &os, const MPO &in)
Helper function to print vector with ODT:
Definition Accessor.hpp:12
uint64_t cytnx_uint64
Definition Type.hpp:55
int64_t cytnx_int64
Definition Type.hpp:58