TRIQS/triqs_ctseg 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
solver_core.cpp
1// Copyright (c) 2022--present, The Simons Foundation
2// Copyright (c) 2022--present, Max Planck Institute for Polymer Research, Mainz, Germany
3// This file is part of TRIQS/ctseg and is licensed under the terms of GPLv3 or later.
4// SPDX-License-Identifier: GPL-3.0-or-later
5// See LICENSE in the root of this distribution for details.
6
7#include <triqs/mc_tools/mc_generic.hpp>
8#include <triqs/utility/callbacks.hpp>
9
10#include "solver_core.hpp"
11#include "work_data.hpp"
12#include "configuration.hpp"
13#include "measures.hpp"
14#include "moves.hpp"
15#include "logs.hpp"
16
17namespace triqs_ctseg {
18
19 // ---------------------------------------------------------------------------
20
22
23 beta = p.beta;
24 tau_t::set_beta(beta);
25
26 inputs.Delta = block_gf<imtime>({beta, Fermion, p.n_tau}, p.gf_struct);
27 inputs.D0t = make_block2_gf<imtime>({beta, Boson, p.n_tau_bosonic}, p.gf_struct);
28 inputs.Jperpt = gf<imtime>({beta, Boson, p.n_tau_bosonic}, {1, 1});
29
30 inputs.Delta() = 0;
31 inputs.D0t() = 0;
32 inputs.Jperpt() = 0;
33 };
34
35 // ---------------------------------------------------------------------------
36
37 void solver_core::solve(solve_params_t const &solve_params_input) {
38
39 // http://patorjk.com/software/taag/#p=display&f=Calvin%20S&t=TRIQS%20ctseg
40 if (c.rank() == 0)
41 std::cout << "\n"
42 "╔╦╗╦═╗╦╔═╗ ╔═╗ ┌─┐┌┬┐┌─┐┌─┐┌─┐\n"
43 " ║ ╠╦╝║║═╬╗╚═╗ │ │ └─┐├┤ │ ┬\n"
44 " ╩ ╩╚═╩╚═╝╚╚═╝ └─┘ ┴ └─┘└─┘└─┘\n";
45
46 // ................ Parameters .................
47 // Store the solve_params
48 solve_params = solve_params_input;
49 // Set tau mesh parameters for results to default if not supplied
50 if (solve_params_input.n_tau_G == 0) solve_params.n_tau_G = constr_params.n_tau;
51 if (solve_params_input.n_tau_G == 0) solve_params.n_tau_chi2 = constr_params.n_tau_bosonic;
52 // Merge constr_params and solve_params
54
55 // ................ Work data & Configuration ...................
56
57 // Initialize work data
58 work_data_t wdata{p, inputs, c};
59 // Initialize configuration
60 configuration_t config{wdata.n_color};
61 // Start from a non-empty configuration when Delta(tau) = 0
62 if (not wdata.has_Delta) { config.seglists[0].push_back(segment_t::full_line()); }
63
64 // ................ QMC ...................
65
66 auto CTQMC = triqs::mc_tools::mc_generic<double>(p.random_name, p.random_seed, p.verbosity);
67
68 // Initialize moves
69 if (wdata.has_Delta) {
70 if (p.move_insert_segment) CTQMC.add_move(moves::insert_segment{wdata, config, CTQMC.get_rng()}, "insert");
71 if (p.move_remove_segment) CTQMC.add_move(moves::remove_segment{wdata, config, CTQMC.get_rng()}, "remove");
72 if (p.move_double_insert_segment) CTQMC.add_move(moves::double_insert_segment{wdata, config, CTQMC.get_rng()}, "double insert");
73 if (p.move_double_remove_segment) CTQMC.add_move(moves::double_remove_segment{wdata, config, CTQMC.get_rng()}, "double remove");
74 if (p.move_move_segment) CTQMC.add_move(moves::move_segment{wdata, config, CTQMC.get_rng()}, "move");
75 if (p.move_split_segment) CTQMC.add_move(moves::split_segment{wdata, config, CTQMC.get_rng()}, "split");
76 if (p.move_regroup_segment) CTQMC.add_move(moves::regroup_segment{wdata, config, CTQMC.get_rng()}, "regroup");
77 }
78
79 if (wdata.has_Jperp) {
81 CTQMC.add_move(moves::insert_spin_segment{wdata, config, CTQMC.get_rng()}, "spin insert");
82
84 CTQMC.add_move(moves::remove_spin_segment{wdata, config, CTQMC.get_rng()}, "spin remove");
85 }
86
87 if (wdata.has_Jperp and wdata.has_Delta) {
89 CTQMC.add_move(moves::split_spin_segment{wdata, config, CTQMC.get_rng()}, "spin split");
90
92 CTQMC.add_move(moves::regroup_spin_segment{wdata, config, CTQMC.get_rng()}, "spin regroup");
93 }
94
95 if (wdata.has_Jperp) {
96 if (p.move_swap_spin_lines) CTQMC.add_move(moves::swap_spin_lines{wdata, config, CTQMC.get_rng()}, "spin swap");
97 }
98
99 // Initialize measurements
100 if (p.measure_G_tau) CTQMC.add_measure(measures::G_F_tau{p, wdata, config, results}, "G(tau)/F(tau)");
101 if (p.measure_densities) CTQMC.add_measure(measures::densities{p, wdata, config, results}, "Densities");
102 if (p.measure_average_sign) CTQMC.add_measure(measures::average_sign{p, wdata, config, results}, "Average Sign");
103 if (p.measure_nn_static) CTQMC.add_measure(measures::nn_static{p, wdata, config, results}, "<nn>");
104 if (p.measure_nn_tau) CTQMC.add_measure(measures::nn_tau{p, wdata, config, results}, "<n(tau)n(0)>");
105 if (p.measure_nn_nu_dlr) CTQMC.add_measure(measures::nn_nu_dlr{p, wdata, config, results}, "<n(nu)n(-nu)>");
106 if (p.measure_Sperp_tau) CTQMC.add_measure(measures::Sperp_tau{p, wdata, config, results}, "<S_x(tau)S_x(0)>");
107 if (p.measure_pert_order) {
108 if (wdata.has_Delta) {
109 CTQMC.add_measure(measures::pert_order{[&]() { return config.Delta_order(); }, results.pert_order_Delta,
110 results.average_order_Delta},
111 "Perturbation order Delta");
112 }
113 if (wdata.has_Jperp) {
114 CTQMC.add_measure(measures::pert_order{[&]() { return config.Jperp_order(); }, results.pert_order_Jperp,
115 results.average_order_Jperp},
116 "Perturbation order Jperp");
117 }
118 }
119 if (p.measure_state_hist) CTQMC.add_measure(measures::state_hist{p, wdata, config, results}, "State histograms");
120 if (p.measure_g2w || p.measure_g3w)
121 CTQMC.add_measure(measures::four_point{p, wdata, config, results}, "Four-point correlation function");
122 if (p.visualize_config) CTQMC.add_measure(measures::visualize_config{config}, "Visualizing configurations");
123
124 // Run and collect results
125 CTQMC.warmup_and_accumulate(p.n_warmup_cycles, p.n_cycles, p.length_cycle,
126 triqs::utility::clock_callback(p.max_time));
127 CTQMC.collect_results(c);
128
129 // Report sign and average order
130 if (c.rank() == 0) {
131 spdlog::info("Average sign: {}", results.average_sign);
132 if (results.average_order_Delta)
133 spdlog::info("Average perturbation order in Delta: {:.3f}", results.average_order_Delta.value());
134 if (results.average_order_Jperp)
135 spdlog::info("Average perturbation order in Jperp: {:.3f}", results.average_order_Jperp.value());
136 }
137
138 } // solve
139
140 // ----------------- Save to h5 file -----------------------
141
142#define STR(x) #x
143#define STRINGIZE(x) STR(x)
144
145 // Function that writes the solver_core to hdf5 file
146 void h5_write(h5::group h5group, std::string subgroup_name, solver_core const &s) {
147 auto grp = h5group.create_group(subgroup_name);
148 h5_write_attribute(grp, "Format", solver_core::hdf5_format());
149 h5_write_attribute(grp, "TRIQS_GIT_HASH", std::string(STRINGIZE(TRIQS_GIT_HASH)));
150 h5_write_attribute(grp, "CTSEG_GIT_HASH", std::string(STRINGIZE(CTSEG_GIT_HASH)));
151 h5_write(grp, "constr_params", s.constr_params);
152 h5_write(grp, "solve_params", s.solve_params);
153 h5_write(grp, "inputs", s.inputs);
154 h5_write(grp, "results", s.results);
155 }
156
157 // Function that reads all containers in hdf5 file
158 solver_core solver_core::h5_read_construct(h5::group h5group, std::string subgroup_name) {
159 auto grp = h5group.open_group(subgroup_name);
160 auto constr_params = h5_read<constr_params_t>(grp, "constr_params");
161 auto s = solver_core{constr_params};
162 h5_read(grp, "solve_params", s.solve_params);
163 h5_read(grp, "inputs", s.inputs);
164 h5_read(grp, "results", s.results);
165 return s;
166 }
167
168} // namespace triqs_ctseg
Continuous-time hybridization-expansion quantum Monte Carlo solver.
results_t results
Container for all results accumulated by the CTQMC simulation.
solver_core(constr_params_t const &p)
Initialize the solver.
void solve(solve_params_t const &p)
Solve the impurity problem.
constr_params_t constr_params
Parameters used for constructing the solver.
solve_params_t solve_params
Parameters passed to the solve() method.
static void set_beta(double beta)
Set the temperature.
Definition tau_t.hpp:42
Parameters used for constructing the solver class.
Definition params.hpp:16
gf_struct_t gf_struct
Structure of the Green's function (names and sizes of blocks).
Definition params.hpp:22
int n_tau_bosonic
Number of time slices for bosonic functions.
Definition params.hpp:28
int n_tau
Number of time slices for fermionic functions.
Definition params.hpp:25
double beta
Inverse temperature .
Definition params.hpp:19
A struct combining both constr_params_t and solve_params_t.
Definition params.hpp:187
Parameters passed to the solve() method of the solver class.
Definition params.hpp:34
bool move_insert_spin_segment
Whether to perform the move insert spin segment.
Definition params.hpp:105
int n_tau_G
Number of points on which to measure / (defaults to n_tau).
Definition params.hpp:43
bool move_double_insert_segment
Whether to perform the move double insert segment.
Definition params.hpp:90
bool move_move_segment
Whether to perform the move move segment.
Definition params.hpp:96
bool measure_nn_static
Whether to measure .
Definition params.hpp:137
bool move_swap_spin_lines
Whether to perform the move swap spin lines.
Definition params.hpp:117
bool measure_average_sign
Whether to measure the average sign.
Definition params.hpp:134
int verbosity
Verbosity level.
Definition params.hpp:79
bool move_remove_segment
Whether to perform the move remove segment.
Definition params.hpp:87
bool visualize_config
Output characteristic configurations in a separate file.
Definition params.hpp:183
int n_warmup_cycles
Number of cycles for thermalization.
Definition params.hpp:67
bool measure_g2w
Whether to measure three-point correlation function.
Definition params.hpp:152
bool measure_state_hist
Whether to measure state histograms.
Definition params.hpp:149
bool measure_Sperp_tau
Whether to measure .
Definition params.hpp:146
bool measure_nn_nu_dlr
Whether to measure .
Definition params.hpp:143
bool move_double_remove_segment
Whether to perform the move double remove segment.
Definition params.hpp:93
bool measure_nn_tau
Whether to measure .
Definition params.hpp:140
bool move_insert_segment
Whether to perform the move insert segment.
Definition params.hpp:84
int n_cycles
Number of QMC cycles.
Definition params.hpp:61
bool measure_g3w
Whether to measure four-point correlation function.
Definition params.hpp:155
bool move_regroup_spin_segment
Whether to perform the move remove spin segment.
Definition params.hpp:114
int max_time
Maximum runtime in seconds, use -1 to set infinite.
Definition params.hpp:76
int random_seed
Seed for random number generator.
Definition params.hpp:70
std::string random_name
Name of random number generator.
Definition params.hpp:73
bool measure_G_tau
Whether to measure .
Definition params.hpp:125
bool move_regroup_segment
Whether to perform the move group into spin segment.
Definition params.hpp:102
int length_cycle
Length of a single QMC cycle.
Definition params.hpp:64
bool move_split_spin_segment
Whether to perform the move insert spin segment.
Definition params.hpp:111
bool move_split_segment
Whether to perform the move split segment.
Definition params.hpp:99
bool measure_pert_order
Whether to measure the perturbation order histograms (order in Delta and Jperp).
Definition params.hpp:122
bool measure_densities
Whether to measure densities.
Definition params.hpp:131
bool move_remove_spin_segment
Whether to perform the move remove spin segment.
Definition params.hpp:108