mirror of
				https://github.com/paboyle/Grid.git
				synced 2025-11-04 05:54:32 +00:00 
			
		
		
		
	Added all required functionalities, time for cleaning
All actions to be added
This commit is contained in:
		@@ -84,12 +84,13 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
 | 
			
		||||
#include <Grid/parallelIO/BinaryIO.h>
 | 
			
		||||
#include <Grid/parallelIO/IldgIO.h>
 | 
			
		||||
#include <Grid/parallelIO/NerscIO.h>
 | 
			
		||||
#include <Grid/qcd/modules/mods.h>
 | 
			
		||||
#include <Grid/qcd/hmc/checkpointers/CheckPointers.h>
 | 
			
		||||
#include <Grid/qcd/hmc/HMCModules.h>
 | 
			
		||||
#include <Grid/qcd/hmc/HMCResourceManager.h>
 | 
			
		||||
#include <Grid/qcd/hmc/HmcRunner.h>
 | 
			
		||||
#include <Grid/qcd/hmc/GenericHMCrunner.h>
 | 
			
		||||
 | 
			
		||||
#include <Grid/qcd/hmc/HMCRunnerModule.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -516,6 +516,6 @@ namespace QCD {
 | 
			
		||||
#include <Grid/qcd/hmc/HMC.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <Grid/qcd/modules/mods.h>
 | 
			
		||||
//#include <Grid/qcd/modules/mods.h>
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -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 Implementation,
 | 
			
		||||
          template <typename, typename, typename> class Integrator,
 | 
			
		||||
          class RepresentationsPolicy = NoHirep>
 | 
			
		||||
class HMCWrapperTemplate: public HMCBase {
 | 
			
		||||
          class RepresentationsPolicy = NoHirep, class ReaderClass = XmlReader>
 | 
			
		||||
class HMCWrapperTemplate: public HMCRunnerBase<ReaderClass> {
 | 
			
		||||
 public:
 | 
			
		||||
  INHERIT_FIELD_TYPES(Implementation);
 | 
			
		||||
  typedef Implementation ImplPolicy;  // visible from outside
 | 
			
