2017-03-14 05:55:18 +00:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
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>
|
2017-03-15 06:16:16 +00:00
|
|
|
namespace Grid {
|
2017-03-14 05:55:18 +00:00
|
|
|
class ScalarActionParameters : Serializable {
|
|
|
|
public:
|
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(ScalarActionParameters,
|
|
|
|
double, mass_squared,
|
2017-10-25 10:49:50 +01:00
|
|
|
double, lambda,
|
|
|
|
double, g);
|
2017-05-05 17:36:43 +01:00
|
|
|
|
2018-05-02 14:36:32 +01:00
|
|
|
ScalarActionParameters() = default;
|
2017-05-05 17:36:43 +01:00
|
|
|
|
|
|
|
template <class ReaderClass >
|
|
|
|
ScalarActionParameters(Reader<ReaderClass>& Reader){
|
|
|
|
read(Reader, "ScalarAction", *this);
|
|
|
|
}
|
|
|
|
|
2017-03-14 05:55:18 +00:00
|
|
|
};
|
|
|
|
}
|
2017-05-11 11:40:44 +01:00
|
|
|
|
|
|
|
using namespace Grid;
|
2018-01-15 09:37:58 +00:00
|
|
|
;
|
2017-05-11 11:40:44 +01:00
|
|
|
|
|
|
|
template <class Impl>
|
2017-06-27 14:38:45 +01:00
|
|
|
class MagMeas : public HmcObservable<typename Impl::Field> {
|
2017-05-11 11:40:44 +01:00
|
|
|
public:
|
|
|
|
typedef typename Impl::Field Field;
|
|
|
|
typedef typename Impl::Simd::scalar_type Trace;
|
|
|
|
|
|
|
|
void TrajectoryComplete(int traj,
|
|
|
|
Field &U,
|
|
|
|
GridSerialRNG &sRNG,
|
|
|
|
GridParallelRNG &pRNG) {
|
|
|
|
|
|
|
|
int def_prec = std::cout.precision();
|
|
|
|
|
|
|
|
std::cout << std::setprecision(std::numeric_limits<Real>::digits10 + 1);
|
|
|
|
std::cout << GridLogMessage
|
|
|
|
<< "m= " << TensorRemove(trace(sum(U))) << std::endl;
|
|
|
|
std::cout << GridLogMessage
|
|
|
|
<< "m^2= " << TensorRemove(trace(sum(U)*sum(U))) << std::endl;
|
2017-05-17 12:25:14 +01:00
|
|
|
std::cout << GridLogMessage
|
|
|
|
<< "phi^2= " << TensorRemove(sum(trace(U*U))) << std::endl;
|
2017-05-11 11:40:44 +01:00
|
|
|
std::cout.precision(def_prec);
|
|
|
|
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class Impl>
|
2017-06-27 14:38:45 +01:00
|
|
|
class MagMod: public ObservableModule<MagMeas<Impl>, NoParameters>{
|
|
|
|
typedef ObservableModule<MagMeas<Impl>, NoParameters> ObsBase;
|
2017-05-11 11:40:44 +01:00
|
|
|
using ObsBase::ObsBase; // for constructors
|
|
|
|
|
|
|
|
// acquire resource
|
|
|
|
virtual void initialize(){
|
2017-06-27 14:38:45 +01:00
|
|
|
this->ObservablePtr.reset(new MagMeas<Impl>());
|
2017-05-11 11:40:44 +01:00
|
|
|
}
|
|
|
|
public:
|
|
|
|
MagMod(): ObsBase(NoParameters()){}
|
|
|
|
};
|
|
|
|
|
2017-03-14 05:55:18 +00:00
|
|
|
int main(int argc, char **argv) {
|
2017-05-05 17:36:43 +01:00
|
|
|
typedef Grid::JSONReader Serialiser;
|
|
|
|
|
2017-03-14 05:55:18 +00:00
|
|
|
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;
|
|
|
|
|
2017-03-15 06:16:16 +00:00
|
|
|
// Typedefs to simplify notation
|
2017-05-11 11:40:44 +01:00
|
|
|
constexpr int Ncolours = 2;
|
2017-05-05 17:36:43 +01:00
|
|
|
constexpr int Ndimensions = 3;
|
|
|
|
typedef ScalarNxNAdjGenericHMCRunner<Ncolours> HMCWrapper; // Uses the default minimum norm, real scalar fields
|
|
|
|
typedef ScalarAdjActionR<Ncolours, Ndimensions> ScalarAction;
|
2017-03-14 05:55:18 +00:00
|
|
|
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
|
|
HMCWrapper TheHMC;
|
2017-05-05 17:36:43 +01:00
|
|
|
TheHMC.ReadCommandLine(argc, argv);
|
|
|
|
|
|
|
|
if (TheHMC.ParameterFile.empty()){
|
|
|
|
std::cout << "Input file not specified."
|
|
|
|
<< "Use --ParameterFile option in the command line.\nAborting"
|
|
|
|
<< std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
Serialiser Reader(TheHMC.ParameterFile);
|
2017-03-14 05:55:18 +00:00
|
|
|
|
|
|
|
// Grid from the command line
|
|
|
|
GridModule ScalarGrid;
|
2017-05-05 17:36:43 +01:00
|
|
|
if (GridDefaultLatt().size() != Ndimensions){
|
|
|
|
std::cout << "Incorrect dimension of the grid\n. Expected dim="<< Ndimensions << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (GridDefaultMpi().size() != Ndimensions){
|
|
|
|
std::cout << "Incorrect dimension of the mpi grid\n. Expected dim="<< Ndimensions << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
ScalarGrid.set_full(new GridCartesian(GridDefaultLatt(),GridDefaultSimd(Ndimensions, vComplex::Nsimd()),GridDefaultMpi()));
|
|
|
|
ScalarGrid.set_rb(new GridRedBlackCartesian(ScalarGrid.get_full()));
|
2017-03-14 05:55:18 +00:00
|
|
|
TheHMC.Resources.AddGrid("scalar", ScalarGrid);
|
2017-05-05 17:36:43 +01:00
|
|
|
std::cout << "Lattice size : " << GridDefaultLatt() << std::endl;
|
2017-03-14 05:55:18 +00:00
|
|
|
|
2018-05-02 14:36:32 +01:00
|
|
|
ScalarActionParameters SPar(Reader);
|
2017-03-14 05:55:18 +00:00
|
|
|
|
|
|
|
// Checkpointer definition
|
2017-05-05 17:36:43 +01:00
|
|
|
CheckpointerParameters CPparams(Reader);
|
2018-05-02 14:36:32 +01:00
|
|
|
//TheHMC.Resources.LoadBinaryCheckpointer(CPparams);
|
|
|
|
TheHMC.Resources.LoadScidacCheckpointer(CPparams, SPar);
|
2017-03-14 05:55:18 +00:00
|
|
|
|
2017-05-05 17:36:43 +01:00
|
|
|
RNGModuleParameters RNGpar(Reader);
|
2017-03-14 05:55:18 +00:00
|
|
|
TheHMC.Resources.SetRNGSeeds(RNGpar);
|
2017-05-11 11:40:44 +01:00
|
|
|
|
|
|
|
// Construct observables
|
|
|
|
typedef MagMod<HMCWrapper::ImplPolicy> MagObs;
|
|
|
|
TheHMC.Resources.AddObservable<MagObs>();
|
|
|
|
|
2017-03-14 05:55:18 +00:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
// Collect actions, here use more encapsulation
|
|
|
|
|
|
|
|
// Scalar action in adjoint representation
|
2017-10-25 10:49:50 +01:00
|
|
|
ScalarAction Saction(SPar.mass_squared, SPar.lambda, SPar.g);
|
2017-03-14 05:55:18 +00:00
|
|
|
|
|
|
|
// Collect actions
|
2017-05-05 17:36:43 +01:00
|
|
|
ActionLevel<ScalarAction::Field, ScalarNxNMatrixFields<Ncolours>> Level1(1);
|
2017-03-14 05:55:18 +00:00
|
|
|
Level1.push_back(&Saction);
|
|
|
|
TheHMC.TheAction.push_back(Level1);
|
|
|
|
/////////////////////////////////////////////////////////////
|
2017-05-05 17:36:43 +01:00
|
|
|
TheHMC.Parameters.initialize(Reader);
|
2017-03-14 05:55:18 +00:00
|
|
|
|
|
|
|
TheHMC.Run();
|
|
|
|
|
|
|
|
Grid_finalize();
|
2017-03-15 06:16:16 +00:00
|
|
|
} // main
|
2017-05-05 17:36:43 +01:00
|
|
|
|
|
|
|
/* Examples for input files
|
|
|
|
|
|
|
|
JSON
|
|
|
|
|
|
|
|
{
|
|
|
|
"Checkpointer": {
|
|
|
|
"config_prefix": "ckpoint_scalar_lat",
|
|
|
|
"rng_prefix": "ckpoint_scalar_rng",
|
|
|
|
"saveInterval": 1,
|
|
|
|
"format": "IEEE64BIG"
|
|
|
|
},
|
|
|
|
"RandomNumberGenerator": {
|
|
|
|
"serial_seeds": "1 2 3 4 6",
|
|
|
|
"parallel_seeds": "6 7 8 9 11"
|
|
|
|
},
|
|
|
|
"ScalarAction":{
|
|
|
|
"mass_squared": 0.5,
|
|
|
|
"lambda": 0.1
|
|
|
|
},
|
|
|
|
"HMC":{
|
|
|
|
"StartTrajectory": 0,
|
|
|
|
"Trajectories": 100,
|
|
|
|
"MetropolisTest": true,
|
|
|
|
"NoMetropolisUntil": 10,
|
|
|
|
"StartingType": "HotStart",
|
|
|
|
"MD":{
|
|
|
|
"name": "MinimumNorm2",
|
|
|
|
"MDsteps": 15,
|
|
|
|
"trajL": 2.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
XML example not provided yet
|
|
|
|
|
2017-05-11 11:40:44 +01:00
|
|
|
*/
|