Grid 0.7.0
OneFlavourRationalRatio.h
Go to the documentation of this file.
1 /*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/qcd/action/pseudofermion/OneFlavourRationalRatio.h
6
7 Copyright (C) 2015
8
9Author: Peter Boyle <paboyle@ph.ed.ac.uk>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License along
22 with this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 See the full license in the file "LICENSE" in the top level distribution directory
26 *************************************************************************************/
27 /* END LEGAL */
28#ifndef QCD_PSEUDOFERMION_ONE_FLAVOUR_RATIONAL_RATIO_H
29#define QCD_PSEUDOFERMION_ONE_FLAVOUR_RATIONAL_RATIO_H
30
32
34 // One flavour rational
36
37 // S_f = chi^dag* P(V^dag*V)/Q(V^dag*V)* N(M^dag*M)/D(M^dag*M)* P(V^dag*V)/Q(V^dag*V)* chi
38 //
39 // Here P/Q \sim R_{1/4} ~ (V^dagV)^{1/4}
40 // Here N/D \sim R_{-1/2} ~ (M^dagM)^{-1/2}
41
42 template<class Impl>
43 class OneFlavourRatioRationalPseudoFermionAction : public Action<typename Impl::GaugeField> {
44 public:
45
47
50
55
58 private:
59
60 FermionOperator<Impl> & NumOp;// the basic operator
61 FermionOperator<Impl> & DenOp;// the basic operator
62 FermionField Phi; // the pseudo fermion field for this trajectory
63
64 public:
65
67 FermionOperator<Impl> &_DenOp,
68 Params & p
69 ) : NumOp(_NumOp), DenOp(_DenOp), Phi(_NumOp.FermionGrid()), param(p)
70 {
71 AlgRemez remez(param.lo,param.hi,param.precision);
72
73 // MdagM^(+- 1/2)
74 std::cout<<GridLogMessage << "Generating degree "<<param.degree<<" for x^(1/2)"<<std::endl;
75 remez.generateApprox(param.degree,1,2);
76 PowerHalf.Init(remez,param.tolerance,false);
77 PowerNegHalf.Init(remez,param.tolerance,true);
78 MDPowerNegHalf.Init(remez,param.mdtolerance,true);
79
80 // MdagM^(+- 1/4)
81 std::cout<<GridLogMessage << "Generating degree "<<param.degree<<" for x^(1/4)"<<std::endl;
82 remez.generateApprox(param.degree,1,4);
83 PowerQuarter.Init(remez,param.tolerance,false);
84 MDPowerQuarter.Init(remez,param.mdtolerance,false);
85 PowerNegQuarter.Init(remez,param.tolerance,true);
86 };
87
88 virtual std::string action_name(){
89 std::stringstream sstream;
90 sstream<<"OneFlavourRatioRationalPseudoFermionAction("
91 <<DenOp.Mass()<<") / det("<<NumOp.Mass()<<")";
92 return sstream.str();
93 }
94
95 virtual std::string LogParameters(){
96 std::stringstream sstream;
97 sstream << GridLogMessage << "["<<action_name()<<"] Low :" << param.lo << std::endl;
98 sstream << GridLogMessage << "["<<action_name()<<"] High :" << param.hi << std::endl;
99 sstream << GridLogMessage << "["<<action_name()<<"] Max iterations :" << param.MaxIter << std::endl;
100 sstream << GridLogMessage << "["<<action_name()<<"] Tolerance :" << param.tolerance << std::endl;
101 sstream << GridLogMessage << "["<<action_name()<<"] Degree :" << param.degree << std::endl;
102 sstream << GridLogMessage << "["<<action_name()<<"] Precision :" << param.precision << std::endl;
103 return sstream.str();
104 }
105
106
107 virtual void refresh(const GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG& pRNG) {
108
109 // S_f = chi^dag* P(V^dag*V)/Q(V^dag*V)* N(M^dag*M)/D(M^dag*M)* P(V^dag*V)/Q(V^dag*V)* chi
110 //
111 // P(phi) = e^{- phi^dag (VdagV)^1/4 (MdagM)^-1/2 (VdagV)^1/4 phi}
112 // = e^{- phi^dag (VdagV)^1/4 (MdagM)^-1/4 (MdagM)^-1/4 (VdagV)^1/4 phi}
113 //
114 // Phi = (VdagV)^-1/4 Mdag^{1/4} eta
115 //
116 // P(eta) = e^{- eta^dag eta}
117 //
118 // e^{x^2/2 sig^2} => sig^2 = 0.5.
119 //
120 // So eta should be of width sig = 1/sqrt(2).
121
122 RealD scale = std::sqrt(0.5);
123
124 FermionField tmp(NumOp.FermionGrid());
125 FermionField eta(NumOp.FermionGrid());
126
127 gaussian(pRNG,eta);
128
129 NumOp.ImportGauge(U);
130 DenOp.ImportGauge(U);
131
132 // MdagM^1/4 eta
135 msCG_M(MdagM,eta,tmp);
136
137 // VdagV^-1/4 MdagM^1/4 eta
140 msCG_V(VdagV,tmp,Phi);
141
142 Phi=Phi*scale;
143
144 };
145
147 // S_f = chi^dag* P(V^dag*V)/Q(V^dag*V)* N(M^dag*M)/D(M^dag*M)* P(V^dag*V)/Q(V^dag*V)* chi
149 virtual RealD S(const GaugeField &U) {
150
151 NumOp.ImportGauge(U);
152 DenOp.ImportGauge(U);
153
154 FermionField X(NumOp.FermionGrid());
155 FermionField Y(NumOp.FermionGrid());
156
157 // VdagV^1/4 Phi
160 msCG_V(VdagV,Phi,X);
161
162 // MdagM^-1/4 VdagV^1/4 Phi
165 msCG_M(MdagM,X,Y);
166
167 // Randomly apply rational bounds checks.
168 auto grid = NumOp.FermionGrid();
169 auto r=rand();
170 grid->Broadcast(0,r);
171 if ( (r%param.BoundsCheckFreq)==0 ) {
172 FermionField gauss(NumOp.FermionGrid());
173 gauss = Phi;
174 HighBoundCheck(MdagM,gauss,param.hi);
175 InverseSqrtBoundsCheck(param.MaxIter,param.tolerance*100,MdagM,gauss,PowerNegHalf);
176 }
177
178 // Phidag VdagV^1/4 MdagM^-1/4 MdagM^-1/4 VdagV^1/4 Phi
179 RealD action = norm2(Y);
180
181 return action;
182 };
183
184 // S_f = chi^dag* P(V^dag*V)/Q(V^dag*V)* N(M^dag*M)/D(M^dag*M)* P(V^dag*V)/Q(V^dag*V)* chi
185 //
186 // Here, M is some 5D operator and V is the Pauli-Villars field
187 // N and D makeup the rat. poly of the M term and P and & makeup the rat.poly of the denom term
188 //
189 // Need
190 // dS_f/dU = chi^dag d[P/Q] N/D P/Q chi
191 // + chi^dag P/Q d[N/D] P/Q chi
192 // + chi^dag P/Q N/D d[P/Q] chi
193 //
194 // P/Q is expressed as partial fraction expansion:
195 //
196 // a0 + \sum_k ak/(V^dagV + bk)
197 //
198 // d[P/Q] is then
199 //
200 // \sum_k -ak [V^dagV+bk]^{-1} [ dV^dag V + V^dag dV ] [V^dag V + bk]^{-1}
201 //
202 // and similar for N/D.
203 //
204 // Need
205 // MpvPhi_k = [Vdag V + bk]^{-1} chi
206 // MpvPhi = {a0 + \sum_k ak [Vdag V + bk]^{-1} }chi
207 //
208 // MfMpvPhi_k = [MdagM+bk]^{-1} MpvPhi
209 // MfMpvPhi = {a0 + \sum_k ak [Mdag M + bk]^{-1} } MpvPhi
210 //
211 // MpvMfMpvPhi_k = [Vdag V + bk]^{-1} MfMpvchi
212 //
213
214 virtual void deriv(const GaugeField &U,GaugeField & dSdU) {
215
216 const int n_f = MDPowerNegHalf.poles.size();
217 const int n_pv = MDPowerQuarter.poles.size();
218
219 std::vector<FermionField> MpvPhi_k (n_pv,NumOp.FermionGrid());
220 std::vector<FermionField> MpvMfMpvPhi_k(n_pv,NumOp.FermionGrid());
221 std::vector<FermionField> MfMpvPhi_k (n_f,NumOp.FermionGrid());
222
223 FermionField MpvPhi(NumOp.FermionGrid());
224 FermionField MfMpvPhi(NumOp.FermionGrid());
225 FermionField MpvMfMpvPhi(NumOp.FermionGrid());
226 FermionField Y(NumOp.FermionGrid());
227
228 GaugeField tmp(NumOp.GaugeGrid());
229
230 NumOp.ImportGauge(U);
231 DenOp.ImportGauge(U);
232
235
238
239 msCG_V(VdagV,Phi,MpvPhi_k,MpvPhi);
240 msCG_M(MdagM,MpvPhi,MfMpvPhi_k,MfMpvPhi);
241 msCG_V(VdagV,MfMpvPhi,MpvMfMpvPhi_k,MpvMfMpvPhi);
242
243 RealD ak;
244
245 dSdU = Zero();
246
247 // With these building blocks
248 //
249 // dS/dU =
250 // \sum_k -ak MfMpvPhi_k^dag [ dM^dag M + M^dag dM ] MfMpvPhi_k (1)
251 // + \sum_k -ak MpvMfMpvPhi_k^\dag [ dV^dag V + V^dag dV ] MpvPhi_k (2)
252 // -ak MpvPhi_k^dag [ dV^dag V + V^dag dV ] MpvMfMpvPhi_k (3)
253
254 //(1)
255 for(int k=0;k<n_f;k++){
256 ak = MDPowerNegHalf.residues[k];
257 DenOp.M(MfMpvPhi_k[k],Y);
258 DenOp.MDeriv(tmp , MfMpvPhi_k[k], Y,DaggerYes ); dSdU=dSdU+ak*tmp;
259 DenOp.MDeriv(tmp , Y, MfMpvPhi_k[k], DaggerNo ); dSdU=dSdU+ak*tmp;
260 }
261
262 //(2)
263 //(3)
264 for(int k=0;k<n_pv;k++){
265
266 ak = MDPowerQuarter.residues[k];
267
268 NumOp.M(MpvPhi_k[k],Y);
269 NumOp.MDeriv(tmp,MpvMfMpvPhi_k[k],Y,DaggerYes); dSdU=dSdU+ak*tmp;
270 NumOp.MDeriv(tmp,Y,MpvMfMpvPhi_k[k],DaggerNo); dSdU=dSdU+ak*tmp;
271
272 NumOp.M(MpvMfMpvPhi_k[k],Y); // V as we take Ydag
273 NumOp.MDeriv(tmp,Y, MpvPhi_k[k], DaggerNo); dSdU=dSdU+ak*tmp;
274 NumOp.MDeriv(tmp,MpvPhi_k[k], Y,DaggerYes); dSdU=dSdU+ak*tmp;
275
276 }
277
278 //dSdU = Ta(dSdU);
279
280 };
281 };
282
284
285#endif
void InverseSqrtBoundsCheck(int MaxIter, double tol, LinearOperatorBase< Field > &HermOp, Field &GaussNoise, MultiShiftFunction &PowerNegHalf)
Definition Bounds.h:42
void HighBoundCheck(LinearOperatorBase< Field > &HermOp, Field &Phi, RealD hi)
Definition Bounds.h:6
RealD norm2(const Lattice< vobj > &arg)
void gaussian(GridParallelRNG &rng, Lattice< vobj > &l)
GridLogger GridLogMessage(1, "Message", GridLogColours, "NORMAL")
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
static constexpr int DaggerYes
Definition QCD.h:70
static constexpr int DaggerNo
Definition QCD.h:69
double RealD
Definition Simd.h:61
static INTERNAL_PRECISION U
Definition Zolotarev.cc:230
Base class for all actions.
Definition ActionBase.h:64
double generateApprox(int num_degree, int den_degree, unsigned long power_num, unsigned long power_den, int a_len, double *a_param, int *a_pow)
Definition Remez.cc:114
virtual std::string LogParameters()
Print the parameters of the action.
virtual std::string action_name()
Report the name of the action.
OneFlavourRatioRationalPseudoFermionAction(FermionOperator< Impl > &_NumOp, FermionOperator< Impl > &_DenOp, Params &p)
virtual RealD S(const GaugeField &U)
Evaluate this action with the given gauge field.
virtual void deriv(const GaugeField &U, GaugeField &dSdU)
virtual void refresh(const GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG)
Refresh pseudofermion fields.
Definition Simd.h:194