mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-13 04:37:05 +01:00
Skeleton of HMC/Integrators
This commit is contained in:
@ -413,5 +413,8 @@ namespace QCD {
|
||||
#include <qcd/utils/WilsonLoops.h>
|
||||
#include <qcd/utils/SUn.h>
|
||||
#include <qcd/action/Actions.h>
|
||||
#include <qcd/hmc/integrators/Integrator_base.h>
|
||||
#include <qcd/hmc/HMC.h>
|
||||
|
||||
|
||||
#endif
|
||||
|
0
lib/qcd/hmc/.dirstamp
Normal file
0
lib/qcd/hmc/.dirstamp
Normal file
98
lib/qcd/hmc/HMC.cc
Normal file
98
lib/qcd/hmc/HMC.cc
Normal file
@ -0,0 +1,98 @@
|
||||
#include <Grid.h>
|
||||
|
||||
namespace Grid{
|
||||
namespace QCD{
|
||||
|
||||
HMCparameters::HMCparameters(){
|
||||
// FIXME fill this constructor now just default values
|
||||
|
||||
////////////////////////////// Default values
|
||||
Nsweeps = 10;
|
||||
TotalSweeps = 10;
|
||||
ThermalizationSteps = 0;
|
||||
StartingConfig = 0;
|
||||
SaveInterval = 1;
|
||||
Filename_prefix = "Conf_";
|
||||
/////////////////////////////////
|
||||
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
HybridMonteCarlo::HybridMonteCarlo(GridSerialRNG& R):RNG(R){
|
||||
//FIXME
|
||||
}
|
||||
|
||||
|
||||
void HybridMonteCarlo::evolve(LatticeColourMatrix& Uin)const{
|
||||
Real DeltaH;
|
||||
Real timer;
|
||||
|
||||
// Thermalizations
|
||||
for(int iter=1; iter <= Params.ThermalizationSteps; ++iter){
|
||||
std::cout << "-- # Thermalization step = "<< iter << "\n";
|
||||
|
||||
DeltaH = evolve_step(Uin);
|
||||
|
||||
std::cout<< "[Timing] Trajectory time (s) : "<< timer/1000.0 << "\n";
|
||||
std::cout<< "dH = "<< DeltaH << "\n";
|
||||
|
||||
// Update matrix
|
||||
//Uin = md_->get_U(); //accept every time
|
||||
}
|
||||
|
||||
// Actual updates
|
||||
for(int iter=Params.StartingConfig;
|
||||
iter < Params.Nsweeps+Params.StartingConfig; ++iter){
|
||||
std::cout << "-- # Sweep = "<< iter << "\n";
|
||||
|
||||
DeltaH = evolve_step(Uin);
|
||||
|
||||
if(metropolis_test(DeltaH)) {};//Uin = md_->get_U();
|
||||
// need sync?
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
RealD HybridMonteCarlo::evolve_step(LatticeColourMatrix& Uin)const{
|
||||
/*
|
||||
md_->init(Uin,RNG); // set U and initialize P and phi's
|
||||
RealD H0 = md_->S(); // current state
|
||||
std::cout<<"Total H_before = "<< H0 << "\n";
|
||||
|
||||
md_->integrator();
|
||||
|
||||
RealD H1 = md_->calc_H(); // updated state
|
||||
std::cout<<"Total H_after = "<< H1 << "\n";
|
||||
|
||||
return (H1-H0);
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool HybridMonteCarlo::metropolis_test(const RealD DeltaH)const{
|
||||
RealD rn_test;
|
||||
RealD prob = std::exp(-DeltaH);
|
||||
random(RNG,rn_test);
|
||||
|
||||
std::cout<< "--------------------------------------------\n";
|
||||
std::cout<< "dH = "<<DeltaH << " Random = "<< rn_test
|
||||
<< "\nAcc. Probability = " << ((prob<1.0)? prob: 1.0)<< " ";
|
||||
|
||||
if((prob >1.0) || (rn_test <= prob)){ // accepted
|
||||
std::cout <<"-- ACCEPTED\n";
|
||||
return true;
|
||||
} else { // rejected
|
||||
std::cout <<"-- REJECTED\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
50
lib/qcd/hmc/HMC.h
Normal file
50
lib/qcd/hmc/HMC.h
Normal file
@ -0,0 +1,50 @@
|
||||
//--------------------------------------------------------------------
|
||||
/*! @file HMC.h
|
||||
* @brief Declaration of classes for HybridMonteCarlo update
|
||||
*
|
||||
* @author Guido Cossu
|
||||
*/
|
||||
//--------------------------------------------------------------------
|
||||
#ifndef HMC_INCLUDED
|
||||
#define HMC_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace Grid{
|
||||
namespace QCD{
|
||||
|
||||
struct HMCparameters{
|
||||
Integer Nsweeps; /* @brief Number of sweeps in this run */
|
||||
Integer TotalSweeps; /* @brief If provided, the total number of sweeps */
|
||||
Integer ThermalizationSteps;
|
||||
Integer StartingConfig;
|
||||
Integer SaveInterval; //Setting to 0 does not save configurations
|
||||
std::string Filename_prefix; // To save configurations
|
||||
|
||||
HMCparameters();
|
||||
};
|
||||
|
||||
|
||||
class HybridMonteCarlo{
|
||||
const HMCparameters Params;
|
||||
GridSerialRNG& RNG;
|
||||
// FIXME need the integrator
|
||||
|
||||
bool metropolis_test(const RealD DeltaH)const;
|
||||
RealD evolve_step(LatticeColourMatrix&)const;
|
||||
|
||||
|
||||
public:
|
||||
HybridMonteCarlo(GridSerialRNG&);
|
||||
~HybridMonteCarlo(){};
|
||||
|
||||
void evolve(LatticeColourMatrix& Uin)const;
|
||||
|
||||
};
|
||||
|
||||
}// QCD
|
||||
}// Grid
|
||||
|
||||
|
||||
#endif
|
0
lib/qcd/hmc/integrators/.dirstamp
Normal file
0
lib/qcd/hmc/integrators/.dirstamp
Normal file
22
lib/qcd/hmc/integrators/Integrator_base.cc
Normal file
22
lib/qcd/hmc/integrators/Integrator_base.cc
Normal file
@ -0,0 +1,22 @@
|
||||
/*!
|
||||
@file Integrator_base.cc
|
||||
@brief utilities for MD including funcs to generate initial HMC momentum
|
||||
*/
|
||||
|
||||
|
||||
#include <Grid.h>
|
||||
|
||||
static const double sq3i = 1.0/sqrt(3.0);
|
||||
|
||||
namespace Grid{
|
||||
namespace QCD{
|
||||
|
||||
|
||||
|
||||
void MDutils::generate_momenta_su3(LatticeColourMatrix& P,GridParallelRNG& pRNG){
|
||||
SU3::GaussianLieAlgebraMatrix(pRNG, P);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
50
lib/qcd/hmc/integrators/Integrator_base.h
Normal file
50
lib/qcd/hmc/integrators/Integrator_base.h
Normal file
@ -0,0 +1,50 @@
|
||||
//--------------------------------------------------------------------
|
||||
/*! @file Integrator_base.h
|
||||
* @brief Declaration of classes for the abstract Molecular Dynamics integrator
|
||||
*
|
||||
* @author Guido Cossu
|
||||
*/
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
#ifndef INTEGRATOR_INCLUDED
|
||||
#define INTEGRATOR_INCLUDED
|
||||
|
||||
class Action;
|
||||
class RandNum;
|
||||
class Observer;
|
||||
|
||||
typedef std::vector<Action*> ActionLevel;
|
||||
typedef std::vector<ActionLevel> ActionSet;
|
||||
typedef std::vector<Observer*> ObserverList;
|
||||
|
||||
/*! @brief Abstract base class for Molecular Dynamics management */
|
||||
|
||||
namespace Grid{
|
||||
namespace QCD{
|
||||
|
||||
class Integrator{
|
||||
private:
|
||||
virtual void update_P(int lv,double ep) = 0;
|
||||
virtual void update_U(double ep) = 0;
|
||||
|
||||
virtual void register_observers() = 0;
|
||||
virtual void notify_observers() = 0;
|
||||
|
||||
public:
|
||||
virtual ~Integrator(){}
|
||||
virtual void init(const LatticeColourMatrix&,
|
||||
const GridParallelRNG& RNG)=0;
|
||||
virtual double S()const =0;
|
||||
virtual void integrate(int level) =0;
|
||||
virtual const LatticeColourMatrix get_U() const =0;
|
||||
|
||||
void generate_momenta(LatticeColourMatrix& P,const RandNum& rand);
|
||||
};
|
||||
|
||||
namespace MDutils{
|
||||
void generate_momenta_su3(LatticeColourMatrix& P,GridParallelRNG& RNG);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif//INTEGRATOR_INCLUDED
|
@ -543,6 +543,26 @@ Note that in step D setting B ~ X - A and using B in place of A in step E will g
|
||||
taExp(lie,out);
|
||||
}
|
||||
|
||||
static void GaussianLieAlgebraMatrix(GridParallelRNG &pRNG,LatticeMatrix &out,double scale=1.0){
|
||||
GridBase *grid = out._grid;
|
||||
LatticeComplex ca (grid);
|
||||
LatticeMatrix lie(grid);
|
||||
LatticeMatrix la (grid);
|
||||
Complex ci(0.0,scale);
|
||||
Matrix ta;
|
||||
|
||||
out=zero;
|
||||
for(int a=0;a<generators();a++){
|
||||
|
||||
gaussian(pRNG,ca);
|
||||
generator(a,ta);
|
||||
|
||||
la=ci*ca*ta;
|
||||
out = lie+la; // e^{i la ta}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void HotConfiguration(GridParallelRNG &pRNG,LatticeGaugeField &out){
|
||||
LatticeMatrix Umu(out._grid);
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
|
Reference in New Issue
Block a user