From 34717d93bd30dac428b6aba6b1e2474b6f63c0c7 Mon Sep 17 00:00:00 2001 From: Andreas Singraber Date: Fri, 18 Feb 2022 23:47:17 +0100 Subject: [PATCH 1/3] Added keyword "energy_force_ratio" --- src/libnnp/Settings.cpp | 1 + src/libnnptrain/Training.cpp | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/libnnp/Settings.cpp b/src/libnnp/Settings.cpp index 063e6ef2e..fb45cdc17 100644 --- a/src/libnnp/Settings.cpp +++ b/src/libnnp/Settings.cpp @@ -68,6 +68,7 @@ map> const createKnownKeywordsMap() m["rmse_threshold_trials_charge" ] = ""; m["energy_fraction" ] = ""; m["force_fraction" ] = ""; + m["energy_force_ratio" ] = ""; m["charge_fraction" ] = ""; m["use_old_weights_short" ] = ""; m["use_old_weights_charge" ] = ""; diff --git a/src/libnnptrain/Training.cpp b/src/libnnptrain/Training.cpp index 602454c2b..1327b207b 100644 --- a/src/libnnptrain/Training.cpp +++ b/src/libnnptrain/Training.cpp @@ -2875,6 +2875,29 @@ void Training::setupUpdatePlan(string const& property) Property& pa = p[property]; string keyword = property + "_fraction"; pa.epochFraction = atof(settings[keyword].c_str()); + + // Override force fraction if keyword "energy_force_ratio" is provided. + if (property == "force" && + p.exists("energy") && + settings.keywordExists("energy_force_ratio")) + { + double const ratio = atof(settings["energy_force_ratio"].c_str()); + if (settings.keywordExists(keyword)) + { + log << "WARNING: Given force fraction is ignored because " + "energy/force ratio is provided.\n"; + } + log << strpr("- Desired energy to force update ratio : %.6f\n", + ratio); + pa.epochFraction = (p["energy"].numTrainPatterns * ratio) + / p["force"].numTrainPatterns; + } + // Default action = read "_fraction" keyword. + else + { + pa.epochFraction = atof(settings[keyword].c_str()); + } + keyword = "task_batch_size_" + property; pa.taskBatchSize = (size_t)atoi(settings[keyword].c_str()); if (pa.taskBatchSize == 0) @@ -2933,8 +2956,12 @@ void Training::setupUpdatePlan(string const& property) log << "Update plan for property \"" + property + "\":\n"; log << strpr("- Per-task batch size : %zu\n", pa.taskBatchSize); - log << strpr("- Fraction of patterns used per epoch : %.4f\n", + log << strpr("- Fraction of patterns used per epoch : %.6f\n", pa.epochFraction); + if (pa.numUpdates == 0) + { + log << "WARNING: No updates are planned for this property."; + } log << strpr("- Updates per epoch : %zu\n", pa.numUpdates); log << strpr("- Patterns used per update (rank %3d / global) : " From 6172c860d7cb80da178180c5ff491bcc7d4d8c9e Mon Sep 17 00:00:00 2001 From: Andreas Singraber Date: Sat, 19 Feb 2022 00:15:36 +0100 Subject: [PATCH 2/3] New keyword: cosmetic changes and bugfix. --- examples/input.nn.recommended | 3 ++- src/libnnp/Settings.cpp | 2 +- src/libnnptrain/Training.cpp | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/input.nn.recommended b/examples/input.nn.recommended index 17ee56cfd..42b0a770f 100644 --- a/examples/input.nn.recommended +++ b/examples/input.nn.recommended @@ -41,7 +41,8 @@ memorize_symfunc_results # Keep symmetry function results test_fraction 0.1 # Fraction of structures kept for testing. force_weight 10.0 # Weight of force updates relative to energy updates. short_energy_fraction 1.000 # Fraction of energy updates per epoch. -short_force_fraction 0.02315 # Fraction of force updates per epoch. +#short_force_fraction 0.02315 # Fraction of force updates per epoch (not necessary if force_energy_ratio given). +force_energy_ratio 10.0 # Specifies ratio between force and energy updates (ratio = updates_force / updates_energy). short_energy_error_threshold 0.00 # RMSE threshold for energy update candidates. short_force_error_threshold 1.00 # RMSE threshold for force update candidates. rmse_threshold_trials 3 # Maximum number of RMSE threshold trials. diff --git a/src/libnnp/Settings.cpp b/src/libnnp/Settings.cpp index fb45cdc17..76ce23a78 100644 --- a/src/libnnp/Settings.cpp +++ b/src/libnnp/Settings.cpp @@ -68,7 +68,7 @@ map> const createKnownKeywordsMap() m["rmse_threshold_trials_charge" ] = ""; m["energy_fraction" ] = ""; m["force_fraction" ] = ""; - m["energy_force_ratio" ] = ""; + m["force_energy_ratio" ] = ""; m["charge_fraction" ] = ""; m["use_old_weights_short" ] = ""; m["use_old_weights_charge" ] = ""; diff --git a/src/libnnptrain/Training.cpp b/src/libnnptrain/Training.cpp index 1327b207b..f7bed9b66 100644 --- a/src/libnnptrain/Training.cpp +++ b/src/libnnptrain/Training.cpp @@ -2874,21 +2874,21 @@ void Training::setupUpdatePlan(string const& property) // Actual property modified here. Property& pa = p[property]; string keyword = property + "_fraction"; - pa.epochFraction = atof(settings[keyword].c_str()); // Override force fraction if keyword "energy_force_ratio" is provided. if (property == "force" && p.exists("energy") && - settings.keywordExists("energy_force_ratio")) + settings.keywordExists("force_energy_ratio")) { - double const ratio = atof(settings["energy_force_ratio"].c_str()); + double const ratio = atof(settings["force_energy_ratio"].c_str()); if (settings.keywordExists(keyword)) { log << "WARNING: Given force fraction is ignored because " - "energy/force ratio is provided.\n"; + "force/energy ratio is provided.\n"; } - log << strpr("- Desired energy to force update ratio : %.6f\n", + log << strpr("Desired force/energy update ratio : %.6f\n", ratio); + log << "----------------------------------------------\n"; pa.epochFraction = (p["energy"].numTrainPatterns * ratio) / p["force"].numTrainPatterns; } From 985a26d936663326f8f342b4f3f499364542e6d7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 23 Apr 2022 05:25:56 -0400 Subject: [PATCH 3/3] destructors in polymorph (base) classes should be virtual --- src/libnnp/Mode.h | 2 ++ src/libnnpif/LAMMPS/InterfaceLammps.h | 1 + 2 files changed, 3 insertions(+) diff --git a/src/libnnp/Mode.h b/src/libnnp/Mode.h index dbd9e0865..12298573c 100644 --- a/src/libnnp/Mode.h +++ b/src/libnnp/Mode.h @@ -91,6 +91,8 @@ class Mode }; Mode(); + virtual ~Mode() {}; + /** Write welcome message with version information. */ void initialize(); diff --git a/src/libnnpif/LAMMPS/InterfaceLammps.h b/src/libnnpif/LAMMPS/InterfaceLammps.h index d896cedf0..8c1d21a7e 100644 --- a/src/libnnpif/LAMMPS/InterfaceLammps.h +++ b/src/libnnpif/LAMMPS/InterfaceLammps.h @@ -31,6 +31,7 @@ class InterfaceLammps : public Mode { public: InterfaceLammps(); + virtual ~InterfaceLammps() {}; /** Initialize the LAMMPS interface. *