1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-06-12 20:27:06 +01:00

Implemented specialisations of NamedTensor as derived classes, however this suffers a number of problems:

1) virtual functions not available in base class constructor where I'd like to use them - e.g. IndexNames
2) Must define new constructors in derived classes
... so the specialisations are fatter than I'd like. Would prefer to revert to specifying tensor name and index name defaults in template
This commit is contained in:
Michael Marshall
2019-11-08 11:55:00 +00:00
parent 65aa54804e
commit f8e1941327
5 changed files with 102 additions and 68 deletions

View File

@ -169,7 +169,7 @@ void TDistilVectors<FImpl>::setup(void)
const int SI{ static_cast<int>( perambulator.tensor.dimension(5) ) };
const int Nt_inv{ static_cast<int>( perambulator.tensor.dimension(4) ) };
const int nnoise{ static_cast<int>( perambulator.tensor.dimension(3) ) };
assert( nnoise >= static_cast<int>( noise.dimension(0) ) && "Not enough noise vectors for perambulator" );
assert( nnoise >= static_cast<int>( noise.tensor.dimension(0) ) && "Not enough noise vectors for perambulator" );
// Nvec defaults to what's in the perambulator unless overriden
const int nvec_per{ static_cast<int>( perambulator.tensor.dimension(1) ) };
const int nvec{Hadrons::MDistil::DistilParameters::ParameterDefault(par().nvec, nvec_per, true) };
@ -254,7 +254,7 @@ void TDistilVectors<FImpl>::execute(void)
for (int ik = dk; ik < nvec; ik += LI){
for (int is = ds; is < Ns; is += SI){
ExtractSliceLocal(evec3d,epack.evec[ik],0,t_inv-Ntfirst,Tdir);
tmp3d_nospin = evec3d * noise(inoise, t_inv, ik, is);
tmp3d_nospin = evec3d * noise.tensor(inoise, t_inv, ik, is);
tmp3d=0;
pokeSpin(tmp3d,tmp3d_nospin,is);
tmp2=0;

View File

@ -45,9 +45,9 @@ public:
GRID_SERIALIZABLE_CLASS_MEMBERS(NoisesPar,
int, nnoise,
int, nvec,
std::string, UniqueIdentifier,
std::string, TI,
std::string, LI)
std::string, LI,
std::string, NoiseFileName)
};
template <typename FImpl>
@ -113,10 +113,6 @@ void TNoises<FImpl>::execute(void)
const int LI{ Hadrons::MDistil::DistilParameters::ParameterDefault( par().LI, nvec, false) };
const bool full_tdil{ TI == Nt }; \
const bool exact_distillation{ full_tdil && LI == nvec }; \
std::string UniqueIdentifier{par().UniqueIdentifier};
if (UniqueIdentifier.empty())
UniqueIdentifier = getName();
UniqueIdentifier.append( std::to_string( vm().getTrajectory() ) );
// We use our own seeds so we can specify different noises per quark
Real rn;
@ -126,17 +122,24 @@ void TNoises<FImpl>::execute(void)
for (int ivec = 0; ivec < nvec; ivec++) {
for (int is = 0; is < Ns; is++) {
if (exact_distillation)
noise(inoise, t, ivec, is) = 1.;
noise.tensor(inoise, t, ivec, is) = 1.;
else{
random(rngSerial(),rn);
// We could use a greater number of complex roots of unity
// ... but this seems to work well
noise(inoise, t, ivec, is) = (rn > 0.5) ? -1 : 1;
noise.tensor(inoise, t, ivec, is) = (rn > 0.5) ? -1 : 1;
}
}
}
}
}
if (env().getGrid()->IsBoss())
{
std::string sName {par().NoiseFileName};
sName.append(".");
sName.append(std::to_string(vm().getTrajectory()));
noise.write(sName.c_str());
}
}
END_MODULE_NAMESPACE

View File

@ -35,13 +35,23 @@ using namespace MDistil;
template class Grid::Hadrons::MDistil::TPerambulator<FIMPL>;
BEGIN_HADRONS_NAMESPACE
// Global constants for distillation
const std::string Grid::Hadrons::MDistil::PerambTensorName{ "Perambulator" };
const std::array<std::string, 6> Grid::Hadrons::MDistil::PerambIndexNames{"nT", "nVec", "LI", "nNoise", "nT_inv", "SI"};
#ifdef HAVE_HDF5
extern const std::string Grid::Hadrons::NamedTensorFileExtension{".h5"};
extern const std::string NamedTensorFileExtension{".h5"};
#else
extern const std::string Grid::Hadrons::NamedTensorFileExtension{".dat"};
extern const std::string NamedTensorFileExtension{".dat"};
#endif
BEGIN_MODULE_NAMESPACE(MDistil)
const std::string NoiseTensor::Name_{"Noises"};
const std::vector<std::string> NoiseTensor::DefaultIndexNames_{"nNoise", "nT", "nVec", "nS"};
const std::string PerambTensor::Name_{"Perambulator"};
const std::vector<std::string> PerambTensor::DefaultIndexNames_{"nT", "nVec", "LI", "nNoise", "nT_inv", "SI"};
END_MODULE_NAMESPACE
END_HADRONS_NAMESPACE

View File

@ -208,7 +208,7 @@ void TPerambulator<FImpl>::execute(void)
for (int is = ds; is < Ns; is += SI)
{
ExtractSliceLocal(evec3d,epack.evec[ik],0,t_inv-Ntfirst,Tdir);
tmp3d_nospin = evec3d * noise(inoise, t_inv, ik, is);
tmp3d_nospin = evec3d * noise.tensor(inoise, t_inv, ik, is);
tmp3d=0;
pokeSpin(tmp3d,tmp3d_nospin,is);
tmp2=0;
@ -276,8 +276,6 @@ void TPerambulator<FImpl>::execute(void)
if (grid4d->IsBoss())
{
std::string sPerambName {par().PerambFileName};
if (sPerambName.empty())
sPerambName = getName();
sPerambName.append(".");
sPerambName.append(std::to_string(vm().getTrajectory()));
perambulator.write(sPerambName.c_str());