From e250e6b7bbd82abf196952f966235e6bbf17130e Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Fri, 14 Oct 2016 17:22:32 +0100 Subject: [PATCH] Moving parameters outside of the HMCrunner --- lib/qcd/hmc/GenericHMCrunner.h | 57 +++++++++++-------- lib/qcd/hmc/integrators/Integrator.h | 17 +++--- lib/qcd/smearing/APEsmearing.h | 8 +-- .../hmc/Test_hmc_WilsonFermionGauge_Binary.cc | 23 +++++++- 4 files changed, 68 insertions(+), 37 deletions(-) diff --git a/lib/qcd/hmc/GenericHMCrunner.h b/lib/qcd/hmc/GenericHMCrunner.h index d627c47b..bad3b9cf 100644 --- a/lib/qcd/hmc/GenericHMCrunner.h +++ b/lib/qcd/hmc/GenericHMCrunner.h @@ -7,6 +7,7 @@ Source file: ./lib/qcd/hmc/GenericHmcRunner.h Copyright (C) 2015 Author: paboyle +Author: Guido Cossu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -49,17 +50,39 @@ class BinaryHmcRunnerTemplate { // that can be injected from outside std::vector< HmcObservable* > ObservablesList; + IntegratorParameters MDparameters; GridCartesian *UGrid; GridCartesian *FGrid; GridRedBlackCartesian *UrbGrid; GridRedBlackCartesian *FrbGrid; + std::vector SerialSeed; + std::vector ParallelSeed; + + void RNGSeeds(std::vector S, std::vector P){ + SerialSeed = S; + ParallelSeed = P; + } + virtual void BuildTheAction(int argc, char **argv) = 0; // necessary? -// add here the smearing implementation? -template > + // A couple of wrapper classes + template void Run(int argc, char **argv, IOCheckpointer &Checkpoint) { + NoSmearing S; + Runner(argc, argv, Checkpoint, S); + } + + template + void Run(int argc, char **argv, IOCheckpointer &CP, SmearingPolicy &S) { + Runner(argc, argv, CP, S); + } + ////////////////////////////// + + template + void Runner(int argc, char **argv, IOCheckpointer &Checkpoint, + SmearingPolicy &Smearing) { StartType_t StartType = HotStart; std::string arg; @@ -111,17 +134,10 @@ template > GridParallelRNG pRNG(UGrid); Field U(UGrid); - // This outside - std::vector SerSeed({1, 2, 3, 4, 5}); - std::vector ParSeed({6, 7, 8, 9, 10}); - - // these decisions outside - NoSmearing SmearingPolicy; - typedef MinimumNorm2, + typedef MinimumNorm2 IntegratorType; // change here to change the algorithm - IntegratorParameters MDpar(20, 1.0); - IntegratorType MDynamics(UGrid, MDpar, TheAction, SmearingPolicy); + IntegratorType MDynamics(UGrid, MDparameters, TheAction, Smearing); HMCparameters HMCpar; HMCpar.StartTrajectory = StartTraj; @@ -131,20 +147,20 @@ template > if (StartType == HotStart) { // Hot start HMCpar.MetropolisTest = true; - sRNG.SeedFixedIntegers(SerSeed); - pRNG.SeedFixedIntegers(ParSeed); + sRNG.SeedFixedIntegers(SerialSeed); + pRNG.SeedFixedIntegers(ParallelSeed); Implementation::HotConfiguration(pRNG, U); } else if (StartType == ColdStart) { // Cold start HMCpar.MetropolisTest = true; - sRNG.SeedFixedIntegers(SerSeed); - pRNG.SeedFixedIntegers(ParSeed); + sRNG.SeedFixedIntegers(SerialSeed); + pRNG.SeedFixedIntegers(ParallelSeed); Implementation::ColdConfiguration(pRNG, U); } else if (StartType == TepidStart) { // Tepid start HMCpar.MetropolisTest = true; - sRNG.SeedFixedIntegers(SerSeed); - pRNG.SeedFixedIntegers(ParSeed); + sRNG.SeedFixedIntegers(SerialSeed); + pRNG.SeedFixedIntegers(ParallelSeed); Implementation::TepidConfiguration(pRNG, U); } else if (StartType == CheckpointStart) { HMCpar.MetropolisTest = true; @@ -152,10 +168,9 @@ template > Checkpoint.CheckpointRestore(StartTraj, U, sRNG, pRNG); } - SmearingPolicy.set_Field(U); + Smearing.set_Field(U); HybridMonteCarlo HMC(HMCpar, MDynamics, sRNG, pRNG, U); - //HMC.AddObservable(&Checkpoint); for (int obs = 0; obs < ObservablesList.size(); obs++) HMC.AddObservable(ObservablesList[obs]); @@ -170,16 +185,12 @@ typedef BinaryHmcRunnerTemplate BinaryHmcRunner; typedef BinaryHmcRunnerTemplate BinaryHmcRunnerF; typedef BinaryHmcRunnerTemplate BinaryHmcRunnerD; -//typedef BinaryHmcRunnerTemplate > NerscTestHmcRunner; - - template using BinaryHmcRunnerTemplateHirep = BinaryHmcRunnerTemplate; -//typedef BinaryHmcRunnerTemplate, ScalarFields> ScalarBinaryHmcRunner; typedef BinaryHmcRunnerTemplate ScalarBinaryHmcRunner; } } diff --git a/lib/qcd/hmc/integrators/Integrator.h b/lib/qcd/hmc/integrators/Integrator.h index 29c1912d..43974f48 100644 --- a/lib/qcd/hmc/integrators/Integrator.h +++ b/lib/qcd/hmc/integrators/Integrator.h @@ -46,27 +46,28 @@ namespace Grid { namespace QCD { struct IntegratorParameters { - unsigned int - Nexp; // number of terms in the Taylor expansion of the exponential unsigned int MDsteps; // number of outer steps RealD trajL; // trajectory length RealD stepsize; // trajectory stepsize - IntegratorParameters(int MDsteps_, RealD trajL_ = 1.0, - unsigned int Nexp_ = 12) - : Nexp(Nexp_), - MDsteps(MDsteps_), + IntegratorParameters(int MDsteps_ = 10, RealD trajL_ = 1.0) + : MDsteps(MDsteps_), trajL(trajL_), stepsize(trajL / MDsteps){ // empty body constructor }; + void set(int MDsteps_, RealD trajL_){ + MDsteps = MDsteps_; + trajL = trajL_; + stepsize = trajL/MDsteps; + } + + void print_parameters() { std::cout << GridLogMessage << "[Integrator] Trajectory length : " << trajL << std::endl; std::cout << GridLogMessage << "[Integrator] Number of MD steps : " << MDsteps << std::endl; std::cout << GridLogMessage << "[Integrator] Step size : " << stepsize << std::endl; - std::cout << GridLogMessage << "[Integrator] Exponential approx.: " << Nexp << std::endl; - } }; diff --git a/lib/qcd/smearing/APEsmearing.h b/lib/qcd/smearing/APEsmearing.h index 4db11338..467bf2c6 100644 --- a/lib/qcd/smearing/APEsmearing.h +++ b/lib/qcd/smearing/APEsmearing.h @@ -92,19 +92,19 @@ temp_Sigma = -rho_numu*staple*iLambda_nu; //ok //-r_numu*U_nu(x+mu)*Udag_mu(x+nu)*Udag_nu(x)*Lambda_nu(x) - Gimpl::AddGaugeLink(SigmaTerm, temp_Sigma, mu); + Gimpl::AddLink(SigmaTerm, temp_Sigma, mu); sh_field = Cshift(iLambda_nu, mu, 1);// general also for Gparity? temp_Sigma = rho_numu*sh_field*staple; //ok //r_numu*Lambda_nu(mu)*U_nu(x+mu)*Udag_mu(x+nu)*Udag_nu(x) - Gimpl::AddGaugeLink(SigmaTerm, temp_Sigma, mu); + Gimpl::AddLink(SigmaTerm, temp_Sigma, mu); sh_field = Cshift(iLambda_mu, nu, 1); temp_Sigma = -rho_munu*staple*U_nu*sh_field*adj(U_nu); //ok //-r_munu*U_nu(x+mu)*Udag_mu(x+nu)*Lambda_mu(x+nu)*Udag_nu(x) - Gimpl::AddGaugeLink(SigmaTerm, temp_Sigma, mu); + Gimpl::AddLink(SigmaTerm, temp_Sigma, mu); staple = zero; sh_field = Cshift(U_nu, mu, 1); @@ -116,7 +116,7 @@ sh_field = Cshift(u_tmp, mu, 1); temp_Sigma += -rho_numu*sh_field*adj(U_mu)*U_nu; sh_field = Cshift(temp_Sigma, nu, -1); - Gimpl::AddGaugeLink(SigmaTerm, sh_field, mu); + Gimpl::AddLink(SigmaTerm, sh_field, mu); } } diff --git a/tests/hmc/Test_hmc_WilsonFermionGauge_Binary.cc b/tests/hmc/Test_hmc_WilsonFermionGauge_Binary.cc index 6a5b6f52..9024b4e2 100644 --- a/tests/hmc/Test_hmc_WilsonFermionGauge_Binary.cc +++ b/tests/hmc/Test_hmc_WilsonFermionGauge_Binary.cc @@ -49,6 +49,8 @@ class HMCRunnerParameters : Serializable { std::string, format, std::string, conf_prefix, std::string, rng_prefix, + double, rho, + int, SmearingLevels, ); HMCRunnerParameters() {} @@ -115,11 +117,21 @@ class HmcRunner : public BinaryHmcRunner { // Then force all checkpoint to have few common functions // return an object that is then passed to the Run function - PlaquetteLogger PlaqLog(std::string("Plaquette")); + PlaquetteLogger PlaqLog( + std::string("Plaquette")); ObservablesList.push_back(&PlaqLog); ObservablesList.push_back(&Checkpoint); - Run(argc, argv, Checkpoint); + // Smearing section, omit if not needed + double rho = 0.1; // smearing parameter + int Nsmear = 2; // number of smearing levels + Smear_Stout Stout(rho); + SmearedConfiguration SmearingPolicy( + UGrid, Nsmear, Stout); + /////////////////// + + // Run(argc, argv, Checkpoint, SmearingPolicy); + Run(argc, argv, Checkpoint); // no smearing }; }; } @@ -134,5 +146,12 @@ int main(int argc, char **argv) { HmcRunner TheHMC; + // Seeds for the random number generators + std::vector SerSeed({1, 2, 3, 4, 5}); + std::vector ParSeed({6, 7, 8, 9, 10}); + TheHMC.RNGSeeds(SerSeed, ParSeed); + + TheHMC.MDparameters.set(20, 1.0);// MDsteps, traj length + TheHMC.BuildTheAction(argc, argv); }