7#include "regroup_segment.hpp"
10namespace triqs_ctseg::moves {
12 double regroup_segment::attempt() {
14 LOG(
"\n =================== ATTEMPT REGROUP ================ \n");
18 color = rng(config.n_color());
19 auto &sl = config.seglists[color];
20 LOG(
"Regrouping at color {}", color);
24 LOG(
"Color is empty");
29 making_full_line = sl.size() == 1;
30 if (making_full_line) {
31 if (is_full_line(sl[0])) {
32 LOG(
"Segment is full line");
38 left_seg_idx = rng(sl.size());
39 right_seg_idx = (left_seg_idx == sl.size() - 1) ? 0 : left_seg_idx + 1;
41 left_seg = sl[left_seg_idx];
42 right_seg = sl[right_seg_idx];
44 if (left_seg.J_cdag or right_seg.J_c) {
45 LOG(
"At least one of the operators has spin line attached, cannot regroup.");
49 LOG(
"Regroup at positions {} and {}: removing c at {}, cdag at {}", left_seg_idx, right_seg_idx, right_seg.tau_c,
54 auto inserted_seg = segment_t{left_seg.tau_cdag, right_seg.tau_c};
55 double ln_trace_ratio = wdata.mu(color) * inserted_seg.length();
57 for (
auto c : range(config.n_color())) {
58 if (c != color) { ln_trace_ratio += -wdata.U(color, c) * overlap(config.seglists[c], inserted_seg); }
60 ln_trace_ratio -= K_overlap(config.seglists[c], right_seg.tau_c, left_seg.tau_cdag, wdata.K, color, c);
65 real(wdata.K(
double(right_seg.tau_c - left_seg.tau_cdag))(color, color));
67 double trace_ratio = std::exp(ln_trace_ratio);
71 auto bl = wdata.block_number[color];
72 auto &D = wdata.dets[bl];
73 auto det_ratio = D.try_remove(det_lower_bound_x(D, left_seg.tau_cdag),
74 det_lower_bound_y(D, right_seg.tau_c));
78 double future_number_segments = making_full_line ? 1 : sl.size() - 1;
79 double current_number_intervals = sl.size();
81 auto new_seg_len = (making_full_line ?
tau_t::beta() : left_seg.tau_c - right_seg.tau_cdag);
86 current_number_intervals / (future_number_segments * new_seg_len * new_seg_len / (making_full_line ? 1 : 2));
88 LOG(
"trace_ratio = {}, prop_ratio = {}, det_ratio = {}", trace_ratio, prop_ratio, det_ratio);
90 det_sign = (det_ratio > 0) ? 1.0 : -1.0;
91 double prod = trace_ratio * det_ratio * prop_ratio;
93 return (std::isfinite(prod)) ? prod : det_sign;
98 double regroup_segment::accept() {
100 LOG(
"\n - - - - - ====> ACCEPT - - - - - - - - - - -\n");
102 double initial_sign = trace_sign(wdata);
103 LOG(
"Initial sign is {}. Initial configuration: {}", initial_sign, config);
106 wdata.dets[wdata.block_number[color]].complete_operation();
109 auto &sl = config.seglists[color];
110 if (making_full_line) {
114 sl[left_seg_idx] = segment_t{left_seg.tau_c, right_seg.tau_cdag, left_seg.J_c, right_seg.J_cdag};
116 sl.erase(sl.begin() + right_seg_idx);
119 double final_sign = trace_sign(wdata);
120 double sign_ratio = final_sign / initial_sign;
121 LOG(
"Final sign is {}", final_sign);
124 if constexpr (print_logs or ctseg_debug) check_invariant(config, wdata);
126 if (sign_ratio * det_sign == -1.0) wdata.minus_sign =
true;
127 LOG(
"Configuration is {}", config);
133 void regroup_segment::reject() {
134 LOG(
"\n - - - - - ====> REJECT - - - - - - - - - - -\n");
135 wdata.dets[wdata.block_number[color]].reject_last_try();
static tau_t beta()
tau_t at tau = beta
static tau_t zero()
$\tau = 0$