Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2016-2021 The VES code team 3 : (see the PEOPLE-VES file at the root of this folder for a list of names) 4 : 5 : See http://www.ves-code.org for more information. 6 : 7 : This file is part of VES code module. 8 : 9 : The VES code module is free software: you can redistribute it and/or modify 10 : it under the terms of the GNU Lesser General Public License as published by 11 : the Free Software Foundation, either version 3 of the License, or 12 : (at your option) any later version. 13 : 14 : The VES code module is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU Lesser General Public License for more details. 18 : 19 : You should have received a copy of the GNU Lesser General Public License 20 : along with the VES code module. If not, see <http://www.gnu.org/licenses/>. 21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 22 : 23 : #include "Optimizer.h" 24 : #include "CoeffsVector.h" 25 : 26 : #include "core/ActionRegister.h" 27 : 28 : 29 : namespace PLMD { 30 : namespace ves { 31 : 32 : //+PLUMEDOC VES_OPTIMIZER OPT_DUMMY 33 : /* 34 : Dummy optimizer for debugging. 35 : 36 : This is dummy optimizer that can be used for debugging. It will not update the 37 : coefficients but can be used to monitor the gradient and Hessian for a given 38 : VES bias. 39 : 40 : \par Examples 41 : 42 : In the following input we use the OPT_DUMMY to monitor the gradient and 43 : Hessian for a given VES bias every 1 iteration. 44 : \plumedfile 45 : phi: TORSION ATOMS=5,7,9,15 46 : 47 : bf1: BF_FOURIER ORDER=5 MINIMUM=-pi MAXIMUM=pi 48 : 49 : VES_LINEAR_EXPANSION ... 50 : ARG=phi 51 : BASIS_FUNCTIONS=bf1 52 : LABEL=ves1 53 : TEMP=300.0 54 : GRID_BINS=100 55 : ... VES_LINEAR_EXPANSION 56 : 57 : OPT_DUMMY ... 58 : BIAS=ves1 59 : STRIDE=1000 60 : LABEL=o1 61 : MONITOR_HESSIAN 62 : GRADIENT_FILE=gradient.data 63 : GRADIENT_OUTPUT=1 64 : GRADIENT_FMT=%12.6f 65 : HESSIAN_FILE=hessian.data 66 : HESSIAN_OUTPUT=1 67 : HESSIAN_FMT=%12.6f 68 : ... OPT_DUMMY 69 : \endplumedfile 70 : 71 : */ 72 : //+ENDPLUMEDOC 73 : 74 : 75 : 76 : class Opt_Dummy : public Optimizer { 77 : 78 : public: 79 : static void registerKeywords(Keywords&); 80 : explicit Opt_Dummy(const ActionOptions&); 81 : void coeffsUpdate(const unsigned int c_id = 0) override; 82 : }; 83 : 84 : 85 : PLUMED_REGISTER_ACTION(Opt_Dummy,"OPT_DUMMY") 86 : 87 : 88 3 : void Opt_Dummy::registerKeywords(Keywords& keys) { 89 3 : Optimizer::registerKeywords(keys); 90 : // 91 3 : Optimizer::useMultipleWalkersKeywords(keys); 92 3 : Optimizer::useHessianKeywords(keys); 93 3 : Optimizer::useMonitorAverageGradientKeywords(keys); 94 6 : keys.addFlag("MONITOR_HESSIAN",false,"also monitor the Hessian"); 95 3 : } 96 : 97 : 98 1 : Opt_Dummy::Opt_Dummy(const ActionOptions&ao): 99 1 : PLUMED_VES_OPTIMIZER_INIT(ao) 100 : { 101 1 : log.printf(" fake optimizer that does not update coefficients\n"); 102 1 : log.printf(" can be used to monitor gradient and Hessian for debugging purposes\n"); 103 1 : bool monitor_hessian = false; 104 1 : parseFlag("MONITOR_HESSIAN",monitor_hessian); 105 1 : if(monitor_hessian) { 106 1 : turnOnHessian(); 107 1 : log.printf(" the Hessian will also be monitored\n"); 108 : } 109 : else { 110 0 : turnOffHessian(); 111 : } 112 1 : turnOffCoeffsOutputFiles(); 113 1 : checkRead(); 114 1 : } 115 : 116 : 117 10 : void Opt_Dummy::coeffsUpdate(const unsigned int c_id) {} 118 : 119 : 120 : } 121 : }