Xped
Loading...
Searching...
No Matches
OneSiteObservable.hpp
Go to the documentation of this file.
1#ifndef XPED_ONE_SITE_OBSERVABLE_HPP_
2#define XPED_ONE_SITE_OBSERVABLE_HPP_
3
4#include "fmt/core.h"
5
6#include <highfive/H5DataSpace.hpp>
7
11#include "Xped/PEPS/TMatrix.hpp"
13
14namespace Xped {
15
16template <typename, typename, std::size_t, bool, Opts::CTMCheckpoint>
17class CTM;
18
19template <typename Scalar, typename Symmetry, bool HERMITIAN = true>
21{
22 using ObsScalar = std::conditional_t<HERMITIAN, typename ScalarTraits<Scalar>::Real, typename ScalarTraits<Scalar>::Comp>;
23
24 explicit OneSiteObservable(const Pattern& pat, const std::string& name_in = "")
25 : ObservableBase(name_in)
26 , data(pat)
27 , obs(pat)
28 {}
29
31 {
32 if(std::all_of(charges.cbegin(), charges.cend(), [](auto c) { return c == Symmetry::qvacuum(); })) { return *this; }
34 for(int x = 0; x < data.pat.Lx; ++x) {
35 for(int y = 0; y < data.pat.Ly; ++y) {
36 if(not data.pat.isUnique(x, y)) { continue; }
37 // out.data(x, y) = data(x, y).template shiftQN<0, 1>(std::array{charges(x, y), charges(x, y)});
39 c.push_back(charges(x, y), 1);
40 Tensor<Scalar, 1, 1, Symmetry> id({{c}}, {{c}});
41 id.setIdentity();
42 auto tmp = data(x, y).template contract<std::array{-1, -3}, std::array{-2, -4}, 2>(id);
43 Tensor<Scalar, 2, 1, Symmetry> fuser({{data(x, y).uncoupledCodomain()[0], c}},
44 {{data(x, y).uncoupledCodomain()[0].combine(c).forgetHistory()}});
45 fuser.setIdentity();
46 out.data(x, y) = tmp.template contract<std::array{-1, -2, 1, 2}, std::array{1, 2, -3}, 2>(fuser)
47 .template contract<std::array{1, 2, -2}, std::array{-1, 1, 2}, 1>(fuser.adjoint().eval().twist(1).twist(2));
48 }
49 }
50 return out;
51 }
52
53 virtual std::string getResString(const std::string& offset) const override
54 {
55 std::string res;
56 fmt::format_to(std::back_inserter(res),
57 "{}{:<10}: avg={:+.2f}, vals={::+.4f}",
58 offset,
59 this->name,
60 obs.sum() / static_cast<ObsScalar>(obs.size()),
62 return res;
63 }
64
65 virtual void toFile(HighFive::File& file, const std::string& root = "/") const override
66 {
67 if(not file.exist(root + this->name)) {
68 HighFive::DataSpace dataspace = HighFive::DataSpace({0, 0}, {HighFive::DataSpace::UNLIMITED, HighFive::DataSpace::UNLIMITED});
69
70 // Use chunking
71 HighFive::DataSetCreateProps props;
72 props.add(HighFive::Chunking(std::vector<hsize_t>{2, 2}));
73
74 // Create the dataset
75 HighFive::DataSet dataset = file.createDataSet(root + this->name, dataspace, HighFive::create_datatype<ObsScalar>(), props);
76 }
77 auto d = file.getDataSet(root + this->name);
78 std::vector<std::vector<ObsScalar>> data;
79 data.push_back(obs.uncompressedVector());
80 std::size_t curr_size = d.getDimensions()[0];
81 d.resize({curr_size + 1, data[0].size()});
82 d.select({curr_size, 0}, {1, data[0].size()}).write(data);
83 }
84
87};
88
89} // namespace Xped
90
91#endif
Definition: Qbasis.hpp:39
void push_back(const qType &q, const size_t &inner_dim)
Definition: Qbasis.cpp:32
Definition: Tensor.hpp:40
Definition: bench.cpp:62
Definition: ObservableBase.hpp:11
std::string name
Definition: ObservableBase.hpp:24
Definition: OneSiteObservable.hpp:21
virtual std::string getResString(const std::string &offset) const override
Definition: OneSiteObservable.hpp:53
OneSiteObservable< Scalar, Symmetry, HERMITIAN > shiftQN(const TMatrix< typename Symmetry::qType > &charges)
Definition: OneSiteObservable.hpp:30
TMatrix< ObsScalar > obs
Definition: OneSiteObservable.hpp:86
std::conditional_t< HERMITIAN, typename ScalarTraits< Scalar >::Real, typename ScalarTraits< Scalar >::Comp > ObsScalar
Definition: OneSiteObservable.hpp:22
TMatrix< Tensor< Scalar, 1, 1, Symmetry, false > > data
Definition: OneSiteObservable.hpp:85
virtual void toFile(HighFive::File &file, const std::string &root="/") const override
Definition: OneSiteObservable.hpp:65
OneSiteObservable(const Pattern &pat, const std::string &name_in="")
Definition: OneSiteObservable.hpp:24
Definition: Pattern.hpp:18
Definition: ScalarTraits.hpp:10
Definition: TMatrix.hpp:13
Ttype sum() const
Definition: TMatrix.hpp:77
auto cbegin() const
Definition: TMatrix.hpp:70
std::size_t size() const
Definition: TMatrix.hpp:38
std::vector< Ttype > uncompressedVector() const
Definition: TMatrix.hpp:85
auto cend() const
Definition: TMatrix.hpp:71