7#include "insert_segment.hpp"
11namespace triqs_ctseg::moves {
13 double insert_segment::attempt() {
15 LOG(
"\n =================== ATTEMPT INSERT ================ \n");
19 color = rng(config.n_color());
20 auto &sl = config.seglists[color];
21 LOG(
"Inserting at color {}", color);
29 if (is_full_line(sl.back())) {
30 LOG(
"Full line, cannot insert.");
34 long seg_idx = rng(sl.size());
35 tau_left = sl[seg_idx].tau_cdag;
36 tau_right = sl[modulo(seg_idx + 1, sl.size())].tau_c;
41 LOG(
"Insertion window is tau_left = {}, tau_right = {}", tau_left, tau_right);
42 tau_t window_length = tau_left - tau_right;
45 auto dt1 = tau_t::random(rng, window_length);
46 auto dt2 = tau_t::random(rng, window_length);
48 LOG(
"Insert_segment: generated equal times. Rejecting");
55 if (dt1 > dt2 and not sl.empty()) std::swap(dt1, dt2);
58 prop_seg = segment_t{tau_left - dt1, tau_left - dt2};
59 LOG(
"Inserting segment with c at {}, cdag at {}", prop_seg.tau_c, prop_seg.tau_cdag);
62 double ln_trace_ratio = wdata.mu(color) * prop_seg.length();
64 for (
auto c : range(config.n_color())) {
65 if (c != color) ln_trace_ratio += -wdata.U(color, c) * overlap(config.seglists[c], prop_seg);
67 ln_trace_ratio += K_overlap(config.seglists[c], prop_seg.tau_c, prop_seg.tau_cdag, wdata.K, color, c);
70 ln_trace_ratio += -real(wdata.K(
double(prop_seg.length()))(color, color));
71 double trace_ratio = std::exp(ln_trace_ratio);
75 auto &bl = wdata.block_number[color];
76 auto &bl_idx = wdata.index_in_block[color];
77 auto &D = wdata.dets[bl];
78 if (wdata.offdiag_Delta) {
79 if (cdag_in_det(prop_seg.tau_cdag, D) or c_in_det(prop_seg.tau_c, D)) {
80 LOG(
"One of the proposed times already exists in another line of the same block. Rejecting.");
84 auto det_ratio = D.try_insert(det_lower_bound_x(D, prop_seg.tau_cdag),
85 det_lower_bound_y(D, prop_seg.tau_c),
86 {prop_seg.tau_cdag, bl_idx}, {prop_seg.tau_c, bl_idx});
90 double current_number_intervals = std::max(
long(1),
long(sl.size()));
91 double future_number_segments = sl.size() + 1;
96 (current_number_intervals * window_length * window_length / (sl.empty() ? 1 : 2)) / future_number_segments;
99 LOG(
"trace_ratio = {}, prop_ratio = {}, det_ratio = {}", trace_ratio, prop_ratio, det_ratio);
101 double prod = trace_ratio * det_ratio * prop_ratio;
102 det_sign = (det_ratio > 0) ? 1.0 : -1.0;
104 return (std::isfinite(prod) ? prod : det_sign);
109 double insert_segment::accept() {
111 LOG(
"\n - - - - - ====> ACCEPT - - - - - - - - - - -\n");
113 double initial_sign = trace_sign(wdata);
114 LOG(
"Initial sign is {}. Initial configuration: {}", initial_sign, config);
117 wdata.dets[wdata.block_number[color]].complete_operation();
120 auto &sl = config.seglists[color];
121 sl.insert(std::upper_bound(sl.begin(), sl.end(), prop_seg), prop_seg);
124 if constexpr (print_logs or ctseg_debug) check_invariant(config, wdata);
126 double final_sign = trace_sign(wdata);
127 double sign_ratio = final_sign / initial_sign;
128 LOG(
"Final sign is {}", final_sign);
130 if (sign_ratio * det_sign == -1.0) wdata.minus_sign =
true;
132 LOG(
"Configuration is {}", config);
138 void insert_segment::reject() {
139 LOG(
"\n - - - - - ====> REJECT - - - - - - - - - - -\n");
140 wdata.dets[wdata.block_number[color]].reject_last_try();
static tau_t beta()
tau_t at tau = beta
static tau_t zero()
$\tau = 0$