2019-04-26 07:24:56 +01:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
|
|
|
Source file: Hadrons/Modules/MDistil/Noises.hpp
|
|
|
|
|
2019-04-26 07:39:05 +01:00
|
|
|
Copyright (C) 2019
|
2019-04-26 07:24:56 +01:00
|
|
|
|
|
|
|
Author: Felix Erben <ferben@ed.ac.uk>
|
|
|
|
Author: Michael Marshall <Michael.Marshall@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 */
|
|
|
|
|
2019-03-25 14:13:03 +00:00
|
|
|
#ifndef Hadrons_MDistil_Noises_hpp_
|
|
|
|
#define Hadrons_MDistil_Noises_hpp_
|
|
|
|
|
2019-11-12 17:31:42 +00:00
|
|
|
#include <Hadrons/Modules/MDistil/Distil.hpp>
|
2019-03-25 14:13:03 +00:00
|
|
|
|
|
|
|
BEGIN_HADRONS_NAMESPACE
|
2019-11-02 14:58:32 +00:00
|
|
|
BEGIN_MODULE_NAMESPACE(MDistil)
|
2019-03-25 14:13:03 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Noises *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
class NoisesPar: Serializable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(NoisesPar,
|
2019-11-12 12:23:34 +00:00
|
|
|
std::string, DistilPar,
|
2019-11-08 11:55:00 +00:00
|
|
|
std::string, NoiseFileName)
|
2019-03-25 14:13:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename FImpl>
|
|
|
|
class TNoises: public Module<NoisesPar>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
TNoises(const std::string name);
|
|
|
|
// destructor
|
|
|
|
virtual ~TNoises(void) {};
|
|
|
|
// dependency relation
|
|
|
|
virtual std::vector<std::string> getInput(void);
|
|
|
|
virtual std::vector<std::string> getOutput(void);
|
|
|
|
// setup
|
|
|
|
virtual void setup(void);
|
|
|
|
// execution
|
|
|
|
virtual void execute(void);
|
2019-11-12 12:23:34 +00:00
|
|
|
protected:
|
|
|
|
std::string DParName;
|
2019-03-25 14:13:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_REGISTER_TMP(Noises, TNoises<FIMPL>, MDistil);
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* TNoises implementation *
|
|
|
|
******************************************************************************/
|
|
|
|
// constructor /////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
TNoises<FImpl>::TNoises(const std::string name)
|
|
|
|
: Module<NoisesPar>(name)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// dependencies/products ///////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
std::vector<std::string> TNoises<FImpl>::getInput(void)
|
|
|
|
{
|
2019-11-12 12:23:34 +00:00
|
|
|
DParName = par().DistilPar;
|
|
|
|
return { DParName };
|
2019-03-25 14:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FImpl>
|
|
|
|
std::vector<std::string> TNoises<FImpl>::getOutput(void)
|
|
|
|
{
|
2019-11-02 16:15:48 +00:00
|
|
|
return {getName()};
|
2019-03-25 14:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// setup ///////////////////////////////////////////////////////////////////////
|
2019-04-30 23:53:57 +01:00
|
|
|
|
2019-03-25 14:13:03 +00:00
|
|
|
template <typename FImpl>
|
|
|
|
void TNoises<FImpl>::setup(void)
|
|
|
|
{
|
2019-11-12 12:23:34 +00:00
|
|
|
auto &DPar = envGet(MDistil::DistilParameters, DParName);
|
2019-11-11 17:29:55 +00:00
|
|
|
const int Nt{env().getDim(Tdir)};
|
2019-11-12 12:23:34 +00:00
|
|
|
const int nvec{DPar.nvec};
|
|
|
|
const int nnoise{DPar.nnoise};
|
2019-11-02 16:15:48 +00:00
|
|
|
envCreate(NoiseTensor, getName(), 1, nnoise, Nt, nvec, Ns);
|
2019-03-25 14:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// execution ///////////////////////////////////////////////////////////////////
|
|
|
|
template <typename FImpl>
|
|
|
|
void TNoises<FImpl>::execute(void)
|
|
|
|
{
|
2019-11-12 12:23:34 +00:00
|
|
|
auto &DPar = envGet(MDistil::DistilParameters, DParName);
|
2019-11-02 16:15:48 +00:00
|
|
|
const int Nt{env().getDim(Tdir)};
|
2019-11-12 12:23:34 +00:00
|
|
|
const int nnoise{DPar.nnoise};
|
|
|
|
const int nvec{DPar.nvec};
|
|
|
|
const int TI{DPar.TI};
|
|
|
|
const int LI{DPar.LI};
|
2019-11-11 17:29:55 +00:00
|
|
|
const bool full_tdil{ TI == Nt };
|
|
|
|
const bool exact_distillation{ full_tdil && LI == nvec };
|
2019-11-02 16:15:48 +00:00
|
|
|
|
|
|
|
// We use our own seeds so we can specify different noises per quark
|
|
|
|
Real rn;
|
|
|
|
auto &noise = envGet(NoiseTensor, getName());
|
|
|
|
for (int inoise = 0; inoise < nnoise; inoise++) {
|
|
|
|
for (int t = 0; t < Nt; t++) {
|
|
|
|
for (int ivec = 0; ivec < nvec; ivec++) {
|
|
|
|
for (int is = 0; is < Ns; is++) {
|
|
|
|
if (exact_distillation)
|
2019-11-08 11:55:00 +00:00
|
|
|
noise.tensor(inoise, t, ivec, is) = 1.;
|
2019-11-02 16:15:48 +00:00
|
|
|
else{
|
2019-11-07 14:00:40 +00:00
|
|
|
random(rngSerial(),rn);
|
2019-11-02 16:15:48 +00:00
|
|
|
// We could use a greater number of complex roots of unity
|
|
|
|
// ... but this seems to work well
|
2019-11-08 11:55:00 +00:00
|
|
|
noise.tensor(inoise, t, ivec, is) = (rn > 0.5) ? -1 : 1;
|
2019-11-02 16:15:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-30 14:41:48 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-08 11:55:00 +00:00
|
|
|
if (env().getGrid()->IsBoss())
|
|
|
|
{
|
|
|
|
std::string sName {par().NoiseFileName};
|
|
|
|
sName.append(".");
|
|
|
|
sName.append(std::to_string(vm().getTrajectory()));
|
|
|
|
noise.write(sName.c_str());
|
|
|
|
}
|
2019-03-25 14:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
END_MODULE_NAMESPACE
|
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
#endif // Hadrons_MDistil_Noises_hpp_
|