From 47429218bbbbf47af4b19d5fdb6d5f839cb9bc26 Mon Sep 17 00:00:00 2001 From: Mashy Green Date: Wed, 27 Nov 2024 16:29:22 +0000 Subject: [PATCH 01/12] patched version + modifications to deriv -> staple in qcd/gauge --- Grid/qcd/action/gauge/WilsonGaugeAction.h | 17 ++++++++++++----- HMC/FTHMC2p1f.cc | 10 ++++++++-- HMC/FTHMC2p1f_3GeV.cc | 9 +++++++++ HMC/HMC2p1f_3GeV.cc | 8 ++++++++ 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Grid/qcd/action/gauge/WilsonGaugeAction.h b/Grid/qcd/action/gauge/WilsonGaugeAction.h index f535b54f..661b0ca5 100644 --- a/Grid/qcd/action/gauge/WilsonGaugeAction.h +++ b/Grid/qcd/action/gauge/WilsonGaugeAction.h @@ -69,15 +69,22 @@ public: RealD factor = 0.5 * beta / RealD(Nc); - GaugeLinkField Umu(U.Grid()); + // GaugeLinkField Umu(U.Grid()); + std::vector Uvec(Nd, U.Grid()); + for (int d = 0; d < Nd; d++) { + Uvec[d] = PeekIndex(U, d); + } + GaugeLinkField dSdU_mu(U.Grid()); for (int mu = 0; mu < Nd; mu++) { - Umu = PeekIndex(U, mu); - + // Umu = PeekIndex(U, mu); + // Staple in direction mu - WilsonLoops::Staple(dSdU_mu, U, mu); - dSdU_mu = Ta(Umu * dSdU_mu) * factor; + // WilsonLoops::Staple(dSdU_mu, U, mu); + // dSdU_mu = Ta(Umu * dSdU_mu) * factor; + WilsonLoops::Staple(dSdU_mu, Uvec, mu); + dSdU_mu = Ta(Uvec[mu] * dSdU_mu) * factor; PokeIndex(dSdU, dSdU_mu, mu); } diff --git a/HMC/FTHMC2p1f.cc b/HMC/FTHMC2p1f.cc index 7d93d168..1e914e87 100644 --- a/HMC/FTHMC2p1f.cc +++ b/HMC/FTHMC2p1f.cc @@ -25,13 +25,20 @@ directory *************************************************************************************/ /* END LEGAL */ #include + +#if Nc == 3 #include #include +#endif using namespace Grid; int main(int argc, char **argv) { +#if Nc != 3 +#warning FTHMC2p1f will not work for Nc != 3 + std::cout << "This program will currently only work for Nc == 3." << std::endl; +#else std::cout << std::setprecision(12); Grid_init(&argc, &argv); @@ -220,7 +227,6 @@ int main(int argc, char **argv) TheHMC.Run(SmearingPolicy); // for smearing Grid_finalize(); +#endif } // main - - diff --git a/HMC/FTHMC2p1f_3GeV.cc b/HMC/FTHMC2p1f_3GeV.cc index a8aa67f8..36d5caa3 100644 --- a/HMC/FTHMC2p1f_3GeV.cc +++ b/HMC/FTHMC2p1f_3GeV.cc @@ -24,14 +24,22 @@ See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ + #include + +#if Nc == 3 #include #include +#endif using namespace Grid; int main(int argc, char **argv) { +#if Nc != 3 +#warning FTHMC2p1f_3GeV will not work for Nc != 3 + std::cout << "This program will currently only work for Nc == 3." << std::endl; +#else std::cout << std::setprecision(12); Grid_init(&argc, &argv); @@ -220,6 +228,7 @@ int main(int argc, char **argv) TheHMC.Run(SmearingPolicy); // for smearing Grid_finalize(); +#endif } // main diff --git a/HMC/HMC2p1f_3GeV.cc b/HMC/HMC2p1f_3GeV.cc index 4bf088d7..199d4be8 100644 --- a/HMC/HMC2p1f_3GeV.cc +++ b/HMC/HMC2p1f_3GeV.cc @@ -25,13 +25,20 @@ directory *************************************************************************************/ /* END LEGAL */ #include + +#if Nc == 3 #include #include +#endif using namespace Grid; int main(int argc, char **argv) { +#if Nc != 3 +#warning HMC2p1f_3GeV will not work for Nc != 3 + std::cout << "This program will currently only work for Nc == 3." << std::endl; +#else std::cout << std::setprecision(12); Grid_init(&argc, &argv); @@ -220,6 +227,7 @@ int main(int argc, char **argv) TheHMC.Run(SmearingPolicy); // for smearing Grid_finalize(); +#endif } // main From 3ba019c747bc22411406c3ea142ad9aa5c66bc59 Mon Sep 17 00:00:00 2001 From: Mashy Green Date: Tue, 3 Dec 2024 15:23:00 +0000 Subject: [PATCH 02/12] Cleaning up and aligning variable naming between action deriv versions --- .../action/gauge/PlaqPlusRectangleAction.h | 30 ++-- Grid/qcd/action/gauge/WilsonGaugeAction.h | 22 ++- Grid/qcd/utils/WilsonLoops.h | 25 ++-- tests/run_regression_test.py | 134 ++++++++++++++++++ ...hmc_Sp_WilsonFundFermionGauge_expected.txt | 1 + 5 files changed, 169 insertions(+), 43 deletions(-) create mode 100644 tests/run_regression_test.py create mode 100644 tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge_expected.txt diff --git a/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h b/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h index b9d6ac16..55b98986 100644 --- a/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h +++ b/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h @@ -71,30 +71,30 @@ public: return action; }; - virtual void deriv(const GaugeField &Umu,GaugeField & dSdU) { - //extend Ta to include Lorentz indexes - RealD factor_p = c_plaq/RealD(Nc)*0.5; - RealD factor_r = c_rect/RealD(Nc)*0.5; + virtual void deriv(const GaugeField &U, GaugeField &dSdU) { + // extend Ta to include Lorentz indexes + RealD factor_p = c_plaq / RealD(Nc) * 0.5; + RealD factor_r = c_rect / RealD(Nc) * 0.5; - GridBase *grid = Umu.Grid(); + GridBase *grid = U.Grid(); - std::vector U (Nd,grid); - for(int mu=0;mu(Umu,mu); + std::vector Umu(Nd, grid); + for (int mu = 0; mu < Nd; mu++) { + Umu[mu] = PeekIndex(U, mu); } - std::vector RectStaple(Nd,grid), Staple(Nd,grid); - WilsonLoops::StapleAndRectStapleAll(Staple, RectStaple, U, workspace); + std::vector RectStaple(Nd, grid), Staple(Nd, grid); + WilsonLoops::StapleAndRectStapleAll(Staple, RectStaple, Umu, + workspace); GaugeLinkField dSdU_mu(grid); GaugeLinkField staple(grid); - for (int mu=0; mu < Nd; mu++){ - dSdU_mu = Ta(U[mu]*Staple[mu])*factor_p; - dSdU_mu = dSdU_mu + Ta(U[mu]*RectStaple[mu])*factor_r; - + for (int mu = 0; mu < Nd; mu++) { + dSdU_mu = Ta(Umu[mu] * Staple[mu]) * factor_p; + dSdU_mu = dSdU_mu + Ta(Umu[mu] * RectStaple[mu]) * factor_r; + PokeIndex(dSdU, dSdU_mu, mu); } - }; }; diff --git a/Grid/qcd/action/gauge/WilsonGaugeAction.h b/Grid/qcd/action/gauge/WilsonGaugeAction.h index 661b0ca5..952536b3 100644 --- a/Grid/qcd/action/gauge/WilsonGaugeAction.h +++ b/Grid/qcd/action/gauge/WilsonGaugeAction.h @@ -68,27 +68,23 @@ public: // extend Ta to include Lorentz indexes RealD factor = 0.5 * beta / RealD(Nc); + GridBase *grid = U.Grid(); - // GaugeLinkField Umu(U.Grid()); - std::vector Uvec(Nd, U.Grid()); - for (int d = 0; d < Nd; d++) { - Uvec[d] = PeekIndex(U, d); + GaugeLinkField dSdU_mu(grid); + std::vector Umu(Nd, grid); + for (int mu = 0; mu < Nd; mu++) { + Umu[mu] = PeekIndex(U, mu); } - GaugeLinkField dSdU_mu(U.Grid()); for (int mu = 0; mu < Nd; mu++) { - - // Umu = PeekIndex(U, mu); - // Staple in direction mu - // WilsonLoops::Staple(dSdU_mu, U, mu); - // dSdU_mu = Ta(Umu * dSdU_mu) * factor; - WilsonLoops::Staple(dSdU_mu, Uvec, mu); - dSdU_mu = Ta(Uvec[mu] * dSdU_mu) * factor; - + WilsonLoops::Staple(dSdU_mu, Umu, mu); + dSdU_mu = Ta(Umu[mu] * dSdU_mu) * factor; + PokeIndex(dSdU, dSdU_mu, mu); } } + private: RealD beta; }; diff --git a/Grid/qcd/utils/WilsonLoops.h b/Grid/qcd/utils/WilsonLoops.h index 851ba172..cd281033 100644 --- a/Grid/qcd/utils/WilsonLoops.h +++ b/Grid/qcd/utils/WilsonLoops.h @@ -292,18 +292,16 @@ public: ////////////////////////////////////////////////// // the sum over all nu-oriented staples for nu != mu on each site ////////////////////////////////////////////////// - static void Staple(GaugeMat &staple, const GaugeLorentz &Umu, int mu) { + static void Staple(GaugeMat &staple, const GaugeLorentz &U, int mu) { - GridBase *grid = Umu.Grid(); - - std::vector U(Nd, grid); + std::vector Umu(Nd, U.grid()); for (int d = 0; d < Nd; d++) { - U[d] = PeekIndex(Umu, d); + Umu[d] = PeekIndex(U, d); } - Staple(staple, U, mu); + Staple(staple, Umu, mu); } - static void Staple(GaugeMat &staple, const std::vector &U, int mu) { + static void Staple(GaugeMat &staple, const std::vector &Umu, int mu) { staple = Zero(); for (int nu = 0; nu < Nd; nu++) { @@ -318,13 +316,10 @@ public: // | // __| // - + staple += Gimpl::ShiftStaple( - Gimpl::CovShiftForward( - U[nu], nu, - Gimpl::CovShiftBackward( - U[mu], mu, Gimpl::CovShiftIdentityBackward(U[nu], nu))), - mu); + Gimpl::CovShiftForward(Umu[nu], nu, + Gimpl::CovShiftBackward(Umu[mu], mu, Gimpl::CovShiftIdentityBackward(Umu[nu], nu))), mu); // __ // | @@ -333,8 +328,8 @@ public: // staple += Gimpl::ShiftStaple( - Gimpl::CovShiftBackward(U[nu], nu, - Gimpl::CovShiftBackward(U[mu], mu, U[nu])), mu); + Gimpl::CovShiftBackward(Umu[nu], nu, + Gimpl::CovShiftBackward(Umu[mu], mu, Umu[nu])), mu); } } } diff --git a/tests/run_regression_test.py b/tests/run_regression_test.py new file mode 100644 index 00000000..c7ad0367 --- /dev/null +++ b/tests/run_regression_test.py @@ -0,0 +1,134 @@ +def read_expected(test_name="Test_hmc_Sp_WilsonFundFermionGauge", grid="8.8.8.8", mpi="1.1.1.1"): + """ + Read expected values from file. + + The file contains one or more entries of the following format: + + Eg. + 8.8.8.8 1.1.1.1 0.0256253844 922c392f d1e4cc1c + """ + + with open(f"{test_name}_expected.txt") as file: + for line in file: + line_split = line.split() + if line_split[0] == grid and line_split[1] == mpi: + return float(line_split[2]), line_split[3], line_split[4] + + +def read_output(): + """ + Read test output and fish out values of interest. + """ + + checksum_rng = None + checksum_lat = None + plaquette = None + with open("output.txt", 'r') as file: + for line in file: + if "Written NERSC" in line: + subline = line.split('checksum ')[1] + if len(subline.split()) == 1: # this is the rng checksum line + checksum_rng = subline.strip() + elif len(subline.split()) == 3: # this is the lat checksum and plaquette value line + checksum_lat = subline.split()[0] + plaquette = float(subline.split()[2]) + else: + print("Picked wrong line...") + + if (checksum_rng is None) or (checksum_lat is None) or (plaquette is None): + print("Error reading values from output file. Make sure you compile the test with CPparams.saveInterval=1 in order to produce the required output.") + exit(1) + + return plaquette, checksum_rng, checksum_lat + + +def compare(actual, expected, what, stop=False): + """ + Compare actual with expected output, and output message if failed. + """ + + if actual != expected: + print(f"{what} comparison failed: actual={actual} , expected={expected}") + if stop: + exit(1) + else: + return False + return True + + + +if __name__ == '__main__': + import argparse + import subprocess + import os + + parser = argparse.ArgumentParser(description='Run end-to-end tests and compare results with expectations.') + parser.add_argument("test_name", help="File name of the test") + parser.add_argument("grid", help="Grid configuration") + parser.add_argument("mpi", help="MPI configuration") + parser.add_argument("-s", "--stop", action='store_true', help="Flag to stop testing when a test fails.") + args = parser.parse_args() + + expected_plaquette, expected_checksum_rng, expected_checksum_lat = read_expected(args.test_name, args.grid, args.mpi) + + result = subprocess.run([f"./{args.test_name} --grid {args.grid} --mpi {args.mpi} --Thermalizations 0 --Trajectories 1 > output.txt"], shell=True, encoding="text") + plaquette, checksum_rng, checksum_lat = read_output() + + print(f"Running {args.test_name}") + result = compare(plaquette, expected_plaquette, "plaquette", args.stop) + result = result and compare(checksum_rng, expected_checksum_rng, "Checksum RNG file ", args.stop) + result = result and compare(checksum_lat, expected_checksum_lat, "Checksum LAT file ", args.stop) + if result: + print("All tests passed!") + else: + print("Some tests failed...") + + os.remove("output.txt") + os.remove("ckpoint_rng.1") + os.remove("ckpoint_lat.1") + +#result = subprocess.run(["./Test_hmc_Sp_WilsonFundFermionGauge --grid 8.8.8.8 --mpi 1.1.1.1 --Thermalizations 0 --Trajectories 1 > output1.txt"], shell=True, encoding="text") + +# expected_value = 0.0256253844 +# checksum_rng = "922c392f" +# checksum_lat = "d1e4cc1c" + +# with open("output1.txt", 'r') as file: +# for line in file: +# # if "Plaquette" in line: +# # #print(line) +# # plaquette_value = float(line.split('] ')[1]) +# # #print(plaquette_value) +# # if plaquette_value == expected_value: +# # print("Success!") +# if "Written NERSC" in line: +# print(line) +# subline = line.split('checksum ')[1] +# if len(subline.split()) == 1: # this is the rng checksum line +# print(subline) +# if subline.strip() == checksum_rng: +# print("RNG file checksum success!") +# else: +# print("RNG file checksum failed!") +# elif len(subline.split()) == 3: # this is the lat checksum and plaquette value line +# print(subline) +# checksum_value = subline.split()[0] +# plaquette_value = float(subline.split()[2]) +# print(checksum_value, plaquette_value) +# if checksum_value == checksum_lat: +# print("LAT file checksum success!") +# else: +# print("LAT file checksum failed!") +# if plaquette_value == expected_value: +# print("Plaquette value success!") +# else: +# print("Plaquette value failed!") +# else: +# print("Picked wrong line...") + + +#loc1 = result.find("Plaquette") +#print(loc1) +#loc2 = result.find("Smeared") +#print(loc2) +#print(result[loc1,loc2]) diff --git a/tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge_expected.txt b/tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge_expected.txt new file mode 100644 index 00000000..7edc6fa0 --- /dev/null +++ b/tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge_expected.txt @@ -0,0 +1 @@ +8.8.8.8 1.1.1.1 0.0256253844 922c392f d1e4cc1c From e99d42404e64e6f3833616dc9c975ce001744b52 Mon Sep 17 00:00:00 2001 From: Mashy Green Date: Mon, 16 Dec 2024 16:31:22 +0000 Subject: [PATCH 03/12] Removing the regresion test files that were also in this branch for a clean PR --- tests/run_regression_test.py | 134 ------------------ ...hmc_Sp_WilsonFundFermionGauge_expected.txt | 1 - 2 files changed, 135 deletions(-) delete mode 100644 tests/run_regression_test.py delete mode 100644 tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge_expected.txt diff --git a/tests/run_regression_test.py b/tests/run_regression_test.py deleted file mode 100644 index c7ad0367..00000000 --- a/tests/run_regression_test.py +++ /dev/null @@ -1,134 +0,0 @@ -def read_expected(test_name="Test_hmc_Sp_WilsonFundFermionGauge", grid="8.8.8.8", mpi="1.1.1.1"): - """ - Read expected values from file. - - The file contains one or more entries of the following format: - - Eg. - 8.8.8.8 1.1.1.1 0.0256253844 922c392f d1e4cc1c - """ - - with open(f"{test_name}_expected.txt") as file: - for line in file: - line_split = line.split() - if line_split[0] == grid and line_split[1] == mpi: - return float(line_split[2]), line_split[3], line_split[4] - - -def read_output(): - """ - Read test output and fish out values of interest. - """ - - checksum_rng = None - checksum_lat = None - plaquette = None - with open("output.txt", 'r') as file: - for line in file: - if "Written NERSC" in line: - subline = line.split('checksum ')[1] - if len(subline.split()) == 1: # this is the rng checksum line - checksum_rng = subline.strip() - elif len(subline.split()) == 3: # this is the lat checksum and plaquette value line - checksum_lat = subline.split()[0] - plaquette = float(subline.split()[2]) - else: - print("Picked wrong line...") - - if (checksum_rng is None) or (checksum_lat is None) or (plaquette is None): - print("Error reading values from output file. Make sure you compile the test with CPparams.saveInterval=1 in order to produce the required output.") - exit(1) - - return plaquette, checksum_rng, checksum_lat - - -def compare(actual, expected, what, stop=False): - """ - Compare actual with expected output, and output message if failed. - """ - - if actual != expected: - print(f"{what} comparison failed: actual={actual} , expected={expected}") - if stop: - exit(1) - else: - return False - return True - - - -if __name__ == '__main__': - import argparse - import subprocess - import os - - parser = argparse.ArgumentParser(description='Run end-to-end tests and compare results with expectations.') - parser.add_argument("test_name", help="File name of the test") - parser.add_argument("grid", help="Grid configuration") - parser.add_argument("mpi", help="MPI configuration") - parser.add_argument("-s", "--stop", action='store_true', help="Flag to stop testing when a test fails.") - args = parser.parse_args() - - expected_plaquette, expected_checksum_rng, expected_checksum_lat = read_expected(args.test_name, args.grid, args.mpi) - - result = subprocess.run([f"./{args.test_name} --grid {args.grid} --mpi {args.mpi} --Thermalizations 0 --Trajectories 1 > output.txt"], shell=True, encoding="text") - plaquette, checksum_rng, checksum_lat = read_output() - - print(f"Running {args.test_name}") - result = compare(plaquette, expected_plaquette, "plaquette", args.stop) - result = result and compare(checksum_rng, expected_checksum_rng, "Checksum RNG file ", args.stop) - result = result and compare(checksum_lat, expected_checksum_lat, "Checksum LAT file ", args.stop) - if result: - print("All tests passed!") - else: - print("Some tests failed...") - - os.remove("output.txt") - os.remove("ckpoint_rng.1") - os.remove("ckpoint_lat.1") - -#result = subprocess.run(["./Test_hmc_Sp_WilsonFundFermionGauge --grid 8.8.8.8 --mpi 1.1.1.1 --Thermalizations 0 --Trajectories 1 > output1.txt"], shell=True, encoding="text") - -# expected_value = 0.0256253844 -# checksum_rng = "922c392f" -# checksum_lat = "d1e4cc1c" - -# with open("output1.txt", 'r') as file: -# for line in file: -# # if "Plaquette" in line: -# # #print(line) -# # plaquette_value = float(line.split('] ')[1]) -# # #print(plaquette_value) -# # if plaquette_value == expected_value: -# # print("Success!") -# if "Written NERSC" in line: -# print(line) -# subline = line.split('checksum ')[1] -# if len(subline.split()) == 1: # this is the rng checksum line -# print(subline) -# if subline.strip() == checksum_rng: -# print("RNG file checksum success!") -# else: -# print("RNG file checksum failed!") -# elif len(subline.split()) == 3: # this is the lat checksum and plaquette value line -# print(subline) -# checksum_value = subline.split()[0] -# plaquette_value = float(subline.split()[2]) -# print(checksum_value, plaquette_value) -# if checksum_value == checksum_lat: -# print("LAT file checksum success!") -# else: -# print("LAT file checksum failed!") -# if plaquette_value == expected_value: -# print("Plaquette value success!") -# else: -# print("Plaquette value failed!") -# else: -# print("Picked wrong line...") - - -#loc1 = result.find("Plaquette") -#print(loc1) -#loc2 = result.find("Smeared") -#print(loc2) -#print(result[loc1,loc2]) diff --git a/tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge_expected.txt b/tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge_expected.txt deleted file mode 100644 index 7edc6fa0..00000000 --- a/tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge_expected.txt +++ /dev/null @@ -1 +0,0 @@ -8.8.8.8 1.1.1.1 0.0256253844 922c392f d1e4cc1c From d4868991af63ef01e4ebf108ddbaa0d42974da72 Mon Sep 17 00:00:00 2001 From: Mashy Green Date: Fri, 10 Jan 2025 14:53:19 +0000 Subject: [PATCH 04/12] Fixed wrong lib for NVTX in configure.ac and updated to nvtx3 --- Grid/perfmon/Tracing.h | 2 +- configure.ac | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Grid/perfmon/Tracing.h b/Grid/perfmon/Tracing.h index 10b638dc..88c9a4f8 100644 --- a/Grid/perfmon/Tracing.h +++ b/Grid/perfmon/Tracing.h @@ -3,7 +3,7 @@ NAMESPACE_BEGIN(Grid); #ifdef GRID_TRACING_NVTX -#include +#include class GridTracer { public: GridTracer(const char* name) { diff --git a/configure.ac b/configure.ac index 8e8d67af..51b51b6d 100644 --- a/configure.ac +++ b/configure.ac @@ -136,7 +136,6 @@ AC_ARG_ENABLE([tracing], case ${ac_TRACING} in nvtx) AC_DEFINE([GRID_TRACING_NVTX],[1],[use NVTX]) - LIBS="${LIBS} -lnvToolsExt64_1" ;; roctx) AC_DEFINE([GRID_TRACING_ROCTX],[1],[use ROCTX]) From aaab753982fc293bdb7dff552fd8081c1887fe8f Mon Sep 17 00:00:00 2001 From: Mashy Green Date: Wed, 29 Jan 2025 12:57:38 +0000 Subject: [PATCH 05/12] Reverting to older version of nvtx for Tursa support --- Grid/perfmon/Tracing.h | 2 +- configure.ac | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Grid/perfmon/Tracing.h b/Grid/perfmon/Tracing.h index 88c9a4f8..10b638dc 100644 --- a/Grid/perfmon/Tracing.h +++ b/Grid/perfmon/Tracing.h @@ -3,7 +3,7 @@ NAMESPACE_BEGIN(Grid); #ifdef GRID_TRACING_NVTX -#include +#include class GridTracer { public: GridTracer(const char* name) { diff --git a/configure.ac b/configure.ac index 51b51b6d..1483bcae 100644 --- a/configure.ac +++ b/configure.ac @@ -136,6 +136,7 @@ AC_ARG_ENABLE([tracing], case ${ac_TRACING} in nvtx) AC_DEFINE([GRID_TRACING_NVTX],[1],[use NVTX]) + LIBS="${LIBS} -lnvToolsExt" ;; roctx) AC_DEFINE([GRID_TRACING_ROCTX],[1],[use ROCTX]) From 7726ee4b16d90a85813f08704b504a09f9390e0c Mon Sep 17 00:00:00 2001 From: Mashy Green Date: Mon, 17 Feb 2025 17:16:28 +0000 Subject: [PATCH 06/12] Reverting whitespace changes --- .../action/gauge/PlaqPlusRectangleAction.h | 26 +++++++++---------- Grid/qcd/utils/WilsonLoops.h | 11 +++++--- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h b/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h index 55b98986..a3b49973 100644 --- a/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h +++ b/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h @@ -72,29 +72,29 @@ public: }; virtual void deriv(const GaugeField &U, GaugeField &dSdU) { - // extend Ta to include Lorentz indexes - RealD factor_p = c_plaq / RealD(Nc) * 0.5; - RealD factor_r = c_rect / RealD(Nc) * 0.5; + //extend Ta to include Lorentz indexes + RealD factor_p = c_plaq/RealD(Nc)*0.5; + RealD factor_r = c_rect/RealD(Nc)*0.5; - GridBase *grid = U.Grid(); + GridBase *grid = Umu.Grid(); - std::vector Umu(Nd, grid); - for (int mu = 0; mu < Nd; mu++) { - Umu[mu] = PeekIndex(U, mu); + std::vector U (Nd,grid); + for(int mu=0;mu(Umu,mu); } - std::vector RectStaple(Nd, grid), Staple(Nd, grid); - WilsonLoops::StapleAndRectStapleAll(Staple, RectStaple, Umu, - workspace); + std::vector RectStaple(Nd,grid), Staple(Nd,grid); + WilsonLoops::StapleAndRectStapleAll(Staple, RectStaple, U, workspace); GaugeLinkField dSdU_mu(grid); GaugeLinkField staple(grid); - for (int mu = 0; mu < Nd; mu++) { - dSdU_mu = Ta(Umu[mu] * Staple[mu]) * factor_p; - dSdU_mu = dSdU_mu + Ta(Umu[mu] * RectStaple[mu]) * factor_r; + for (int mu=0; mu < Nd; mu++){ + dSdU_mu = Ta(U[mu]*Staple[mu])*factor_p; + dSdU_mu = dSdU_mu + Ta(U[mu]*RectStaple[mu])*factor_r; PokeIndex(dSdU, dSdU_mu, mu); } + }; }; diff --git a/Grid/qcd/utils/WilsonLoops.h b/Grid/qcd/utils/WilsonLoops.h index cd281033..b4ab35d7 100644 --- a/Grid/qcd/utils/WilsonLoops.h +++ b/Grid/qcd/utils/WilsonLoops.h @@ -318,8 +318,11 @@ public: // staple += Gimpl::ShiftStaple( - Gimpl::CovShiftForward(Umu[nu], nu, - Gimpl::CovShiftBackward(Umu[mu], mu, Gimpl::CovShiftIdentityBackward(Umu[nu], nu))), mu); + Gimpl::CovShiftForward( + U[nu], nu, + Gimpl::CovShiftBackward( + U[mu], mu, Gimpl::CovShiftIdentityBackward(U[nu], nu))), + mu); // __ // | @@ -328,8 +331,8 @@ public: // staple += Gimpl::ShiftStaple( - Gimpl::CovShiftBackward(Umu[nu], nu, - Gimpl::CovShiftBackward(Umu[mu], mu, Umu[nu])), mu); + Gimpl::CovShiftBackward(U[nu], nu, + Gimpl::CovShiftBackward(U[mu], mu, U[nu])), mu); } } } From d2dd8f54e2ae7b5e953f9cd5895e064bf24ea2ba Mon Sep 17 00:00:00 2001 From: Mashy Green Date: Mon, 17 Feb 2025 17:32:27 +0000 Subject: [PATCH 07/12] Fixing after revering too much! --- Grid/qcd/action/gauge/PlaqPlusRectangleAction.h | 12 ++++++------ Grid/qcd/utils/WilsonLoops.h | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h b/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h index a3b49973..e6ead936 100644 --- a/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h +++ b/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h @@ -76,21 +76,21 @@ public: RealD factor_p = c_plaq/RealD(Nc)*0.5; RealD factor_r = c_rect/RealD(Nc)*0.5; - GridBase *grid = Umu.Grid(); + GridBase *grid = U.Grid(); - std::vector U (Nd,grid); + std::vector Umu (Nd,grid); for(int mu=0;mu(Umu,mu); + Umu[mu] = PeekIndex(U,mu); } std::vector RectStaple(Nd,grid), Staple(Nd,grid); - WilsonLoops::StapleAndRectStapleAll(Staple, RectStaple, U, workspace); + WilsonLoops::StapleAndRectStapleAll(Staple, RectStaple, Umu, workspace); GaugeLinkField dSdU_mu(grid); GaugeLinkField staple(grid); for (int mu=0; mu < Nd; mu++){ - dSdU_mu = Ta(U[mu]*Staple[mu])*factor_p; - dSdU_mu = dSdU_mu + Ta(U[mu]*RectStaple[mu])*factor_r; + dSdU_mu = Ta(Umu[mu]*Staple[mu])*factor_p; + dSdU_mu = dSdU_mu + Ta(Umu[mu]*RectStaple[mu])*factor_r; PokeIndex(dSdU, dSdU_mu, mu); } diff --git a/Grid/qcd/utils/WilsonLoops.h b/Grid/qcd/utils/WilsonLoops.h index b4ab35d7..655255d6 100644 --- a/Grid/qcd/utils/WilsonLoops.h +++ b/Grid/qcd/utils/WilsonLoops.h @@ -319,9 +319,9 @@ public: staple += Gimpl::ShiftStaple( Gimpl::CovShiftForward( - U[nu], nu, + Umu[nu], nu, Gimpl::CovShiftBackward( - U[mu], mu, Gimpl::CovShiftIdentityBackward(U[nu], nu))), + Umu[mu], mu, Gimpl::CovShiftIdentityBackward(Umu[nu], nu))), mu); // __ @@ -331,8 +331,8 @@ public: // staple += Gimpl::ShiftStaple( - Gimpl::CovShiftBackward(U[nu], nu, - Gimpl::CovShiftBackward(U[mu], mu, U[nu])), mu); + Gimpl::CovShiftBackward(Umu[nu], nu, + Gimpl::CovShiftBackward(Umu[mu], mu, Umu[nu])), mu); } } } From fe05bf48b1534f30ed275281195a65e61361fed7 Mon Sep 17 00:00:00 2001 From: Mashy Green Date: Mon, 17 Feb 2025 18:52:04 +0000 Subject: [PATCH 08/12] Improvements to WilsonGaugeAction deriv function (#16) * patched version + modifications to deriv -> staple in qcd/gauge * Cleaning up and aligning variable naming between action deriv versions * Removing the regresion test files that were also in this branch for a clean PR * Reverting whitespace changes * Fixing after revering too much! --------- Co-authored-by: Mashy Green --- .../action/gauge/PlaqPlusRectangleAction.h | 16 +++++++------- Grid/qcd/action/gauge/WilsonGaugeAction.h | 17 ++++++++------ Grid/qcd/utils/WilsonLoops.h | 22 +++++++++---------- HMC/FTHMC2p1f.cc | 10 +++++++-- HMC/FTHMC2p1f_3GeV.cc | 9 ++++++++ HMC/HMC2p1f_3GeV.cc | 8 +++++++ 6 files changed, 53 insertions(+), 29 deletions(-) diff --git a/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h b/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h index b9d6ac16..e6ead936 100644 --- a/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h +++ b/Grid/qcd/action/gauge/PlaqPlusRectangleAction.h @@ -71,27 +71,27 @@ public: return action; }; - virtual void deriv(const GaugeField &Umu,GaugeField & dSdU) { + virtual void deriv(const GaugeField &U, GaugeField &dSdU) { //extend Ta to include Lorentz indexes RealD factor_p = c_plaq/RealD(Nc)*0.5; RealD factor_r = c_rect/RealD(Nc)*0.5; - GridBase *grid = Umu.Grid(); + GridBase *grid = U.Grid(); - std::vector U (Nd,grid); + std::vector Umu (Nd,grid); for(int mu=0;mu(Umu,mu); + Umu[mu] = PeekIndex(U,mu); } std::vector RectStaple(Nd,grid), Staple(Nd,grid); - WilsonLoops::StapleAndRectStapleAll(Staple, RectStaple, U, workspace); + WilsonLoops::StapleAndRectStapleAll(Staple, RectStaple, Umu, workspace); GaugeLinkField dSdU_mu(grid); GaugeLinkField staple(grid); for (int mu=0; mu < Nd; mu++){ - dSdU_mu = Ta(U[mu]*Staple[mu])*factor_p; - dSdU_mu = dSdU_mu + Ta(U[mu]*RectStaple[mu])*factor_r; - + dSdU_mu = Ta(Umu[mu]*Staple[mu])*factor_p; + dSdU_mu = dSdU_mu + Ta(Umu[mu]*RectStaple[mu])*factor_r; + PokeIndex(dSdU, dSdU_mu, mu); } diff --git a/Grid/qcd/action/gauge/WilsonGaugeAction.h b/Grid/qcd/action/gauge/WilsonGaugeAction.h index f535b54f..952536b3 100644 --- a/Grid/qcd/action/gauge/WilsonGaugeAction.h +++ b/Grid/qcd/action/gauge/WilsonGaugeAction.h @@ -68,20 +68,23 @@ public: // extend Ta to include Lorentz indexes RealD factor = 0.5 * beta / RealD(Nc); + GridBase *grid = U.Grid(); - GaugeLinkField Umu(U.Grid()); - GaugeLinkField dSdU_mu(U.Grid()); + GaugeLinkField dSdU_mu(grid); + std::vector Umu(Nd, grid); for (int mu = 0; mu < Nd; mu++) { + Umu[mu] = PeekIndex(U, mu); + } - Umu = PeekIndex(U, mu); - + for (int mu = 0; mu < Nd; mu++) { // Staple in direction mu - WilsonLoops::Staple(dSdU_mu, U, mu); - dSdU_mu = Ta(Umu * dSdU_mu) * factor; - + WilsonLoops::Staple(dSdU_mu, Umu, mu); + dSdU_mu = Ta(Umu[mu] * dSdU_mu) * factor; + PokeIndex(dSdU, dSdU_mu, mu); } } + private: RealD beta; }; diff --git a/Grid/qcd/utils/WilsonLoops.h b/Grid/qcd/utils/WilsonLoops.h index 851ba172..655255d6 100644 --- a/Grid/qcd/utils/WilsonLoops.h +++ b/Grid/qcd/utils/WilsonLoops.h @@ -292,18 +292,16 @@ public: ////////////////////////////////////////////////// // the sum over all nu-oriented staples for nu != mu on each site ////////////////////////////////////////////////// - static void Staple(GaugeMat &staple, const GaugeLorentz &Umu, int mu) { + static void Staple(GaugeMat &staple, const GaugeLorentz &U, int mu) { - GridBase *grid = Umu.Grid(); - - std::vector U(Nd, grid); + std::vector Umu(Nd, U.grid()); for (int d = 0; d < Nd; d++) { - U[d] = PeekIndex(Umu, d); + Umu[d] = PeekIndex(U, d); } - Staple(staple, U, mu); + Staple(staple, Umu, mu); } - static void Staple(GaugeMat &staple, const std::vector &U, int mu) { + static void Staple(GaugeMat &staple, const std::vector &Umu, int mu) { staple = Zero(); for (int nu = 0; nu < Nd; nu++) { @@ -318,12 +316,12 @@ public: // | // __| // - + staple += Gimpl::ShiftStaple( Gimpl::CovShiftForward( - U[nu], nu, + Umu[nu], nu, Gimpl::CovShiftBackward( - U[mu], mu, Gimpl::CovShiftIdentityBackward(U[nu], nu))), + Umu[mu], mu, Gimpl::CovShiftIdentityBackward(Umu[nu], nu))), mu); // __ @@ -333,8 +331,8 @@ public: // staple += Gimpl::ShiftStaple( - Gimpl::CovShiftBackward(U[nu], nu, - Gimpl::CovShiftBackward(U[mu], mu, U[nu])), mu); + Gimpl::CovShiftBackward(Umu[nu], nu, + Gimpl::CovShiftBackward(Umu[mu], mu, Umu[nu])), mu); } } } diff --git a/HMC/FTHMC2p1f.cc b/HMC/FTHMC2p1f.cc index 7d93d168..1e914e87 100644 --- a/HMC/FTHMC2p1f.cc +++ b/HMC/FTHMC2p1f.cc @@ -25,13 +25,20 @@ directory *************************************************************************************/ /* END LEGAL */ #include + +#if Nc == 3 #include #include +#endif using namespace Grid; int main(int argc, char **argv) { +#if Nc != 3 +#warning FTHMC2p1f will not work for Nc != 3 + std::cout << "This program will currently only work for Nc == 3." << std::endl; +#else std::cout << std::setprecision(12); Grid_init(&argc, &argv); @@ -220,7 +227,6 @@ int main(int argc, char **argv) TheHMC.Run(SmearingPolicy); // for smearing Grid_finalize(); +#endif } // main - - diff --git a/HMC/FTHMC2p1f_3GeV.cc b/HMC/FTHMC2p1f_3GeV.cc index a8aa67f8..36d5caa3 100644 --- a/HMC/FTHMC2p1f_3GeV.cc +++ b/HMC/FTHMC2p1f_3GeV.cc @@ -24,14 +24,22 @@ See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ + #include + +#if Nc == 3 #include #include +#endif using namespace Grid; int main(int argc, char **argv) { +#if Nc != 3 +#warning FTHMC2p1f_3GeV will not work for Nc != 3 + std::cout << "This program will currently only work for Nc == 3." << std::endl; +#else std::cout << std::setprecision(12); Grid_init(&argc, &argv); @@ -220,6 +228,7 @@ int main(int argc, char **argv) TheHMC.Run(SmearingPolicy); // for smearing Grid_finalize(); +#endif } // main diff --git a/HMC/HMC2p1f_3GeV.cc b/HMC/HMC2p1f_3GeV.cc index 4bf088d7..199d4be8 100644 --- a/HMC/HMC2p1f_3GeV.cc +++ b/HMC/HMC2p1f_3GeV.cc @@ -25,13 +25,20 @@ directory *************************************************************************************/ /* END LEGAL */ #include + +#if Nc == 3 #include #include +#endif using namespace Grid; int main(int argc, char **argv) { +#if Nc != 3 +#warning HMC2p1f_3GeV will not work for Nc != 3 + std::cout << "This program will currently only work for Nc == 3." << std::endl; +#else std::cout << std::setprecision(12); Grid_init(&argc, &argv); @@ -220,6 +227,7 @@ int main(int argc, char **argv) TheHMC.Run(SmearingPolicy); // for smearing Grid_finalize(); +#endif } // main From 717f6474187311e419f16f66a885b2281e916b64 Mon Sep 17 00:00:00 2001 From: Mashy Green Date: Mon, 24 Feb 2025 08:40:07 +0000 Subject: [PATCH 09/12] added the WilsonFlow patch from upstream PR #471 --- Grid/qcd/smearing/WilsonFlow.h | 9 ++++++--- tests/smearing/Test_WilsonFlow.cc | 13 +++---------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Grid/qcd/smearing/WilsonFlow.h b/Grid/qcd/smearing/WilsonFlow.h index f169d02b..dc135823 100644 --- a/Grid/qcd/smearing/WilsonFlow.h +++ b/Grid/qcd/smearing/WilsonFlow.h @@ -207,11 +207,14 @@ std::vector WilsonFlowBase::flowMeasureEnergyDensityCloverleaf(con } template -void WilsonFlowBase::setDefaultMeasurements(int topq_meas_interval){ - addMeasurement(1, [](int step, RealD t, const typename Gimpl::GaugeField &U){ +void WilsonFlowBase::setDefaultMeasurements(int meas_interval){ + addMeasurement(meas_interval, [](int step, RealD t, const typename Gimpl::GaugeField &U){ std::cout << GridLogMessage << "[WilsonFlow] Energy density (plaq) : " << step << " " << t << " " << energyDensityPlaquette(t,U) << std::endl; }); - addMeasurement(topq_meas_interval, [](int step, RealD t, const typename Gimpl::GaugeField &U){ + addMeasurement(meas_interval, [](int step, RealD t, const typename Gimpl::GaugeField &U){ + std::cout << GridLogMessage << "[WilsonFlow] Energy density (cloverleaf) : " << step << " " << t << " " << energyDensityCloverleaf(t,U) << std::endl; + }); + addMeasurement(meas_interval, [](int step, RealD t, const typename Gimpl::GaugeField &U){ std::cout << GridLogMessage << "[WilsonFlow] Top. charge : " << step << " " << WilsonLoops::TopologicalCharge(U) << std::endl; }); } diff --git a/tests/smearing/Test_WilsonFlow.cc b/tests/smearing/Test_WilsonFlow.cc index e0726f87..4acd3b4f 100644 --- a/tests/smearing/Test_WilsonFlow.cc +++ b/tests/smearing/Test_WilsonFlow.cc @@ -33,8 +33,7 @@ namespace Grid{ GRID_SERIALIZABLE_CLASS_MEMBERS(WFParameters, int, steps, double, step_size, - int, meas_interval, - double, maxTau); // for the adaptive algorithm + int, meas_interval); template @@ -86,7 +85,7 @@ int main(int argc, char **argv) { WFParameters WFPar(Reader); ConfParameters CPar(Reader); CheckpointerParameters CPPar(CPar.conf_prefix, CPar.rng_prefix); - BinaryHmcCheckpointer CPBin(CPPar); + NerscHmcCheckpointer CPBin(CPPar); for (int conf = CPar.StartConfiguration; conf <= CPar.EndConfiguration; conf+= CPar.Skip){ @@ -96,19 +95,13 @@ int main(int argc, char **argv) { std::cout << GridLogMessage << "Initial plaquette: " << WilsonLoops::avgPlaquette(Umu) << std::endl; - int t=WFPar.maxTau; - WilsonFlowAdaptive WF(WFPar.step_size, WFPar.maxTau, - 1.0e-4, + WilsonFlow WF(WFPar.step_size, WFPar.steps, WFPar.meas_interval); WF.smear(Uflow, Umu); RealD WFlow_plaq = WilsonLoops::avgPlaquette(Uflow); - RealD WFlow_TC = WilsonLoops::TopologicalCharge(Uflow); - RealD WFlow_T0 = WF.energyDensityPlaquette(t,Uflow); std::cout << GridLogMessage << "Plaquette "<< conf << " " << WFlow_plaq << std::endl; - std::cout << GridLogMessage << "T0 "<< conf << " " << WFlow_T0 << std::endl; - std::cout << GridLogMessage << "TopologicalCharge "<< conf << " " << WFlow_TC << std::endl; std::cout<< GridLogMessage << " Admissibility check:\n"; const double sp_adm = 0.067; // admissible threshold From b1ba2096962590245b25227cbb002da2413ce55a Mon Sep 17 00:00:00 2001 From: Muhammad Asif <19404936+asifsamiarain@users.noreply.github.com> Date: Mon, 24 Feb 2025 11:38:42 +0000 Subject: [PATCH 10/12] Latest upstream with np-su3 patch and modified Sp_WilsonFunfFermionGauge test to be small (#22) Co-authored-by: Mashy Green merging no-su3 patch --- tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge.cc b/tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge.cc index d302911d..e655000f 100644 --- a/tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge.cc +++ b/tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge.cc @@ -64,8 +64,8 @@ int main(int argc, char **argv) { TheHMC.TheAction.push_back(Level1); TheHMC.TheAction.push_back(Level2); - TheHMC.Parameters.MD.MDsteps = 36; - TheHMC.Parameters.MD.trajL = 1.0; + TheHMC.Parameters.MD.MDsteps = 2; + TheHMC.Parameters.MD.trajL = 0.1; TheHMC.ReadCommandLine(argc, argv); TheHMC.Run(); From 785bc7a14f15dedfe26977a1af16b16f0c3d01ad Mon Sep 17 00:00:00 2001 From: Mashy Green Date: Mon, 10 Mar 2025 12:29:04 +0000 Subject: [PATCH 11/12] Adding staple zeroing fix --- Grid/qcd/utils/WilsonLoops.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Grid/qcd/utils/WilsonLoops.h b/Grid/qcd/utils/WilsonLoops.h index 655255d6..6e9318c0 100644 --- a/Grid/qcd/utils/WilsonLoops.h +++ b/Grid/qcd/utils/WilsonLoops.h @@ -302,7 +302,11 @@ public: } static void Staple(GaugeMat &staple, const std::vector &Umu, int mu) { - staple = Zero(); + + autoView(staple_v, staple, AcceleratorWrite); + accelerator_for(i, staple.Grid()->oSites(), Simd::Nsimd(), { + staple_v[i] = Zero(); + }); for (int nu = 0; nu < Nd; nu++) { From d41542c64be818920cf21be7c794fbff9e38d401 Mon Sep 17 00:00:00 2001 From: Mashy Green Date: Mon, 24 Mar 2025 08:29:15 +0000 Subject: [PATCH 12/12] reverted sp2n test wilsonfundfermiongauge to original --- tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge.cc b/tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge.cc index e655000f..d302911d 100644 --- a/tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge.cc +++ b/tests/sp2n/Test_hmc_Sp_WilsonFundFermionGauge.cc @@ -64,8 +64,8 @@ int main(int argc, char **argv) { TheHMC.TheAction.push_back(Level1); TheHMC.TheAction.push_back(Level2); - TheHMC.Parameters.MD.MDsteps = 2; - TheHMC.Parameters.MD.trajL = 0.1; + TheHMC.Parameters.MD.MDsteps = 36; + TheHMC.Parameters.MD.trajL = 1.0; TheHMC.ReadCommandLine(argc, argv); TheHMC.Run();