OPT_AVERAGED_SGD

This is part of the ves module | |

It is only available if you configure PLUMED with ./configure –enable-modules=ves . Furthermore, this feature is still being developed so take care when using it and report any problems on the mailing list. |

Averaged stochastic gradient decent with fixed step size.

- Algorithm

This optimizer updates the coefficients according to the averaged stochastic gradient decent algorithm described in ref [5]. This algorithm considers two sets of coefficients, the so-called instantaneous coefficients that are updated according to the recursion formula given by

\[ \boldsymbol{\alpha}^{(n+1)} = \boldsymbol{\alpha}^{(n)} - \mu \left[ \nabla \Omega(\bar{\boldsymbol{\alpha}}^{(n)}) + \mathbf{H}(\bar{\boldsymbol{\alpha}}^{(n)}) [\boldsymbol{\alpha}^{(n)}-\bar{\boldsymbol{\alpha}}^{(n)}] \right], \]

where \(\mu\) is a fixed step size and the gradient \( \nabla\Omega(\bar{\boldsymbol{\alpha}}^{(n)})\) and the Hessian \(\mathbf{H}(\bar{\boldsymbol{\alpha}}^{(n)})\) depend on the averaged coefficients defined as

\[ \bar{\boldsymbol{\alpha}}^{(n)} = \frac{1}{n+1} \sum_{k=0}^{n} \boldsymbol{\alpha}^{(k)}. \]

This means that the bias acting on the system depends on the averaged coefficients \(\bar{\boldsymbol{\alpha}}^{(n)}\) which leads to a smooth convergence of the bias and the estimated free energy surface. Furthermore, this allows for a rather short sampling time for each iteration, for classical MD simulations typical sampling times are on the order of few ps (around 1000-4000 MD steps).

Currently it is only supported to employ the diagonal part of the Hessian which is generally sufficient. Support for employing the full Hessian will be added later on.

The VES bias that is to be optimized should be specified using the BIAS keyword. The fixed step size \(\mu\) is given using the STEPSIZE keyword. The frequency of updating the coefficients is given using the STRIDE keyword where the value is given in the number of MD steps. For example, if the MD time step is 0.02 ps and STRIDE=2000 will the coefficients be updated every 4 ps. The coefficients will be outputted to the file given by the COEFFS_FILE keyword. How often the coefficients are written to this file is controlled by the COEFFS_OUTPUT keyword.

If the VES bias employs a dynamic target distribution that needs to be iteratively updated (e.g. TD_WELLTEMPERED) [103], you will need to specify the stride for updating the target distribution by using the TARGETDIST_STRIDE keyword where the stride is given in terms coefficient iterations. For example if the MD time step is 0.02 ps and STRIDE=1000, such that the coefficients are updated every 2 ps, will TARGETDIST_STRIDE=500 mean that the target distribution will be updated every 1000 ps.

The output of the free energy surfaces and biases is controlled by the FES_OUTPUT and the BIAS_OUTPUT keywords. It is also possible to output one-dimensional projections of the free energy surfaces by using the FES_PROJ_OUTPUT keyword but for that to work you will need to select for which argument to do the projections by using the numbered PROJ_ARG keyword in the VES bias that is optimized. You can also output dynamic target distributions by using the TARGETDIST_OUTPUT and TARGETDIST_PROJ_OUTPUT keywords.

It is possible to start the optimization from some initial set of coefficients that have been previously obtained by using the INITIAL_COEFFS keyword.

When restarting simulations it should be sufficient to put the RESTART action in the beginning of the input files (or some MD codes the PLUMED should automatically detect if it is a restart run) and keep the same input as before The restarting of the optimization should be automatic as the optimizer will then read in the coefficients from the file given in COEFFS_FILE. For dynamic target distribution the code will also read in the final target distribution from the previous run (which is always outputted even if the TARGETDIST_OUTPUT keyword is not used).

This optimizer supports the usage of multiple walkers where different copies of the system share the same bias potential (i.e. coefficients) and cooperatively sample the averages needed for the gradient and Hessian. This can significantly help with convergence in difficult cases. It is of course best to start the different copies from different positions in CV space. To activate this option you just need to add the MULTIPLE_WALKERS flag. Note that this is only supported if the MD code support running multiple replicas connected via MPI.

The optimizer supports the usage of a so-called mask file that can be used to employ different step sizes for different coefficients and/or deactivate the optimization of certain coefficients (by putting values of 0.0). The mask file is read in by using the MASK_FILE keyword and should be in the same format as the coefficient file. It is possible to generate a template mask file by using the OUTPUT_MASK_FILE keyword.

- Description of components

The names of the components in this action can be customized by the user in the actions input file. However, in addition to the components that can be customized the following quantities will always be output

Quantity | Keyword | Description |

gradrms | MONITOR_INSTANTANEOUS_GRADIENT | the root mean square value of the coefficient gradient. For multiple biases this component is labeled using the number of the bias as gradrms-#. |

gradmax | MONITOR_INSTANTANEOUS_GRADIENT | the largest absolute value of the coefficient gradient. For multiple biases this component is labeled using the number of the bias as gradmax-#. |

avergradrms | MONITOR_AVERAGE_GRADIENT | the root mean square value of the averaged coefficient gradient. For multiple biases this component is labeled using the number of the bias as gradrms-#. |

avergradmax | MONITOR_AVERAGE_GRADIENT | the largest absolute value of the averaged coefficient gradient. For multiple biases this component is labeled using the number of the bias as gradmax-#. |

- Compulsory keywords

BIAS | the label of the VES bias to be optimized |

STRIDE | the frequency of updating the coefficients given in the number of MD steps. |

