1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-12-24 11:55:27 +00:00

Added Scalar action for fields in the adjoint representation

This commit is contained in:
Guido Cossu 2017-03-14 14:55:18 +09:00
parent b3dede4dd3
commit 831ca4e3bf
7 changed files with 227 additions and 121 deletions

View File

@ -69,6 +69,7 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
//////////////////////////////////////////// ////////////////////////////////////////////
#include <Grid/qcd/action/scalar/ScalarImpl.h> #include <Grid/qcd/action/scalar/ScalarImpl.h>
#include <Grid/qcd/action/scalar/ScalarAction.h> #include <Grid/qcd/action/scalar/ScalarAction.h>
#include <Grid/qcd/action/scalar/ScalarInteractionAction.h>
namespace Grid { namespace Grid {
namespace QCD { namespace QCD {
@ -106,6 +107,10 @@ typedef ScalarAction<ScalarImplR> ScalarActionR;
typedef ScalarAction<ScalarImplF> ScalarActionF; typedef ScalarAction<ScalarImplF> ScalarActionF;
typedef ScalarAction<ScalarImplD> ScalarActionD; typedef ScalarAction<ScalarImplD> ScalarActionD;
typedef ScalarInteractionAction<ScalarAdjImplR> ScalarAdjActionR;
typedef ScalarInteractionAction<ScalarAdjImplF> ScalarAdjActionF;
typedef ScalarInteractionAction<ScalarAdjImplD> ScalarAdjActionD;
}} }}
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -6,10 +6,10 @@
Copyright (C) 2015 Copyright (C) 2015
Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk> Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
Author: Peter Boyle <paboyle@ph.ed.ac.uk> Author: Peter Boyle <paboyle@ph.ed.ac.uk>
Author: neo <cossu@post.kek.jp> Author: neo <cossu@post.kek.jp>
Author: paboyle <paboyle@ph.ed.ac.uk> Author: paboyle <paboyle@ph.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
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -35,50 +35,49 @@ directory
namespace Grid { namespace Grid {
// FIXME drop the QCD namespace everywhere here // FIXME drop the QCD namespace everywhere here
template <class Impl> template <class Impl>
class ScalarAction : public QCD::Action<typename Impl::Field> { class ScalarAction : public QCD::Action<typename Impl::Field> {
public: public:
INHERIT_FIELD_TYPES(Impl); INHERIT_FIELD_TYPES(Impl);
private: private:
RealD mass_square; RealD mass_square;
RealD lambda; RealD lambda;
public:
ScalarAction(RealD ms, RealD l) : mass_square(ms), lambda(l){};
virtual std::string LogParameters(){ public:
ScalarAction(RealD ms, RealD l) : mass_square(ms), lambda(l) {}
virtual std::string LogParameters() {
std::stringstream sstream; std::stringstream sstream;
sstream << GridLogMessage << "[ScalarAction] lambda : " << lambda << std::endl; sstream << GridLogMessage << "[ScalarAction] lambda : " << lambda << std::endl;
sstream << GridLogMessage << "[ScalarAction] mass_square : " << mass_square << std::endl; sstream << GridLogMessage << "[ScalarAction] mass_square : " << mass_square << std::endl;
return sstream.str(); return sstream.str();
} }
virtual std::string action_name() {return "ScalarAction";}
virtual std::string action_name(){return "ScalarAction";}
virtual void refresh(const Field &U, GridParallelRNG &pRNG) {} // noop as no pseudoferms
virtual void refresh(const Field &U,
GridParallelRNG &pRNG){}; // noop as no pseudoferms
virtual RealD S(const Field &p) { virtual RealD S(const Field &p) {
return (mass_square * 0.5 + QCD::Nd) * ScalarObs<Impl>::sumphisquared(p) + return (mass_square * 0.5 + QCD::Nd) * ScalarObs<Impl>::sumphisquared(p) +
(lambda / 24.) * ScalarObs<Impl>::sumphifourth(p) + (lambda / 24.) * ScalarObs<Impl>::sumphifourth(p) +
ScalarObs<Impl>::sumphider(p); ScalarObs<Impl>::sumphider(p);
}; };
virtual void deriv(const Field &p, virtual void deriv(const Field &p,
Field &force) { Field &force) {
Field tmp(p._grid); Field tmp(p._grid);
Field p2(p._grid); Field p2(p._grid);
ScalarObs<Impl>::phisquared(p2, p); ScalarObs<Impl>::phisquared(p2, p);
tmp = -(Cshift(p, 0, -1) + Cshift(p, 0, 1)); tmp = -(Cshift(p, 0, -1) + Cshift(p, 0, 1));
for (int mu = 1; mu < QCD::Nd; mu++) tmp -= Cshift(p, mu, -1) + Cshift(p, mu, 1); for (int mu = 1; mu < QCD::Nd; mu++) tmp -= Cshift(p, mu, -1) + Cshift(p, mu, 1);
force=+(mass_square + 2. * QCD::Nd) * p + (lambda / 6.) * p2 * p + tmp; force =+(mass_square + 2. * QCD::Nd) * p + (lambda / 6.) * p2 * p + tmp;
}; }
}; };
} // Grid
} // namespace Grid
#endif // SCALAR_ACTION_H #endif // SCALAR_ACTION_H