		||||
@@ -55,11 +58,24 @@ class HMCWrapperTemplate: public HMCBase {
 | 
			
		||||
  HMCparameters Parameters;
 | 
			
		||||
  HMCResourceManager<Implementation> Resources;
 | 
			
		||||
 | 
			
		||||
  // The set of actions
 | 
			
		||||
  // The set of actions (keep here for lower level users, for now)
 | 
			
		||||
  ActionSet<Field, RepresentationsPolicy> TheAction;
 | 
			
		||||
 | 
			
		||||
  // A vector of HmcObservable that can be injected from outside
 | 
			
		||||
  std::vector<HmcObservable<typename Implementation::Field> *> 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<TheIntegrator> 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 <class RepresentationsPolicy,
 | 
			
		||||
using GenericHMCRunnerHirep =
 | 
			
		||||
    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>
 | 
			
		||||
    ScalarGenericHMCRunner;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -87,6 +87,8 @@ struct HMCparameters: Serializable {
 | 
			
		||||
  
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Move this to a different file
 | 
			
		||||
template <class Field>
 | 
			
		||||
class HmcObservable {
 | 
			
		||||
 public:
 | 
			
		||||
@@ -95,13 +97,13 @@ class HmcObservable {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
  // this is only defined for a gauge theory
 | 
			
		||||
template <class Gimpl>
 | 
			
		||||
class PlaquetteLogger : public HmcObservable<typename Gimpl::Field> {
 | 
			
		||||
template <class Impl>
 | 
			
		||||
class PlaquetteLogger : public HmcObservable<typename Impl::Field> {
 | 
			
		||||
 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<typename Gimpl::Field> {
 | 
			
		||||
    RealD peri_plaq = WilsonLoops<PeriodicGimplR>::avgPlaquette(U);
 | 
			
		||||
    RealD peri_rect = WilsonLoops<PeriodicGimplR>::avgRectangle(U);
 | 
			
		||||
 | 
			
		||||
    RealD impl_plaq = WilsonLoops<Gimpl>::avgPlaquette(U);
 | 
			
		||||
    RealD impl_rect = WilsonLoops<Gimpl>::avgRectangle(U);
 | 
			
		||||
    RealD impl_plaq = WilsonLoops<Impl>::avgPlaquette(U);
 | 
			
		||||
    RealD impl_rect = WilsonLoops<Impl>::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<typename Gimpl::Field> {
 | 
			
		||||
              << "  " << peri_plaq << " " << peri_rect << std::endl;
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
//////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
template <class IntegratorType>
 | 
			
		||||
class HybridMonteCarlo {
 | 
			
		||||
@@ -142,13 +147,16 @@ class HybridMonteCarlo {
 | 
			
		||||
  const HMCparameters Params;
 | 
			
		||||
 | 
			
		||||
  typedef typename IntegratorType::Field Field;
 | 
			
		||||
  typedef std::vector< HmcObservable<Field> * > 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<HmcObservable<Field> *> 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<Field> *obs) {
 | 
			
		||||
    Observables.push_back(obs);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void evolve(void) {
 | 
			
		||||
    Real DeltaH;
 | 
			
		||||
 | 
			
		||||
@@ -262,6 +267,7 @@ class HybridMonteCarlo {
 | 
			
		||||
      std::cout << GridLogMessage << ":::::::::::::::::::::::::::::::::::::::::::" << std::endl;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}  // QCD
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -56,15 +56,23 @@ namespace QCD {
 | 
			
		||||
template <class ImplementationPolicy>
 | 
			
		||||
class HMCResourceManager {
 | 
			
		||||
  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)
 | 
			
		||||
  std::unordered_map<std::string, GridModule> Grids;
 | 
			
		||||
  RNGModule RNGs;
 | 
			
		||||
 | 
			
		||||
  // 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_CheckPointer;
 | 
			
		||||
 | 
			
		||||
@@ -96,9 +104,68 @@ class HMCResourceManager {
 | 
			
		||||
    RNGModuleParameters RNGpar(Read);
 | 
			
		||||
    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
 | 
			
		||||
  //////////////////////////////////////////////////////////////
 | 
			
		||||
@@ -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<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
 | 
			
		||||
@@ -37,4 +37,4 @@ directory
 | 
			
		||||
#include <Grid/qcd/hmc/checkpointers/CheckPointerModules.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif // CHECKPOINTERS_H
 | 
			
		||||
#endif // CHECKPOINTERS_H
 | 
			
		||||
 
 | 
			
		||||
@@ -31,5 +31,7 @@ namespace Grid{
 | 
			
		||||
 | 
			
		||||
char gauge_string[] = "gauge";
 | 
			
		||||
char cp_string[]    = "CheckPointer";
 | 
			
		||||
char hmc_string[]   = "HMC";
 | 
			
		||||
char observable_string[] = "Observable";
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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 <class ReaderClass>
 | 
			
		||||
  Parametrized(Reader<ReaderClass> & Reader){
 | 
			
		||||
    read(Reader, section_name(), Par_);
 | 
			
		||||
  Parametrized(Reader<ReaderClass> & 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<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
 | 
			
		||||
*/
 | 
			
		||||
template < class Prod >
 | 
			
		||||
class HMCModuleBase{
 | 
			
		||||
public:
 | 
			
		||||
template <class Prod>
 | 
			
		||||
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<typename ActionType::GaugeField> > Base;
 | 
			
		||||
  typedef typename Base::Product Product;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  std::unique_ptr<ActionType> ActionPtr;
 | 
			
		||||
 | 
			
		||||
  ActionModule(APar Par) : Parametrized<APar>(Par) {}
 | 
			
		||||
@@ -108,7 +123,7 @@ class ActionModule
 | 
			
		||||
  ActionModule(Reader<ReaderClass>& Reader) : Parametrized<APar>(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 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{
 | 
			
		||||
 | 
			
		||||
class WilsonGaugeActionParameters : Serializable {
 | 
			
		||||
@@ -140,7 +194,7 @@ class WilsonGaugeActionParameters : Serializable {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
template<class Impl>
 | 
			
		||||
template <class Impl >
 | 
			
		||||
class WilsonGModule: public ActionModule<WilsonGaugeAction<Impl>, WilsonGaugeActionParameters> {
 | 
			
		||||
  typedef ActionModule<WilsonGaugeAction<Impl>, WilsonGaugeActionParameters> ActionBase;
 | 
			
		||||
  using ActionBase::ActionBase; // for constructors
 | 
			
		||||
@@ -155,6 +209,44 @@ class WilsonGModule: public ActionModule<WilsonGaugeAction<Impl>, WilsonGaugeAct
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -173,7 +265,7 @@ typedef WilsonGModule<PeriodicGimplR> 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 <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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
extern char observable_string[];
 | 
			
		||||
static Registrar<QCD::PlaquetteMod<QCD::PeriodicGimplR>, HMC_ObservablesModuleFactory<observable_string, XmlReader> > __OBSPLmodXMLInit("Plaquette"); 
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -35,4 +35,4 @@ directory
 | 
			
		||||
#include <Grid/qcd/modules/Modules.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif //MODS_H
 | 
			
		||||
#endif //MODS_H
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -120,6 +120,7 @@ namespace Grid
 | 
			
		||||
    std::string buf;
 | 
			
		||||
    
 | 
			
		||||
    readDefault(s, buf);
 | 
			
		||||
    std::cout << s << "   " << buf << std::endl;
 | 
			
		||||
    fromString(output, buf);
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user