Cytnx v0.9.1
Loading...
Searching...
No Matches
DMRG.hpp
Go to the documentation of this file.
1#ifndef _H_DMRG_
2#define _H_DMRG_
3
4#include "cytnx_error.hpp"
5#include "Device.hpp"
7#include "UniTensor.hpp"
8#include <iostream>
9#include <fstream>
10#include "utils/vec_clone.hpp"
11#include "Accessor.hpp"
12#include <vector>
13#include <initializer_list>
14#include <string>
15#include "Scalar.hpp"
16#include "tn_algo/MPS.hpp"
17#include "tn_algo/MPO.hpp"
18
19namespace cytnx {
20 namespace tn_algo {
22 class DMRG_impl : public intrusive_ptr_base<DMRG_impl> {
23 private:
24 public:
25 MPS mps;
26 MPO mpo;
27
28 // for getting excited states:
29 std::vector<MPS> ortho_mps;
30 double weight;
31
32 // iterative solver param:
33 cytnx_int64 maxit;
34 cytnx_int64 krydim;
35
36 // environ:
37 std::vector<UniTensor> LR;
38 std::vector<std::vector<UniTensor>> hLRs; // excited states
39
40 friend class MPS;
41 friend class MPO;
42
43 void initialize();
44 Scalar sweep(const bool &verbose, const cytnx_int64 &maxit, const cytnx_int64 &krydim);
45 Scalar sweepv2(const bool &verbose, const cytnx_int64 &maxit, const cytnx_int64 &krydim);
46 };
48
49 // API
50 class DMRG {
51 private:
52 public:
54 boost::intrusive_ptr<DMRG_impl> _impl;
55 DMRG(MPO mpo, MPS mps, std::vector<MPS> ortho_mps = {}, const double &weight = 30)
56 : _impl(new DMRG_impl()) {
57 // currently default init is DMRG_impl;
58
59 // mpo and mps:
60 this->_impl->mpo = mpo;
61 this->_impl->mps = mps;
62
63 // for getting excited states:
64 this->_impl->ortho_mps = ortho_mps;
65 this->_impl->weight = weight;
66 };
67
68 DMRG(const DMRG &rhs) { _impl = rhs._impl; }
70
71 DMRG &operator=(const DMRG &rhs) {
72 _impl = rhs._impl;
73 return *this;
74 }
75
77 this->_impl->initialize();
78 return *this;
79 }
80
81 // return the current energy
82 Scalar sweep(const bool &verbose = false, const cytnx_int64 &maxit = 4000,
83 const cytnx_int64 &krydim = 4) {
84 return this->_impl->sweep(verbose, maxit, krydim);
85 }
86
87 // return the current energy
88 Scalar sweepv2(const bool &verbose = false, const cytnx_int64 &maxit = 4000,
89 const cytnx_int64 &krydim = 4) {
90 return this->_impl->sweepv2(verbose, maxit, krydim);
91 }
92 };
93
94 } // namespace tn_algo
95} // namespace cytnx
96
97#endif
A class to represent a scalar.
Definition Scalar.hpp:2470
Definition DMRG.hpp:50
Scalar sweepv2(const bool &verbose=false, const cytnx_int64 &maxit=4000, const cytnx_int64 &krydim=4)
Definition DMRG.hpp:88
DMRG & initialize()
Definition DMRG.hpp:76
DMRG & operator=(const DMRG &rhs)
Definition DMRG.hpp:71
Scalar sweep(const bool &verbose=false, const cytnx_int64 &maxit=4000, const cytnx_int64 &krydim=4)
Definition DMRG.hpp:82
Definition MPO.hpp:49
Definition MPS.hpp:167
Definition Accessor.hpp:12
int64_t cytnx_int64
Definition Type.hpp:48