View File

@ -5,96 +5,99 @@
namespace Grid { namespace Grid {
//namespace QCD { //namespace QCD {
template <class S> template <class S>
class ScalarImplTypes { class ScalarImplTypes {
public: public:
typedef S Simd; typedef S Simd;
template <typename vtype> template <typename vtype>
using iImplField = iScalar<iScalar<iScalar<vtype> > >; using iImplField = iScalar<iScalar<iScalar<vtype> > >;
typedef iImplField<Simd> SiteField; typedef iImplField<Simd> SiteField;
typedef Lattice<SiteField> Field; typedef Lattice<SiteField> Field;
static inline void generate_momenta(Field& P, GridParallelRNG& pRNG){ static inline void generate_momenta(Field& P, GridParallelRNG& pRNG) {
gaussian(pRNG, P); gaussian(pRNG, P);
} }
static inline Field projectForce(Field& P){return P;} static inline Field projectForce(Field& P){return P;}
static inline void update_field(Field& P, Field& U, double ep){ static inline void update_field(Field& P, Field& U, double ep) {
U += P*ep; U += P*ep;
} }
static inline RealD FieldSquareNorm(Field& U){ static inline RealD FieldSquareNorm(Field& U) {
return (- sum(trace(U*U))/2.0); return (- sum(trace(U*U))/2.0);
} }
static inline void HotConfiguration(GridParallelRNG &pRNG, Field &U) { static inline void HotConfiguration(GridParallelRNG &pRNG, Field &U) {
gaussian(pRNG, U); gaussian(pRNG, U);
} }
static inline void TepidConfiguration(GridParallelRNG &pRNG, Field &U) { static inline void TepidConfiguration(GridParallelRNG &pRNG, Field &U) {
gaussian(pRNG, U); gaussian(pRNG, U);
} }
static inline void ColdConfiguration(GridParallelRNG &pRNG, Field &U) { static inline void ColdConfiguration(GridParallelRNG &pRNG, Field &U) {
U = 1.0; U = 1.0;
} }
}; };
template <class S, unsigned int N> template <class S, unsigned int N>
class ScalarMatrixImplTypes { class ScalarAdjMatrixImplTypes {
public: public:
typedef S Simd; typedef S Simd;
template <typename vtype> template <typename vtype>
using iImplField = iScalar<iScalar<iMatrix<vtype, N> > >; using iImplField = iScalar<iScalar<iMatrix<vtype, N> > >;
typedef iImplField<Simd> SiteField; typedef iImplField<Simd> SiteField;
typedef Lattice<SiteField> Field; typedef Lattice<SiteField> Field;
static inline void generate_momenta(Field& P, GridParallelRNG& pRNG){ static inline void generate_momenta(Field& P, GridParallelRNG& pRNG) {
gaussian(pRNG, P); QCD::SU<N>::GaussianFundamentalLieAlgebraMatrix(pRNG, P);
} }
static inline Field projectForce(Field& P){return P;} static inline Field projectForce(Field& P) {return P;}
static inline void update_field(Field& P, Field& U, double ep){ static inline void update_field(Field& P, Field& U, double ep) {
U += P*ep; U += P*ep;
} }
static inline RealD FieldSquareNorm(Field& U){ static inline RealD FieldSquareNorm(Field& U) {
return (TensorRemove(- sum(trace(U*U))*0.5).real()); return (TensorRemove(sum(trace(U*U))).real());
} }
static inline void HotConfiguration(GridParallelRNG &pRNG, Field &U) { static inline void HotConfiguration(GridParallelRNG &pRNG, Field &U) {
gaussian(pRNG, U); QCD::SU<N>::LieRandomize(pRNG, U);
} }
static inline void TepidConfiguration(GridParallelRNG &pRNG, Field &U) { static inline void TepidConfiguration(GridParallelRNG &pRNG, Field &U) {
gaussian(pRNG, U); QCD::SU<N>::LieRandomize(pRNG, U, 0.01);
} }
static inline void ColdConfiguration(GridParallelRNG &pRNG, Field &U) { static inline void ColdConfiguration(GridParallelRNG &pRNG, Field &U) {
U = 1.0; U = zero;
} }
}; };
typedef ScalarImplTypes<vReal> ScalarImplR; typedef ScalarImplTypes<vReal> ScalarImplR;
typedef ScalarImplTypes<vRealF> ScalarImplF; typedef ScalarImplTypes<vRealF> ScalarImplF;
typedef ScalarImplTypes<vRealD> ScalarImplD; typedef ScalarImplTypes<vRealD> ScalarImplD;
//} // Hardcoding here the size of the matrices
} typedef ScalarAdjMatrixImplTypes<vComplex, QCD::Nc> ScalarAdjImplR;
typedef ScalarAdjMatrixImplTypes<vComplexF, QCD::Nc> ScalarAdjImplF;
typedef ScalarAdjMatrixImplTypes<vComplexD, QCD::Nc> ScalarAdjImplD;
//}
}
#endif #endif

