From 7907e4ca03a2232d6db973659bd90caef3b86df7 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Sat, 11 Jul 2015 23:06:31 +0900 Subject: [PATCH 01/10] This file drives me crazy --- INSTALL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL b/INSTALL index f812f5a2..80a61507 120000 --- a/INSTALL +++ b/INSTALL @@ -1 +1 @@ -/usr/share/automake-1.14/INSTALL \ No newline at end of file +/opt/local/share/automake-1.15/INSTALL \ No newline at end of file From 8a7b7f1e2b2a953f5ce81449b22f024158f45b05 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Tue, 21 Jul 2015 12:12:29 +0900 Subject: [PATCH 02/10] verbose --- lib/algorithms/iterative/ConjugateGradient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/algorithms/iterative/ConjugateGradient.h b/lib/algorithms/iterative/ConjugateGradient.h index 3829dad8..e281d765 100644 --- a/lib/algorithms/iterative/ConjugateGradient.h +++ b/lib/algorithms/iterative/ConjugateGradient.h @@ -15,7 +15,7 @@ public: Integer MaxIterations; int verbose; ConjugateGradient(RealD tol,Integer maxit) : Tolerance(tol), MaxIterations(maxit) { - verbose=1; + verbose=0; }; From c515d069cdef2584e33e590cd12acd6249313d95 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Tue, 21 Jul 2015 12:13:03 +0900 Subject: [PATCH 03/10] Tweaks to subspace set up to put in g5 r5 hermiticity --- lib/algorithms/CoarsenedMatrix.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/algorithms/CoarsenedMatrix.h b/lib/algorithms/CoarsenedMatrix.h index e257294c..998292b2 100644 --- a/lib/algorithms/CoarsenedMatrix.h +++ b/lib/algorithms/CoarsenedMatrix.h @@ -117,15 +117,15 @@ namespace Grid { } Orthogonalise(); } - virtual void CreateSubspace(GridParallelRNG &RNG,LinearOperatorBase &hermop) { + virtual void CreateSubspace(GridParallelRNG &RNG,LinearOperatorBase &hermop,int nn=nbasis) { RealD scale; - ConjugateGradient CG(1.0e-4,10000); + ConjugateGradient CG(2.0e-3,10000); FineField noise(FineGrid); FineField Mn(FineGrid); - for(int b=0;b "< "< Date: Tue, 21 Jul 2015 13:48:57 +0900 Subject: [PATCH 04/10] More info --- lib/algorithms/approx/Chebyshev.h | 46 ++++++++++++++++--------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/lib/algorithms/approx/Chebyshev.h b/lib/algorithms/approx/Chebyshev.h index 0dad7179..f629ab08 100644 --- a/lib/algorithms/approx/Chebyshev.h +++ b/lib/algorithms/approx/Chebyshev.h @@ -50,6 +50,15 @@ namespace Grid { return; } + // Convenience for plotting the approximation + void PlotApprox(std::ostream &out) { + out<<"Polynomial approx ["< &Linop, const Field &in, Field &out) { - Field T0 = in; - Field T1 = T0; // Field T1(T0._grid); more efficient but hardwires Lattice class - Field T2 = T1; + GridBase *grid=in._grid; + + int vol=grid->gSites(); + + Field T0(grid); T0 = in; + Field T1(grid); + Field T2(grid); + Field y(grid); - // use a pointer trick to eliminate copies Field *Tnm = &T0; Field *Tn = &T1; Field *Tnp = &T2; - Field y = in; - + + std::cout << "Chebyshev ["< Date: Tue, 21 Jul 2015 13:51:56 +0900 Subject: [PATCH 05/10] Printing change --- lib/algorithms/iterative/PrecGeneralisedConjugateResidual.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/algorithms/iterative/PrecGeneralisedConjugateResidual.h b/lib/algorithms/iterative/PrecGeneralisedConjugateResidual.h index 148359a8..fee41fa8 100644 --- a/lib/algorithms/iterative/PrecGeneralisedConjugateResidual.h +++ b/lib/algorithms/iterative/PrecGeneralisedConjugateResidual.h @@ -137,7 +137,7 @@ namespace Grid { cp = axpy_norm(r,-a,q[peri_k],r); - std::cout<< " VPCG_step resid" < Date: Tue, 21 Jul 2015 13:52:23 +0900 Subject: [PATCH 06/10] This file is being developed and will remain hacky until the new algorithm is complete --- tests/Test_dwf_hdcr.cc | 176 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 169 insertions(+), 7 deletions(-) diff --git a/tests/Test_dwf_hdcr.cc b/tests/Test_dwf_hdcr.cc index bafdb639..488f7277 100644 --- a/tests/Test_dwf_hdcr.cc +++ b/tests/Test_dwf_hdcr.cc @@ -6,6 +6,10 @@ using namespace std; using namespace Grid; using namespace Grid::QCD; +RealD InverseApproximation(RealD x){ + return 1.0/x; +} + template class MultiGridPreconditioner : public LinearFunction< Lattice > { public: @@ -33,6 +37,27 @@ public: _Matrix(FineMatrix) { } + + void PowerMethod(const FineField &in) { + + FineField p1(in._grid); + FineField p2(in._grid); + + MdagMLinearOperator fMdagMOp(_Matrix); + + p1=in; + RealD absp2; + for(int i=0;i<20;i++){ + RealD absp1=std::sqrt(norm2(p1)); + fMdagMOp.HermOp(p1,p2);// this is the G5 herm bit + // _FineOperator.Op(p1,p2);// this is the G5 herm bit + RealD absp2=std::sqrt(norm2(p2)); + if(i%10==9) + std::cout << "Power method on mdagm "< fCG(1.0e-1,1000); + ConjugateGradient fCG(1.0e-3,1000); ConjugateGradient CG(1.0e-8,100000); //////////////////////////////////////////////////////////////////////// @@ -164,6 +189,7 @@ public: } #endif // ADEF1: [MP+Q ] in =M [1 - A Q] in + Q in +#if 0 void operator()(const FineField &in, FineField & out) { CoarseVector Csrc(_CoarseOperator.Grid()); @@ -171,11 +197,11 @@ public: CoarseVector Csol(_CoarseOperator.Grid()); Csol=zero; ConjugateGradient CG(1.0e-10,100000); - ConjugateGradient fCG(1.0e-3,1000); + ConjugateGradient fCG(3.0e-2,1000); HermitianLinearOperator HermOp(_CoarseOperator); MdagMLinearOperator MdagMOp(_CoarseOperator); - MdagMLinearOperator fMdagMOp(_Matrix); + ShiftedMdagMLinearOperator fMdagMOp(_Matrix,0.1); FineField tmp(in._grid); FineField res(in._grid); @@ -191,7 +217,7 @@ public: CG(MdagMOp,Ctmp,Csol); _Aggregates.PromoteFromSubspace(Csol,Qin); - + // Qin=0; _FineOperator.Op(Qin,tmp);// A Q in tmp = in - tmp; // in - A Q in @@ -206,6 +232,116 @@ public: std::cout<<"preconditioner thinks residual is "< fMdagMOp(_Matrix); + ShiftedMdagMLinearOperator fMdagMOp(_Matrix,0.5); + + RealD Ni,r; + + Ni = norm2(in); + + for(int ilo=0;ilo<4;ilo++){ + for(int ord=10;ord<60;ord+=10){ + + _FineOperator.AdjOp(in,vec1); + + Chebyshev Cheby (lo[ilo],70.0,ord,InverseApproximation); + Cheby(fMdagMOp,vec1,vec2); // solves MdagM = g5 M g5M + + _FineOperator.Op(vec2,vec1);// this is the G5 herm bit + vec1 = in - vec1; // tmp = in - A Min + r=norm2(vec1); + std::cout << "Smoother resid "< CG(1.0e-5,100000); + ConjugateGradient fCG(3.0e-2,1000); + + HermitianLinearOperator HermOp(_CoarseOperator); + MdagMLinearOperator MdagMOp(_CoarseOperator); + // MdagMLinearOperator fMdagMOp(_Matrix); + ShiftedMdagMLinearOperator fMdagMOp(_Matrix,0.5); + + FineField vec1(in._grid); + FineField vec2(in._grid); + + // Chebyshev Cheby (0.5,70.0,30,InverseApproximation); + // Chebyshev ChebyAccu(0.5,70.0,30,InverseApproximation); + Chebyshev Cheby (1.0,70.0,20,InverseApproximation); + Chebyshev ChebyAccu(1.0,70.0,20,InverseApproximation); + + _Aggregates.ProjectToSubspace (Csrc,in); + _Aggregates.PromoteFromSubspace(Csrc,out); + std::cout<<"Completeness: "< clatt = GridDefaultLatt(); for(int d=0;d Subspace; typedef CoarsenedMatrix CoarseOperator; @@ -276,7 +413,19 @@ int main (int argc, char ** argv) std::cout << "**************************************************"<< std::endl; MdagMLinearOperator HermDefOp(Ddwf); Subspace Aggregates(Coarse5d,FGrid); - Aggregates.CreateSubspace(RNG5,HermDefOp); + // Aggregates.CreateSubspace(RNG5,HermDefOp,nbasis); + assert ( (nbasis & 0x1)==0); + int nb=nbasis/2; + std::cout << " nbasis/2 = "< simple; ConjugateGradient fCG(1.0e-8,100000); fCG(HermDefOp,src,result); + // exit(0); std::cout << "**************************************************"<< std::endl; std::cout << "Testing GCR on indef matrix "<< std::endl; @@ -332,6 +487,13 @@ int main (int argc, char ** argv) // PrecGeneralisedConjugateResidual UPGCR(1.0e-8,100000,simple,8,128); // UPGCR(HermIndefOp,src,result); + + /// Get themax eval + std::cout << "**************************************************"<< std::endl; + std::cout <<" Applying power method to find spectral range "< Date: Tue, 21 Jul 2015 13:52:59 +0900 Subject: [PATCH 07/10] This was needed to compile on gcc --- lib/qcd/hmc/integrators/Integrator.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/qcd/hmc/integrators/Integrator.h b/lib/qcd/hmc/integrators/Integrator.h index 5eb319b2..90707d51 100644 --- a/lib/qcd/hmc/integrators/Integrator.h +++ b/lib/qcd/hmc/integrators/Integrator.h @@ -69,10 +69,10 @@ namespace Grid{ LatticeColourMatrix Umu(U._grid); LatticeColourMatrix Pmu(U._grid); for (int mu = 0; mu < Nd; mu++){ - Umu=peekLorentz(U, mu); - Pmu=peekLorentz(*P, mu); + Umu=PeekIndex(U, mu); + Pmu=PeekIndex(*P, mu); Umu = expMat(Pmu, ep, Params.Nexp)*Umu; - pokeLorentz(U, Umu, mu); + PokeIndex(U, Umu, mu); } } From 8d654a86de43bc680f2a80ef3bff1da85ecc677f Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Tue, 21 Jul 2015 13:53:23 +0900 Subject: [PATCH 08/10] Small pretty layout change --- lib/qcd/action/fermion/g5HermitianLinop.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/qcd/action/fermion/g5HermitianLinop.h b/lib/qcd/action/fermion/g5HermitianLinop.h index e5b691d8..864af86d 100644 --- a/lib/qcd/action/fermion/g5HermitianLinop.h +++ b/lib/qcd/action/fermion/g5HermitianLinop.h @@ -1,7 +1,9 @@ #ifndef G5_HERMITIAN_LINOP #define G5_HERMITIAN_LINOP + namespace Grid { namespace QCD { + //////////////////////////////////////////////////////////////////// // Wrap an already herm matrix //////////////////////////////////////////////////////////////////// From 5ac625f7167ec14ec0fff81c317f0a103f769612 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Tue, 21 Jul 2015 13:54:09 +0900 Subject: [PATCH 09/10] No changes shown on git diff --- lib/algorithms/LinearOperator.h | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/lib/algorithms/LinearOperator.h b/lib/algorithms/LinearOperator.h index a804bceb..31e086ba 100644 --- a/lib/algorithms/LinearOperator.h +++ b/lib/algorithms/LinearOperator.h @@ -71,6 +71,47 @@ namespace Grid { } }; + //////////////////////////////////////////////////////////////////// + // Construct herm op and shift it for mgrid smoother + //////////////////////////////////////////////////////////////////// + template + class ShiftedMdagMLinearOperator : public LinearOperatorBase { + Matrix &_Mat; + RealD _shift; + public: + ShiftedMdagMLinearOperator(Matrix &Mat,RealD shift): _Mat(Mat), _shift(shift){}; + // Support for coarsening to a multigrid + void OpDiag (const Field &in, Field &out) { + _Mat.Mdiag(in,out); + assert(0); + } + void OpDir (const Field &in, Field &out,int dir,int disp) { + _Mat.Mdir(in,out,dir,disp); + assert(0); + } + void Op (const Field &in, Field &out){ + _Mat.M(in,out); + assert(0); + } + void AdjOp (const Field &in, Field &out){ + _Mat.Mdag(in,out); + assert(0); + } + void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){ + _Mat.MdagM(in,out,n1,n2); + out = out + _shift*in; + + ComplexD dot; + dot= innerProduct(in,out); + n1=real(dot); + n2=norm2(out); + } + void HermOp(const Field &in, Field &out){ + RealD n1,n2; + HermOpAndNorm(in,out,n1,n2); + } + }; + //////////////////////////////////////////////////////////////////// // Wrap an already herm matrix //////////////////////////////////////////////////////////////////// From 4e94ddad46ba32509ba5f5821f733440cc2a1565 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Tue, 21 Jul 2015 13:56:22 +0900 Subject: [PATCH 10/10] Merge --- lib/algorithms/approx/Remez.h | 2 +- lib/qcd/action/fermion/WilsonKernels.cc | 2 - lib/qcd/hmc/integrators/Integrator.cc | 2 +- lib/qcd/hmc/integrators/Integrator_base.h | 212 ++++++++++++++++++++++ tests/Test_multishift_sqrt.cc | 35 +++- 5 files changed, 247 insertions(+), 6 deletions(-) create mode 100644 lib/qcd/hmc/integrators/Integrator_base.h diff --git a/lib/algorithms/approx/Remez.h b/lib/algorithms/approx/Remez.h index e6a973df..336382d2 100644 --- a/lib/algorithms/approx/Remez.h +++ b/lib/algorithms/approx/Remez.h @@ -15,7 +15,7 @@ #ifndef INCLUDED_ALG_REMEZ_H #define INCLUDED_ALG_REMEZ_H -#include +#include #define JMAX 10000 //Maximum number of iterations of Newton's approximation #define SUM_MAX 10 // Maximum number of terms in exponential diff --git a/lib/qcd/action/fermion/WilsonKernels.cc b/lib/qcd/action/fermion/WilsonKernels.cc index 4054280a..bdc18eee 100644 --- a/lib/qcd/action/fermion/WilsonKernels.cc +++ b/lib/qcd/action/fermion/WilsonKernels.cc @@ -1,5 +1,4 @@ #include - namespace Grid { namespace QCD { @@ -13,7 +12,6 @@ void DiracOptDhopSite(CartesianStencil &st,LatticeDoubledGaugeField &U, vHalfSpinColourVector Uchi; int offset,local,perm, ptype; - // Xp int ss = sF; offset = st._offsets [Xp][ss]; diff --git a/lib/qcd/hmc/integrators/Integrator.cc b/lib/qcd/hmc/integrators/Integrator.cc index 8947405e..16a6513e 100644 --- a/lib/qcd/hmc/integrators/Integrator.cc +++ b/lib/qcd/hmc/integrators/Integrator.cc @@ -18,7 +18,7 @@ namespace Grid{ Pmu = zero; for(int mu=0;mu(P, Pmu, mu); } } diff --git a/lib/qcd/hmc/integrators/Integrator_base.h b/lib/qcd/hmc/integrators/Integrator_base.h new file mode 100644 index 00000000..38798d67 --- /dev/null +++ b/lib/qcd/hmc/integrators/Integrator_base.h @@ -0,0 +1,212 @@ +//-------------------------------------------------------------------- +/*! @file Integrator_base.h + * @brief Declaration of classes for the abstract Molecular Dynamics integrator + * + * @author Guido Cossu + */ +//-------------------------------------------------------------------- + +#ifndef INTEGRATOR_INCLUDED +#define INTEGRATOR_INCLUDED + +#include + +class Observer; + + +/*! @brief Abstract base class for Molecular Dynamics management */ + +namespace Grid{ + namespace QCD{ + + typedef Action* ActPtr; // now force the same size as the rest of the code + typedef std::vector ActionLevel; + typedef std::vector ActionSet; + typedef std::vector ObserverList; + + class LeapFrog; + + + struct IntegratorParameters{ + int Nexp; + int MDsteps; // number of outer steps + RealD trajL; // trajectory length + RealD stepsize; + + IntegratorParameters(int Nexp_, + int MDsteps_, + RealD trajL_): + Nexp(Nexp_),MDsteps(MDsteps_),trajL(trajL_),stepsize(trajL/MDsteps){}; + }; + + + namespace MDutils{ + void generate_momenta(LatticeLorentzColourMatrix&,GridParallelRNG&); + void generate_momenta_su3(LatticeLorentzColourMatrix&,GridParallelRNG&); + } + + + + + + template< class IntegratorPolicy > + class Integrator{ + private: + IntegratorParameters Params; + const ActionSet as; + const std::vector Nrel; //relative step size per level + //ObserverList observers; // not yet + std::unique_ptr P; + + IntegratorPolicy TheIntegrator;// contains parameters too + + + void update_P(LatticeLorentzColourMatrix&U, int level,double ep){ + for(int a=0; aderiv(U,force); + *P -= force*ep; + } + } + + + void update_U(LatticeLorentzColourMatrix&U, double ep){ + //rewrite exponential to deal with the lorentz index? + LatticeColourMatrix Umu(U._grid); + LatticeColourMatrix Pmu(U._grid); + for (int mu = 0; mu < Nd; mu++){ + Umu=PeekIndex(U, mu); + Pmu=PeekIndex(*P, mu); + Umu = expMat(Pmu, Complex(ep, 0.0))*Umu; + } + + } + + void register_observers(); + void notify_observers(); + + friend void IntegratorPolicy::step (LatticeLorentzColourMatrix& U, + int level, std::vector& clock, + Integrator* Integ); + public: + Integrator(IntegratorParameters Par, + ActionSet& Aset, std::vector Nrel_): + Params(Par),as(Aset),Nrel(Nrel_){ + assert(as.size() == Nrel.size()); + }; + + ~Integrator(){} + + + //Initialization of momenta and actions + void init(LatticeLorentzColourMatrix& U, + GridParallelRNG& pRNG){ + std::cout<< "Integrator init\n"; + if (!P) + P = new LatticeLorentzColourMatrix(U._grid); + MDutils::generate_momenta(*P,pRNG); + + for(int level=0; level< as.size(); ++level){ + for(int actionID=0; actionIDinit(U, pRNG); + } + } + } + + + + RealD S(LatticeLorentzColourMatrix& U){ + // Momenta + LatticeComplex Hloc = - trace((*P)*adj(*P)); + Complex Hsum = sum(Hloc); + + RealD H = Hsum.real(); + + // Actions + for(int level=0; levelS(U); + + return H; + } + + + + void integrate(LatticeLorentzColourMatrix& U, int level){ + std::vector clock; + clock.resize(as.size(),0); + for(int step=0; step< Params.MDsteps; ++step) // MD step + TheIntegrator.step(U,0,clock, *(this)); + } + }; + + + class MinimumNorm2{ + const double lambda = 0.1931833275037836; + public: + void step (LatticeLorentzColourMatrix& U, int level, std::vector& clock); + + }; + + class LeapFrog{ + public: + void step (LatticeLorentzColourMatrix& U, + int level, std::vector& clock, + Integrator* Integ){ + // cl : current level + // fl : final level + // eps : current step size + + int fl = Integ->as.size() -1; + double eps = Integ->Params.stepsize; + + // Get current level step size + for(int l=0; l<=level; ++l) eps/= Integ->Nrel[l]; + + int fin = 1; + for(int l=0; l<=level; ++l) fin*= Integ->Nrel[l]; + fin = 2*Integ->Params.MDsteps*fin - 1; + + for(int e=0; eNrel[level]; ++e){ + + if(clock[level] == 0){ // initial half step + Integ->update_P(U, level,eps/2); + ++clock[level]; + for(int l=0; lupdate_U(U, eps); + for(int l=0; lupdate_P(U, level,eps/2); + + ++clock[level]; + for(int l=0; lupdate_P(U, level,eps); + + clock[level]+=2; + for(int l=0; l Cheby(0.1,40.0,200,InverseApproximation); + + std::cout<<"Chebuy approx vector "<