mirror of
https://github.com/paboyle/Grid.git
synced 2025-08-02 20:57:06 +01:00
Small change in the HMC interface.
Example of multiple levels in the WilsonFermion hmc test. Merge remote-tracking branch 'upstream/master' Conflicts: lib/qcd/hmc/HMC.h lib/qcd/hmc/integrators/Integrator.h lib/qcd/hmc/integrators/Integrator_algorithm.h tests/Test_simd.cc
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* @brief Classes for Hybrid Monte Carlo update
|
||||
*
|
||||
* @author Guido Cossu
|
||||
* Time-stamp: <2015-07-07 14:58:13 neo>
|
||||
* Time-stamp: <2015-07-30 16:58:26 neo>
|
||||
*/
|
||||
//--------------------------------------------------------------------
|
||||
#ifndef HMC_INCLUDED
|
||||
@@ -28,75 +28,89 @@ namespace Grid{
|
||||
|
||||
template <class Algorithm>
|
||||
class HybridMonteCarlo{
|
||||
|
||||
const HMCparameters Params;
|
||||
GridSerialRNG sRNG;
|
||||
|
||||
GridSerialRNG sRNG; // Fixme: need a RNG management strategy.
|
||||
|
||||
Integrator<Algorithm>& MD;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// Metropolis step
|
||||
/////////////////////////////////////////////////////////
|
||||
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)<< " ";
|
||||
std::cout<<GridLogMessage<< "--------------------------------------------\n";
|
||||
std::cout<<GridLogMessage<< "dH = "<<DeltaH << " Random = "<< rn_test <<"\n";
|
||||
std::cout<<GridLogMessage<< "Acc. Probability = " << ((prob<1.0)? prob: 1.0)<< " ";
|
||||
|
||||
if((prob >1.0) || (rn_test <= prob)){ // accepted
|
||||
std::cout <<"-- ACCEPTED\n";
|
||||
std::cout<<GridLogMessage <<"-- ACCEPTED\n";
|
||||
return true;
|
||||
} else { // rejected
|
||||
std::cout <<"-- REJECTED\n";
|
||||
std::cout<<GridLogMessage <<"-- REJECTED\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// Evolution
|
||||
/////////////////////////////////////////////////////////
|
||||
RealD evolve_step(LatticeGaugeField& U){
|
||||
MD.init(U); // set U and initialize P and phi's
|
||||
|
||||
RealD H0 = MD.S(U); // initial state action
|
||||
std::cout<<"Total H before = "<< H0 << "\n";
|
||||
|
||||
std::cout<<GridLogMessage<<"Total H before = "<< H0 << "\n";
|
||||
|
||||
MD.integrate(U);
|
||||
|
||||
RealD H1 = MD.S(U); // updated state action
|
||||
std::cout<<"Total H after = "<< H1 << "\n";
|
||||
|
||||
std::cout<<GridLogMessage<<"Total H after = "<< H1 << "\n";
|
||||
return (H1-H0);
|
||||
}
|
||||
|
||||
public:
|
||||
HybridMonteCarlo(HMCparameters Pms,
|
||||
Integrator<Algorithm>& MolDyn):
|
||||
Params(Pms),MD(MolDyn){
|
||||
//FIXME
|
||||
|
||||
// initialize RNGs also with seed
|
||||
/////////////////////////////////////////
|
||||
// Constructor
|
||||
/////////////////////////////////////////
|
||||
HybridMonteCarlo(HMCparameters Pms, Integrator<Algorithm>& MolDyn): Params(Pms),MD(MolDyn) {
|
||||
|
||||
//FIXME... initialize RNGs also with seed ; RNG management strategy
|
||||
sRNG.SeedRandomDevice();
|
||||
|
||||
}
|
||||
~HybridMonteCarlo(){};
|
||||
|
||||
|
||||
void evolve(LatticeGaugeField& Uin){
|
||||
Real DeltaH;
|
||||
|
||||
// Thermalizations
|
||||
for(int iter=1; iter <= Params.ThermalizationSteps; ++iter){
|
||||
std::cout << "-- # Thermalization step = "<< iter << "\n";
|
||||
std::cout<<GridLogMessage << "-- # Thermalization step = "<< iter << "\n";
|
||||
|
||||
DeltaH = evolve_step(Uin);
|
||||
std::cout<< " dH = "<< DeltaH << "\n";
|
||||
std::cout<<GridLogMessage<< "dH = "<< DeltaH << "\n";
|
||||
}
|
||||
|
||||
// Actual updates (evolve a copy Ucopy then copy back eventually)
|
||||
LatticeGaugeField Ucopy(Uin._grid);
|
||||
for(int iter=Params.StartingConfig;
|
||||
iter < Params.Nsweeps+Params.StartingConfig; ++iter){
|
||||
std::cout << "-- # Sweep = "<< iter << "\n";
|
||||
std::cout<<GridLogMessage << "-- # Sweep = "<< iter << "\n";
|
||||
|
||||
Ucopy = Uin;
|
||||
DeltaH = evolve_step(Ucopy);
|
||||
|
||||
if(metropolis_test(DeltaH)) Uin = Ucopy;
|
||||
|
||||
// here save config and RNG seed
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user