TRIQS/triqs_ctseg unstable
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 // Measure g3w every cycle if length_cycle_g3 is not supplied
53 if (solve_params_input.length_cycle_g3 == 0) solve_params.length_cycle_g3 = solve_params.length_cycle;
54 // Merge constr_params and solve_params
56
57 // ................ Work data & Configuration ...................
58
59 // Initialize work data
60 work_data_t wdata{p, inputs, c};
61 // Initialize configuration
62 configuration_t config{wdata.n_color};
63 // Start from a non-empty configuration when Delta(tau) = 0
64 if (not wdata.has_Delta) { config.seglists[0].push_back(segment_t::full_line()); }
65
66 // ................ QMC ...................
67
68 auto CTQMC = triqs::mc_tools::mc_generic<double>(p.random_name, p.random_seed, p.verbosity);
69
70 // Initialize moves
71 if (wdata.has_Delta) {
72 if (p.move_insert_segment) CTQMC.add_move(moves::insert_segment{wdata, config, CTQMC.get_rng()}, "insert");
73 if (p.move_remove_segment) CTQMC.add_move(moves::remove_segment{wdata, config, CTQMC.get_rng()}, "remove");
74 if (p.move_double_insert_segment) CTQMC.add_move(moves::double_insert_segment{wdata, config, CTQMC.get_rng()}, "double insert");
75 if (p.move_double_remove_segment) CTQMC.add_move(moves::double_remove_segment{wdata, config, CTQMC.get_rng()}, "double remove");
76 if (p.move_move_segment) CTQMC.add_move(moves::move_segment{wdata, config, CTQMC.get_rng()}, "move");
77 if (p.move_split_segment) CTQMC.add_move(moves::split_segment{wdata, config, CTQMC.get_rng()}, "split");
78 if (p.move_regroup_segment) CTQMC.add_move(moves::regroup_segment{wdata, config, CTQMC.get_rng()}, "regroup");
79 }
80
81 if (wdata.has_Jperp) {
83 CTQMC.add_move(moves::insert_spin_segment{wdata, config, CTQMC.get_rng()}, "spin insert");
84
86 CTQMC.add_move(moves::remove_spin_segment{wdata, config, CTQMC.get_rng()}, "spin remove");
87 }
88
89 if (wdata.has_Jperp and wdata.has_Delta) {
91 CTQMC.add_move(moves::split_spin_segment{wdata, config, CTQMC.get_rng()}, "spin split");
92
94 CTQMC.add_move(moves::regroup_spin_segment{wdata, config, CTQMC.get_rng()}, "spin regroup");
95 }
96
97 if (wdata.has_Jperp) {
98 if (p.move_swap_spin_lines) CTQMC.add_move(moves::swap_spin_lines{wdata, config, CTQMC.get_rng()}, "spin swap");
99 }
100
101 // Initialize measurements
102 if (p.measure_G_tau) CTQMC.add_measure(measures::G_F_tau{p, wdata, config, results}, "G(tau)/F(tau)");
103 if (p.measure_densities) CTQMC.add_measure(measures::densities{p, wdata, config, results}, "Densities");
104 if (p.measure_average_sign) CTQMC.add_measure(measures::average_sign{p, wdata, config, results}, "Average Sign");
105 if (p.measure_nn_static) CTQMC.add_measure(measures::nn_static{p, wdata, config, results}, "<nn>");
106 if (p.measure_nn_tau) CTQMC.add_measure(measures::nn_tau{p, wdata, config, results}, "<n(tau)n(0)>");
107 if (p.measure_nn_nu_dlr) CTQMC.add_measure(measures::nn_nu_dlr{p, wdata, config, results}, "<n(nu)n(-nu)>");
108 if (p.measure_Sperp_tau) CTQMC.add_measure(measures::Sperp_tau{p, wdata, config, results}, "<S_x(tau)S_x(0)>");
109 if (p.measure_pert_order) {
110 if (wdata.has_Delta) {
111 CTQMC.add_measure(measures::pert_order{[&]() { return config.Delta_order(); }, results.pert_order_Delta,
112 results.average_order_Delta},
113 "Perturbation order Delta");
114 }
115 if (wdata.has_Jperp) {
116 CTQMC.add_measure(measures::pert_order{[&]() { return config.Jperp_order(); }, results.pert_order_Jperp,
117 results.average_order_Jperp},
118 "Perturbation order Jperp");
119 }
120 }
121 if (p.measure_state_hist) CTQMC.add_measure(measures::state_hist{p, wdata, config, results}, "State histograms");
122 if (p.measure_g2w || p.measure_g3w)
123 CTQMC.add_measure(measures::four_point{p, wdata, config, results}, "Four-point correlation function");
124 if (p.visualize_config) CTQMC.add_measure(measures::visualize_config{config}, "Visualizing configurations");
125
126 // Run and collect results
127 CTQMC.warmup_and_accumulate(p.n_warmup_cycles, p.n_cycles, p.length_cycle,
128 triqs::utility::clock_callback(p.max_time));
129 CTQMC.collect_results(c);
130
131 // Report sign and average order
132 if (c.rank() == 0) {
133 spdlog::info("Average sign: {}", results.average_sign);
134 if (results.average_order_Delta)
135 spdlog::info("Average perturbation order in Delta: {:.3f}", results.average_order_Delta.value());
136 if (results.average_order_Jperp)
137 spdlog::info("Average perturbation order in Jperp: {:.3f}", results.average_order_Jperp.value());
138 }
139
140 } // solve
141
142 // ----------------- Save to h5 file -----------------------
143
144#define STR(x) #x
145#define STRINGIZE(x) STR(x)
146
147 // Function that writes the solver_core to hdf5 file
148 void h5_write(h5::group h5group, std::string subgroup_name, solver_core const &s) {
149 auto grp = h5group.create_group(subgroup_name);
150 h5_write_attribute(grp, "Format", solver_core::hdf5_format());
151 h5_write_attribute(grp, "TRIQS_GIT_HASH", std::string(STRINGIZE(TRIQS_GIT_HASH)));
152 h5_write_attribute(grp, "CTSEG_GIT_HASH", std::string(STRINGIZE(CTSEG_GIT_HASH)));
153 h5_write(grp, "constr_params", s.constr_params);
154 h5_write(grp, "solve_params", s.solve_params);
155 h5_write(grp, "inputs", s.inputs);
156 h5_write(grp, "results", s.results);
157 }
158
159 // Function that reads all containers in hdf5 file
160 solver_core solver_core::h5_read_construct(h5::group h5group, std::string subgroup_name) {
161 auto grp = h5group.open_group(subgroup_name);
162 auto constr_params = h5_read<constr_params_t>(grp, "constr_params");
163 auto s = solver_core{constr_params};
164 h5_read(grp, "solve_params", s.solve_params);
165 h5_read(grp, "inputs", s.inputs);
166 h5_read(grp, "results", s.results);
167 return s;
168 }
169
170} // 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:191
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:109
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:94
bool move_move_segment
Whether to perform the move move segment.
Definition params.hpp:100
bool measure_nn_static
Whether to measure .
Definition params.hpp:141
bool move_swap_spin_lines
Whether to perform the move swap spin lines.
Definition params.hpp:121
bool measure_average_sign
Whether to measure the average sign.
Definition params.hpp:138
int verbosity
Verbosity level.
Definition params.hpp:83
bool move_remove_segment
Whether to perform the move remove segment.
Definition params.hpp:91
bool visualize_config
Output characteristic configurations in a separate file.
Definition params.hpp:187
int n_warmup_cycles
Number of cycles for thermalization.
Definition params.hpp:71
bool measure_g2w
Whether to measure three-point correlation function.
Definition params.hpp:156
bool measure_state_hist
Whether to measure state histograms.
Definition params.hpp:153
bool measure_Sperp_tau
Whether to measure .
Definition params.hpp:150
bool measure_nn_nu_dlr
Whether to measure .
Definition params.hpp:147
bool move_double_remove_segment
Whether to perform the move double remove segment.
Definition params.hpp:97
bool measure_nn_tau
Whether to measure .
Definition params.hpp:144
bool move_insert_segment
Whether to perform the move insert segment.
Definition params.hpp:88
int n_cycles
Number of QMC cycles.
Definition params.hpp:61
bool measure_g3w
Whether to measure four-point correlation function.
Definition params.hpp:159
bool move_regroup_spin_segment
Whether to perform the move remove spin segment.
Definition params.hpp:118
int max_time
Maximum runtime in seconds, use -1 to set infinite.
Definition params.hpp:80
int random_seed
Seed for random number generator.
Definition params.hpp:74
std::string random_name
Name of random number generator.
Definition params.hpp:77
bool measure_G_tau
Whether to measure .
Definition params.hpp:129
bool move_regroup_segment
Whether to perform the move group into spin segment.
Definition params.hpp:106
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:115
bool move_split_segment
Whether to perform the move split segment.
Definition params.hpp:103
bool measure_pert_order
Whether to measure the perturbation order histograms (order in Delta and Jperp).
Definition params.hpp:126
bool measure_densities
Whether to measure densities.
Definition params.hpp:135
bool move_remove_spin_segment
Whether to perform the move remove spin segment.
Definition params.hpp:112