11#include "utils/vec_clone.hpp"
16#include <initializer_list>
31 std::string getname(
const int &mps_type);
33 extern MPSType_class MPSType;
35 class MPS_impl :
public intrusive_ptr_base<MPS_impl> {
46 MPS_impl() : mps_type_id(MPSType.Void) {}
49 std::vector<UniTensor> _TNs;
51 std::vector<UniTensor> &get_data() {
return this->_TNs; }
53 virtual Scalar norm()
const;
54 virtual boost::intrusive_ptr<MPS_impl> clone()
const;
55 virtual std::ostream &Print(std::ostream &os);
57 virtual void Init(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
58 const cytnx_uint64 &virt_dim,
const cytnx_int64 &dtype);
59 virtual void Init_Msector(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
60 const cytnx_uint64 &virt_dim,
61 const std::vector<cytnx_int64> &select,
const cytnx_int64 &dtype);
71 virtual void Into_Lortho();
72 virtual void S_mvleft();
73 virtual void S_mvright();
75 virtual void _save_dispatch(std::fstream &f);
76 virtual void _load_dispatch(std::fstream &f);
80 class RegularMPS :
public MPS_impl {
84 this->mps_type_id = MPSType.RegularMPS;
90 std::ostream &Print(std::ostream &os);
92 void Init(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
93 const cytnx_uint64 &virt_dim,
const cytnx_int64 &dtype);
94 void Init_Msector(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
95 const cytnx_uint64 &virt_dim,
const std::vector<cytnx_int64> &select,
96 const cytnx_int64 &dtype);
109 boost::intrusive_ptr<MPS_impl> clone()
const {
110 boost::intrusive_ptr<MPS_impl> out(
new RegularMPS());
111 out->S_loc = this->S_loc;
112 out->virt_dim = this->virt_dim;
113 out->_TNs = vec_clone(this->_TNs);
117 void _save_dispatch(std::fstream &f);
118 void _load_dispatch(std::fstream &f);
122 class iMPS :
public MPS_impl {
126 this->mps_type_id = MPSType.iMPS;
131 std::ostream &Print(std::ostream &os);
133 void Init(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
134 const cytnx_uint64 &virt_dim,
const cytnx_int64 &dtype);
135 void Init_Msector(
const cytnx_uint64 &N,
const std::vector<cytnx_uint64> &phys_dim,
136 const cytnx_uint64 &virt_dim,
const std::vector<cytnx_int64> &select,
137 const cytnx_int64 &dtype) {
138 cytnx_error_msg(
true,
"[ERROR][MPS][type=iMPS] cannot call Init_Msector%s",
"\n");
145 cytnx_error_msg(
true,
"[ERROR][MPS][type=iMPS] cannot call Into_Lortho%s",
"\n");
148 cytnx_error_msg(
true,
"[ERROR][MPS][type=iMPS] cannot call S_mvleft%s",
"\n");
151 cytnx_error_msg(
true,
"[ERROR][MPS][type=iMPS] cannot call S_mvright%s",
"\n");
153 boost::intrusive_ptr<MPS_impl> clone()
const {
154 boost::intrusive_ptr<MPS_impl> out(
new RegularMPS());
155 out->S_loc = this->S_loc;
156 out->virt_dim = this->virt_dim;
157 out->_TNs = vec_clone(this->_TNs);
161 void _save_dispatch(std::fstream &f);
162 void _load_dispatch(std::fstream &f);
171 boost::intrusive_ptr<MPS_impl> _impl;
173 : _impl(
new MPS_impl()){
179 : _impl(
new MPS_impl()) {
186 : _impl(
new MPS_impl()) {
190 MPS(
const MPS &rhs) { _impl = rhs._impl; }
192 MPS &operator=(
const MPS &rhs) {
204 this->_impl = boost::intrusive_ptr<MPS_impl>(
new RegularMPS());
206 this->_impl = boost::intrusive_ptr<MPS_impl>(
new iMPS());
210 this->_impl->Init(N, vphys_dim,
virt_dim, dtype);
215 std::vector<cytnx_uint64> vphys_dim(N,
phys_dim);
227 this->_impl = boost::intrusive_ptr<MPS_impl>(
new RegularMPS());
229 this->_impl = boost::intrusive_ptr<MPS_impl>(
new iMPS());
233 this->_impl->Init_Msector(N, vphys_dim,
virt_dim, select, dtype);
255 int mps_type()
const {
return this->_impl->mps_type_id; }
256 std::string
mps_type_str()
const {
return MPSType.getname(this->_impl->mps_type_id); }
260 out._impl = this->_impl->
clone();
264 std::vector<UniTensor> &
data() {
return this->_impl->get_data(); };
288 void _Save(std::fstream &f)
const;
289 void _Load(std::fstream &f);
292 void Save(
const std::string &fname)
const;
293 void Save(
const char *fname)
const;
A class to represent a scalar.
Definition Scalar.hpp:2470
std::string mps_type_str() const
Definition MPS.hpp:256
cytnx_uint64 size()
Definition MPS.hpp:253
void Save(const std::string &fname) const
void Save(const char *fname) const
std::vector< UniTensor > & data()
Definition MPS.hpp:264
MPS & S_mvleft()
Definition MPS.hpp:270
cytnx_int64 phys_dim(const cytnx_int64 &idx)
Definition MPS.hpp:281
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:213
int mps_type() const
Definition MPS.hpp:255
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:200
MPS clone() const
Definition MPS.hpp:258
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:222
MPS & S_mvright()
Definition MPS.hpp:274
Scalar norm() const
Definition MPS.hpp:279
cytnx_int64 & S_loc()
Definition MPS.hpp:285
cytnx_int64 & virt_dim()
Definition MPS.hpp:283
static MPS Load(const std::string &fname)
MPS & Into_Lortho()
Definition MPS.hpp:266
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:16
std::ostream & operator<<(std::ostream &os, const MPO &in)
Definition Accessor.hpp:12
uint64_t cytnx_uint64
Definition Type.hpp:45
int64_t cytnx_int64
Definition Type.hpp:48
Type_class Type
data type
Definition Type.cpp:23