From 7f456b4173382442a0527c3a67d1eb5597072ec4 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Tue, 24 Jan 2017 13:57:32 +0000 Subject: [PATCH] :construction_worker: Added all pseudofermion actions to the serialiser --- lib/qcd/action/ActionParams.h | 21 ++- .../pseudofermion/OneFlavourEvenOddRational.h | 12 ++ .../OneFlavourEvenOddRationalRatio.h | 12 ++ .../action/pseudofermion/OneFlavourRational.h | 14 ++ .../pseudofermion/OneFlavourRationalRatio.h | 12 ++ .../pseudofermion/TwoFlavourEvenOddRatio.h | 7 + lib/qcd/modules/ActionModules.h | 164 +++++++++++++++++- lib/serialisation/JSON_IO.cc | 30 ++-- lib/serialisation/JSON_IO.h | 8 +- tests/IO/Test_serialisation.cc | 10 +- 10 files changed, 257 insertions(+), 33 deletions(-) diff --git a/lib/qcd/action/ActionParams.h b/lib/qcd/action/ActionParams.h index dcbdfce8..48ed23cf 100644 --- a/lib/qcd/action/ActionParams.h +++ b/lib/qcd/action/ActionParams.h @@ -45,15 +45,20 @@ namespace QCD { WilsonImplParams() : overlapCommsCompute(false) {}; }; - struct OneFlavourRationalParams { - RealD lo; - RealD hi; - int MaxIter; // Vector? - RealD tolerance; // Vector? - int degree=10; - int precision=64; + struct OneFlavourRationalParams : Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(OneFlavourRationalParams, + RealD, lo, + RealD, hi, + int, MaxIter, + RealD, tolerance, + int, degree, + int, precision); - OneFlavourRationalParams (RealD _lo,RealD _hi,int _maxit,RealD tol=1.0e-8,int _degree = 10,int _precision=64) : + // MaxIter and tolerance, vectors?? + public: + OneFlavourRationalParams (RealD _lo = 0.0, RealD _hi = 0.0 , + int _maxit = 1000, RealD tol = 1.0e-8, + int _degree = 10, int _precision = 64) : lo(_lo), hi(_hi), MaxIter(_maxit), tolerance(tol), degree(_degree), precision(_precision) {}; }; diff --git a/lib/qcd/action/pseudofermion/OneFlavourEvenOddRational.h b/lib/qcd/action/pseudofermion/OneFlavourEvenOddRational.h index ec3fa9e2..9b89959e 100644 --- a/lib/qcd/action/pseudofermion/OneFlavourEvenOddRational.h +++ b/lib/qcd/action/pseudofermion/OneFlavourEvenOddRational.h @@ -1,3 +1,4 @@ + /************************************************************************************* Grid physics library, www.github.com/paboyle/Grid @@ -91,6 +92,17 @@ class OneFlavourEvenOddRationalPseudoFermionAction }; virtual std::string action_name(){return "OneFlavourEvenOddRationalPseudoFermionAction";} + + virtual std::string LogParameters(){ + std::stringstream sstream; + sstream << GridLogMessage << "["<, BetaGaugeActionPar ///////////////////////////////////////// -template class FermionA > -class PseudoFermionModuleBase: public ActionModule, NoParameters> { +template class FermionA, class Params = NoParameters > +class PseudoFermionModuleBase: public ActionModule, Params> { protected: - typedef ActionModule, NoParameters> ActionBase; + typedef ActionModule, Params> ActionBase; using ActionBase::ActionBase; // for constructors typedef std::unique_ptr> > operator_type; @@ -314,6 +314,158 @@ class TwoFlavourRatioFModule: public PseudoFermionModuleBase +class TwoFlavourRatioEOFModule: public PseudoFermionModuleBase{ + typedef PseudoFermionModuleBase Base; + using Base::Base; + + typename Base::operator_type fop_numerator_mod; + typename Base::operator_type fop_denominator_mod; + typename Base::solver_type solver_mod; + + public: + virtual void acquireResource(typename Base::Resource& GridMod){ + fop_numerator_mod->AddGridPair(GridMod); + fop_denominator_mod->AddGridPair(GridMod); + } + + // constructor + template + TwoFlavourRatioEOFModule(Reader& R): Base(R) { + this->getSolverOperator(R, solver_mod, "Solver"); + this->getFermionOperator(R, fop_numerator_mod, "Numerator"); + this->getFermionOperator(R, fop_denominator_mod, "Denominator"); + } + + // acquire resource + virtual void initialize() { + // here temporarily assuming that the force and action solver are the same + this->ActionPtr.reset(new TwoFlavourEvenOddRatioPseudoFermionAction(*(this->fop_numerator_mod->getPtr()), + *(this->fop_denominator_mod->getPtr()), *(this->solver_mod->getPtr()), *(this->solver_mod->getPtr()))); + } + +}; + + +template +class OneFlavourFModule: public PseudoFermionModuleBase{ + typedef PseudoFermionModuleBase Base; + using Base::Base; + + typename Base::operator_type fop_mod; + + public: + virtual void acquireResource(typename Base::Resource& GridMod){ + fop_mod->AddGridPair(GridMod); + } + + // constructor + template + OneFlavourFModule(Reader& R): Base(R) { + this->getFermionOperator(R, fop_mod, "Operator"); + } + + // acquire resource + virtual void initialize() { + this->ActionPtr.reset(new OneFlavourRationalPseudoFermionAction(*(this->fop_mod->getPtr()), this->Par_ )); + } + +}; + +template +class OneFlavourEOFModule: + public PseudoFermionModuleBase + { + typedef PseudoFermionModuleBase Base; + using Base::Base; + + typename Base::operator_type fop_mod; + + public: + virtual void acquireResource(typename Base::Resource& GridMod){ + fop_mod->AddGridPair(GridMod); + } + + // constructor + template + OneFlavourEOFModule(Reader& R): Base(R) { + this->getFermionOperator(R, fop_mod, "Operator"); + } + + // acquire resource + virtual void initialize() { + this->ActionPtr.reset(new OneFlavourEvenOddRationalPseudoFermionAction(*(this->fop_mod->getPtr()), this->Par_ )); + } + +}; + + +template +class OneFlavourRatioFModule: + public PseudoFermionModuleBase + { + + typedef PseudoFermionModuleBase Base; + using Base::Base; + + typename Base::operator_type fop_numerator_mod; + typename Base::operator_type fop_denominator_mod; + + public: + virtual void acquireResource(typename Base::Resource& GridMod){ + fop_numerator_mod->AddGridPair(GridMod); + fop_denominator_mod->AddGridPair(GridMod); + } + + // constructor + template + OneFlavourRatioFModule(Reader& R): Base(R) { + this->getFermionOperator(R, fop_numerator_mod, "Numerator"); + this->getFermionOperator(R, fop_denominator_mod, "Denominator"); + } + + // acquire resource + virtual void initialize() { + this->ActionPtr.reset(new OneFlavourRatioRationalPseudoFermionAction( *(this->fop_numerator_mod->getPtr()), + *(this->fop_denominator_mod->getPtr()), + this->Par_ )); + } + +}; + + +template +class OneFlavourRatioEOFModule: + public PseudoFermionModuleBase + { + + typedef PseudoFermionModuleBase Base; + using Base::Base; + + typename Base::operator_type fop_numerator_mod; + typename Base::operator_type fop_denominator_mod; + + public: + virtual void acquireResource(typename Base::Resource& GridMod){ + fop_numerator_mod->AddGridPair(GridMod); + fop_denominator_mod->AddGridPair(GridMod); + } + + // constructor + template + OneFlavourRatioEOFModule(Reader& R): Base(R) { + this->getFermionOperator(R, fop_numerator_mod, "Numerator"); + this->getFermionOperator(R, fop_denominator_mod, "Denominator"); + } + + // acquire resource + virtual void initialize() { + this->ActionPtr.reset(new OneFlavourEvenOddRatioRationalPseudoFermionAction(*(this->fop_numerator_mod->getPtr()), + *(this->fop_denominator_mod->getPtr()), + this->Par_ )); + } + +}; @@ -379,6 +531,12 @@ static Registrar , HMC_LGTActionModuleFactory > __TwoFlavourFmodXMLInit("TwoFlavours"); static Registrar , HMC_LGTActionModuleFactory > __TwoFlavourRatioFmodXMLInit("TwoFlavoursRatio"); static Registrar , HMC_LGTActionModuleFactory > __TwoFlavourEOFmodXMLInit("TwoFlavoursEvenOdd"); +static Registrar , HMC_LGTActionModuleFactory > __TwoFlavourRatioEOFmodXMLInit("TwoFlavoursEvenOddRatio"); +static Registrar , HMC_LGTActionModuleFactory > __OneFlavourFmodXMLInit("OneFlavour"); +static Registrar , HMC_LGTActionModuleFactory > __OneFlavourEOFmodXMLInit("OneFlavourEvenOdd"); +static Registrar , HMC_LGTActionModuleFactory > __OneFlavourRatioFmodXMLInit("OneFlavourRatio"); +static Registrar , HMC_LGTActionModuleFactory > __OneFlavourRatioEOFmodXMLInit("OneFlavourEvenOddRatio"); + diff --git a/lib/serialisation/JSON_IO.cc b/lib/serialisation/JSON_IO.cc index 22117abe..168ad6ff 100644 --- a/lib/serialisation/JSON_IO.cc +++ b/lib/serialisation/JSON_IO.cc @@ -106,15 +106,15 @@ bool JSONReader::push(const string &s) std::cout << "out of range: " << e.what() << '\n'; return false; } - cout << "JSONReader::push : " << s << " : "<< jcur_ << endl; - return true; } else { do_pop.push_back(false); - return true; } + + + return true; } void JSONReader::pop(void) @@ -134,19 +134,17 @@ bool JSONReader::nextElement(const std::string &s) { // JSON dictionaries do not support multiple names // Same name objects must be packed in vectors - cout << "JSONReader::nextElement(string) : " << s << " : "<< jcur_ << endl; - /* - if (node_.next_sibling(s.c_str())) - { - node_ = node_.next_sibling(s.c_str()); - - return true; - } - else - { - return false; - } -*/ + ++it_; + + //if (it_ == it_end_){ + // return false; + //} + + jcur_ = *it_; + //cout << "JSONReader::nextElement(string) : " << s << " : "<< jcur_ << endl; + //return true; + + return false; } template <> diff --git a/lib/serialisation/JSON_IO.h b/lib/serialisation/JSON_IO.h index face96e6..b62cf318 100644 --- a/lib/serialisation/JSON_IO.h +++ b/lib/serialisation/JSON_IO.h @@ -84,6 +84,8 @@ namespace Grid std::vector jold_; // previous json object std::string fileName_; std::vector do_pop; + json::iterator it_; + json::iterator it_end_; }; // Writer template implementation //////////////////////////////////////////// @@ -125,12 +127,7 @@ namespace Grid template void JSONReader::readDefault(const std::string &s, U &output) { - //std::string buf; std::cout << "JSONReader::readDefault(U) : " << s << " : "<< jcur_ << std::endl; - //readDefault(s, output); - - //std::cout << s << " " << buf << std::endl; - //fromString(output, buf); if (s.size()){ std::cout << "String: "<< jcur_[s] << std::endl; @@ -164,6 +161,7 @@ namespace Grid output.resize(i + 1); read("", output[i++]); } + jcur_ = j; if (s.size()) diff --git a/tests/IO/Test_serialisation.cc b/tests/IO/Test_serialisation.cc index 61eaf989..3bd83848 100644 --- a/tests/IO/Test_serialisation.cc +++ b/tests/IO/Test_serialisation.cc @@ -49,7 +49,7 @@ namespace Grid { myclass() {} myclass(int i) - : array(4,5.1), twodimarray(3,std::vector(2,1.23456)), ve(2, myenum::blue) + : array(4,5.1), twodimarray(3,std::vector(2,1.23456)), ve({myenum::blue, myenum::red}) { e=myenum::red; x=i; @@ -202,5 +202,13 @@ int main(int argc,char **argv) std::cout << jcopy1 << std::endl << jveccopy1 << std::endl; } + { + // Testing the next element function + JSONReader RD("test.json"); + RD.push("grid"); + RD.push("Observable"); + std::string name; + read(RD,"name", name); + } }