From 23e0561dd693df44e6e0c7d0c8ceca074aa0c13f Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Wed, 18 Jan 2017 16:31:51 +0000 Subject: [PATCH] Added all required functionalities, time for cleaning All actions to be added --- lib/Grid.h | 3 +- lib/qcd/QCD.h | 2 +- lib/qcd/hmc/GenericHMCrunner.h | 43 ++++-- lib/qcd/hmc/HMC.h | 36 ++--- lib/qcd/hmc/HMCModules.h | 2 +- lib/qcd/hmc/HMCResourceManager.h | 98 +++++++++++++- lib/qcd/hmc/HMCRunnerModule.h | 138 +++++++++++++++++++ lib/qcd/hmc/checkpointers/CheckPointers.h | 2 +- lib/qcd/modules/Modules.cc | 2 + lib/qcd/modules/Modules.h | 155 +++++++++++++++++++--- lib/qcd/modules/mods.h | 2 +- lib/serialisation/XmlIO.cc | 1 + lib/serialisation/XmlIO.h | 1 + tests/hmc/Test_hmc_Factories.cc | 54 +++----- tests/hmc/Test_hmc_WilsonGauge_Binary.cc | 6 +- 15 files changed, 454 insertions(+), 91 deletions(-) create mode 100644 lib/qcd/hmc/HMCRunnerModule.h diff --git a/lib/Grid.h b/lib/Grid.h index e6a445bb..915f8e39 100644 --- a/lib/Grid.h +++ b/lib/Grid.h @@ -84,12 +84,13 @@ Author: paboyle #include #include #include +#include #include #include #include #include #include - +#include #endif diff --git a/lib/qcd/QCD.h b/lib/qcd/QCD.h index 9b5a2a2d..9fb0d900 100644 --- a/lib/qcd/QCD.h +++ b/lib/qcd/QCD.h @@ -516,6 +516,6 @@ namespace QCD { #include -#include +//#include #endif diff --git a/lib/qcd/hmc/GenericHMCrunner.h b/lib/qcd/hmc/GenericHMCrunner.h index de9b36d3..730ff6db 100644 --- a/lib/qcd/hmc/GenericHMCrunner.h +++ b/lib/qcd/hmc/GenericHMCrunner.h @@ -35,17 +35,20 @@ with this program; if not, write to the Free Software Foundation, Inc., namespace Grid { namespace QCD { -class HMCBase{ + +// very ugly here but possibly resolved if we have a base Reader class +template < class ReaderClass > +class HMCRunnerBase { public: virtual void Run() = 0; - + virtual void initialize(ReaderClass& ) = 0; }; template class Integrator, - class RepresentationsPolicy = NoHirep> -class HMCWrapperTemplate: public HMCBase { + class RepresentationsPolicy = NoHirep, class ReaderClass = XmlReader> +class HMCWrapperTemplate: public HMCRunnerBase { public: INHERIT_FIELD_TYPES(Implementation); typedef Implementation ImplPolicy; // visible from outside @@ -55,11 +58,24 @@ class HMCWrapperTemplate: public HMCBase { HMCparameters Parameters; HMCResourceManager Resources; - // The set of actions + // The set of actions (keep here for lower level users, for now) ActionSet TheAction; - // A vector of HmcObservable that can be injected from outside - std::vector *> ObservablesList; + HMCWrapperTemplate() = default; + + 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) { std::string arg; @@ -147,12 +163,8 @@ class HMCWrapperTemplate: public HMCBase { HybridMonteCarlo HMC(Parameters, MDynamics, Resources.GetSerialRNG(), - Resources.GetParallelRNG(), U); - - for (int obs = 0; obs < ObservablesList.size(); obs++) - HMC.AddObservable(ObservablesList[obs]); - HMC.AddObservable(Resources.GetCheckPointer()); - + Resources.GetParallelRNG(), + Resources.GetObservables(), U); // Run it HMC.evolve(); @@ -172,6 +184,11 @@ template ; +template class Integrator> +using GenericHMCRunnerTemplate = HMCWrapperTemplate; + + typedef HMCWrapperTemplate ScalarGenericHMCRunner; diff --git a/lib/qcd/hmc/HMC.h b/lib/qcd/hmc/HMC.h index 3304ad4f..f5be2568 100644 --- a/lib/qcd/hmc/HMC.h +++ b/lib/qcd/hmc/HMC.h @@ -87,6 +87,8 @@ struct HMCparameters: Serializable { }; + +// Move this to a different file template class HmcObservable { public: @@ -95,13 +97,13 @@ class HmcObservable { }; // this is only defined for a gauge theory -template -class PlaquetteLogger : public HmcObservable { +template +class PlaquetteLogger : public HmcObservable { private: std::string Stem; public: - INHERIT_GIMPL_TYPES(Gimpl); + INHERIT_GIMPL_TYPES(Impl); PlaquetteLogger(std::string cf) { Stem = cf; }; void TrajectoryComplete(int traj, GaugeField &U, GridSerialRNG &sRNG, @@ -117,9 +119,10 @@ class PlaquetteLogger : public HmcObservable { RealD peri_plaq = WilsonLoops::avgPlaquette(U); RealD peri_rect = WilsonLoops::avgRectangle(U); - RealD impl_plaq = WilsonLoops::avgPlaquette(U); - RealD impl_rect = WilsonLoops::avgRectangle(U); + RealD impl_plaq = WilsonLoops::avgPlaquette(U); + RealD impl_rect = WilsonLoops::avgRectangle(U); + // Fixme reorganise this output of << traj << " " << impl_plaq << " " << impl_rect << " " << peri_plaq << " " << peri_rect << std::endl; std::cout << GridLogMessage << "traj" @@ -135,6 +138,8 @@ class PlaquetteLogger : public HmcObservable { << " " << peri_plaq << " " << peri_rect << std::endl; } }; +////////////////////////////////////////////////////////////// + template class HybridMonteCarlo { @@ -142,13 +147,16 @@ class HybridMonteCarlo { const HMCparameters Params; typedef typename IntegratorType::Field Field; + typedef std::vector< HmcObservable * > ObsListType; - GridSerialRNG &sRNG; // Fixme: need a RNG management strategy. - GridParallelRNG &pRNG; // Fixme: need a RNG management strategy. + //pass these from the resource manager + GridSerialRNG &sRNG; + GridParallelRNG &pRNG; + Field &Ucur; IntegratorType &TheIntegrator; - std::vector *> Observables; + ObsListType Observables; ///////////////////////////////////////////////////////// // Metropolis step @@ -209,15 +217,12 @@ class HybridMonteCarlo { ///////////////////////////////////////// // Constructor ///////////////////////////////////////// - HybridMonteCarlo(HMCparameters Pams, IntegratorType &_Int, - GridSerialRNG &_sRNG, GridParallelRNG &_pRNG, Field &_U) - : Params(Pams), TheIntegrator(_Int), sRNG(_sRNG), pRNG(_pRNG), Ucur(_U) {} + HybridMonteCarlo(HMCparameters _Pams, IntegratorType &_Int, + GridSerialRNG &_sRNG, GridParallelRNG &_pRNG, + ObsListType _Obs, Field &_U) + : Params(_Pams), TheIntegrator(_Int), sRNG(_sRNG), pRNG(_pRNG), Observables(_Obs), Ucur(_U) {} ~HybridMonteCarlo(){}; - void AddObservable(HmcObservable *obs) { - Observables.push_back(obs); - } - void evolve(void) { Real DeltaH; @@ -262,6 +267,7 @@ class HybridMonteCarlo { std::cout << GridLogMessage << ":::::::::::::::::::::::::::::::::::::::::::" << std::endl; } } + }; } // QCD diff --git a/lib/qcd/hmc/HMCModules.h b/lib/qcd/hmc/HMCModules.h index 68872e74..6fc48dc2 100644 --- a/lib/qcd/hmc/HMCModules.h +++ b/lib/qcd/hmc/HMCModules.h @@ -33,6 +33,7 @@ directory namespace Grid { namespace QCD { +// call these: resources // Some modules for the basic setup @@ -166,7 +167,6 @@ public: }; - /* /////////////////////////////////////////////////////////////////// /// Smearing module diff --git a/lib/qcd/hmc/HMCResourceManager.h b/lib/qcd/hmc/HMCResourceManager.h index 3d115ced..23cd5d51 100644 --- a/lib/qcd/hmc/HMCResourceManager.h +++ b/lib/qcd/hmc/HMCResourceManager.h @@ -56,15 +56,23 @@ namespace QCD { template class HMCResourceManager { typedef HMCModuleBase< QCD::BaseHmcCheckpointer > CheckpointerBaseModule; - + typedef HMCModuleBase< QCD::HmcObservable > ObservableBaseModule; + typedef HMCModuleBase< QCD::Action > ActionBaseModule; // Named storage for grid pairs (std + red-black) std::unordered_map Grids; RNGModule RNGs; // SmearingModule Smearing; - std::unique_ptr CP; - + std::unique_ptr CP; + + // A vector of HmcObservable modules + std::vector > ObservablesList; + + // A vector of HmcObservable modules + std::multimap > ActionsList; + std::vector multipliers; + bool have_RNG; bool have_CheckPointer; @@ -96,9 +104,68 @@ class HMCResourceManager { RNGModuleParameters RNGpar(Read); SetRNGSeeds(RNGpar); - // HMC here + // Observables + auto &ObsFactory = HMC_ObservablesModuleFactory::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 + 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::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 + void GetActionSet(ActionSet& Aset){ + Aset.resize(multipliers.size()); + + for(auto it = ActionsList.begin(); it != ActionsList.end(); it++) + Aset[(*it).first-1].push_back((*it).second->getPtr()); + } + + + ////////////////////////////////////////////////////////////// // Grids ////////////////////////////////////////////////////////////// @@ -181,6 +248,29 @@ class HMCResourceManager { RegisterLoadCheckPointerFunction(Binary); RegisterLoadCheckPointerFunction(Nersc); RegisterLoadCheckPointerFunction(ILDG); + + + //////////////////////////////////////////////////////// + // Observables + //////////////////////////////////////////////////////// + + void AddObservable(ObservableBaseModule *O){ + // acquire resource + ObservablesList.push_back(std::unique_ptr(std::move(O))); + } + + std::vector* > GetObservables(){ + std::vector* > out; + for (auto &i : ObservablesList){ + out.push_back(i->getPtr()); + } + + // Add the checkpointer to the observables + out.push_back(GetCheckPointer()); + return out; + } + + }; } } diff --git a/lib/qcd/hmc/HMCRunnerModule.h b/lib/qcd/hmc/HMCRunnerModule.h new file mode 100644 index 00000000..e1171695 --- /dev/null +++ b/lib/qcd/hmc/HMCRunnerModule.h @@ -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 + +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 HMCModule + : public Parametrized< QCD::HMCparameters >, + public HMCModuleBase< QCD::HMCRunnerBase > { + public: + typedef HMCModuleBase< QCD::HMCRunnerBase > Base; + typedef typename Base::Product Product; + + std::unique_ptr HMCPtr; + + HMCModule(QCD::HMCparameters Par) : Parametrized(Par) {} + + template + HMCModule(Reader& R) : Parametrized(R, "HMC"){}; + + Product* getPtr() { + if (!HMCPtr) initialize(); + + return HMCPtr.get(); + } + + private: + virtual void initialize() = 0; +}; + +// Factory +template +class HMCRunnerModuleFactory + : public Factory < HMCModuleBase< QCD::HMCRunnerBase > , Reader > { + public: + typedef Reader 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, ReaderClass >{ + typedef HMCModule< QCD::GenericHMCRunnerTemplate, ReaderClass > HMCBaseMod; + using HMCBaseMod::HMCBaseMod; + + // aquire resource + virtual void initialize(){ + this->HMCPtr.reset(new QCD::GenericHMCRunnerTemplate(this->Par_) ); + } +}; + +template < class ImplementationPolicy, class RepresentationPolicy, class ReaderClass > +class HMCMinimumNorm2: public HMCModule< QCD::GenericHMCRunnerTemplate, ReaderClass >{ + typedef HMCModule< QCD::GenericHMCRunnerTemplate, ReaderClass > HMCBaseMod; + using HMCBaseMod::HMCBaseMod; + + // aquire resource + virtual void initialize(){ + std::cout << "Initializing the pointer" << std::endl; + this->HMCPtr.reset(new QCD::GenericHMCRunnerTemplate(this->Par_)); + } +}; + + +template < class ImplementationPolicy, class RepresentationPolicy, class ReaderClass > +class HMCForceGradient: public HMCModule< QCD::GenericHMCRunnerTemplate, ReaderClass >{ + typedef HMCModule< QCD::GenericHMCRunnerTemplate, ReaderClass > HMCBaseMod; + using HMCBaseMod::HMCBaseMod; + + // aquire resource + virtual void initialize(){ + this->HMCPtr.reset(new QCD::GenericHMCRunnerTemplate(this->Par_) ); + } +}; + +extern char hmc_string[]; + + + + + + +////////////////////////////////////////////////////////////// + + + +} + +#endif \ No newline at end of file diff --git a/lib/qcd/hmc/checkpointers/CheckPointers.h b/lib/qcd/hmc/checkpointers/CheckPointers.h index 99da6e63..5dc35fca 100644 --- a/lib/qcd/hmc/checkpointers/CheckPointers.h +++ b/lib/qcd/hmc/checkpointers/CheckPointers.h @@ -37,4 +37,4 @@ directory #include -#endif // CHECKPOINTERS_H \ No newline at end of file +#endif // CHECKPOINTERS_H diff --git a/lib/qcd/modules/Modules.cc b/lib/qcd/modules/Modules.cc index faa987e0..4488f7a8 100644 --- a/lib/qcd/modules/Modules.cc +++ b/lib/qcd/modules/Modules.cc @@ -31,5 +31,7 @@ namespace Grid{ char gauge_string[] = "gauge"; char cp_string[] = "CheckPointer"; +char hmc_string[] = "HMC"; +char observable_string[] = "Observable"; } diff --git a/lib/qcd/modules/Modules.h b/lib/qcd/modules/Modules.h index 42bd5b1e..34a4682b 100644 --- a/lib/qcd/modules/Modules.h +++ b/lib/qcd/modules/Modules.h @@ -36,6 +36,10 @@ for the HMC execution namespace Grid { +// Empty class for no parameters +class NoParameters{}; + + /* Base class for modules with parameters */ @@ -47,8 +51,8 @@ public: Parametrized(Parameters Par):Par_(Par){}; template - Parametrized(Reader & Reader){ - read(Reader, section_name(), Par_); + Parametrized(Reader & Reader, std::string section_name = "parameters"){ + read(Reader, section_name, Par_); } void set_parameters(Parameters Par){ @@ -64,28 +68,41 @@ protected: Parameters Par_; private: - // identifies the section name - // override in derived classes if needed - virtual std::string section_name(){ - return std::string("parameters"); //default - } + std::string section_name; }; +template <> +class Parametrized{ + typedef NoParameters Parameters; + + Parametrized(Parameters Par){}; + + template + Parametrized(Reader & Reader){}; + + void set_parameters(Parameters Par){} + + void print_parameters(){} + +}; + + + /* Lowest level abstract module class */ -template < class Prod > -class HMCModuleBase{ -public: +template +class HMCModuleBase { + public: 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 ////////////////////////////////////////////// @@ -98,8 +115,6 @@ class ActionModule typedef HMCModuleBase< QCD::Action > Base; typedef typename Base::Product Product; - - std::unique_ptr ActionPtr; ActionModule(APar Par) : Parametrized(Par) {} @@ -108,7 +123,7 @@ class ActionModule ActionModule(Reader& Reader) : Parametrized(Reader){}; virtual void print_parameters(){ - std::cout << this->Par_ << std::endl; + std::cout << this->Par_ << std::endl; } Product* getPtr() { @@ -119,7 +134,42 @@ class ActionModule private: virtual void initialize() = 0; +}; + + + +///////////////////////////// +// Observables +///////////////////////////// +// explicit gauge field here.... +template +class ObservableModule + : public Parametrized, + public HMCModuleBase< QCD::HmcObservable > { + public: + typedef HMCModuleBase< QCD::HmcObservable< typename ObservableType::GaugeField> > Base; + typedef typename Base::Product Product; + + std::unique_ptr ObservablePtr; + + ObservableModule(OPar Par) : Parametrized(Par) {} + + virtual void print_parameters(){ + std::cout << this->Par_ << std::endl; + } + + template + ObservableModule(Reader& Reader) : Parametrized(Reader){}; + + Product* getPtr() { + if (!ObservablePtr) initialize(); + + return ObservablePtr.get(); + } + + private: + virtual void initialize() = 0; }; @@ -129,6 +179,10 @@ class ActionModule +//////////////// +// Modules +//////////////// + namespace QCD{ class WilsonGaugeActionParameters : Serializable { @@ -140,7 +194,7 @@ class WilsonGaugeActionParameters : Serializable { -template +template class WilsonGModule: public ActionModule, WilsonGaugeActionParameters> { typedef ActionModule, WilsonGaugeActionParameters> ActionBase; using ActionBase::ActionBase; // for constructors @@ -155,6 +209,44 @@ class WilsonGModule: public ActionModule, WilsonGaugeAct typedef WilsonGModule WilsonGMod; + + + + + + + +//// Observables module +class PlaquetteObsParameters : Serializable { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(PlaquetteObsParameters, + std::string, output_prefix); +}; + +template < class Impl > +class PlaquetteMod: public ObservableModule, PlaquetteObsParameters>{ + typedef ObservableModule, PlaquetteObsParameters> ObsBase; + using ObsBase::ObsBase; // for constructors + + // acquire resource + virtual void initialize(){ + this->ObservablePtr.reset(new PlaquetteLogger(this->Par_.output_prefix)); + } +}; + + + + + + + + + + + + + + }// QCD temporarily here @@ -173,7 +265,7 @@ typedef WilsonGModule WilsonGMod; // Factory is perfectly fine // 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; template @@ -196,7 +288,28 @@ class HMC_LGTActionModuleFactory } }; +// explicit ref to LatticeGaugeField must be changed of put in the factory +typedef HMCModuleBase< QCD::HmcObservable > HMC_ObsModBase; +template +class HMC_ObservablesModuleFactory + : public Factory < HMC_ObsModBase , Reader > { + public: + typedef Reader 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, HMC_ObservablesModuleFactory > __OBSPLmodXMLInit("Plaquette"); + } diff --git a/lib/qcd/modules/mods.h b/lib/qcd/modules/mods.h index 9daa4a19..308bb73d 100644 --- a/lib/qcd/modules/mods.h +++ b/lib/qcd/modules/mods.h @@ -35,4 +35,4 @@ directory #include -#endif //MODS_H \ No newline at end of file +#endif //MODS_H diff --git a/lib/serialisation/XmlIO.cc b/lib/serialisation/XmlIO.cc index d8953a00..d5960bc6 100644 --- a/lib/serialisation/XmlIO.cc +++ b/lib/serialisation/XmlIO.cc @@ -73,6 +73,7 @@ XmlReader::XmlReader(const string &fileName) void XmlReader::push(const string &s) { node_ = node_.child(s.c_str()); + // add error check } void XmlReader::pop(void) diff --git a/lib/serialisation/XmlIO.h b/lib/serialisation/XmlIO.h index f30d9ef1..d05df06d 100644 --- a/lib/serialisation/XmlIO.h +++ b/lib/serialisation/XmlIO.h @@ -120,6 +120,7 @@ namespace Grid std::string buf; readDefault(s, buf); + std::cout << s << " " << buf << std::endl; fromString(output, buf); } diff --git a/tests/hmc/Test_hmc_Factories.cc b/tests/hmc/Test_hmc_Factories.cc index 841d009d..aec6e25c 100644 --- a/tests/hmc/Test_hmc_Factories.cc +++ b/tests/hmc/Test_hmc_Factories.cc @@ -2,12 +2,10 @@ 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 -Author: neo Author: Guido Cossu This program is free software; you can redistribute it and/or modify @@ -30,6 +28,16 @@ directory /* END LEGAL */ #include +namespace Grid{ + // ifdefs ?? Local makefile suggestion , policy as make parameter +typedef QCD::PeriodicGimplR ImplementationPolicy; +typedef QCD::NoHirep RepresentationPolicy; + +static Registrar< HMCLeapFrog , HMCRunnerModuleFactory > __HMCLFmodXMLInit("LeapFrog"); +static Registrar< HMCMinimumNorm2 , HMCRunnerModuleFactory > __HMCMN2modXMLInit("MinimumNorm2"); +static Registrar< HMCForceGradient , HMCRunnerModuleFactory > __HMCFGmodXMLInit("ForceGradient"); +} + int main(int argc, char **argv) { using namespace Grid; 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; // Typedefs to simplify notation - typedef GenericHMCRunner HMCWrapper; // Uses the default minimum norm typedef Grid::XmlReader InputFileReader; // Reader, file should come from command line InputFileReader Reader("input.wilson_gauge.params.xml"); - HMCWrapper TheHMC; + // Test HMC factory (put in an external file) + auto &HMCfactory = HMCRunnerModuleFactory::getInstance(); + // Simplify this step (IntergratorName field?) + HMCparameters HMCpar(Reader); + + // Construct the module + auto myHMCmodule = HMCfactory.create(HMCpar.MD.name, Reader); - TheHMC.Parameters.initialize(Reader); - TheHMC.Resources.initialize(Reader); + myHMCmodule->getPtr()->initialize(Reader); + myHMCmodule->getPtr()->Run(); - // Construct observables - // here there is too much indirection - PlaquetteLogger 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 Level1(1); - Level1.push_back(&Waction); - TheHMC.TheAction.push_back(Level1); - ///////////////////////////////////////////////////////////// - - // eventually smearing here - // ... - //////////////////////////////////////////////////////////////// - - TheHMC.Run(); // no smearing Grid_finalize(); diff --git a/tests/hmc/Test_hmc_WilsonGauge_Binary.cc b/tests/hmc/Test_hmc_WilsonGauge_Binary.cc index c1e67c0b..03be73a0 100644 --- a/tests/hmc/Test_hmc_WilsonGauge_Binary.cc +++ b/tests/hmc/Test_hmc_WilsonGauge_Binary.cc @@ -65,8 +65,10 @@ int main(int argc, char **argv) { // Construct observables // here there is too much indirection - PlaquetteLogger PlaqLog("Plaquette"); - TheHMC.ObservablesList.push_back(&PlaqLog); + PlaquetteObsParameters PlPar; + PlPar.output_prefix = "Plaquette"; + PlaquetteMod PlaqModule(PlPar); + TheHMC.Resources.AddObservable(&PlaqModule); ////////////////////////////////////////////// /////////////////////////////////////////////////////////////