2015-07-03 08:51:41 +01:00
|
|
|
//--------------------------------------------------------------------
|
|
|
|
/*! @file HMC.h
|
2015-07-04 09:47:50 +01:00
|
|
|
* @brief Declaration of classes for Hybrid Monte Carlo update
|
2015-07-03 08:51:41 +01:00
|
|
|
*
|
|
|
|
* @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();
|
|
|
|
};
|
|
|
|
|
2015-07-06 08:46:43 +01:00
|
|
|
template <class Algorithm>
|
2015-07-03 08:51:41 +01:00
|
|
|
class HybridMonteCarlo{
|
|
|
|
const HMCparameters Params;
|
2015-07-03 18:43:14 +01:00
|
|
|
GridSerialRNG sRNG;
|
2015-07-06 08:46:43 +01:00
|
|
|
Integrator<Algorithm>& MD;
|
2015-07-03 08:51:41 +01:00
|
|
|
|
2015-07-03 18:43:14 +01:00
|
|
|
bool metropolis_test(const RealD DeltaH){
|
|
|
|
RealD rn_test;
|
|
|
|
RealD prob = std::exp(-DeltaH);
|
|
|
|
random(sRNG,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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-04 09:47:50 +01:00
|
|
|
RealD evolve_step(LatticeLorentzColourMatrix& U){
|
|
|
|
|
2015-07-06 08:46:43 +01:00
|
|
|
MD.init(U); // set U and initialize P and phi's
|
|
|
|
RealD H0 = MD.S(U); // initial state action
|
2015-07-06 04:58:49 +01:00
|
|
|
std::cout<<"Total H before = "<< H0 << "\n";
|
2015-07-03 18:43:14 +01:00
|
|
|
|
2015-07-06 08:46:43 +01:00
|
|
|
MD.integrate(U);
|
2015-07-03 18:43:14 +01:00
|
|
|
|
2015-07-06 08:46:43 +01:00
|
|
|
RealD H1 = MD.S(U); // updated state action
|
2015-07-06 04:58:49 +01:00
|
|
|
std::cout<<"Total H after = "<< H1 << "\n";
|
2015-07-03 18:43:14 +01:00
|
|
|
|
|
|
|
return (H1-H0);
|
|
|
|
}
|
2015-07-03 08:51:41 +01:00
|
|
|
|
|
|
|
public:
|
2015-07-04 09:47:50 +01:00
|
|
|
HybridMonteCarlo(HMCparameters Pms,
|
2015-07-06 08:46:43 +01:00
|
|
|
Integrator<Algorithm>& MolDyn):
|
2015-07-06 08:17:32 +01:00
|
|
|
Params(Pms),MD(MolDyn){
|
2015-07-03 18:43:14 +01:00
|
|
|
//FIXME
|
|
|
|
|
2015-07-06 08:17:32 +01:00
|
|
|
// initialize RNGs also with seed
|
2015-07-03 18:43:14 +01:00
|
|
|
sRNG.SeedRandomDevice();
|
|
|
|
}
|
2015-07-03 08:51:41 +01:00
|
|
|
~HybridMonteCarlo(){};
|
|
|
|
|
2015-07-03 18:43:14 +01:00
|
|
|
|
|
|
|
|
2015-07-04 09:47:50 +01:00
|
|
|
void evolve(LatticeLorentzColourMatrix& Uin){
|
2015-07-03 18:43:14 +01:00
|
|
|
Real DeltaH;
|
2015-07-06 08:17:32 +01:00
|
|
|
|
2015-07-03 18:43:14 +01:00
|
|
|
// Thermalizations
|
|
|
|
for(int iter=1; iter <= Params.ThermalizationSteps; ++iter){
|
|
|
|
std::cout << "-- # Thermalization step = "<< iter << "\n";
|
|
|
|
|
|
|
|
DeltaH = evolve_step(Uin);
|
2015-07-04 09:47:50 +01:00
|
|
|
std::cout<< " dH = "<< DeltaH << "\n";
|
2015-07-03 18:43:14 +01:00
|
|
|
}
|
|
|
|
|
2015-07-04 09:47:50 +01:00
|
|
|
// Actual updates (evolve a copy Ucopy then copy back eventually)
|
|
|
|
LatticeLorentzColourMatrix Ucopy(Uin._grid);
|
2015-07-03 18:43:14 +01:00
|
|
|
for(int iter=Params.StartingConfig;
|
|
|
|
iter < Params.Nsweeps+Params.StartingConfig; ++iter){
|
|
|
|
std::cout << "-- # Sweep = "<< iter << "\n";
|
2015-07-05 18:24:58 +01:00
|
|
|
|
2015-07-04 09:47:50 +01:00
|
|
|
Ucopy = Uin;
|
|
|
|
DeltaH = evolve_step(Ucopy);
|
2015-07-03 18:43:14 +01:00
|
|
|
|
2015-07-05 18:24:58 +01:00
|
|
|
if(metropolis_test(DeltaH)) Uin = Ucopy;
|
2015-07-06 04:58:49 +01:00
|
|
|
//need sync?
|
2015-07-03 18:43:14 +01:00
|
|
|
}
|
|
|
|
}
|
2015-07-03 08:51:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}// QCD
|
|
|
|
}// Grid
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|