View File

@ -6,10 +6,7 @@
Copyright (C) 2015 Copyright (C) 2015
Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk> Author: Guido Cossu <guido,cossu@ed.ac.uk>
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
Author: neo <cossu@post.kek.jp>
Author: paboyle <paboyle@ph.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
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -30,55 +27,54 @@ directory
*************************************************************************************/ *************************************************************************************/
/* END LEGAL */ /* END LEGAL */
#ifndef SCALAR_ACTION_H #ifndef SCALAR_INT_ACTION_H
#define SCALAR_ACTION_H #define SCALAR_INT_ACTION_H
namespace Grid { namespace Grid {
// FIXME drop the QCD namespace everywhere here // FIXME drop the QCD namespace everywhere here
template <class Impl> template <class Impl>
class ScalarInteractionAction : public QCD::Action<typename Impl::Field> { class ScalarInteractionAction : public QCD::Action<typename Impl::Field> {
public:
INHERIT_FIELD_TYPES(Impl);
private:
RealD mass_square; RealD mass_square;
RealD lambda; RealD lambda;
public:
ScalarAction(RealD ms, RealD l) : mass_square(ms), lambda(l){};
virtual std::string LogParameters(){ public:
INHERIT_FIELD_TYPES(Impl);
ScalarInteractionAction(RealD ms, RealD l) : mass_square(ms), lambda(l) {}
virtual std::string LogParameters() {
std::stringstream sstream; std::stringstream sstream;
sstream << GridLogMessage << "[ScalarAction] lambda : " << lambda << std::endl; sstream << GridLogMessage << "[ScalarAction] lambda : " << lambda << std::endl;
sstream << GridLogMessage << "[ScalarAction] mass_square : " << mass_square << std::endl; sstream << GridLogMessage << "[ScalarAction] mass_square : " << mass_square << std::endl;
return sstream.str(); return sstream.str();
} }
virtual std::string action_name(){return "ScalarAction";}
virtual void refresh(const Field &U,
GridParallelRNG &pRNG){}; // noop as no pseudoferms
virtual RealD S(const Field &p) {
return (mass_square * 0.5 + QCD::Nd) * ScalarObs<Impl>::sumphisquared(p) +
(lambda / 24.) * ScalarObs<Impl>::sumphifourth(p) +
ScalarObs<Impl>::sumphider(p);
};
virtual void deriv(const Field &p,
Field &force) {
Field tmp(p._grid);
Field p2(p._grid);
ScalarObs<Impl>::phisquared(p2, p);
tmp = -(Cshift(p, 0, -1) + Cshift(p, 0, 1));
for (int mu = 1; mu < QCD::Nd; mu++) tmp -= Cshift(p, mu, -1) + Cshift(p, mu, 1);
force=+(mass_square + 2. * QCD::Nd) * p + (lambda / 6.) * p2 * p + tmp;
};
};
} // Grid
#endif // SCALAR_ACTION_H virtual std::string action_name() {return "ScalarAction";}
virtual void refresh(const Field &U,
GridParallelRNG &pRNG) {} // noop as no pseudoferms
virtual RealD S(const Field &p) {
Field action(p._grid);
Field pshift(p._grid);
Field phisquared(p._grid);
phisquared = p*p;
action = (2.0*QCD::Nd + mass_square)*phisquared + lambda*phisquared*phisquared;
for (int mu = 0; mu < QCD::Nd; mu++) {
pshift = Cshift(p, mu, +1); // not efficient implement with stencils
action -= pshift*p + p*pshift;
}
return -(TensorRemove(sum(trace(action)))).real();
};
virtual void deriv(const Field &p,
Field &force) {
force = (2.0*QCD::Nd + mass_square)*p + 2.0*lambda*p*p*p;
// following is inefficient
for (int mu = 0; mu < QCD::Nd; mu++) force -= Cshift(p, mu, -1) + Cshift(p, mu, 1);
}
};
} // namespace Grid
#endif // SCALAR_INT_ACTION_H

