mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-27 14:15:55 +01:00
Added all required functionalities, time for cleaning
All actions to be added
This commit is contained in:
parent
924130833e
commit
23e0561dd6
@ -84,12 +84,13 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
|
|||||||
#include <Grid/parallelIO/BinaryIO.h>
|
#include <Grid/parallelIO/BinaryIO.h>
|
||||||
#include <Grid/parallelIO/IldgIO.h>
|
#include <Grid/parallelIO/IldgIO.h>
|
||||||
#include <Grid/parallelIO/NerscIO.h>
|
#include <Grid/parallelIO/NerscIO.h>
|
||||||
|
#include <Grid/qcd/modules/mods.h>
|
||||||
#include <Grid/qcd/hmc/checkpointers/CheckPointers.h>
|
#include <Grid/qcd/hmc/checkpointers/CheckPointers.h>
|
||||||
#include <Grid/qcd/hmc/HMCModules.h>
|
#include <Grid/qcd/hmc/HMCModules.h>
|
||||||
#include <Grid/qcd/hmc/HMCResourceManager.h>
|
#include <Grid/qcd/hmc/HMCResourceManager.h>
|
||||||
#include <Grid/qcd/hmc/HmcRunner.h>
|
#include <Grid/qcd/hmc/HmcRunner.h>
|
||||||
#include <Grid/qcd/hmc/GenericHMCrunner.h>
|
#include <Grid/qcd/hmc/GenericHMCrunner.h>
|
||||||
|
#include <Grid/qcd/hmc/HMCRunnerModule.h>
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -516,6 +516,6 @@ namespace QCD {
|
|||||||
#include <Grid/qcd/hmc/HMC.h>
|
#include <Grid/qcd/hmc/HMC.h>
|
||||||
|
|
||||||
|
|
||||||
#include <Grid/qcd/modules/mods.h>
|
//#include <Grid/qcd/modules/mods.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -35,17 +35,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
namespace Grid {
|
namespace Grid {
|
||||||
namespace QCD {
|
namespace QCD {
|
||||||
|
|
||||||
class HMCBase{
|
|
||||||
|
// very ugly here but possibly resolved if we have a base Reader class
|
||||||
|
template < class ReaderClass >
|
||||||
|
class HMCRunnerBase {
|
||||||
public:
|
public:
|
||||||
virtual void Run() = 0;
|
virtual void Run() = 0;
|
||||||
|
virtual void initialize(ReaderClass& ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class Implementation,
|
template <class Implementation,
|
||||||
template <typename, typename, typename> class Integrator,
|
template <typename, typename, typename> class Integrator,
|
||||||
class RepresentationsPolicy = NoHirep>
|
class RepresentationsPolicy = NoHirep, class ReaderClass = XmlReader>
|
||||||
class HMCWrapperTemplate: public HMCBase {
|
class HMCWrapperTemplate: public HMCRunnerBase<ReaderClass> {
|
||||||
public:
|
public:
|
||||||
INHERIT_FIELD_TYPES(Implementation);
|
INHERIT_FIELD_TYPES(Implementation);
|
||||||
typedef Implementation ImplPolicy; // visible from outside
|
typedef Implementation ImplPolicy; // visible from outside
|
||||||
@ -55,11 +58,24 @@ class HMCWrapperTemplate: public HMCBase {
|
|||||||
HMCparameters Parameters;
|
HMCparameters Parameters;
|
||||||
HMCResourceManager<Implementation> Resources;
|
HMCResourceManager<Implementation> Resources;
|
||||||
|
|
||||||
// The set of actions
|
// The set of actions (keep here for lower level users, for now)
|
||||||
ActionSet<Field, RepresentationsPolicy> TheAction;
|
ActionSet<Field, RepresentationsPolicy> TheAction;
|
||||||
|
|
||||||
// A vector of HmcObservable that can be injected from outside
|
HMCWrapperTemplate() = default;
|
||||||
std::vector<HmcObservable<typename Implementation::Field> *> ObservablesList;
|
|
||||||
|
HMCWrapperTemplate(HMCparameters Par){
|
||||||
|
Parameters = Par;
|
||||||
|
}
|
||||||
|
|
||||||
|
void initialize(ReaderClass & TheReader){
|
||||||
|
std::cout << "Initialization of the HMC" << std::endl;
|
||||||
|
Resources.initialize(TheReader);
|
||||||
|
|
||||||
|
// eventually add smearing
|
||||||
|
|
||||||
|
Resources.GetActionSet(TheAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ReadCommandLine(int argc, char **argv) {
|
void ReadCommandLine(int argc, char **argv) {
|
||||||
std::string arg;
|
std::string arg;
|
||||||
@ -147,12 +163,8 @@ class HMCWrapperTemplate: public HMCBase {
|
|||||||
|
|
||||||
HybridMonteCarlo<TheIntegrator> HMC(Parameters, MDynamics,
|
HybridMonteCarlo<TheIntegrator> HMC(Parameters, MDynamics,
|
||||||
Resources.GetSerialRNG(),
|
Resources.GetSerialRNG(),
|
||||||
Resources.GetParallelRNG(), U);
|
Resources.GetParallelRNG(),
|
||||||
|
Resources.GetObservables(), U);
|
||||||
for (int obs = 0; obs < ObservablesList.size(); obs++)
|
|
||||||
HMC.AddObservable(ObservablesList[obs]);
|
|
||||||
HMC.AddObservable(Resources.GetCheckPointer());
|
|
||||||
|
|
||||||
|
|
||||||
// Run it
|
// Run it
|
||||||
HMC.evolve();
|
HMC.evolve();
|
||||||
@ -172,6 +184,11 @@ template <class RepresentationsPolicy,
|
|||||||
using GenericHMCRunnerHirep =
|
using GenericHMCRunnerHirep =
|
||||||
HMCWrapperTemplate<PeriodicGimplR, Integrator, RepresentationsPolicy>;
|
HMCWrapperTemplate<PeriodicGimplR, Integrator, RepresentationsPolicy>;
|
||||||
|
|
||||||
|
template <class Implementation, class RepresentationsPolicy,
|
||||||
|
template <typename, typename, typename> class Integrator>
|
||||||
|
using GenericHMCRunnerTemplate = HMCWrapperTemplate<Implementation, Integrator, RepresentationsPolicy>;
|
||||||
|
|
||||||
|
|
||||||
typedef HMCWrapperTemplate<ScalarImplR, MinimumNorm2, ScalarFields>
|
typedef HMCWrapperTemplate<ScalarImplR, MinimumNorm2, ScalarFields>
|
||||||
ScalarGenericHMCRunner;
|
ScalarGenericHMCRunner;
|
||||||
|
|
||||||
|
@ -87,6 +87,8 @@ struct HMCparameters: Serializable {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Move this to a different file
|
||||||
template <class Field>
|
template <class Field>
|
||||||
class HmcObservable {
|
class HmcObservable {
|
||||||
public:
|
public:
|
||||||
@ -95,13 +97,13 @@ class HmcObservable {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// this is only defined for a gauge theory
|
// this is only defined for a gauge theory
|
||||||
template <class Gimpl>
|
template <class Impl>
|
||||||
class PlaquetteLogger : public HmcObservable<typename Gimpl::Field> {
|
class PlaquetteLogger : public HmcObservable<typename Impl::Field> {
|
||||||
private:
|
private:
|
||||||
std::string Stem;
|
std::string Stem;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
INHERIT_GIMPL_TYPES(Gimpl);
|
INHERIT_GIMPL_TYPES(Impl);
|
||||||
PlaquetteLogger(std::string cf) { Stem = cf; };
|
PlaquetteLogger(std::string cf) { Stem = cf; };
|
||||||
|
|
||||||
void TrajectoryComplete(int traj, GaugeField &U, GridSerialRNG &sRNG,
|
void TrajectoryComplete(int traj, GaugeField &U, GridSerialRNG &sRNG,
|
||||||
@ -117,9 +119,10 @@ class PlaquetteLogger : public HmcObservable<typename Gimpl::Field> {
|
|||||||
RealD peri_plaq = WilsonLoops<PeriodicGimplR>::avgPlaquette(U);
|
RealD peri_plaq = WilsonLoops<PeriodicGimplR>::avgPlaquette(U);
|
||||||
RealD peri_rect = WilsonLoops<PeriodicGimplR>::avgRectangle(U);
|
RealD peri_rect = WilsonLoops<PeriodicGimplR>::avgRectangle(U);
|
||||||
|
|
||||||
RealD impl_plaq = WilsonLoops<Gimpl>::avgPlaquette(U);
|
RealD impl_plaq = WilsonLoops<Impl>::avgPlaquette(U);
|
||||||
RealD impl_rect = WilsonLoops<Gimpl>::avgRectangle(U);
|
RealD impl_rect = WilsonLoops<Impl>::avgRectangle(U);
|
||||||
|
|
||||||
|
// Fixme reorganise this output
|
||||||
of << traj << " " << impl_plaq << " " << impl_rect << " " << peri_plaq
|
of << traj << " " << impl_plaq << " " << impl_rect << " " << peri_plaq
|
||||||
<< " " << peri_rect << std::endl;
|
<< " " << peri_rect << std::endl;
|
||||||
std::cout << GridLogMessage << "traj"
|
std::cout << GridLogMessage << "traj"
|
||||||
@ -135,6 +138,8 @@ class PlaquetteLogger : public HmcObservable<typename Gimpl::Field> {
|
|||||||
<< " " << peri_plaq << " " << peri_rect << std::endl;
|
<< " " << peri_plaq << " " << peri_rect << std::endl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
template <class IntegratorType>
|
template <class IntegratorType>
|
||||||
class HybridMonteCarlo {
|
class HybridMonteCarlo {
|
||||||
@ -142,13 +147,16 @@ class HybridMonteCarlo {
|
|||||||
const HMCparameters Params;
|
const HMCparameters Params;
|
||||||
|
|
||||||
typedef typename IntegratorType::Field Field;
|
typedef typename IntegratorType::Field Field;
|
||||||
|
typedef std::vector< HmcObservable<Field> * > ObsListType;
|
||||||
|
|
||||||
|
//pass these from the resource manager
|
||||||
|
GridSerialRNG &sRNG;
|
||||||
|
GridParallelRNG &pRNG;
|
||||||
|
|
||||||
GridSerialRNG &sRNG; // Fixme: need a RNG management strategy.
|
|
||||||
GridParallelRNG &pRNG; // Fixme: need a RNG management strategy.
|
|
||||||
Field &Ucur;
|
Field &Ucur;
|
||||||
|
|
||||||
IntegratorType &TheIntegrator;
|
IntegratorType &TheIntegrator;
|
||||||
std::vector<HmcObservable<Field> *> Observables;
|
ObsListType Observables;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////
|
||||||
// Metropolis step
|
// Metropolis step
|
||||||
@ -209,15 +217,12 @@ class HybridMonteCarlo {
|
|||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
HybridMonteCarlo(HMCparameters Pams, IntegratorType &_Int,
|
HybridMonteCarlo(HMCparameters _Pams, IntegratorType &_Int,
|
||||||
GridSerialRNG &_sRNG, GridParallelRNG &_pRNG, Field &_U)
|
GridSerialRNG &_sRNG, GridParallelRNG &_pRNG,
|
||||||
: Params(Pams), TheIntegrator(_Int), sRNG(_sRNG), pRNG(_pRNG), Ucur(_U) {}
|
ObsListType _Obs, Field &_U)
|
||||||
|
: Params(_Pams), TheIntegrator(_Int), sRNG(_sRNG), pRNG(_pRNG), Observables(_Obs), Ucur(_U) {}
|
||||||
~HybridMonteCarlo(){};
|
~HybridMonteCarlo(){};
|
||||||
|
|
||||||
void AddObservable(HmcObservable<Field> *obs) {
|
|
||||||
Observables.push_back(obs);
|
|
||||||
}
|
|
||||||
|
|
||||||
void evolve(void) {
|
void evolve(void) {
|
||||||
Real DeltaH;
|
Real DeltaH;
|
||||||
|
|
||||||
@ -262,6 +267,7 @@ class HybridMonteCarlo {
|
|||||||
std::cout << GridLogMessage << ":::::::::::::::::::::::::::::::::::::::::::" << std::endl;
|
std::cout << GridLogMessage << ":::::::::::::::::::::::::::::::::::::::::::" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // QCD
|
} // QCD
|
||||||
|
@ -33,6 +33,7 @@ directory
|
|||||||
namespace Grid {
|
namespace Grid {
|
||||||
namespace QCD {
|
namespace QCD {
|
||||||
|
|
||||||
|
// call these: resources
|
||||||
|
|
||||||
// Some modules for the basic setup
|
// Some modules for the basic setup
|
||||||
|
|
||||||
@ -166,7 +167,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
///////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////
|
||||||
/// Smearing module
|
/// Smearing module
|
||||||
|
@ -56,14 +56,22 @@ namespace QCD {
|
|||||||
template <class ImplementationPolicy>
|
template <class ImplementationPolicy>
|
||||||
class HMCResourceManager {
|
class HMCResourceManager {
|
||||||
typedef HMCModuleBase< QCD::BaseHmcCheckpointer<ImplementationPolicy> > CheckpointerBaseModule;
|
typedef HMCModuleBase< QCD::BaseHmcCheckpointer<ImplementationPolicy> > CheckpointerBaseModule;
|
||||||
|
typedef HMCModuleBase< QCD::HmcObservable<typename ImplementationPolicy::Field> > ObservableBaseModule;
|
||||||
|
typedef HMCModuleBase< QCD::Action<typename ImplementationPolicy::Field> > ActionBaseModule;
|
||||||
|
|
||||||
// Named storage for grid pairs (std + red-black)
|
// Named storage for grid pairs (std + red-black)
|
||||||
std::unordered_map<std::string, GridModule> Grids;
|
std::unordered_map<std::string, GridModule> Grids;
|
||||||
RNGModule RNGs;
|
RNGModule RNGs;
|
||||||
|
|
||||||
// SmearingModule<ImplementationPolicy> Smearing;
|
// SmearingModule<ImplementationPolicy> Smearing;
|
||||||
std::unique_ptr<CheckpointerBaseModule > CP;
|
std::unique_ptr<CheckpointerBaseModule> CP;
|
||||||
|
|
||||||
|
// A vector of HmcObservable modules
|
||||||
|
std::vector<std::unique_ptr<ObservableBaseModule> > ObservablesList;
|
||||||
|
|
||||||
|
// A vector of HmcObservable modules
|
||||||
|
std::multimap<int, std::unique_ptr<ActionBaseModule> > ActionsList;
|
||||||
|
std::vector<int> multipliers;
|
||||||
|
|
||||||
bool have_RNG;
|
bool have_RNG;
|
||||||
bool have_CheckPointer;
|
bool have_CheckPointer;
|
||||||
@ -96,9 +104,68 @@ class HMCResourceManager {
|
|||||||
RNGModuleParameters RNGpar(Read);
|
RNGModuleParameters RNGpar(Read);
|
||||||
SetRNGSeeds(RNGpar);
|
SetRNGSeeds(RNGpar);
|
||||||
|
|
||||||
// HMC here
|
// Observables
|
||||||
|
auto &ObsFactory = HMC_ObservablesModuleFactory<observable_string, ReaderClass>::getInstance();
|
||||||
|
Read.push(observable_string);// here must check if existing...
|
||||||
|
do {
|
||||||
|
std::string obs_type;
|
||||||
|
Read.readDefault("name", obs_type);
|
||||||
|
std::cout << "Registered types " << std::endl;
|
||||||
|
std::cout << ObsFactory.getBuilderList() << std::endl;
|
||||||
|
|
||||||
|
ObservablesList.emplace_back(ObsFactory.create(obs_type, Read));
|
||||||
|
ObservablesList[ObservablesList.size() - 1]->print_parameters();
|
||||||
|
} while (Read.nextElement(observable_string));
|
||||||
|
std::cout << "Size of ObservablesList " << ObservablesList.size()
|
||||||
|
<< std::endl;
|
||||||
|
Read.pop();
|
||||||
|
|
||||||
|
// Loop on levels
|
||||||
|
Read.push("Actions");
|
||||||
|
|
||||||
|
Read.push("Level");// push must check if the node exist
|
||||||
|
do {
|
||||||
|
fill_ActionsLevel(Read);
|
||||||
|
} while(Read.nextElement("Level"));
|
||||||
|
Read.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// this private
|
||||||
|
template <class ReaderClass >
|
||||||
|
void fill_ActionsLevel(ReaderClass &Read){
|
||||||
|
// Actions set
|
||||||
|
int m;
|
||||||
|
Read.readDefault("multiplier",m);
|
||||||
|
multipliers.push_back(m);
|
||||||
|
std::cout << "Level : " << multipliers.size() << " with multiplier : " << m << std::endl;
|
||||||
|
// here gauge
|
||||||
|
Read.push("Action");
|
||||||
|
do{
|
||||||
|
auto &ActionFactory = HMC_LGTActionModuleFactory<gauge_string, ReaderClass>::getInstance();
|
||||||
|
std::string action_type;
|
||||||
|
Read.readDefault("name", action_type);
|
||||||
|
std::cout << "Registered types " << std::endl;
|
||||||
|
std::cout << ActionFactory.getBuilderList() << std::endl;
|
||||||
|
|
||||||
|
ActionsList.emplace(m, ActionFactory.create(action_type, Read));
|
||||||
|
|
||||||
|
} while (Read.nextElement("Action"));
|
||||||
|
|
||||||
|
ActionsList.find(m)->second->print_parameters();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class RepresentationPolicy>
|
||||||
|
void GetActionSet(ActionSet<typename ImplementationPolicy::Field, RepresentationPolicy>& Aset){
|
||||||
|
Aset.resize(multipliers.size());
|
||||||
|
|
||||||
|
for(auto it = ActionsList.begin(); it != ActionsList.end(); it++)
|
||||||
|
Aset[(*it).first-1].push_back((*it).second->getPtr());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
// Grids
|
// Grids
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
@ -181,6 +248,29 @@ class HMCResourceManager {
|
|||||||
RegisterLoadCheckPointerFunction(Binary);
|
RegisterLoadCheckPointerFunction(Binary);
|
||||||
RegisterLoadCheckPointerFunction(Nersc);
|
RegisterLoadCheckPointerFunction(Nersc);
|
||||||
RegisterLoadCheckPointerFunction(ILDG);
|
RegisterLoadCheckPointerFunction(ILDG);
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////
|
||||||
|
// Observables
|
||||||
|
////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void AddObservable(ObservableBaseModule *O){
|
||||||
|
// acquire resource
|
||||||
|
ObservablesList.push_back(std::unique_ptr<ObservableBaseModule>(std::move(O)));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<HmcObservable<typename ImplementationPolicy::Field>* > GetObservables(){
|
||||||
|
std::vector<HmcObservable<typename ImplementationPolicy::Field>* > out;
|
||||||
|
for (auto &i : ObservablesList){
|
||||||
|
out.push_back(i->getPtr());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the checkpointer to the observables
|
||||||
|
out.push_back(GetCheckPointer());
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
138
lib/qcd/hmc/HMCRunnerModule.h
Normal file
138
lib/qcd/hmc/HMCRunnerModule.h
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
/*************************************************************************************
|
||||||
|
|
||||||
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
|
Source file: ./lib/qcd/hmc/GenericHmcRunner.h
|
||||||
|
|
||||||
|
Copyright (C) 2015
|
||||||
|
Copyright (C) 2016
|
||||||
|
|
||||||
|
Author: Guido Cossu <guido.cossu@ed.ac.uk>
|
||||||
|
|
||||||
|
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
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
See the full license in the file "LICENSE" in the top level distribution
|
||||||
|
directory
|
||||||
|
*************************************************************************************/
|
||||||
|
/* END LEGAL */
|
||||||
|
#ifndef HMC_RUNNER_MODULE
|
||||||
|
#define HMC_RUNNER_MODULE
|
||||||
|
|
||||||
|
namespace Grid {
|
||||||
|
|
||||||
|
// the reader class is necessary here for the automatic initialization of the resources
|
||||||
|
// if we had a virtual reader would have been unecessary
|
||||||
|
template <class HMCType, class ReaderClass >
|
||||||
|
class HMCModule
|
||||||
|
: public Parametrized< QCD::HMCparameters >,
|
||||||
|
public HMCModuleBase< QCD::HMCRunnerBase<ReaderClass> > {
|
||||||
|
public:
|
||||||
|
typedef HMCModuleBase< QCD::HMCRunnerBase<ReaderClass> > Base;
|
||||||
|
typedef typename Base::Product Product;
|
||||||
|
|
||||||
|
std::unique_ptr<HMCType> HMCPtr;
|
||||||
|
|
||||||
|
HMCModule(QCD::HMCparameters Par) : Parametrized<QCD::HMCparameters>(Par) {}
|
||||||
|
|
||||||
|
template <class ReaderCl>
|
||||||
|
HMCModule(Reader<ReaderCl>& R) : Parametrized<QCD::HMCparameters>(R, "HMC"){};
|
||||||
|
|
||||||
|
Product* getPtr() {
|
||||||
|
if (!HMCPtr) initialize();
|
||||||
|
|
||||||
|
return HMCPtr.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void initialize() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Factory
|
||||||
|
template <char const *str, class ReaderClass >
|
||||||
|
class HMCRunnerModuleFactory
|
||||||
|
: public Factory < HMCModuleBase< QCD::HMCRunnerBase<ReaderClass> > , Reader<ReaderClass> > {
|
||||||
|
public:
|
||||||
|
typedef Reader<ReaderClass> TheReader;
|
||||||
|
// use SINGLETON FUNCTOR MACRO HERE
|
||||||
|
HMCRunnerModuleFactory(const HMCRunnerModuleFactory& e) = delete;
|
||||||
|
void operator=(const HMCRunnerModuleFactory& e) = delete;
|
||||||
|
static HMCRunnerModuleFactory& getInstance(void) {
|
||||||
|
static HMCRunnerModuleFactory e;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
HMCRunnerModuleFactory(void) = default;
|
||||||
|
std::string obj_type() const {
|
||||||
|
return std::string(str);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///////////////
|
||||||
|
// macro for these
|
||||||
|
|
||||||
|
template < class ImplementationPolicy, class RepresentationPolicy, class ReaderClass >
|
||||||
|
class HMCLeapFrog: public HMCModule< QCD::GenericHMCRunnerTemplate<ImplementationPolicy, RepresentationPolicy, QCD::LeapFrog>, ReaderClass >{
|
||||||
|
typedef HMCModule< QCD::GenericHMCRunnerTemplate<ImplementationPolicy, RepresentationPolicy, QCD::LeapFrog>, ReaderClass > HMCBaseMod;
|
||||||
|
using HMCBaseMod::HMCBaseMod;
|
||||||
|
|
||||||
|
// aquire resource
|
||||||
|
virtual void initialize(){
|
||||||
|
this->HMCPtr.reset(new QCD::GenericHMCRunnerTemplate<ImplementationPolicy, RepresentationPolicy, QCD::LeapFrog>(this->Par_) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template < class ImplementationPolicy, class RepresentationPolicy, class ReaderClass >
|
||||||
|
class HMCMinimumNorm2: public HMCModule< QCD::GenericHMCRunnerTemplate<ImplementationPolicy, RepresentationPolicy, QCD::MinimumNorm2>, ReaderClass >{
|
||||||
|
typedef HMCModule< QCD::GenericHMCRunnerTemplate<ImplementationPolicy, RepresentationPolicy, QCD::MinimumNorm2>, ReaderClass > HMCBaseMod;
|
||||||
|
using HMCBaseMod::HMCBaseMod;
|
||||||
|
|
||||||
|
// aquire resource
|
||||||
|
virtual void initialize(){
|
||||||
|
std::cout << "Initializing the pointer" << std::endl;
|
||||||
|
this->HMCPtr.reset(new QCD::GenericHMCRunnerTemplate<ImplementationPolicy, RepresentationPolicy, QCD::MinimumNorm2>(this->Par_));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template < class ImplementationPolicy, class RepresentationPolicy, class ReaderClass >
|
||||||
|
class HMCForceGradient: public HMCModule< QCD::GenericHMCRunnerTemplate<ImplementationPolicy, RepresentationPolicy, QCD::ForceGradient>, ReaderClass >{
|
||||||
|
typedef HMCModule< QCD::GenericHMCRunnerTemplate<ImplementationPolicy, RepresentationPolicy, QCD::ForceGradient>, ReaderClass > HMCBaseMod;
|
||||||
|
using HMCBaseMod::HMCBaseMod;
|
||||||
|
|
||||||
|
// aquire resource
|
||||||
|
virtual void initialize(){
|
||||||
|
this->HMCPtr.reset(new QCD::GenericHMCRunnerTemplate<ImplementationPolicy, RepresentationPolicy, QCD::ForceGradient>(this->Par_) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern char hmc_string[];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -31,5 +31,7 @@ namespace Grid{
|
|||||||
|
|
||||||
char gauge_string[] = "gauge";
|
char gauge_string[] = "gauge";
|
||||||
char cp_string[] = "CheckPointer";
|
char cp_string[] = "CheckPointer";
|
||||||
|
char hmc_string[] = "HMC";
|
||||||
|
char observable_string[] = "Observable";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,10 @@ for the HMC execution
|
|||||||
|
|
||||||
namespace Grid {
|
namespace Grid {
|
||||||
|
|
||||||
|
// Empty class for no parameters
|
||||||
|
class NoParameters{};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Base class for modules with parameters
|
Base class for modules with parameters
|
||||||
*/
|
*/
|
||||||
@ -47,8 +51,8 @@ public:
|
|||||||
Parametrized(Parameters Par):Par_(Par){};
|
Parametrized(Parameters Par):Par_(Par){};
|
||||||
|
|
||||||
template <class ReaderClass>
|
template <class ReaderClass>
|
||||||
Parametrized(Reader<ReaderClass> & Reader){
|
Parametrized(Reader<ReaderClass> & Reader, std::string section_name = "parameters"){
|
||||||
read(Reader, section_name(), Par_);
|
read(Reader, section_name, Par_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_parameters(Parameters Par){
|
void set_parameters(Parameters Par){
|
||||||
@ -64,28 +68,41 @@ protected:
|
|||||||
Parameters Par_;
|
Parameters Par_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// identifies the section name
|
std::string section_name;
|
||||||
// override in derived classes if needed
|
|
||||||
virtual std::string section_name(){
|
|
||||||
return std::string("parameters"); //default
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class Parametrized<NoParameters>{
|
||||||
|
typedef NoParameters Parameters;
|
||||||
|
|
||||||
|
Parametrized(Parameters Par){};
|
||||||
|
|
||||||
|
template <class ReaderClass>
|
||||||
|
Parametrized(Reader<ReaderClass> & Reader){};
|
||||||
|
|
||||||
|
void set_parameters(Parameters Par){}
|
||||||
|
|
||||||
|
void print_parameters(){}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Lowest level abstract module class
|
Lowest level abstract module class
|
||||||
*/
|
*/
|
||||||
template < class Prod >
|
template <class Prod>
|
||||||
class HMCModuleBase{
|
class HMCModuleBase {
|
||||||
public:
|
public:
|
||||||
typedef Prod Product;
|
typedef Prod Product;
|
||||||
virtual Prod* getPtr() = 0;
|
|
||||||
virtual void print_parameters(){}; //default to nothing
|
virtual Prod* getPtr() = 0;
|
||||||
|
|
||||||
|
virtual void print_parameters(){}; // default to nothing
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////
|
//////////////////////////////////////////////
|
||||||
// Actions
|
// Actions
|
||||||
//////////////////////////////////////////////
|
//////////////////////////////////////////////
|
||||||
@ -98,8 +115,6 @@ class ActionModule
|
|||||||
typedef HMCModuleBase< QCD::Action<typename ActionType::GaugeField> > Base;
|
typedef HMCModuleBase< QCD::Action<typename ActionType::GaugeField> > Base;
|
||||||
typedef typename Base::Product Product;
|
typedef typename Base::Product Product;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::unique_ptr<ActionType> ActionPtr;
|
std::unique_ptr<ActionType> ActionPtr;
|
||||||
|
|
||||||
ActionModule(APar Par) : Parametrized<APar>(Par) {}
|
ActionModule(APar Par) : Parametrized<APar>(Par) {}
|
||||||
@ -119,7 +134,42 @@ class ActionModule
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void initialize() = 0;
|
virtual void initialize() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// Observables
|
||||||
|
/////////////////////////////
|
||||||
|
// explicit gauge field here....
|
||||||
|
template <class ObservableType, class OPar>
|
||||||
|
class ObservableModule
|
||||||
|
: public Parametrized<OPar>,
|
||||||
|
public HMCModuleBase< QCD::HmcObservable<typename ObservableType::GaugeField> > {
|
||||||
|
public:
|
||||||
|
typedef HMCModuleBase< QCD::HmcObservable< typename ObservableType::GaugeField> > Base;
|
||||||
|
typedef typename Base::Product Product;
|
||||||
|
|
||||||
|
std::unique_ptr<ObservableType> ObservablePtr;
|
||||||
|
|
||||||
|
ObservableModule(OPar Par) : Parametrized<OPar>(Par) {}
|
||||||
|
|
||||||
|
virtual void print_parameters(){
|
||||||
|
std::cout << this->Par_ << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class ReaderClass>
|
||||||
|
ObservableModule(Reader<ReaderClass>& Reader) : Parametrized<OPar>(Reader){};
|
||||||
|
|
||||||
|
Product* getPtr() {
|
||||||
|
if (!ObservablePtr) initialize();
|
||||||
|
|
||||||
|
return ObservablePtr.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void initialize() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -129,6 +179,10 @@ class ActionModule
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////
|
||||||
|
// Modules
|
||||||
|
////////////////
|
||||||
|
|
||||||
namespace QCD{
|
namespace QCD{
|
||||||
|
|
||||||
class WilsonGaugeActionParameters : Serializable {
|
class WilsonGaugeActionParameters : Serializable {
|
||||||
@ -140,7 +194,7 @@ class WilsonGaugeActionParameters : Serializable {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<class Impl>
|
template <class Impl >
|
||||||
class WilsonGModule: public ActionModule<WilsonGaugeAction<Impl>, WilsonGaugeActionParameters> {
|
class WilsonGModule: public ActionModule<WilsonGaugeAction<Impl>, WilsonGaugeActionParameters> {
|
||||||
typedef ActionModule<WilsonGaugeAction<Impl>, WilsonGaugeActionParameters> ActionBase;
|
typedef ActionModule<WilsonGaugeAction<Impl>, WilsonGaugeActionParameters> ActionBase;
|
||||||
using ActionBase::ActionBase; // for constructors
|
using ActionBase::ActionBase; // for constructors
|
||||||
@ -155,6 +209,44 @@ class WilsonGModule: public ActionModule<WilsonGaugeAction<Impl>, WilsonGaugeAct
|
|||||||
typedef WilsonGModule<PeriodicGimplR> WilsonGMod;
|
typedef WilsonGModule<PeriodicGimplR> WilsonGMod;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//// Observables module
|
||||||
|
class PlaquetteObsParameters : Serializable {
|
||||||
|
public:
|
||||||
|
GRID_SERIALIZABLE_CLASS_MEMBERS(PlaquetteObsParameters,
|
||||||
|
std::string, output_prefix);
|
||||||
|
};
|
||||||
|
|
||||||
|
template < class Impl >
|
||||||
|
class PlaquetteMod: public ObservableModule<PlaquetteLogger<Impl>, PlaquetteObsParameters>{
|
||||||
|
typedef ObservableModule<PlaquetteLogger<Impl>, PlaquetteObsParameters> ObsBase;
|
||||||
|
using ObsBase::ObsBase; // for constructors
|
||||||
|
|
||||||
|
// acquire resource
|
||||||
|
virtual void initialize(){
|
||||||
|
this->ObservablePtr.reset(new PlaquetteLogger<Impl>(this->Par_.output_prefix));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}// QCD temporarily here
|
}// QCD temporarily here
|
||||||
|
|
||||||
|
|
||||||
@ -173,7 +265,7 @@ typedef WilsonGModule<PeriodicGimplR> WilsonGMod;
|
|||||||
// Factory is perfectly fine
|
// Factory is perfectly fine
|
||||||
// Registar must be changed because I do not want to use the ModuleFactory
|
// Registar must be changed because I do not want to use the ModuleFactory
|
||||||
|
|
||||||
// explicit ref to LatticeGaugeField must be changed
|
// explicit ref to LatticeGaugeField must be changed of put in the factory
|
||||||
typedef HMCModuleBase< QCD::Action< QCD::LatticeGaugeField > > HMC_LGTActionModBase;
|
typedef HMCModuleBase< QCD::Action< QCD::LatticeGaugeField > > HMC_LGTActionModBase;
|
||||||
|
|
||||||
template <char const *str, class ReaderClass >
|
template <char const *str, class ReaderClass >
|
||||||
@ -196,7 +288,28 @@ class HMC_LGTActionModuleFactory
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// explicit ref to LatticeGaugeField must be changed of put in the factory
|
||||||
|
typedef HMCModuleBase< QCD::HmcObservable<QCD::LatticeGaugeField> > HMC_ObsModBase;
|
||||||
|
|
||||||
|
template <char const *str, class ReaderClass >
|
||||||
|
class HMC_ObservablesModuleFactory
|
||||||
|
: public Factory < HMC_ObsModBase , Reader<ReaderClass> > {
|
||||||
|
public:
|
||||||
|
typedef Reader<ReaderClass> TheReader;
|
||||||
|
// use SINGLETON FUNCTOR MACRO HERE
|
||||||
|
HMC_ObservablesModuleFactory(const HMC_ObservablesModuleFactory& e) = delete;
|
||||||
|
void operator=(const HMC_ObservablesModuleFactory& e) = delete;
|
||||||
|
static HMC_ObservablesModuleFactory& getInstance(void) {
|
||||||
|
static HMC_ObservablesModuleFactory e;
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
HMC_ObservablesModuleFactory(void) = default;
|
||||||
|
std::string obj_type() const {
|
||||||
|
return std::string(str);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -222,6 +335,10 @@ static Registrar<QCD::WilsonGMod, HMC_LGTActionModuleFactory<gauge_string, XmlRe
|
|||||||
// add here the registration for other implementations and readers
|
// add here the registration for other implementations and readers
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern char observable_string[];
|
||||||
|
static Registrar<QCD::PlaquetteMod<QCD::PeriodicGimplR>, HMC_ObservablesModuleFactory<observable_string, XmlReader> > __OBSPLmodXMLInit("Plaquette");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ XmlReader::XmlReader(const string &fileName)
|
|||||||
void XmlReader::push(const string &s)
|
void XmlReader::push(const string &s)
|
||||||
{
|
{
|
||||||
node_ = node_.child(s.c_str());
|
node_ = node_.child(s.c_str());
|
||||||
|
// add error check
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmlReader::pop(void)
|
void XmlReader::pop(void)
|
||||||
|
@ -120,6 +120,7 @@ namespace Grid
|
|||||||
std::string buf;
|
std::string buf;
|
||||||
|
|
||||||
readDefault(s, buf);
|
readDefault(s, buf);
|
||||||
|
std::cout << s << " " << buf << std::endl;
|
||||||
fromString(output, buf);
|
fromString(output, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,12 +2,10 @@
|
|||||||
|
|
||||||
Grid physics library, www.github.com/paboyle/Grid
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
Source file: ./tests/Test_hmc_WilsonFermionGauge.cc
|
Source file: ./tests/Test_hmc_Factories.cc
|
||||||
|
|
||||||
Copyright (C) 2015
|
Copyright (C) 2016
|
||||||
|
|
||||||
Author: Peter Boyle <pabobyle@ph.ed.ac.uk>
|
|
||||||
Author: neo <cossu@post.kek.jp>
|
|
||||||
Author: Guido Cossu <guido.cossu@ed.ac.uk>
|
Author: Guido Cossu <guido.cossu@ed.ac.uk>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
@ -30,6 +28,16 @@ directory
|
|||||||
/* END LEGAL */
|
/* END LEGAL */
|
||||||
#include <Grid/Grid.h>
|
#include <Grid/Grid.h>
|
||||||
|
|
||||||
|
namespace Grid{
|
||||||
|
// ifdefs ?? Local makefile suggestion , policy as make parameter
|
||||||
|
typedef QCD::PeriodicGimplR ImplementationPolicy;
|
||||||
|
typedef QCD::NoHirep RepresentationPolicy;
|
||||||
|
|
||||||
|
static Registrar< HMCLeapFrog<ImplementationPolicy, RepresentationPolicy, XmlReader> , HMCRunnerModuleFactory<hmc_string, XmlReader> > __HMCLFmodXMLInit("LeapFrog");
|
||||||
|
static Registrar< HMCMinimumNorm2<ImplementationPolicy, RepresentationPolicy, XmlReader> , HMCRunnerModuleFactory<hmc_string, XmlReader> > __HMCMN2modXMLInit("MinimumNorm2");
|
||||||
|
static Registrar< HMCForceGradient<ImplementationPolicy, RepresentationPolicy, XmlReader> , HMCRunnerModuleFactory<hmc_string, XmlReader> > __HMCFGmodXMLInit("ForceGradient");
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
using namespace Grid;
|
using namespace Grid;
|
||||||
using namespace Grid::QCD;
|
using namespace Grid::QCD;
|
||||||
@ -40,42 +48,22 @@ int main(int argc, char **argv) {
|
|||||||
std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl;
|
std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl;
|
||||||
|
|
||||||
// Typedefs to simplify notation
|
// Typedefs to simplify notation
|
||||||
typedef GenericHMCRunner<MinimumNorm2> HMCWrapper; // Uses the default minimum norm
|
|
||||||
typedef Grid::XmlReader InputFileReader;
|
typedef Grid::XmlReader InputFileReader;
|
||||||
|
|
||||||
// Reader, file should come from command line
|
// Reader, file should come from command line
|
||||||
InputFileReader Reader("input.wilson_gauge.params.xml");
|
InputFileReader Reader("input.wilson_gauge.params.xml");
|
||||||
|
|
||||||
HMCWrapper TheHMC;
|
// Test HMC factory (put in an external file)
|
||||||
|
auto &HMCfactory = HMCRunnerModuleFactory<hmc_string, InputFileReader >::getInstance();
|
||||||
|
// Simplify this step (IntergratorName field?)
|
||||||
|
HMCparameters HMCpar(Reader);
|
||||||
|
|
||||||
TheHMC.Parameters.initialize(Reader);
|
// Construct the module
|
||||||
TheHMC.Resources.initialize(Reader);
|
auto myHMCmodule = HMCfactory.create(HMCpar.MD.name, Reader);
|
||||||
|
|
||||||
// Construct observables
|
myHMCmodule->getPtr()->initialize(Reader);
|
||||||
// here there is too much indirection
|
myHMCmodule->getPtr()->Run();
|
||||||
PlaquetteLogger<HMCWrapper::ImplPolicy> PlaqLog("Plaquette");
|
|
||||||
TheHMC.ObservablesList.push_back(&PlaqLog);
|
|
||||||
//////////////////////////////////////////////
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////
|
|
||||||
// Collect actions, here use more encapsulation
|
|
||||||
// need wrappers of the fermionic classes
|
|
||||||
// that have a complex construction
|
|
||||||
|
|
||||||
// standard
|
|
||||||
RealD beta = 5.6 ;
|
|
||||||
WilsonGaugeActionR Waction(beta);
|
|
||||||
|
|
||||||
ActionLevel<HMCWrapper::Field> Level1(1);
|
|
||||||
Level1.push_back(&Waction);
|
|
||||||
TheHMC.TheAction.push_back(Level1);
|
|
||||||
/////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// eventually smearing here
|
|
||||||
// ...
|
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
TheHMC.Run(); // no smearing
|
|
||||||
|
|
||||||
Grid_finalize();
|
Grid_finalize();
|
||||||
|
|
||||||
|
@ -65,8 +65,10 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
// Construct observables
|
// Construct observables
|
||||||
// here there is too much indirection
|
// here there is too much indirection
|
||||||
PlaquetteLogger<HMCWrapper::ImplPolicy> PlaqLog("Plaquette");
|
PlaquetteObsParameters PlPar;
|
||||||
TheHMC.ObservablesList.push_back(&PlaqLog);
|
PlPar.output_prefix = "Plaquette";
|
||||||
|
PlaquetteMod<HMCWrapper::ImplPolicy> PlaqModule(PlPar);
|
||||||
|
TheHMC.Resources.AddObservable(&PlaqModule);
|
||||||
//////////////////////////////////////////////
|
//////////////////////////////////////////////
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user