1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-09-20 01:05:38 +01:00

Merge branch 'rmhmc_fix' into feature/rmhmc

This commit is contained in:
Chulwoo Jung 2020-07-23 14:47:24 -04:00
commit 69bd7082f1
3 changed files with 50 additions and 26 deletions

View File

@ -73,7 +73,8 @@ protected:
double t_U; // Track time passing on each level and for U and for P double t_U; // Track time passing on each level and for U and for P
std::vector<double> t_P; std::vector<double> t_P;
MomentaField P; // MomentaField P;
GeneralisedMomenta<FieldImplementation > P;
SmearingPolicy& Smearer; SmearingPolicy& Smearer;
RepresentationPolicy Representations; RepresentationPolicy Representations;
IntegratorParameters Params; IntegratorParameters Params;
@ -83,7 +84,7 @@ protected:
void update_P(Field& U, int level, double ep) void update_P(Field& U, int level, double ep)
{ {
t_P[level] += ep; t_P[level] += ep;
update_P(P, U, level, ep); update_P(P.Mom, U, level, ep);
std::cout << GridLogIntegrator << "[" << level << "] P " << " dt " << ep << " : t_P " << t_P[level] << std::endl; std::cout << GridLogIntegrator << "[" << level << "] P " << " dt " << ep << " : t_P " << t_P[level] << std::endl;
} }
@ -111,6 +112,21 @@ protected:
// input U actually not used in the fundamental case // input U actually not used in the fundamental case
// Fundamental updates, include smearing // Fundamental updates, include smearing
// Generalised momenta
// Derivative of the kinetic term must be computed before
// Mom is the momenta and gets updated by the
// actions derivatives
MomentaField MomDer(P.Mom.Grid());
P.M.ImportGauge(U);
P.DerivativeU(P.Mom, MomDer);
Mom -= MomDer * ep;
// Auxiliary fields
P.update_auxiliary_momenta(ep*0.5);
P.AuxiliaryFieldsDerivative(MomDer);
Mom -= MomDer * ep;
P.update_auxiliary_momenta(ep*0.5);
for (int a = 0; a < as[level].actions.size(); ++a) { for (int a = 0; a < as[level].actions.size(); ++a) {
double start_full = usecond(); double start_full = usecond();
Field force(U.Grid()); Field force(U.Grid());
@ -143,21 +159,21 @@ protected:
std::cout << GridLogIntegrator << "[" << level << "] P " std::cout << GridLogIntegrator << "[" << level << "] P "
<< " dt " << ep << " : t_P " << t_P[level] << std::endl; << " dt " << ep << " : t_P " << t_P[level] << std::endl;
// Fundamental updates, include smearing // Fundamental updates, include smearing
MomentaField Msum(P.Mom._grid); MomentaField Msum(P.Mom.Grid());
Msum = Zero(); Msum = Zero();
for (int a = 0; a < as[level].actions.size(); ++a) { for (int a = 0; a < as[level].actions.size(); ++a) {
// Compute the force terms for the lagrangian part // Compute the force terms for the lagrangian part
// We need to compute the derivative of the actions // We need to compute the derivative of the actions
// only once // only once
Field force(U._grid); Field force(U.Grid());
conformable(U._grid, P.Mom._grid); conformable(U.Grid(), P.Mom.Grid());
Field& Us = Smearer.get_U(as[level].actions.at(a)->is_smeared); Field& Us = Smearer.get_U(as[level].actions.at(a)->is_smeared);
as[level].actions.at(a)->deriv(Us, force); // deriv should NOT include Ta as[level].actions.at(a)->deriv(Us, force); // deriv should NOT include Ta
std::cout << GridLogIntegrator << "Smearing (on/off): " << as[level].actions.at(a)->is_smeared << std::endl; std::cout << GridLogIntegrator << "Smearing (on/off): " << as[level].actions.at(a)->is_smeared << std::endl;
if (as[level].actions.at(a)->is_smeared) Smearer.smeared_force(force); if (as[level].actions.at(a)->is_smeared) Smearer.smeared_force(force);
force = FieldImplementation::projectForce(force); // Ta for gauge fields force = FieldImplementation::projectForce(force); // Ta for gauge fields
Real force_abs = std::sqrt(norm2(force) / U._grid->gSites()); Real force_abs = std::sqrt(norm2(force) / U.Grid()->gSites());
std::cout << GridLogIntegrator << "|Force| site average: " << force_abs std::cout << GridLogIntegrator << "|Force| site average: " << force_abs
<< std::endl; << std::endl;
Msum += force; Msum += force;
@ -167,11 +183,11 @@ protected:
MomentaField OldMom = P.Mom; MomentaField OldMom = P.Mom;
double threshold = 1e-8; double threshold = 1e-8;
P.M.ImportGauge(U); P.M.ImportGauge(U);
MomentaField MomDer(P.Mom._grid); MomentaField MomDer(P.Mom.Grid());
MomentaField MomDer1(P.Mom._grid); MomentaField MomDer1(P.Mom.Grid());
MomentaField AuxDer(P.Mom._grid); MomentaField AuxDer(P.Mom.Grid());
MomDer1 = Zero(); MomDer1 = Zero();
MomentaField diff(P.Mom._grid); MomentaField diff(P.Mom.Grid());
double factor = 2.0; double factor = 2.0;
if (intermediate){ if (intermediate){
P.DerivativeU(P.Mom, MomDer1); P.DerivativeU(P.Mom, MomDer1);
@ -193,7 +209,7 @@ protected:
// Compute the derivative of the kinetic term // Compute the derivative of the kinetic term
// with respect to the gauge field // with respect to the gauge field
P.DerivativeU(NewMom, MomDer); P.DerivativeU(NewMom, MomDer);
Real force_abs = std::sqrt(norm2(MomDer) / U._grid->gSites()); Real force_abs = std::sqrt(norm2(MomDer) / U.Grid()->gSites());
std::cout << GridLogIntegrator << "|Force| laplacian site average: " << force_abs std::cout << GridLogIntegrator << "|Force| laplacian site average: " << force_abs
<< std::endl; << std::endl;
@ -213,7 +229,7 @@ protected:
void update_U(Field& U, double ep) void update_U(Field& U, double ep)
{ {
update_U(P, U, ep); update_U(P.Mom, U, ep);
t_U += ep; t_U += ep;
int fl = levels - 1; int fl = levels - 1;
@ -237,10 +253,10 @@ protected:
int fl = levels - 1; int fl = levels - 1;
std::cout << GridLogIntegrator << " " << "[" << fl << "] U " << " dt " << ep << " : t_U " << t_U << std::endl; std::cout << GridLogIntegrator << " " << "[" << fl << "] U " << " dt " << ep << " : t_U " << t_U << std::endl;
MomentaField Mom1(P.Mom._grid); MomentaField Mom1(P.Mom.Grid());
MomentaField Mom2(P.Mom._grid); MomentaField Mom2(P.Mom.Grid());
RealD RelativeError; RealD RelativeError;
Field diff(U._grid); Field diff(U.Grid());
Real threshold = 1e-8; Real threshold = 1e-8;
int counter = 1; int counter = 1;
int MaxCounter = 100; int MaxCounter = 100;
@ -286,10 +302,10 @@ protected:
public: public:
Integrator(GridBase* grid, IntegratorParameters Par, Integrator(GridBase* grid, IntegratorParameters Par,
ActionSet<Field, RepresentationPolicy>& Aset, ActionSet<Field, RepresentationPolicy>& Aset,
SmearingPolicy& Sm) SmearingPolicy& Sm, Metric<MomentaField>& M)
: Params(Par), : Params(Par),
as(Aset), as(Aset),
P(grid), P(grid, M),
levels(Aset.size()), levels(Aset.size()),
Smearer(Sm), Smearer(Sm),
Representations(grid) Representations(grid)
@ -326,7 +342,9 @@ public:
void reverse_momenta() void reverse_momenta()
{ {
P *= -1.0; // P *= -1.0;
P.Mom *= -1.0;
P.AuxMom *= -1.0;
} }
// to be used by the actionlevel class to iterate // to be used by the actionlevel class to iterate
@ -346,10 +364,13 @@ public:
// Initialization of momenta and actions // Initialization of momenta and actions
void refresh(Field& U, GridParallelRNG& pRNG) void refresh(Field& U, GridParallelRNG& pRNG)
{ {
assert(P.Grid() == U.Grid()); assert(P.Mom.Grid() == U.Grid());
std::cout << GridLogIntegrator << "Integrator refresh\n"; std::cout << GridLogIntegrator << "Integrator refresh\n";
FieldImplementation::generate_momenta(P, pRNG); // FieldImplementation::generate_momenta(P.Mom, pRNG);
P.M.ImportGauge(U);
P.MomentaDistribution(pRNG);
// Update the smeared fields, can be implemented as observer // Update the smeared fields, can be implemented as observer
// necessary to keep the fields updated even after a reject // necessary to keep the fields updated even after a reject
@ -395,9 +416,11 @@ public:
std::cout << GridLogIntegrator << "Integrator action\n"; std::cout << GridLogIntegrator << "Integrator action\n";
RealD H = - FieldImplementation::FieldSquareNorm(P)/HMC_MOMENTUM_DENOMINATOR; // - trace (P*P)/denom // RealD H = - FieldImplementation::FieldSquareNorm(P)/HMC_MOMENTUM_DENOMINATOR; // - trace (P*P)/denom
P.M.ImportGauge(U);
RealD H = - P.MomentaAction();
RealD Hterm; RealD Hterm;
std::cout << GridLogMessage << "Momentum action H_p = " << H << "\n";
// Actions // Actions
for (int level = 0; level < as.size(); ++level) { for (int level = 0; level < as.size(); ++level) {

View File

@ -102,7 +102,7 @@ public:
std::string integrator_name(){return "LeapFrog";} std::string integrator_name(){return "LeapFrog";}
LeapFrog(GridBase* grid, IntegratorParameters Par, ActionSet<Field, RepresentationPolicy>& Aset, SmearingPolicy& Sm, Metric<Field>& M) LeapFrog(GridBase* grid, IntegratorParameters Par, ActionSet<Field, RepresentationPolicy>& Aset, SmearingPolicy& Sm, Metric<Field>& M)
: Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(grid, Par, Aset, Sm){}; : Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(grid, Par, Aset, Sm,M){};
void step(Field& U, int level, int _first, int _last) { void step(Field& U, int level, int _first, int _last) {
int fl = this->as.size() - 1; int fl = this->as.size() - 1;
@ -145,7 +145,7 @@ public:
INHERIT_FIELD_TYPES(FieldImplementation); INHERIT_FIELD_TYPES(FieldImplementation);
MinimumNorm2(GridBase* grid, IntegratorParameters Par, ActionSet<Field, RepresentationPolicy>& Aset, SmearingPolicy& Sm, Metric<Field>& M) MinimumNorm2(GridBase* grid, IntegratorParameters Par, ActionSet<Field, RepresentationPolicy>& Aset, SmearingPolicy& Sm, Metric<Field>& M)
: Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(grid, Par, Aset, Sm){}; : Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(grid, Par, Aset, Sm,M){};
std::string integrator_name(){return "MininumNorm2";} std::string integrator_name(){return "MininumNorm2";}
@ -209,7 +209,7 @@ public:
ActionSet<Field, RepresentationPolicy>& Aset, ActionSet<Field, RepresentationPolicy>& Aset,
SmearingPolicy& Sm, Metric<Field>& M) SmearingPolicy& Sm, Metric<Field>& M)
: Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>( : Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(
grid, Par, Aset, Sm){}; grid, Par, Aset, Sm,M){};
std::string integrator_name(){return "ForceGradient";} std::string integrator_name(){return "ForceGradient";}

View File

@ -55,7 +55,8 @@ int main(int argc, char **argv) {
// Typedefs to simplify notation // Typedefs to simplify notation
typedef GenericHMCRunner<ImplicitMinimumNorm2> HMCWrapper; // Uses the default minimum norm typedef GenericHMCRunner<ImplicitMinimumNorm2> HMCWrapper; // Uses the default minimum norm
// Serialiser // Serialiser
typedef Grid::JSONReader Serialiser; // typedef Grid::JSONReader Serialiser;
typedef Grid::XmlReader Serialiser;
HMCWrapper TheHMC; HMCWrapper TheHMC;