Cytnx v0.9.1
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
18namespace cytnx {
19 namespace tn_algo {
21 class MPO_impl : public intrusive_ptr_base<MPO_impl> {
22 private:
23 public:
24 std::vector<UniTensor> _TNs;
25
26 friend class MPS;
27 friend class MPO;
28
29 boost::intrusive_ptr<MPO_impl> clone() const {
30 boost::intrusive_ptr<MPO_impl> out(new MPO_impl());
31 out->_TNs = vec_clone(this->_TNs);
32 return out;
33 }
34
35 virtual std::ostream &Print(std::ostream &os);
36 virtual cytnx_uint64 size() { return 0; };
37 virtual UniTensor get_op(const cytnx_uint64 &site_idx);
38 };
39
40 class RegularMPO : public MPO_impl {
41 public:
42 std::ostream &Print(std::ostream &os);
43 cytnx_uint64 size() { return this->_TNs.size(); };
44 UniTensor get_op(const cytnx_uint64 &site_idx);
45 };
47
48 // API
49 class MPO {
50 private:
51 public:
53 boost::intrusive_ptr<MPO_impl> _impl;
54 MPO()
55 : _impl(new RegularMPO()){
56 // currently default init is RegularMPO;
57 };
58
59 MPO(const MPO &rhs) { _impl = rhs._impl; }
61
62 MPO &operator=(const MPO &rhs) {
63 _impl = rhs._impl;
64 return *this;
65 }
66
67 cytnx_uint64 size() { return this->_impl->size(); }
68
69 void append(const UniTensor &rc) { this->_impl->_TNs.push_back(rc); }
70
71 void assign(const cytnx_uint64 &N, const UniTensor &rc) { this->_impl->_TNs.assign(N, rc); }
72
73 std::vector<UniTensor> &get_all() { return this->_impl->_TNs; }
74
75 const std::vector<UniTensor> &get_all() const { return this->_impl->_TNs; }
76
77 // expose to user:
78 virtual UniTensor get_op(const cytnx_uint64 &site_idx) {
79 return this->_impl->get_op(site_idx);
80 };
81 };
82
83 std::ostream &operator<<(std::ostream &os, const MPO &in);
84
85 } // namespace tn_algo
86} // namespace cytnx
87
88#endif
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:2449
Definition MPO.hpp:49
const std::vector< UniTensor > & get_all() const
Definition MPO.hpp:75
cytnx_uint64 size()
Definition MPO.hpp:67
MPO & operator=(const MPO &rhs)
Definition MPO.hpp:62
virtual UniTensor get_op(const cytnx_uint64 &site_idx)
Definition MPO.hpp:78
std::vector< UniTensor > & get_all()
Definition MPO.hpp:73
void assign(const cytnx_uint64 &N, const UniTensor &rc)
Definition MPO.hpp:71
void append(const UniTensor &rc)
Definition MPO.hpp:69
std::ostream & operator<<(std::ostream &os, const MPO &in)
Definition Accessor.hpp:12
uint64_t cytnx_uint64
Definition Type.hpp:45