/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./tests/debug/Test_reweight_dwf_eofa.cc Copyright (C) 2017 Author: Peter Boyle Author: paboyle Author: David Murphy 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 using namespace std; using namespace Grid; ; // parameters for test const std::vector grid_dim = { 8, 8, 8, 8 }; const int Ls = 8; const int Nhits = 25; const int max_iter = 5000; const RealD mf = 0.1; const RealD mb = 0.11; const RealD M5 = 1.8; const RealD stop_tol = 1.0e-12; RealD mean(const std::vector& data) { int N = data.size(); RealD mean(0.0); for(int i=0; i& data, int sample) { int N = data.size(); RealD mean(0.0); for(int i=0; i& jacks, RealD mean) { int N = jacks.size(); RealD std(0.0); for(int i=0; i jack_stats(const std::vector& data) { int N = data.size(); std::vector jack_samples(N); std::vector jack_stats(2); jack_stats[0] = mean(data); for(int i=0; i seeds4({1, 2, 3, 4}); std::vector seeds5({5, 6, 7, 8}); GridParallelRNG RNG5(FGrid); RNG5.SeedFixedIntegers(seeds5); GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4); // Random gauge field LatticeGaugeField Umu(UGrid); SU::HotConfiguration(RNG4, Umu); // Initialize RHMC fermion operators DomainWallFermionR Ddwf_f(Umu, *FGrid, *FrbGrid, *UGrid, *UrbGrid, mf, M5); DomainWallFermionR Ddwf_b(Umu, *FGrid, *FrbGrid, *UGrid, *UrbGrid, mb, M5); SchurDiagMooeeOperator MdagM(Ddwf_f); SchurDiagMooeeOperator VdagV(Ddwf_b); // Degree 12 rational approximations to x^(1/4) and x^(-1/4) double lo = 0.0001; double hi = 95.0; int precision = 64; int degree = 12; AlgRemez remez(lo, hi, precision); std::cout << GridLogMessage << "Generating degree " << degree << " for x^(1/4)" << std::endl; remez.generateApprox(degree, 1, 4); MultiShiftFunction PowerQuarter(remez, stop_tol, false); MultiShiftFunction PowerNegQuarter(remez, stop_tol, true); // Stochastically estimate reweighting factor via RHMC RealD scale = std::sqrt(0.5); std::vector rw_rhmc(Nhits); ConjugateGradientMultiShift msCG_V(max_iter, PowerQuarter); ConjugateGradientMultiShift msCG_M(max_iter, PowerNegQuarter); std::cout.precision(12); for(int hit=0; hit tmp(2, Ddwf_f.FermionRedBlackGrid()); gaussian(RNG5, Phi); Phi = Phi*scale; pickCheckerboard(Odd, PhiOdd, Phi); // evaluate -log(rw) msCG_V(VdagV, PhiOdd, tmp[0]); msCG_M(MdagM, tmp[0], tmp[1]); rw_rhmc[hit] = norm2(tmp[1]) - norm2(PhiOdd); std::cout << std::endl << "==================================================" << std::endl; std::cout << " --- RHMC: Hit " << hit << ": rw = " << rw_rhmc[hit]; std::cout << std::endl << "==================================================" << std::endl << std::endl; } // Initialize EOFA fermion operators RealD shift_L = 0.0; RealD shift_R = -1.0; int pm = 1; DomainWallEOFAFermionR Deofa_L(Umu, *FGrid, *FrbGrid, *UGrid, *UrbGrid, mf, mf, mb, shift_L, pm, M5); DomainWallEOFAFermionR Deofa_R(Umu, *FGrid, *FrbGrid, *UGrid, *UrbGrid, mb, mf, mb, shift_R, pm, M5); MdagMLinearOperator LdagL(Deofa_L); MdagMLinearOperator RdagR(Deofa_R); // Stochastically estimate reweighting factor via EOFA RealD k = Deofa_L.k; std::vector rw_eofa(Nhits); ConjugateGradient CG(stop_tol, max_iter); SchurRedBlackDiagMooeeSolve SchurSolver(CG); for(int hit=0; hit tmp(2, Deofa_L.FermionGrid()); gaussian(RNG5, Phi); Phi = Phi*scale; // evaluate -log(rw) // LH term for(int s=0; s rhmc_result = jack_stats(rw_rhmc); std::vector eofa_result = jack_stats(rw_eofa); std::cout << std::endl << "RHMC: rw = " << rhmc_result[0] << " +/- " << rhmc_result[1] << std::endl; std::cout << std::endl << "EOFA: rw = " << eofa_result[0] << " +/- " << eofa_result[1] << std::endl; Grid_finalize(); }