COEFFS_FILE | ( default=coeffs.data ) the name of output file for the coefficients |

COEFFS_OUTPUT | ( default=100 ) how often the coefficients should be written to file. This parameter is given as the number of iterations. |

STEPSIZE | the step size used for the optimization |

- Options

MONITOR_INSTANTANEOUS_GRADIENT | ( default=off ) if quantities related to the instantaneous gradient should be outputted. |

MULTIPLE_WALKERS | ( default=off ) if optimization is to be performed using multiple walkers connected via MPI |

START_OPTIMIZATION_AFRESH | ( default=off ) if the iterations should be started afresh when a restart has been triggered by the RESTART keyword or the MD code. |

MONITOR_AVERAGE_GRADIENT | ( default=off ) if the averaged gradient should be monitored and quantities related to it should be outputted. |

COEFFS_FMT | specify format for coefficient file(s) (useful for decrease the number of digits in regtests) |

COEFFS_SET_ID_PREFIX | suffix to add to the filename given in FILE to identify the bias, should only be given if a single filename is given in FILE when optimizing multiple biases. |

INITIAL_COEFFS | the name(s) of file(s) with the initial coefficients |

TARGETDIST_AVERAGES_FILE | the name of output file for the target distribution averages. By default it is targetdist-averages.data. |

TARGETDIST_AVERAGES_OUTPUT | how often the target distribution averages should be written out to file. Note that the value is given in terms of coefficient iterations. If no value is given are the averages only written at the beginning of the optimization |

BIAS_OUTPUT | how often the bias(es) should be written out to file. Note that the value is given in terms of coefficient iterations. |

FES_OUTPUT | how often the FES(s) should be written out to file. Note that the value is given in terms of coefficient iterations. |

FES_PROJ_OUTPUT | how often the projections of the FES(s) should be written out to file. Note that the value is given in terms of coefficient iterations. |

RESTART | allows per-action setting of restart (YES/NO/AUTO) |

UPDATE_FROM | Only update this action from this time |

UPDATE_UNTIL | Only update this action until this time |

MASK_FILE | read in a mask file which allows one to employ different step sizes for different coefficients and/or deactivate the optimization of certain coefficients (by putting values of 0.0). One can write out the resulting mask by using the OUTPUT_MASK_FILE keyword. |

OUTPUT_MASK_FILE | Name of the file to write out the mask resulting from using the MASK_FILE keyword. Can also be used to generate a template mask file. |

MONITOR_AVERAGES_GRADIENT_EXP_DECAY | use an exponentially decaying averaging with a given time constant when monitoring the averaged gradient |

TARGETDIST_STRIDE | stride for updating a target distribution that is iteratively updated during the optimization. Note that the value is given in terms of coefficient iterations. |

TARGETDIST_OUTPUT | how often the dynamic target distribution(s) should be written out to file. Note that the value is given in terms of coefficient iterations. |

TARGETDIST_PROJ_OUTPUT | how often the projections of the dynamic target distribution(s) should be written out to file. Note that the value is given in terms of coefficient iterations. |

EXP_DECAYING_AVER | calculate the averaged coefficients using exponentially decaying averaging using the decaying constant given here in the number of iterations |

- Examples

In the following input we employ an averaged stochastic gradient decent with a fixed step size of 1.0 and update the coefficient every 1000 MD steps (e.g. every 2 ps if the MD time step is 0.02 ps). The coefficient are outputted to the coefficients.data every 50 iterations while the FES and bias is outputted to files every 500 iterations (e.g. every 1000 ps).

phi: TORSION ATOMS=5,7,9,15 bf1: BF_FOURIER ORDER=5 MINIMUM=-pi MAXIMUM=pi VES_LINEAR_EXPANSION ... ARG=phi BASIS_FUNCTIONS=bf1 LABEL=ves1 TEMP=300.0 GRID_BINS=100 ... VES_LINEAR_EXPANSION OPT_AVERAGED_SGD ... BIAS=ves1 STRIDE=1000 LABEL=o1 STEPSIZE=1.0 COEFFS_FILE=coefficients.data COEFFS_OUTPUT=50 FES_OUTPUT=500 BIAS_OUTPUT=500 ... OPT_AVERAGED_SGD

In the following example we employ a well-tempered target distribution that is updated every 500 iterations (e.g. every 1000 ps). The target distribution is also output to a file every 2000 iterations (the TARGETDIST_OUTPUT keyword). Here we also employ MULTIPLE_WALKERS flag to enable the usage of multiple walkers.

#SETTINGS NREPLICAS=2 phi: TORSION ATOMS=5,7,9,15 psi: TORSION ATOMS=7,9,15,17 bf1: BF_FOURIER ORDER=5 MINIMUM=-pi MAXIMUM=pi bf2: BF_FOURIER ORDER=4 MINIMUM=-pi MAXIMUM=pi td1: TD_WELLTEMPERED BIASFACTOR=10 VES_LINEAR_EXPANSION ... ARG=phi,psi BASIS_FUNCTIONS=bf1,bf2 LABEL=ves1 TEMP=300.0 GRID_BINS=100,100 TARGET_DISTRIBUTION=td1 PROJ_ARG1=phi PROJ_ARG2=psi ... VES_LINEAR_EXPANSION OPT_AVERAGED_SGD ... BIAS=ves1 STRIDE=1000 LABEL=o1 STEPSIZE=1.0 MULTIPLE_WALKERS COEFFS_FILE=coefficients.data COEFFS_OUTPUT=50 FES_OUTPUT=500 FES_PROJ_OUTPUT=500 BIAS_OUTPUT=500 TARGETDIST_STRIDE=500 TARGETDIST_OUTPUT=2000 ... OPT_AVERAGED_SGD