Cytnx v0.9.4
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 "tn_algo/MPS.hpp"
16#include "tn_algo/MPO.hpp"
17
18#ifdef BACKEND_TORCH
19#else
20 #include "backend/Scalar.hpp"
21
22namespace cytnx {
23 namespace tn_algo {
25 class DMRG_impl : public intrusive_ptr_base<DMRG_impl> {
26 private:
27 public:
28 MPS mps;
29 MPO mpo;
30
31 // for getting excited states:
32 std::vector<MPS> ortho_mps;
33 double weight;
34
35 // iterative solver param:
36 cytnx_int64 maxit;
37 cytnx_int64 krydim;
38
39 // environ:
40 std::vector<UniTensor> LR;
41 std::vector<std::vector<UniTensor>> hLRs; // excited states
42
43 friend class MPS;
44 friend class MPO;
45
46 void initialize();
47 Scalar sweep(const bool &verbose, const cytnx_int64 &maxit, const cytnx_int64 &krydim);
48 Scalar sweepv2(const bool &verbose, const cytnx_int64 &maxit, const cytnx_int64 &krydim);
49 };
51
52 // API
53 class DMRG {
54 private:
55 public:
57 boost::intrusive_ptr<DMRG_impl> _impl;
58 DMRG(MPO mpo, MPS mps, std::vector<MPS> ortho_mps = {}, const double &weight = 30)
59 : _impl(new DMRG_impl()) {
60 // currently default init is DMRG_impl;
61
62 // mpo and mps:
63 this->_impl->mpo = mpo;
64 this->_impl->mps = mps;
65
66 // for getting excited states:
67 this->_impl->ortho_mps = ortho_mps;
68 this->_impl->weight = weight;
69 };
70
71 DMRG(const DMRG &rhs) { _impl = rhs._impl; }
73
74 DMRG &operator=(const DMRG &rhs) {
75 _impl = rhs._impl;
76 return *this;
77 }
78
80 this->_impl->initialize();
81 return *this;
82 }
83
84 // return the current energy
85 Scalar sweep(const bool &verbose = false, const cytnx_int64 &maxit = 4000,
86 const cytnx_int64 &krydim = 4) {
87 return this->_impl->sweep(verbose, maxit, krydim);
88 }
89
90 // return the current energy
91 Scalar sweepv2(const bool &verbose = false, const cytnx_int64 &maxit = 4000,
92 const cytnx_int64 &krydim = 4) {
93 return this->_impl->sweepv2(verbose, maxit, krydim);
94 }
95 };
96
97 } // namespace tn_algo
98} // namespace cytnx
99
100#endif // BACKEND_TORCH
101
102#endif
Definition DMRG.hpp:53
Scalar sweepv2(const bool &verbose=false, const cytnx_int64 &maxit=4000, const cytnx_int64 &krydim=4)
Definition DMRG.hpp:91
DMRG & initialize()
Definition DMRG.hpp:79
DMRG & operator=(const DMRG &rhs)
Definition DMRG.hpp:74
Scalar sweep(const bool &verbose=false, const cytnx_int64 &maxit=4000, const cytnx_int64 &krydim=4)
Definition DMRG.hpp:85
Definition MPO.hpp:53
Definition MPS.hpp:169
Helper function to print vector with ODT:
Definition Accessor.hpp:12
int64_t cytnx_int64
Definition Type.hpp:58