From 68fe0769a11a15e0f6ac19ab79c53d2a79cd9b36 Mon Sep 17 00:00:00 2001 From: neo Date: Mon, 6 Jul 2015 16:17:32 +0900 Subject: [PATCH] Added minimum norm integrator Little rearrangement of HMC and integrator classes --- lib/qcd/hmc/HMC.h | 15 +-- lib/qcd/hmc/integrators/Integrator_base.h | 111 +++++++++++++++++----- tests/Test_hmc_WilsonGauge.cc | 7 +- 3 files changed, 94 insertions(+), 39 deletions(-) diff --git a/lib/qcd/hmc/HMC.h b/lib/qcd/hmc/HMC.h index 01fb2f9c..f2bb4bcb 100644 --- a/lib/qcd/hmc/HMC.h +++ b/lib/qcd/hmc/HMC.h @@ -10,7 +10,6 @@ #include #include -#include namespace Grid{ namespace QCD{ @@ -30,10 +29,8 @@ namespace Grid{ class HybridMonteCarlo{ const HMCparameters Params; GridSerialRNG sRNG; - GridParallelRNG pRNG; Integrator& MD; - bool metropolis_test(const RealD DeltaH){ RealD rn_test; RealD prob = std::exp(-DeltaH); @@ -54,7 +51,7 @@ namespace Grid{ RealD evolve_step(LatticeLorentzColourMatrix& U){ - MD.init(U,pRNG); // set U and initialize P and phi's + MD.init(U); // set U and initialize P and phi's RealD H0 = MD.S(U); // current state std::cout<<"Total H before = "<< H0 << "\n"; @@ -70,14 +67,12 @@ namespace Grid{ public: HybridMonteCarlo(HMCparameters Pms, - Integrator& MolDyn, - GridBase* grid): - Params(Pms),MD(MolDyn),pRNG(grid){ + Integrator& MolDyn): + Params(Pms),MD(MolDyn){ //FIXME - // initialize RNGs + // initialize RNGs also with seed sRNG.SeedRandomDevice(); - pRNG.SeedRandomDevice(); } ~HybridMonteCarlo(){}; @@ -85,7 +80,7 @@ namespace Grid{ void evolve(LatticeLorentzColourMatrix& Uin){ Real DeltaH; - + // Thermalizations for(int iter=1; iter <= Params.ThermalizationSteps; ++iter){ std::cout << "-- # Thermalization step = "<< iter << "\n"; diff --git a/lib/qcd/hmc/integrators/Integrator_base.h b/lib/qcd/hmc/integrators/Integrator_base.h index 4891eb5e..9b47a19d 100644 --- a/lib/qcd/hmc/integrators/Integrator_base.h +++ b/lib/qcd/hmc/integrators/Integrator_base.h @@ -24,9 +24,6 @@ namespace Grid{ typedef std::vector ActionSet; typedef std::vector ObserverList; - class LeapFrog; - - struct IntegratorParameters{ int Nexp; int MDsteps; // number of outer steps @@ -46,20 +43,20 @@ namespace Grid{ } - - - template< class IntegratorPolicy > class Integrator{ private: IntegratorParameters Params; const ActionSet as; const std::vector Nrel; //relative step size per level - //ObserverList observers; // not yet std::unique_ptr P; - - IntegratorPolicy TheIntegrator;// contains parameters too + GridParallelRNG pRNG; + //ObserverList observers; // not yet + + IntegratorPolicy TheIntegrator; + void register_observers(); + void notify_observers(); void update_P(LatticeLorentzColourMatrix&U, int level,double ep){ for(int a=0; a& clock, - Integrator* Integ); + Integrator* Integ); public: - Integrator(IntegratorParameters Par, + Integrator(GridBase* grid, IntegratorParameters Par, ActionSet& Aset, std::vector Nrel_): - Params(Par),as(Aset),Nrel(Nrel_){ + Params(Par),as(Aset),Nrel(Nrel_),P(new LatticeLorentzColourMatrix(grid)),pRNG(grid){ assert(as.size() == Nrel.size()); + pRNG.SeedRandomDevice(); }; ~Integrator(){} //Initialization of momenta and actions - void init(LatticeLorentzColourMatrix& U, - GridParallelRNG& pRNG){ + void init(LatticeLorentzColourMatrix& U){ std::cout<< "Integrator init\n"; - if (!P){ - std::unique_ptr Pnew(new LatticeLorentzColourMatrix(U._grid)); - P = std::move(Pnew); - } + MDutils::generate_momenta(*P,pRNG); for(int level=0; level< as.size(); ++level){ for(int actionID=0; actionID& clock); + void step (LatticeLorentzColourMatrix& U, + int level, std::vector& clock, + Integrator* Integ){ + // level : current level + // fl : final level + // eps : current step size + + int fl = Integ->as.size() -1; + double eps = Integ->Params.stepsize; + + for(int l=0; l<=level; ++l) eps/= 2.0*Integ->Nrel[l]; + + int fin = Integ->Nrel[0]; + for(int l=1; l<=level; ++l) fin*= 2.0*Integ->Nrel[l]; + fin = 3*Integ->Params.MDsteps*fin -1; + + + for(int e=0; eNrel[level]; ++e){ + + if(clock[level] == 0){ // initial half step + Integ->update_P(U,level,lambda*eps); + ++clock[level]; + for(int l=0; lupdate_U(U,0.5*eps); + + for(int l=0; lupdate_P(U,level,(1.0-2.0*lambda)*eps); + ++clock[level]; + for(int l=0; lupdate_U(U,0.5*eps); + + for(int l=0; lupdate_P(U,level,lambda*eps); + + ++clock[level]; + for(int l=0; lupdate_P(U,level,lambda*2.0*eps); + + clock[level]+=2; + for(int l=0; l& clock, Integrator* Integ){ - // cl : current level // fl : final level // eps : current step size @@ -179,7 +238,7 @@ namespace Grid{ for(int e=0; eNrel[level]; ++e){ if(clock[level] == 0){ // initial half step - Integ->update_P(U, level,eps/2); + Integ->update_P(U, level,eps/2.0); ++clock[level]; for(int l=0; lupdate_P(U, level,eps/2); + Integ->update_P(U, level,eps/2.0); ++clock[level]; for(int l=0; l Waction(6.0); //Collect actions @@ -39,13 +39,14 @@ int main (int argc, char ** argv) FullSet.push_back(Level1); // Create integrator + typedef MinimumNorm2 IntegratorAlgorithm;// change here to change the algorithm IntegratorParameters MDpar(12,30,1.0); std::vector rel ={1}; - Integrator MDleapfrog(MDpar, FullSet,rel); + Integrator MDynamics(&Fine,MDpar, FullSet,rel); // Create HMC HMCparameters HMCpar; - HybridMonteCarlo HMC(HMCpar, MDleapfrog, &Fine); + HybridMonteCarlo HMC(HMCpar, MDynamics); HMC.evolve(U);