mirror of
				https://github.com/paboyle/Grid.git
				synced 2025-11-04 05:54:32 +00:00 
			
		
		
		
	Correcting modules use in test files
This commit is contained in:
		@@ -138,15 +138,7 @@ class HMCWrapperTemplate: public HMCRunnerBase<ReaderClass> {
 | 
			
		||||
 | 
			
		||||
    // Can move this outside?
 | 
			
		||||
    typedef IntegratorType<SmearingPolicy> TheIntegrator;
 | 
			
		||||
    // Metric
 | 
			
		||||
    //TrivialMetric<typename Implementation::Field> Mtr;
 | 
			
		||||
    ConjugateGradient<LatticeGaugeField> CG(1.0e-8,10000);
 | 
			
		||||
    LaplacianParams LapPar(0.0001, 1.0, 1000, 1e-8, 12, 64);
 | 
			
		||||
    RealD Kappa = 0.6;
 | 
			
		||||
 | 
			
		||||
    // Better to pass the generalised momenta to the integrator
 | 
			
		||||
    LaplacianAdjointField<PeriodicGimplR> Laplacian(UGrid, CG, LapPar, Kappa);
 | 
			
		||||
    TheIntegrator MDynamics(UGrid, Parameters.MD, TheAction, Smearing, Laplacian);
 | 
			
		||||
    TheIntegrator MDynamics(UGrid, Parameters.MD, TheAction, Smearing);
 | 
			
		||||
 | 
			
		||||
    if (Parameters.StartingType == "HotStart") {
 | 
			
		||||
      // Hot start
 | 
			
		||||
 
 | 
			
		||||
@@ -77,8 +77,7 @@ class Integrator {
 | 
			
		||||
  double t_U;  // Track time passing on each level and for U and for P
 | 
			
		||||
  std::vector<double> t_P;  
 | 
			
		||||
 | 
			
		||||
  //MomentaField P;
 | 
			
		||||
  GeneralisedMomenta<FieldImplementation > P;
 | 
			
		||||
  MomentaField P;
 | 
			
		||||
  SmearingPolicy& Smearer;
 | 
			
		||||
  RepresentationPolicy Representations;
 | 
			
		||||
  IntegratorParameters Params;
 | 
			
		||||
@@ -87,7 +86,7 @@ class Integrator {
 | 
			
		||||
 | 
			
		||||
  void update_P(Field& U, int level, double ep) {
 | 
			
		||||
    t_P[level] += ep;
 | 
			
		||||
    update_P(P.Mom, U, level, ep);
 | 
			
		||||
    update_P(P, U, level, ep);
 | 
			
		||||
 | 
			
		||||
    std::cout << GridLogIntegrator << "[" << level << "] P "
 | 
			
		||||
              << " dt " << ep << " : t_P " << t_P[level] << std::endl;
 | 
			
		||||
@@ -115,23 +114,7 @@ class Integrator {
 | 
			
		||||
    // input U actually not used in the fundamental case
 | 
			
		||||
    // 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) {
 | 
			
		||||
      Field force(U._grid);
 | 
			
		||||
      conformable(U._grid, Mom._grid);
 | 
			
		||||
      Field& Us = Smearer.get_U(as[level].actions.at(a)->is_smeared);
 | 
			
		||||
@@ -145,89 +128,12 @@ class Integrator {
 | 
			
		||||
      Mom -= force * ep; 
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // Force from the other representations
 | 
			
		||||
    as[level].apply(update_P_hireps, Representations, Mom, U, ep);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void implicit_update_P(Field& U, int level, double ep, bool intermediate = false) {
 | 
			
		||||
    t_P[level] += ep;
 | 
			
		||||
 | 
			
		||||
    std::cout << GridLogIntegrator << "[" << level << "] P "
 | 
			
		||||
              << " dt " << ep << " : t_P " << t_P[level] << std::endl;
 | 
			
		||||
    // Fundamental updates, include smearing
 | 
			
		||||
    MomentaField Msum(P.Mom._grid);
 | 
			
		||||
    Msum = zero;
 | 
			
		||||
    for (int a = 0; a < as[level].actions.size(); ++a) {
 | 
			
		||||
      // Compute the force terms for the lagrangian part
 | 
			
		||||
      // We need to compute the derivative of the actions
 | 
			
		||||
      // only once
 | 
			
		||||
      Field force(U._grid);
 | 
			
		||||
      conformable(U._grid, P.Mom._grid);
 | 
			
		||||
      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
 | 
			
		||||
 | 
			
		||||
      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);
 | 
			
		||||
      force = FieldImplementation::projectForce(force);  // Ta for gauge fields
 | 
			
		||||
      Real force_abs = std::sqrt(norm2(force) / U._grid->gSites());
 | 
			
		||||
      std::cout << GridLogIntegrator << "|Force| site average: " << force_abs
 | 
			
		||||
                << std::endl;
 | 
			
		||||
      Msum += force;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    MomentaField NewMom = P.Mom;
 | 
			
		||||
    MomentaField OldMom = P.Mom;
 | 
			
		||||
    double threshold = 1e-6;
 | 
			
		||||
    P.M.ImportGauge(U);
 | 
			
		||||
    MomentaField MomDer(P.Mom._grid);
 | 
			
		||||
    MomentaField MomDer1(P.Mom._grid);
 | 
			
		||||
    MomentaField AuxDer(P.Mom._grid);
 | 
			
		||||
    MomDer1 = zero;
 | 
			
		||||
    MomentaField diff(P.Mom._grid);
 | 
			
		||||
    double factor = 2.0;
 | 
			
		||||
    if (intermediate){
 | 
			
		||||
      P.DerivativeU(P.Mom, MomDer1);
 | 
			
		||||
      factor = 1.0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Auxiliary fields
 | 
			
		||||
    P.update_auxiliary_momenta(ep*0.5);
 | 
			
		||||
    P.AuxiliaryFieldsDerivative(AuxDer);
 | 
			
		||||
    Msum += AuxDer;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    // Here run recursively
 | 
			
		||||
    int counter = 1;
 | 
			
		||||
    RealD RelativeError;
 | 
			
		||||
    do {
 | 
			
		||||
      std::cout << GridLogIntegrator << "UpdateP implicit step "<< counter << std::endl;
 | 
			
		||||
 | 
			
		||||
      // Compute the derivative of the kinetic term
 | 
			
		||||
      // with respect to the gauge field
 | 
			
		||||
      P.DerivativeU(NewMom, MomDer);
 | 
			
		||||
      Real force_abs = std::sqrt(norm2(MomDer) / U._grid->gSites());
 | 
			
		||||
      std::cout << GridLogIntegrator << "|Force| laplacian site average: " << force_abs
 | 
			
		||||
                << std::endl;
 | 
			
		||||
 | 
			
		||||
      NewMom = P.Mom - ep* 0.5 * (2.0*Msum + factor*MomDer + MomDer1);// simplify
 | 
			
		||||
      diff = NewMom - OldMom;
 | 
			
		||||
      counter++;
 | 
			
		||||
      RelativeError = std::sqrt(norm2(diff))/std::sqrt(norm2(NewMom));
 | 
			
		||||
      std::cout << GridLogIntegrator << "UpdateP RelativeError: " << RelativeError << std::endl;
 | 
			
		||||
      OldMom = NewMom;
 | 
			
		||||
    } while (RelativeError > threshold);
 | 
			
		||||
 | 
			
		||||
    P.Mom = NewMom;
 | 
			
		||||
 | 
			
		||||
    // update the auxiliary fields momenta    
 | 
			
		||||
    P.update_auxiliary_momenta(ep*0.5);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  void update_U(Field& U, double ep) {
 | 
			
		||||
    update_U(P.Mom, U, ep);
 | 
			
		||||
    update_U(P, U, ep);
 | 
			
		||||
 | 
			
		||||
    t_U += ep;
 | 
			
		||||
    int fl = levels - 1;
 | 
			
		||||
@@ -245,68 +151,15 @@ class Integrator {
 | 
			
		||||
    Representations.update(U);  // void functions if fundamental representation
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void implicit_update_U(Field&U, double ep){
 | 
			
		||||
    t_U += ep;
 | 
			
		||||
    int fl = levels - 1;
 | 
			
		||||
    std::cout << GridLogIntegrator << "   " << "[" << fl << "] U " << " dt " << ep << " : t_U " << t_U << std::endl;
 | 
			
		||||
 | 
			
		||||
    MomentaField Mom1(P.Mom._grid);
 | 
			
		||||
    MomentaField Mom2(P.Mom._grid);
 | 
			
		||||
    RealD RelativeError;
 | 
			
		||||
    Field diff(U._grid);
 | 
			
		||||
    Real threshold = 1e-8;
 | 
			
		||||
    int counter = 1;
 | 
			
		||||
    int MaxCounter = 100;
 | 
			
		||||
 | 
			
		||||
    Field OldU = U;
 | 
			
		||||
    Field NewU = U;
 | 
			
		||||
 | 
			
		||||
    P.M.ImportGauge(U);
 | 
			
		||||
    P.DerivativeP(Mom1); // first term in the derivative 
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
    P.update_auxiliary_fields(ep*0.5);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    do {
 | 
			
		||||
      std::cout << GridLogIntegrator << "UpdateU implicit step "<< counter << std::endl;
 | 
			
		||||
      
 | 
			
		||||
      P.DerivativeP(Mom2); // second term in the derivative, on the updated U
 | 
			
		||||
      MomentaField sum = (Mom1 + Mom2);
 | 
			
		||||
      //std::cout << GridLogMessage << "sum Norm " << norm2(sum) << std::endl;
 | 
			
		||||
 | 
			
		||||
      for (int mu = 0; mu < Nd; mu++) {
 | 
			
		||||
        auto Umu = PeekIndex<LorentzIndex>(U, mu);
 | 
			
		||||
        auto Pmu = PeekIndex<LorentzIndex>(sum, mu);
 | 
			
		||||
        Umu = expMat(Pmu, ep * 0.5, 24) * Umu;
 | 
			
		||||
        PokeIndex<LorentzIndex>(NewU, ProjectOnGroup(Umu), mu);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      diff = NewU - OldU;
 | 
			
		||||
      RelativeError = std::sqrt(norm2(diff))/std::sqrt(norm2(NewU));
 | 
			
		||||
      std::cout << GridLogIntegrator << "UpdateU RelativeError: " << RelativeError << std::endl;
 | 
			
		||||
      
 | 
			
		||||
      P.M.ImportGauge(NewU);
 | 
			
		||||
      OldU = NewU; // some redundancy to be eliminated
 | 
			
		||||
      counter++;
 | 
			
		||||
    } while (RelativeError > threshold && counter < MaxCounter);
 | 
			
		||||
 | 
			
		||||
    U = NewU;
 | 
			
		||||
 | 
			
		||||
    P.update_auxiliary_fields(ep*0.5);
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  virtual void step(Field& U, int level, int first, int last) = 0;
 | 
			
		||||
 | 
			
		||||
 public:
 | 
			
		||||
  Integrator(GridBase* grid, IntegratorParameters Par,
 | 
			
		||||
             ActionSet<Field, RepresentationPolicy>& Aset,
 | 
			
		||||
             SmearingPolicy& Sm, Metric<MomentaField>& M)
 | 
			
		||||
             SmearingPolicy& Sm)
 | 
			
		||||
      : Params(Par),
 | 
			
		||||
        as(Aset),
 | 
			
		||||
        P(grid, M),
 | 
			
		||||
        P(grid),
 | 
			
		||||
        levels(Aset.size()),
 | 
			
		||||
        Smearer(Sm),
 | 
			
		||||
        Representations(grid) {
 | 
			
		||||
@@ -339,8 +192,7 @@ class Integrator {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void reverse_momenta(){
 | 
			
		||||
    P.Mom *= -1.0;
 | 
			
		||||
    P.AuxMom *= -1.0;
 | 
			
		||||
    P *= -1.0;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // to be used by the actionlevel class to iterate
 | 
			
		||||
@@ -359,13 +211,10 @@ class Integrator {
 | 
			
		||||
 | 
			
		||||
  // Initialization of momenta and actions
 | 
			
		||||
  void refresh(Field& U, GridParallelRNG& pRNG) {
 | 
			
		||||
    assert(P.Mom._grid == U._grid);
 | 
			
		||||
    assert(P._grid == U._grid);
 | 
			
		||||
    std::cout << GridLogIntegrator << "Integrator refresh\n";
 | 
			
		||||
 | 
			
		||||
    //FieldImplementation::generate_momenta(P, pRNG);
 | 
			
		||||
 | 
			
		||||
    P.M.ImportGauge(U);
 | 
			
		||||
    P.MomentaDistribution(pRNG);
 | 
			
		||||
    FieldImplementation::generate_momenta(P, pRNG);
 | 
			
		||||
 | 
			
		||||
    // Update the smeared fields, can be implemented as observer
 | 
			
		||||
    // necessary to keep the fields updated even after a reject
 | 
			
		||||
@@ -411,9 +260,7 @@ class Integrator {
 | 
			
		||||
  // Calculate action
 | 
			
		||||
  RealD S(Field& U) {  // here also U not used
 | 
			
		||||
 | 
			
		||||
    //RealD H = - FieldImplementation::FieldSquareNorm(P.Mom); // - trace (P*P)
 | 
			
		||||
    P.M.ImportGauge(U);
 | 
			
		||||
    RealD H = - P.MomentaAction();
 | 
			
		||||
    RealD H = - FieldImplementation::FieldSquareNorm(P); // - trace (P*P)
 | 
			
		||||
    RealD Hterm;
 | 
			
		||||
    std::cout << GridLogMessage << "Momentum action H_p = " << H << "\n";
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -287,141 +287,6 @@ class ForceGradient : public Integrator<FieldImplementation, SmearingPolicy,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
////////////////////////////////
 | 
			
		||||
// Riemannian Manifold HMC
 | 
			
		||||
// Girolami et al
 | 
			
		||||
////////////////////////////////
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// correct
 | 
			
		||||
template <class FieldImplementation, class SmearingPolicy,
 | 
			
		||||
          class RepresentationPolicy =
 | 
			
		||||
              Representations<FundamentalRepresentation> >
 | 
			
		||||
class ImplicitLeapFrog : public Integrator<FieldImplementation, SmearingPolicy,
 | 
			
		||||
                                           RepresentationPolicy> {
 | 
			
		||||
 public:
 | 
			
		||||
  typedef ImplicitLeapFrog<FieldImplementation, SmearingPolicy, RepresentationPolicy>
 | 
			
		||||
      Algorithm;
 | 
			
		||||
  INHERIT_FIELD_TYPES(FieldImplementation);
 | 
			
		||||
 | 
			
		||||
  // Riemannian manifold metric operator
 | 
			
		||||
  // Hermitian operator Fisher
 | 
			
		||||
 | 
			
		||||
  std::string integrator_name(){return "ImplicitLeapFrog";}
 | 
			
		||||
 | 
			
		||||
  ImplicitLeapFrog(GridBase* grid, IntegratorParameters Par,
 | 
			
		||||
           ActionSet<Field, RepresentationPolicy>& Aset, SmearingPolicy& Sm, Metric<Field>& M)
 | 
			
		||||
      : Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(
 | 
			
		||||
            grid, Par, Aset, Sm, M){};
 | 
			
		||||
 | 
			
		||||
  void step(Field& U, int level, int _first, int _last) {
 | 
			
		||||
    int fl = this->as.size() - 1;
 | 
			
		||||
    // level  : current level
 | 
			
		||||
    // fl     : final level
 | 
			
		||||
    // eps    : current step size
 | 
			
		||||
 | 
			
		||||
    // Get current level step size
 | 
			
		||||
    RealD eps = this->Params.trajL/this->Params.MDsteps;
 | 
			
		||||
    for (int l = 0; l <= level; ++l) eps /= this->as[l].multiplier;
 | 
			
		||||
 | 
			
		||||
    int multiplier = this->as[level].multiplier;
 | 
			
		||||
    for (int e = 0; e < multiplier; ++e) {
 | 
			
		||||
      int first_step = _first && (e == 0);
 | 
			
		||||
      int last_step = _last && (e == multiplier - 1);
 | 
			
		||||
 | 
			
		||||
      if (first_step) {  // initial half step
 | 
			
		||||
       this->implicit_update_P(U, level, eps / 2.0);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (level == fl) {  // lowest level
 | 
			
		||||
        this->implicit_update_U(U, eps);
 | 
			
		||||
      } else {  // recursive function call
 | 
			
		||||
        this->step(U, level + 1, first_step, last_step);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      //int mm = last_step ? 1 : 2;
 | 
			
		||||
      if (last_step){
 | 
			
		||||
        this->update_P(U, level, eps / 2.0);
 | 
			
		||||
      } else {
 | 
			
		||||
      this->implicit_update_P(U, level, eps, true);// works intermediate step
 | 
			
		||||
      //  this->update_P(U, level, eps); // looks not reversible
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// This is not completely tested
 | 
			
		||||
template <class FieldImplementation, class SmearingPolicy,
 | 
			
		||||
          class RepresentationPolicy =
 | 
			
		||||
              Representations<FundamentalRepresentation> >
 | 
			
		||||
class ImplicitMinimumNorm2 : public Integrator<FieldImplementation, SmearingPolicy,
 | 
			
		||||
                                       RepresentationPolicy> {
 | 
			
		||||
 private:
 | 
			
		||||
  const RealD lambda = 0.1931833275037836;
 | 
			
		||||
 | 
			
		||||
 public:
 | 
			
		||||
  INHERIT_FIELD_TYPES(FieldImplementation);
 | 
			
		||||
 | 
			
		||||
  ImplicitMinimumNorm2(GridBase* grid, IntegratorParameters Par,
 | 
			
		||||
               ActionSet<Field, RepresentationPolicy>& Aset, SmearingPolicy& Sm, Metric<Field>& M)
 | 
			
		||||
      : Integrator<FieldImplementation, SmearingPolicy, RepresentationPolicy>(
 | 
			
		||||
            grid, Par, Aset, Sm, M){};
 | 
			
		||||
 | 
			
		||||
  std::string integrator_name(){return "ImplicitMininumNorm2";}
 | 
			
		||||
 | 
			
		||||
  void step(Field& U, int level, int _first, int _last) {
 | 
			
		||||
    // level  : current level
 | 
			
		||||
    // fl     : final level
 | 
			
		||||
    // eps    : current step size
 | 
			
		||||
 | 
			
		||||
    int fl = this->as.size() - 1;
 | 
			
		||||
 | 
			
		||||
    RealD eps = this->Params.trajL/this->Params.MDsteps * 2.0;
 | 
			
		||||
    for (int l = 0; l <= level; ++l) eps /= 2.0 * this->as[l].multiplier;
 | 
			
		||||
 | 
			
		||||
    // Nesting:  2xupdate_U of size eps/2
 | 
			
		||||
    // Next level is eps/2/multiplier
 | 
			
		||||
 | 
			
		||||
    int multiplier = this->as[level].multiplier;
 | 
			
		||||
    for (int e = 0; e < multiplier; ++e) {  // steps per step
 | 
			
		||||
 | 
			
		||||
      int first_step = _first && (e == 0);
 | 
			
		||||
      int last_step = _last && (e == multiplier - 1);
 | 
			
		||||
 | 
			
		||||
      if (first_step) {  // initial half step
 | 
			
		||||
        this->implicit_update_P(U, level, lambda * eps);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      if (level == fl) {  // lowest level
 | 
			
		||||
        this->implicit_update_U(U, 0.5 * eps);
 | 
			
		||||
      } else {  // recursive function call
 | 
			
		||||
        this->step(U, level + 1, first_step, 0);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      this->implicit_update_P(U, level, (1.0 - 2.0 * lambda) * eps);
 | 
			
		||||
 | 
			
		||||
      if (level == fl) {  // lowest level
 | 
			
		||||
        this->implicit_update_U(U, 0.5 * eps);
 | 
			
		||||
      } else {  // recursive function call
 | 
			
		||||
        this->step(U, level + 1, 0, last_step);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      //int mm = (last_step) ? 1 : 2;
 | 
			
		||||
      //this->update_P(U, level, lambda * eps * mm);
 | 
			
		||||
 | 
			
		||||
      if (last_step) {
 | 
			
		||||
        this->update_P(U, level, eps * lambda);
 | 
			
		||||
      } else {
 | 
			
		||||
        this->implicit_update_P(U, level, lambda * eps*2.0);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user