Cytnx v0.9.7
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
16#include "tn_algo/MPS.hpp"
17
18#ifdef BACKEND_TORCH
19#else
20 #include "backend/Scalar.hpp"
21
22namespace cytnx {
23 namespace tn_algo {
25 class MPO_impl : public intrusive_ptr_base<MPO_impl> {
26 private:
27 public:
28 std::vector<UniTensor> _TNs;
29
30 friend class MPS;
31 friend class MPO;
32
33 boost::intrusive_ptr<MPO_impl> clone() const {
34 boost::intrusive_ptr<MPO_impl> out(new MPO_impl());
35 out->_TNs = vec_clone(this->_TNs);
36 return out;
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 class RegularMPO : public MPO_impl {
45 public:
46 std::ostream &Print(std::ostream &os);
47 cytnx_uint64 size() { return this->_TNs.size(); };
48 UniTensor get_op(const cytnx_uint64 &site_idx);
49 };
51
52 // API
53 class MPO {
54 private:
55 public:
57 boost::intrusive_ptr<MPO_impl> _impl;
58 MPO()
59 : _impl(new RegularMPO()){
60 // currently default init is RegularMPO;
61 };
62
63 MPO(const MPO &rhs) { _impl = rhs._impl; }
65
66 MPO &operator=(const MPO &rhs) {
67 _impl = rhs._impl;
68 return *this;
69 }
70
71 cytnx_uint64 size() { return this->_impl->size(); }
72
73 void append(const UniTensor &rc) { this->_impl->_TNs.push_back(rc); }
74
75 void assign(const cytnx_uint64 &N, const UniTensor &rc) { this->_impl->_TNs.assign(N, rc); }
76
77 std::vector<UniTensor> &get_all() { return this->_impl->_TNs; }
78
79 const std::vector<UniTensor> &get_all() const { return this->_impl->_TNs; }
80
81 // expose to user:
82 virtual UniTensor get_op(const cytnx_uint64 &site_idx) {
83 return this->_impl->get_op(site_idx);
84 };
85 };
86
87 std::ostream &operator<<(std::ostream &os, const MPO &in);
88
89 } // namespace tn_algo
90} // namespace cytnx
91
92#endif // BACKEND_TORCH
93
94#endif
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:1783
Definition MPO.hpp:53
const std::vector< UniTensor > & get_all() const
Definition MPO.hpp:79
cytnx_uint64 size()
Definition MPO.hpp:71
MPO & operator=(const MPO &rhs)
Definition MPO.hpp:66
virtual UniTensor get_op(const cytnx_uint64 &site_idx)
Definition MPO.hpp:82
std::vector< UniTensor > & get_all()
Definition MPO.hpp:77
void assign(const cytnx_uint64 &N, const UniTensor &rc)
Definition MPO.hpp:75
void append(const UniTensor &rc)
Definition MPO.hpp:73
std::ostream & operator<<(std::ostream &os, const MPO &in)
Helper function to print vector with ODT:
Definition Accessor.hpp:12
uint64_t cytnx_uint64
Definition Type.hpp:55