TRIQS/triqs_cthyb 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
remove.cpp
1/*******************************************************************************
2 *
3 * TRIQS: a Toolbox for Research in Interacting Quantum Systems
4 *
5 * Copyright (C) 2014, P. Seth, I. Krivenko, M. Ferrero and O. Parcollet
6 *
7 * TRIQS is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later
10 * version.
11 *
12 * TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * TRIQS. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ******************************************************************************/
21
22#include "./remove.hpp"
23
24namespace triqs_cthyb {
25
26 histogram * move_remove_c_cdag::add_histo(std::string const &name, histo_map_t *histos) {
27 if (!histos) return nullptr;
28 auto new_histo = histos->insert({name, {.0, config.beta(), 100}});
29 return &(new_histo.first->second);
30 }
31
32 move_remove_c_cdag::move_remove_c_cdag(int block_index, int block_size, std::string const &block_name, qmc_data &data, mc_tools::random_generator &rng,
33 histo_map_t *histos)
34 : data(data),
35 config(data.config),
36 rng(rng),
37 block_index(block_index),
38 block_size(block_size),
39 histo_proposed(add_histo("remove_length_proposed_" + block_name, histos)),
40 histo_accepted(add_histo("remove_length_accepted_" + block_name, histos)) {}
41
42 mc_weight_t move_remove_c_cdag::attempt() {
43
44#ifdef EXT_DEBUG
45 std::cerr << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
46 std::cerr << "In config " << config.get_id() << std::endl;
47 std::cerr << "* Attempt for move_remove_c_cdag (block " << block_index << ")" << std::endl;
48#endif
49
50 auto &det = data.dets[block_index];
51
52 // Pick up a couple of C, Cdagger to remove at random
53 // Remove the operators from the traces
54 int det_size = det.size();
55 if (det_size == 0) return 0; // nothing to remove
56 int num_c_dag = rng(det_size), num_c = rng(det_size);
57
58#ifdef EXT_DEBUG
59 std::cerr << "* Proposing to remove: ";
60 std::cerr << num_c_dag << "-th Cdag(" << block_index << ",...), ";
61 std::cerr << num_c << "-th C(" << block_index << ",...)" << std::endl;
62#endif
63
64 // now mark 2 nodes for deletion
65 tau1 = data.imp_trace.try_delete(num_c, block_index, false);
66 tau2 = data.imp_trace.try_delete(num_c_dag, block_index, true);
67
68 // record the length of the proposed removal
69 dtau = double(tau2 - tau1);
70 if (histo_proposed) *histo_proposed << dtau;
71
72 auto det_ratio = det.try_remove(num_c_dag, num_c);
73
74 // proposition probability
75 auto t_ratio = std::pow(block_size * config.beta() / double(det_size), 2); // Size of the det before the try_delete!
76
77 // For quick abandon
78 double random_number = rng.preview();
79 if (random_number == 0.0) return 0;
80 double p_yee = std::abs(det_ratio / t_ratio / data.atomic_weight);
81
82 // recompute the atomic_weight
83 std::tie(new_atomic_weight, new_atomic_reweighting) = data.imp_trace.compute(p_yee, random_number);
84 if (new_atomic_weight == 0.0) {
85#ifdef EXT_DEBUG
86 std::cerr << "atomic_weight == 0" << std::endl;
87#endif
88 return 0;
89 }
90 auto atomic_weight_ratio = new_atomic_weight / data.atomic_weight;
91 if (!isfinite(atomic_weight_ratio))
92 TRIQS_RUNTIME_ERROR << "(remove) atomic_weight_ratio not finite " << new_atomic_weight << " " << data.atomic_weight << " "
93 << new_atomic_weight / data.atomic_weight << " in config " << config.get_id();
94
95 mc_weight_t p = atomic_weight_ratio * det_ratio;
96
97#ifdef EXT_DEBUG
98 std::cerr << "Trace ratio: " << atomic_weight_ratio << '\t';
99 std::cerr << "Det ratio: " << det_ratio << '\t';
100 std::cerr << "Prefactor: " << t_ratio << '\t';
101 std::cerr << "Weight: " << p / t_ratio << std::endl;
102#endif
103
104 if (!isfinite(p)) {
105 std::cerr << "Remove move info\n";
106 std::cerr << "Trace ratio: " << atomic_weight_ratio << '\t';
107 std::cerr << "Det ratio: " << det_ratio << '\t';
108 std::cerr << "Prefactor: " << t_ratio << '\t';
109 std::cerr << "Weight: " << p / t_ratio << std::endl;
110 TRIQS_RUNTIME_ERROR << "(remove) p not finite :" << p << " in config " << config.get_id();
111 }
112
113 if (!isfinite(p / t_ratio)){
114 TRIQS_RUNTIME_ERROR << "(remove) p / t_ratio not finite p : " << p << " t_ratio : " << t_ratio << " in config " << config.get_id();
115 }
116 return p / t_ratio;
117 }
118
119 mc_weight_t move_remove_c_cdag::accept() {
120
121 // remove from the tree
122 data.imp_trace.confirm_delete();
123
124 // remove from the configuration
125 config.erase(tau1);
126 config.erase(tau2);
127 config.finalize();
128
129 // remove from the determinants
130 data.dets[block_index].complete_operation();
131 data.update_sign();
132 data.atomic_weight = new_atomic_weight;
133 data.atomic_reweighting = new_atomic_reweighting;
134 if (histo_accepted) *histo_accepted << dtau;
135
136#ifdef EXT_DEBUG
137 std::cerr << "* Move move_remove_c_cdag accepted" << std::endl;
138 std::cerr << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
139 check_det_sequence(data.dets[block_index], config.get_id());
140#endif
141
142 return data.current_sign / data.old_sign;
143 }
144
145 void move_remove_c_cdag::reject() {
146
147 config.finalize();
148 data.imp_trace.cancel_delete();
149 data.dets[block_index].reject_last_try();
150
151#ifdef EXT_DEBUG
152 std::cerr << "* Move move_remove_c_cdag rejected" << std::endl;
153 std::cerr << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
154 check_det_sequence(data.dets[block_index], config.get_id());
155#endif
156 }
157}