View File

@ -202,6 +202,9 @@ using GenericHMCRunnerTemplate = HMCWrapperTemplate<Implementation, Integrator,
typedef HMCWrapperTemplate<ScalarImplR, MinimumNorm2, ScalarFields> typedef HMCWrapperTemplate<ScalarImplR, MinimumNorm2, ScalarFields>
ScalarGenericHMCRunner; ScalarGenericHMCRunner;
typedef HMCWrapperTemplate<ScalarAdjImplR, MinimumNorm2, ScalarMatrixFields>
ScalarAdjGenericHMCRunner;
} // namespace QCD } // namespace QCD
} // namespace Grid } // namespace Grid

View File

@ -62,7 +62,7 @@ class Representations {
typedef Representations<FundamentalRepresentation> NoHirep; typedef Representations<FundamentalRepresentation> NoHirep;
typedef Representations<EmptyRep<typename ScalarImplR::Field> > ScalarFields; typedef Representations<EmptyRep<typename ScalarImplR::Field> > ScalarFields;
//typedef Representations<EmptyRep<typename ScalarMatrixImplR::Field> > ScalarMatrixFields; typedef Representations<EmptyRep<typename ScalarAdjImplR::Field> > ScalarMatrixFields;
// Helper classes to access the elements // Helper classes to access the elements
// Strips the first N parameters from the tuple // Strips the first N parameters from the tuple

View File

@ -0,0 +1,100 @@
/*************************************************************************************
Grid physics library, www.github.com/paboyle/Grid
Source file: ./tests/Test_hmc_WilsonFermionGauge.cc
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 */
#include <Grid/Grid.h>
namespace Grid{
class ScalarActionParameters : Serializable {
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(ScalarActionParameters,
double, mass_squared,
double, lambda);
};
}
int main(int argc, char **argv) {
using namespace Grid;
using namespace Grid::QCD;
Grid_init(&argc, &argv);
int threads = GridThread::GetThreads();
// here make a routine to print all the relevant information on the run
std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl;
// Typedefs to simplify notation
typedef ScalarAdjGenericHMCRunner HMCWrapper; // Uses the default minimum norm, real scalar fields
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
HMCWrapper TheHMC;
// Grid from the command line
GridModule ScalarGrid;
ScalarGrid.set_full( SpaceTimeGrid::makeFourDimGrid(
GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()),
GridDefaultMpi()));
ScalarGrid.set_rb(SpaceTimeGrid::makeFourDimRedBlackGrid(ScalarGrid.get_full()));
TheHMC.Resources.AddGrid("scalar", ScalarGrid);
// Possibile to create the module by hand
// hardcoding parameters or using a Reader
// Checkpointer definition
CheckpointerParameters CPparams;
CPparams.config_prefix = "ckpoint_scalar_lat";
CPparams.rng_prefix = "ckpoint_scalar_rng";
CPparams.saveInterval = 50;
CPparams.format = "IEEE64BIG";
TheHMC.Resources.LoadBinaryCheckpointer(CPparams);
RNGModuleParameters RNGpar;
RNGpar.serial_seeds = "1 2 3 4 5";
RNGpar.parallel_seeds = "6 7 8 9 10";
TheHMC.Resources.SetRNGSeeds(RNGpar);
/////////////////////////////////////////////////////////////
// Collect actions, here use more encapsulation
// Scalar action in adjoint representation
ScalarActionParameters SPar;
SPar.mass_squared = 0.5;
SPar.lambda = 0.1;
ScalarAdjActionR Saction(SPar.mass_squared, SPar.lambda);
// Collect actions
ActionLevel<ScalarAdjActionR::Field, ScalarMatrixFields> Level1(1);
Level1.push_back(&Saction);
TheHMC.TheAction.push_back(Level1);
/////////////////////////////////////////////////////////////
// HMC parameters are serialisable
TheHMC.Parameters.MD.MDsteps = 10;
TheHMC.Parameters.MD.trajL = 1.0;
TheHMC.ReadCommandLine(argc, argv);
TheHMC.Run();
Grid_finalize();
} // main