Cytnx v0.7.6
Loading...
Searching...
No Matches
MPO.hpp
Go to the documentation of this file.
1#ifndef _H_MPO_
2#define _H_MPO_
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
18
19namespace cytnx{
20 namespace tn_algo{
22 class MPO_impl: public intrusive_ptr_base<MPO_impl>{
23 private:
24
25 public:
26
27 std::vector<UniTensor> _TNs;
28
29 friend class MPS;
30 friend class MPO;
31
32 boost::intrusive_ptr<MPO_impl> clone() const{
33 boost::intrusive_ptr<MPO_impl> out(new MPO_impl());
34 out->_TNs = vec_clone(this->_TNs);
35 return out;
36 }
37
38
39 virtual std::ostream& Print(std::ostream &os);
40 virtual cytnx_uint64 size(){return 0;};
41 virtual UniTensor get_op(const cytnx_uint64 &site_idx);
42 };
43
44
45 class RegularMPO: public MPO_impl{
46 public:
47 std::ostream& Print(std::ostream &os);
48 cytnx_uint64 size(){return this->_TNs.size();};
49 UniTensor get_op(const cytnx_uint64 &site_idx);
50 };
52
53 // API
54 class MPO{
55 private:
56
57 public:
58
60 boost::intrusive_ptr<MPO_impl> _impl;
61 MPO(): _impl(new RegularMPO()){
62 // currently default init is RegularMPO;
63 };
64
65 MPO(const MPO &rhs){
66 _impl = rhs._impl;
67 }
69
70 MPO& operator=(const MPO &rhs){
71 _impl = rhs._impl;
72 return *this;
73 }
74
76 return this->_impl->size();
77 }
78
79 void append(const UniTensor &rc){
80 this->_impl->_TNs.push_back(rc);
81 }
82
83 void assign(const cytnx_uint64 &N, const UniTensor &rc){
84 this->_impl->_TNs.assign(N,rc);
85 }
86
87 std::vector<UniTensor> & get_all(){
88 return this->_impl->_TNs;
89 }
90
91 const std::vector<UniTensor> & get_all() const{
92 return this->_impl->_TNs;
93 }
94
95 // expose to user:
96 virtual UniTensor get_op(const cytnx_uint64 &site_idx){
97 return this->_impl->get_op(site_idx);
98 };
99
100
101 };
102
103 std::ostream& operator<<(std::ostream& os, const MPO &in);
104
105
106
107
108
109 }
110}
111
112#endif
113
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:1122
Definition MPO.hpp:54
const std::vector< UniTensor > & get_all() const
Definition MPO.hpp:91
cytnx_uint64 size()
Definition MPO.hpp:75
MPO & operator=(const MPO &rhs)
Definition MPO.hpp:70
virtual UniTensor get_op(const cytnx_uint64 &site_idx)
Definition MPO.hpp:96
std::vector< UniTensor > & get_all()
Definition MPO.hpp:87
void assign(const cytnx_uint64 &N, const UniTensor &rc)
Definition MPO.hpp:83
void append(const UniTensor &rc)
Definition MPO.hpp:79
std::ostream & operator<<(std::ostream &os, const MPO &in)
Definition Accessor.hpp:12
uint64_t cytnx_uint64
Definition Type.hpp:22