7#include "remove_segment.hpp"
10namespace triqs_ctseg::moves {
12 double remove_segment::attempt() {
14 LOG(
"\n =================== ATTEMPT REMOVE ================ \n");
18 color = rng(config.n_color());
19 auto &sl = config.seglists[color];
20 LOG(
"Removing at color {}", color);
24 LOG(
"remove_segment: reject : color is empty.");
29 prop_seg_idx = rng(sl.size());
30 prop_seg = sl[prop_seg_idx];
31 if (is_full_line(prop_seg)) {
32 LOG(
"Cannot remove full line.");
35 if (prop_seg.J_c or prop_seg.J_cdag) {
36 LOG(
"Segment has spin line attached, cannot remove.");
40 LOG(
"Removing segment at position {} : c at {}, cdag at {}", prop_seg_idx, prop_seg.tau_c, prop_seg.tau_cdag);
44 double ln_trace_ratio = -wdata.mu(color) * prop_seg.length();
45 for (
auto c : range(config.n_color())) {
46 if (c != color) { ln_trace_ratio -= -wdata.U(color, c) * overlap(config.seglists[c], prop_seg); }
48 ln_trace_ratio -= K_overlap(config.seglists[c], prop_seg.tau_c, prop_seg.tau_cdag, wdata.K, color, c);
50 if (wdata.has_Dt) ln_trace_ratio -= real(wdata.K(
double(prop_seg.length()))(color, color));
52 double trace_ratio = std::exp(ln_trace_ratio);
56 auto bl = wdata.block_number[color];
57 auto &D = wdata.dets[bl];
58 auto det_ratio = D.try_remove(det_lower_bound_x(D, prop_seg.tau_cdag),
59 det_lower_bound_y(D, prop_seg.tau_c));
63 double current_number_segments = sl.size();
64 double future_number_intervals = std::max(1,
int(sl.size()) - 1);
68 if (current_number_segments != 1) {
70 tau_right = sl[modulo(prop_seg_idx + 1, sl.size())].tau_c;
71 tau_left = sl[modulo(prop_seg_idx - 1, sl.size())].tau_cdag;
73 auto window_length = double(tau_left - tau_right);
75 double prop_ratio = current_number_segments
76 / (future_number_intervals * window_length * window_length / (current_number_segments == 1 ? 1 : 2));
77 LOG(
"trace_ratio = {}, prop_ratio = {}, det_ratio = {}", trace_ratio, prop_ratio, det_ratio);
79 det_sign = (det_ratio > 0) ? 1.0 : -1.0;
80 double prod = trace_ratio * det_ratio * prop_ratio;
82 return (std::isfinite(prod)) ? prod : det_sign;
87 double remove_segment::accept() {
89 LOG(
"\n - - - - - ====> ACCEPT - - - - - - - - - - -\n");
91 double initial_sign = trace_sign(wdata);
92 LOG(
"Initial sign is {}. Initial configuration: {}", initial_sign, config);
95 wdata.dets[wdata.block_number[color]].complete_operation();
97 auto &sl = config.seglists[color];
99 sl.erase(sl.begin() + prop_seg_idx);
101 double final_sign = trace_sign(wdata);
102 double sign_ratio = initial_sign / final_sign;
103 LOG(
"Final sign is {}", final_sign);
106 if constexpr (print_logs or ctseg_debug) check_invariant(config, wdata);
108 if (sign_ratio * det_sign == -1.0) wdata.minus_sign =
true;
110 LOG(
"Configuration is {}", config);
116 void remove_segment::reject() {
117 LOG(
"\n - - - - - ====> REJECT - - - - - - - - - - -\n");
118 wdata.dets[wdata.block_number[color]].reject_last_try();
static tau_t beta()
tau_t at tau = beta
static tau_t zero()
$\tau = 0$