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 : ## 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 : 45 : ```plumed 46 : phi: TORSION ATOMS=5,7,9,15 47 : 48 : bf1: BF_FOURIER ORDER=5 MINIMUM=-pi MAXIMUM=pi 49 : 50 : VES_LINEAR_EXPANSION ... 51 : ARG=phi 52 : BASIS_FUNCTIONS=bf1 53 : LABEL=ves1 54 : TEMP=300.0 55 : GRID_BINS=100 56 : ... VES_LINEAR_EXPANSION 57 : 58 : OPT_DUMMY ... 59 : BIAS=ves1 60 : STRIDE=1000 61 : LABEL=o1 62 : MONITOR_HESSIAN 63 : GRADIENT_FILE=gradient.data 64 : GRADIENT_OUTPUT=1 65 : GRADIENT_FMT=%12.6f 66 : HESSIAN_FILE=hessian.data 67 : HESSIAN_OUTPUT=1 68 : HESSIAN_FMT=%12.6f 69 : ... OPT_DUMMY 70 : ``` 71 : 72 : */ 73 : //+ENDPLUMEDOC 74 : 75 : 76 : 77 : class Opt_Dummy : public Optimizer { 78 : 79 : public: 80 : static void registerKeywords(Keywords&); 81 : explicit Opt_Dummy(const ActionOptions&); 82 : void coeffsUpdate(const unsigned int c_id = 0) override; 83 : }; 84 : 85 : 86 : PLUMED_REGISTER_ACTION(Opt_Dummy,"OPT_DUMMY") 87 : 88 : 89 3 : void Opt_Dummy::registerKeywords(Keywords& keys) { 90 3 : Optimizer::registerKeywords(keys); 91 : // 92 3 : Optimizer::useMultipleWalkersKeywords(keys); 93 3 : Optimizer::useHessianKeywords(keys); 94 3 : Optimizer::useMonitorAverageGradientKeywords(keys); 95 3 : keys.addFlag("MONITOR_HESSIAN",false,"also monitor the Hessian"); 96 3 : } 97 : 98 : 99 1 : Opt_Dummy::Opt_Dummy(const ActionOptions&ao): 100 1 : PLUMED_VES_OPTIMIZER_INIT(ao) { 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 : } else { 109 0 : turnOffHessian(); 110 : } 111 1 : turnOffCoeffsOutputFiles(); 112 1 : checkRead(); 113 1 : } 114 : 115 : 116 10 : void Opt_Dummy::coeffsUpdate(const unsigned int c_id) {} 117 : 118 : 119 : } 120 : }