TRIQS/triqs_ctint 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
auto_corr_time.cpp
1// Copyright (c) 2021--present, The Simons Foundation
2// This file is part of TRIQS/ctint and is licensed under the terms of GPLv3 or later.
3// SPDX-License-Identifier: GPL-3.0-or-later
4// See LICENSE in the root of this distribution for details.
5
6#include "./auto_corr_time.hpp"
7
8namespace triqs_ctint::measures {
9
10 auto_corr_time::auto_corr_time(params_t const &params, qmc_config_t const &qmc_config, container_set *results)
11 : params(params), qmc_config(qmc_config), auto_corr_time_(results->auto_corr_time) {
12
13 // Count total density orbitals
14 int n_orbitals = 0;
15 for (auto const &[bl, bl_size] : params.gf_struct) n_orbitals += bl_size;
16
17 // [0] = perturbation order, [1..] = sign * density per orbital
18 log_accs.reserve(1 + n_orbitals);
19 for (int i = 0; i < 1 + n_orbitals; ++i) log_accs.emplace_back(dcomplex{0.0}, -1);
20 }
21
22 void auto_corr_time::accumulate(mc_weight_t sign) {
23 log_accs[0] << dcomplex(qmc_config.perturbation_order());
24
25 // Accumulate sign * diagonal densities
26 int idx = 1;
27 for (int bl = 0; bl < params.n_blocks(); ++bl) {
28 auto const &det = qmc_config.dets[bl];
29 int bl_size = params.gf_struct[bl].second;
30
31 nda::array<c_t, 1> cs(bl_size);
32 nda::array<cdag_t, 1> cdags(bl_size);
33 for (int a = 0; a < bl_size; ++a) {
34 cs(a) = c_t{tau_t::get_zero(), a};
35 cdags(a) = cdag_t{tau_t::get_zero_plus(), a};
36 }
37
38 auto ratios = det.insert_ratios(0, 0, cs, cdags);
39 for (int a = 0; a < bl_size; ++a) log_accs[idx++] << sign * ratios(a);
40 }
41 }
42
43 void auto_corr_time::collect_results(mpi::communicator const &comm) {
44 using triqs::stat::log_binning;
45
46 auto_corr_time_ = 0.0;
47
48 for (auto &log_acc : log_accs) {
49 auto [mean, errs, taus, effs] = log_acc.mean_errors_and_taus(comm);
50 if (!taus.empty()) { auto_corr_time_ = std::max(auto_corr_time_, std::real(taus.back())); }
51
52 // Reset the accumulator
53 log_acc = log_binning<dcomplex>{dcomplex{0.0}, -1};
54 }
55 mpi::broadcast(auto_corr_time_, comm, 0);
56 }
57
58} // namespace triqs_ctint::measures
Measurement of the auto-correlation time based on perturbation order and diagonal densities.
void accumulate(mc_weight_t sign)
Accumulate observables for autocorrelation analysis.
void collect_results(mpi::communicator const &comm)
Reduce and normalize.
static constexpr tau_t get_zero()
Return \tau = 0.
Definition vertex.hpp:48
static constexpr tau_t get_zero_plus()
Return \tau = 0^{+} = 0 + \delta.
Definition vertex.hpp:51