34#if defined STOUTMODE && STOUTMODE>0
36#include "gauge/stout_smear_nch.h"
38#include "gauge/stout_smear_nchm.h"
40#include "gauge/stout_smear.h"
44#include "gauge/stout_smear.h"
46#define STOUTSTEPS STOUTSMEAR
56int stout_nsteps = STOUTSTEPS;
73 std::string config_file;
81template <
typename group,
typename atype = hila::arithmetic_type<group>>
88 stout_smear(U, tU, stoutc, stout_nsteps);
90 nch_stout_smear(U, tU, stoutc, stout_nsteps);
92 std::vector<std::array<Field<int>, NDIM>> niterl(stout_nsteps);
93 nchm_stout_smear(U, tU, niterl, stoutc);
95 for(
int i=0; i<niterl.size(); ++i) {
100 titerl[X] = (double)niterl[i][d][X];
102 int tmaxiter = titerl.
max();
103 if(tmaxiter>maxiter) {
107 hila::out0 <<
"stout step "<<i<<
" exp niter: " << maxiter <<
"\n";
110 stout_smear(U, tU, stoutc, stout_nsteps);
120 double res = measure_s_bp(tU);
122 atype c12 = -1.0 / 12.0;
123 atype c11 = 1.0 - 8.0 * c12;
124 double res = measure_s_impr(tU, c11, c12);
127 atype c11 = 1.0 - 8.0 * c12;
128 double res = measure_s_impr(tU, c11, c12);
131 atype c11 = 1.0 - 8.0 * c12;
132 double res = measure_s_impr(tU, c11, c12);
134 double res = measure_s_log_plaq(tU);
136 double res = measure_s_wplaq(tU);
142template <
typename group,
typename atype = hila::arithmetic_type<group>>
145 atype eps = delta / group::size();
149 std::vector<GaugeField<group>> tUl(stout_nsteps + 1);
150 std::vector<VectorField<group>> tstapl(stout_nsteps);
153 stout_smear(U, tUl, tstapl, stoutc);
155 nch_stout_smear(U, tUl, tstapl, stoutc);
157 std::vector<std::array<Field<int>, NDIM>> niterl(stout_nsteps);
158 nchm_stout_smear(U, tUl, tstapl, niterl, stoutc);
160 std::vector<VectorField<group>> tUKl(stout_nsteps);
161 stout_smeark(U, tUl, tstapl, tUKl, stoutc);
179 get_force_bp_add(tU, tE, eps);
181 atype c12 = -1.0 / 12.0;
182 atype c11 = 1.0 - 8.0 * c12;
183 get_force_impr_add(tU, tE, eps * c11, eps * c12);
186 atype c11 = 1.0 - 8.0 * c12;
187 get_force_impr_add(tU, tE, eps * c11, eps * c12);
190 atype c11 = 1.0 - 8.0 * c12;
191 get_force_impr_add(tU, tE, eps * c11, eps * c12);
193 get_force_log_plaq_add(tU, tE, eps);
195 get_force_wplaq_add(tU, tE, eps);
203 stout_smear_force(tUl, tstapl, tE, KS, stoutc);
205 nch_stout_smear_force(tUl, tstapl, tE, KS, stoutc);
207 nchm_stout_smear_force(tUl, tstapl, tE, KS, niterl, stoutc);
209 stout_smeark_force(tUl, tstapl, tUKl, tE, KS, stoutc);
213 onsites(
ALL) E[d1][X] += KS[d1][X];
220template <
typename group,
typename atype = hila::arithmetic_type<group>>
224 onsites(
ALL) U[d][X] =
chexp(E[d][X].expand_scaled(delta)) * U[d][X];
228template <
typename group>
234 onsites(
ALL) e2 += E[d][X].squarenorm();
236 return e2.
value() / 2;
239template <
typename group>
241 const parameters &p,
double &plaq) {
243 plaq = p.beta * measure_s(U);
244 double e2 = measure_e2(E);
245 return plaq + e2 / 2;
248template <
typename group>
250 const parameters &p) {
253 return measure_action(U, E, p, plaq);
257template <
typename group,
typename atype = hila::arithmetic_type<group>>
262 update_U(U, E, p.dt / 2);
264 for (
int n = 0; n < p.trajlen - 1; ++n) {
265 update_E(U, E, p.beta * p.dt);
266 update_U(U, E, p.dt);
269 update_E(U, E, p.beta * p.dt);
270 update_U(U, E, p.dt / 2);
279template <
typename group>
283 static bool first =
true;
287 <<
"LMEAS: s-local plaq E^2 P.real P.imag\n";
290 auto slocal = measure_s(U) / (lattice.volume() * NDIM * (NDIM - 1) / 2);
291 auto plaq = measure_s_wplaq(U) / (lattice.volume() * NDIM * (NDIM - 1) / 2);
292 auto e2 = measure_e2(E) / (lattice.volume() * NDIM);
294 hila::out0 << string_format(
"MEAS % 0.6e % 0.6e % 0.6e % 0.6e % 0.6e", slocal, plaq, e2,
295 poly.real(), poly.imag())
303template <
typename group>
304void checkpoint(
const GaugeField<group> &U,
int trajectory,
const parameters &p) {
307 std::string config_file =
308 p.config_file +
"_" + std::to_string(
abs((trajectory + 1) / p.n_save) % 2);
314 outf.open(
"run_status", std::ios::out | std::ios::trunc);
315 outf <<
"trajectory " << trajectory + 1 <<
'\n';
316 outf <<
"seed " <<
static_cast<uint64_t
>(
hila::random() * (1UL << 61)) <<
'\n';
319 outf <<
"config name " << config_file <<
'\n';
322 std::stringstream msg;
324 hila::timestamp(msg.str().c_str());
327template <
typename group>
333 if (status.
open(
"run_status",
false,
false)) {
335 trajectory = status.
get(
"trajectory");
336 seed = status.
get(
"seed");
337 p.time_offset = status.
get(
"time");
339 std::string config_file = status.
get(
"config name");
342 U.config_read(config_file);
346 in.open(p.config_file, std::ios::in | std::ios::binary);
350 U.config_read(p.config_file);
363int main(
int argc,
char **argv) {
395 hila::out0 <<
"Using floating point epsilon: " << fp<ftype>::epsilon <<
"\n";
403 lsize = par.get(
"lattice size");
405 p.beta = par.get(
"beta");
407 p.dt = par.get(
"dt");
409 p.trajlen = par.get(
"trajectory length");
411 p.n_traj = par.get(
"number of trajectories");
413 p.n_therm = par.get(
"thermalization trajs");
415 p.gflow_freq = par.get(
"gflow freq");
417 p.gflow_max_l = par.get(
"gflow max lambda");
419 p.gflow_l_step = par.get(
"gflow lambda step");
421 p.gflow_a_accu = par.get(
"gflow abs. accuracy");
423 p.gflow_r_accu = par.get(
"gflow rel. accuracy");
425 long seed = par.get(
"random seed");
427 p.n_save = par.get(
"trajs/saved");
429 p.config_file = par.get(
"config name");
434 hila::out0 <<
"using stout smearing: nsteps=" << stout_nsteps <<
" , c=" << stoutc <<
" , ";
447 lattice.
setup(lsize);
457 if (!restore_checkpoint(U, start_traj, p)) {
459 hila::out0 <<
"cold start: initial link variables set to identity\n";
467 auto orig_trajlen = p.trajlen;
471 double g_act_old, act_old, g_act_new, act_new;
472 g_act_old = p.beta * measure_s(U);
474 for (
int trajectory = start_traj; trajectory < p.n_traj; ++trajectory) {
475 if (trajectory < p.n_therm) {
479 if (trajectory < p.n_therm * 3.0 / 4.0) {
480 p.dt = orig_dt * (0.1 + 0.9 * 4.0 / 3.0 * trajectory / p.n_therm);
481 p.trajlen = orig_trajlen;
484 p.trajlen = orig_trajlen;
490 for (
int irej = 0; irej < nreject - 1; ++irej) {
494 hila::out0 <<
" thermalization step size(reduzed due to multiple reject) dt="
495 << std::setprecision(8) << p.dt <<
'\n';
497 hila::out0 <<
" thermalization step size dt=" << std::setprecision(8) << p.dt
500 }
else if (trajectory == p.n_therm) {
502 p.trajlen = orig_trajlen;
503 hila::out0 <<
" normal stepsize dt=" << std::setprecision(8) << p.dt <<
'\n';
506 update_timer.start();
513 act_old = g_act_old + measure_e2(E) / 2;
517 act_new = measure_action(U, E, p, g_act_new);
522 if (trajectory < p.n_therm) {
534 hila::out0 << std::setprecision(12) <<
"HMC " << trajectory <<
" S_TOT_start " << act_old
535 <<
" dS_TOT " << std::setprecision(6) << act_new - act_old
536 << std::setprecision(12);
538 hila::out0 <<
" REJECT" <<
" --> S_GAUGE " << g_act_old;
541 hila::out0 <<
" ACCEPT" <<
" --> S_GAUGE " << g_act_new;
542 g_act_old = g_act_new;
549 hila::out0 <<
"Measure_start " << trajectory <<
'\n';
551 measure_timer.start();
555 measure_timer.stop();
557 hila::out0 <<
"Measure_end " << trajectory <<
'\n';
559 if (trajectory >= p.n_therm) {
561 if (p.gflow_freq > 0 && trajectory % p.gflow_freq == 0) {
562 int gtrajectory = trajectory / p.gflow_freq;
563 if (p.gflow_l_step > 0) {
567 int nflow_steps = (int)(p.gflow_max_l / p.gflow_l_step);
570 hila::out0 <<
"Gflow_start " << gtrajectory <<
'\n';
574 ftype t_step = t_step0;
575 measure_gradient_flow_stuff(V, (ftype)0.0, t_step);
576 t_step = do_gradient_flow_adapt(V, (ftype)0.0, p.gflow_l_step, p.gflow_a_accu,
577 p.gflow_r_accu, t_step);
578 measure_gradient_flow_stuff(V, p.gflow_l_step, t_step);
581 for (
int i = 1; i < nflow_steps; ++i) {
584 do_gradient_flow_adapt(V, i * p.gflow_l_step, (i + 1) * p.gflow_l_step,
585 p.gflow_a_accu, p.gflow_r_accu, t_step);
587 measure_gradient_flow_stuff(V, (i + 1) * p.gflow_l_step, t_step);
592 hila::out0 <<
"Gflow_end " << gtrajectory <<
" time " << std::setprecision(3)
598 if (p.n_save > 0 && trajectory>=0 && (trajectory + 1) % p.n_save == 0) {
599 checkpoint(U, trajectory, p);
Array< n, m, T > exp(Array< n, m, T > a)
Exponential.
The field class implements the standard methods for accessing Fields. Hilapp replaces the parity acce...
T max(Parity par=ALL) const
Find maximum value from Field.
void reunitarize_gauge()
Reunitarize Gauge Field consisting of matrices.
void config_write(const std::string &filename) const
config_write writes the gauge field to file, with additional "verifying" header
static constexpr int size()
Returns size of Vector or square Matrix.
Special reduction class: enables delayed and non-blocking reductions, which are not possible with the...
const T value()
Return value of the reduction variable. Wait for the comms if needed.
Reduction & allreduce(bool b=true)
allreduce(bool) turns allreduce on or off. By default on.
Reduction & delayed(bool b=true)
deferred(bool) turns deferred on or off. By default turns on.
void setup(const CoordinateVector &siz)
General lattice setup.
T abs(const Complex< T > &a)
Return absolute value of Complex number.
#define foralldir(d)
Macro to loop over (all) Direction(s)
constexpr Parity ALL
bit pattern: 011
int chexp(const Matrix_t< n, m, T, MT > &mat, Matrix_t< n, m, T, MT > &omat, Mt(&pl)[n])
Calculate exp of a square matrix.
double random()
Real valued uniform random number generator.
int myrank()
rank of this node
std::ostream out0
This writes output only from main process (node 0)
void initialize(int argc, char **argv)
Read in command line arguments. Initialise default stream and MPI communication.
void seed_random(uint64_t seed, bool device_rng=true)
Seed random generators with 64-bit unsigned value. On MPI shuffles the seed so that different MPI ran...
T broadcast(T &var, int rank=0)
Broadcast the value of var to all MPI ranks from rank (default=0).
void finishrun()
Normal, controlled exit - all nodes must call this. Prints timing information and information about c...
Complex< double > measure_polyakov(const GaugeField< T > &U, Direction dir=Direction(NDIM - 1))
Measure Polyakov lines to direction dir.
void do_trajectory(GaugeField< group > &U, const parameters &p)
Evolve gauge field.
void measure_stuff(const GaugeField< group > &U, const parameters &p)
Measures Polyakov lines and Wilson action.