TRIQS/triqs_ctint 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
remove.cpp
1// Copyright (c) 2017--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 "./remove.hpp"
7
8namespace triqs_ctint::moves {
9
10 mc_weight_t remove::attempt() {
11 TRIQS_ASSERT(n_removals > 0);
12 vpos.reserve(n_removals);
13 vpos.clear();
14
15 // Don't remove if config is empty
16 if (qmc_config->perturbation_order() == 0) return 0.0;
17
18 // Prepare remove of single vertex
19 auto single_remove = [&](int p) {
20 // Lazy remove the vertex at given position
21 auto &v = qmc_config->vertex_lst[p];
22 lazy_op << v;
23
24 // Calculate insertion proposition probability
25 double insert_proposition_proba = v.proposition_proba / vertex_factories.size();
26
27 // Return ratio of insertion proposition probability and vertex amplitude
28 return insert_proposition_proba / v.amplitude;
29 };
30
31 // Choose one of the vertices for removal
32 U_scalar_t ratio = 1;
33 for (int i = 0; i < n_removals; ++i) {
34 int const this_vpos = rng(qmc_config->perturbation_order());
35 // In case of double remove we pick up another vertex
36 if (std::find(vpos.begin(), vpos.end(), this_vpos) == vpos.end()) {
37 vpos.emplace_back(this_vpos);
38 // Lazy insert and capture the weight for the vertex
39 ratio *= single_remove(this_vpos);
40 } else {
41 lazy_op.reset();
42 return 0;
43 }
44 }
45
46 // Execute the removal move
47 g_tau_scalar_t det_ratio = lazy_op.execute_try_remove();
48
49 double remove_proposition_proba = 0.0;
50 if (max_order == -1 || qmc_config->perturbation_order() < max_order) {
51 remove_proposition_proba = 1.0 / std::pow(qmc_config->perturbation_order(), n_removals);
52 }
53
54 // Return the overall weight
55 return mc_weight_t{det_ratio} * ratio / remove_proposition_proba;
56 }
57
58 mc_weight_t remove::accept() {
59
60 // Finish the removal from the determinants
61 for (auto &d : qmc_config->dets) d.complete_operation(); // maybe doing nothing if not try_insert but it is quick
62
63 // sort the vertices in reverse order
64 std::sort(vpos.begin(), vpos.end(), std::greater<>());
65
66 // Remove the vertices from vertex_lst
67 for (auto &&this_vpos : vpos) { qmc_config->vertex_lst.erase(begin(qmc_config->vertex_lst) + this_vpos); }
68
69 return 1.0; // no need for a correction of the sign
70 }
71
73 for (auto &d : qmc_config->dets) d.reject_last_try(); // reject the last try in all determinants
74 }
75
76} // namespace triqs_ctint::moves
qmc_config_t * qmc_config
The Monte-Carlo configuration.
Definition remove.hpp:18
int max_order
Maximum perturbation order (<0 : unlimited).
Definition remove.hpp:30
triqs::mc_tools::random_generator & rng
The random number generator.
Definition remove.hpp:24
lazy_det_operation_t lazy_op
Object that allows to delay determinant operations, necessary for multi-inserts/removes.
Definition remove.hpp:36
int n_removals
Switch for double vertex removals.
Definition remove.hpp:27
mc_weight_t attempt()
Attempt vertex removal.
Definition remove.cpp:10
std::vector< vertex_factory_t > const & vertex_factories
Factory that randomly generates vertices.
Definition remove.hpp:21
mc_weight_t accept()
Accept vertex removal.
Definition remove.cpp:58
std::vector< int > vpos
Positions at which to remove vertices.
Definition remove.hpp:33
void reject()
Reject vertex removal.
Definition remove.cpp:72