diff --git a/regtest/ves/rt-opt-averaged-sgd-monitor-aver-grad-exp-decay/gradient.data.reference b/regtest/ves/rt-opt-averaged-sgd-monitor-aver-grad-exp-decay/gradient.data.reference
new file mode 100644
index 0000000000000000000000000000000000000000..d5ed9cd37331d40602624e78691f857cca92156f
--- /dev/null
+++ b/regtest/ves/rt-opt-averaged-sgd-monitor-aver-grad-exp-decay/gradient.data.reference
@@ -0,0 +1,210 @@
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 2.000000
+#! SET iteration  1
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1    -0.219197    -0.219197       1
+       2     0.970366     0.970366       2
+       3     0.884094     0.884094       3
+       4     0.421298     0.421298       4
+       5     0.590820     0.590820       5
+       6    -0.748809    -0.748809       6
+       7    -0.576392    -0.576392       7
+       8    -0.715341    -0.715341       8
+       9    -0.786645    -0.786645       9
+      10     0.381816     0.381816      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 4.000000
+#! SET iteration  2
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1    -0.171909    -0.171909       1
+       2     0.983056     0.983056       2
+       3     0.933040     0.933040       3
+       4     0.336620     0.336620       4
+       5     0.487305     0.487305       5
+       6    -0.852350    -0.852350       6
+       7    -0.744842    -0.744842       7
+       8    -0.617866    -0.617866       8
+       9    -0.723239    -0.723239       9
+      10     0.615618     0.615618      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 6.000000
+#! SET iteration  3
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1    -0.262470    -0.262470       1
+       2     0.961283     0.961283       2
+       3     0.849109     0.849109       3
+       4     0.501037     0.501037       4
+       5     0.694439     0.694439       5
+       6    -0.674944    -0.674944       6
+       7    -0.456423    -0.456423       7
+       8    -0.826382    -0.826382       8
+       9    -0.887287    -0.887287       9
+      10     0.215323     0.215323      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 8.000000
+#! SET iteration  4
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1     0.123003     0.123003       1
+       2     0.981481     0.981481       2
+       3     0.927275     0.927275       3
+       4    -0.236129    -0.236129       4
+       5    -0.330226    -0.330226       5
+       6    -0.841343    -0.841343       6
+       7    -0.729958    -0.729958       7
+       8     0.397544     0.397544       8
+       9     0.432305     0.432305       9
+      10     0.601249     0.601249      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 10.000000
+#! SET iteration  5
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1     0.106083     0.106083       1
+       2     0.847417     0.847417       2
+       3     0.444583     0.444583       3
+       4    -0.113081    -0.113081       4
+       5     0.025722     0.025722       5
+       6     0.065616     0.065616       6
+       7     0.508739     0.508739       7
+       8    -0.276699    -0.276699       8
+       9    -0.535793    -0.535793       9
+      10    -0.746272    -0.746272      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 12.000000
+#! SET iteration  6
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1    -0.031729    -0.031729       1
+       2     0.975444     0.975444       2
+       3     0.903083     0.903083       3
+       4     0.058812     0.058812       4
+       5     0.076991     0.076991       5
+       6    -0.786761    -0.786761       6
+       7    -0.632645    -0.632645       7
+       8    -0.082751    -0.082751       8
+       9    -0.073628    -0.073628       9
+      10     0.448875     0.448875      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 14.000000
+#! SET iteration  7
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1     0.414884     0.414884       1
+       2     0.568606     0.568606       2
+       3    -0.002782    -0.002782       3
+       4     0.008683     0.008683       4
+       5     0.680270     0.680270       5
+       6    -0.225628    -0.225628       6
+       7    -0.813633    -0.813633       7
+       8    -0.581092    -0.581092       8
+       9     0.007020     0.007020       9
+      10     0.690771     0.690771      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 16.000000
+#! SET iteration  8
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1     0.373431     0.373431       1
+       2     0.754956     0.754956       2
+       3     0.254162     0.254162       3
+       4    -0.332883    -0.332883       4
+       5     0.134220     0.134220       5
+       6     0.026195     0.026195       6
+       7    -0.171032    -0.171032       7
+       8    -0.626246    -0.626246       8
+       9    -0.715567    -0.715567       9
+      10     0.635181     0.635181      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 18.000000
+#! SET iteration  9
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1    -0.042175    -0.042175       1
+       2     0.988022     0.988022       2
+       3     0.952455     0.952455       3
+       4     0.081463     0.081463       4
+       5     0.115095     0.115095       5
+       6    -0.894387    -0.894387       6
+       7    -0.815592    -0.815592       7
+       8    -0.140542    -0.140542       8
+       9    -0.155619    -0.155619       9
+      10     0.718466     0.718466      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 20.000000
+#! SET iteration  10
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1    -0.204695    -0.204695       1
+       2     0.965411     0.965411       2
+       3     0.866280     0.866280       3
+       4     0.384645     0.384645       4
+       5     0.518469     0.518469       5
+       6    -0.715888    -0.715888       6
+       7    -0.534349    -0.534349       7
+       8    -0.591051    -0.591051       8
+       9    -0.595595    -0.595595       9
+      10     0.345874     0.345874      10
+#!-------------------
+
+
diff --git a/regtest/ves/rt-opt-averaged-sgd-monitor-aver-grad-exp-decay/plumed.dat b/regtest/ves/rt-opt-averaged-sgd-monitor-aver-grad-exp-decay/plumed.dat
index 6f21242f9f709b22d3bfc11b921bd31ac16956d2..e97db4661016ebf126fb5d55ad92457367c37e1c 100644
--- a/regtest/ves/rt-opt-averaged-sgd-monitor-aver-grad-exp-decay/plumed.dat
+++ b/regtest/ves/rt-opt-averaged-sgd-monitor-aver-grad-exp-decay/plumed.dat
@@ -27,6 +27,9 @@ OPT_AVERAGED_SGD ...
   FES_OUTPUT=10
   BIAS_OUTPUT=10
   TARGETDIST_AVERAGES_FMT=%12.6f
+  GRADIENT_FILE=gradient.data
+  GRADIENT_OUTPUT=1
+  GRADIENT_FMT=%12.6f
   COMBINED_GRADIENT_FILE=combined_gradient.data
   COMBINED_GRADIENT_OUTPUT=1
   COMBINED_GRADIENT_FMT=%12.6f
diff --git a/regtest/ves/rt-opt-averaged-sgd-monitor-aver-grad/gradient.data.reference b/regtest/ves/rt-opt-averaged-sgd-monitor-aver-grad/gradient.data.reference
new file mode 100644
index 0000000000000000000000000000000000000000..48996868f0db0186cdff3040621b6e3d0e025e8f
--- /dev/null
+++ b/regtest/ves/rt-opt-averaged-sgd-monitor-aver-grad/gradient.data.reference
@@ -0,0 +1,210 @@
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 2.000000
+#! SET iteration  1
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1    -0.219197    -0.219197       1
+       2     0.970366     0.970366       2
+       3     0.884094     0.884094       3
+       4     0.421298     0.421298       4
+       5     0.590820     0.590820       5
+       6    -0.748809    -0.748809       6
+       7    -0.576392    -0.576392       7
+       8    -0.715341    -0.715341       8
+       9    -0.786645    -0.786645       9
+      10     0.381816     0.381816      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 4.000000
+#! SET iteration  2
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1    -0.171909    -0.195553       1
+       2     0.983056     0.976711       2
+       3     0.933040     0.908567       3
+       4     0.336620     0.378959       4
+       5     0.487305     0.539063       5
+       6    -0.852350    -0.800580       6
+       7    -0.744842    -0.660617       7
+       8    -0.617866    -0.666603       8
+       9    -0.723239    -0.754942       9
+      10     0.615618     0.498717      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 6.000000
+#! SET iteration  3
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1    -0.262470    -0.217859       1
+       2     0.961283     0.971569       2
+       3     0.849109     0.888748       3
+       4     0.501037     0.419652       4
+       5     0.694439     0.590855       5
+       6    -0.674944    -0.758701       6
+       7    -0.456423    -0.592552       7
+       8    -0.826382    -0.719863       8
+       9    -0.887287    -0.799057       9
+      10     0.215323     0.404252      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 8.000000
+#! SET iteration  4
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1     0.123003    -0.132643       1
+       2     0.981481     0.974047       2
+       3     0.927275     0.898380       3
+       4    -0.236129     0.255707       4
+       5    -0.330226     0.360584       5
+       6    -0.841343    -0.779362       6
+       7    -0.729958    -0.626904       7
+       8     0.397544    -0.440511       8
+       9     0.432305    -0.491216       9
+      10     0.601249     0.453501      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 10.000000
+#! SET iteration  5
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1     0.106083    -0.084898       1
+       2     0.847417     0.948721       2
+       3     0.444583     0.807620       3
+       4    -0.113081     0.181949       4
+       5     0.025722     0.293612       5
+       6     0.065616    -0.610366       6
+       7     0.508739    -0.399775       7
+       8    -0.276699    -0.407749       8
+       9    -0.535793    -0.500132       9
+      10    -0.746272     0.213547      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 12.000000
+#! SET iteration  6
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1    -0.031729    -0.076037       1
+       2     0.975444     0.953175       2
+       3     0.903083     0.823531       3
+       4     0.058812     0.161426       4
+       5     0.076991     0.257509       5
+       6    -0.786761    -0.639765       6
+       7    -0.632645    -0.438587       7
+       8    -0.082751    -0.353583       8
+       9    -0.073628    -0.429048       9
+      10     0.448875     0.252768      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 14.000000
+#! SET iteration  7
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1     0.414884    -0.005905       1
+       2     0.568606     0.898236       2
+       3    -0.002782     0.705486       3
+       4     0.008683     0.139606       4
+       5     0.680270     0.317903       5
+       6    -0.225628    -0.580603       6
+       7    -0.813633    -0.492165       7
+       8    -0.581092    -0.386084       8
+       9     0.007020    -0.366752       9
+      10     0.690771     0.315340      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 16.000000
+#! SET iteration  8
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1     0.373431     0.041512       1
+       2     0.754956     0.880326       2
+       3     0.254162     0.649070       3
+       4    -0.332883     0.080545       4
+       5     0.134220     0.294943       5
+       6     0.026195    -0.504753       6
+       7    -0.171032    -0.452023       7
+       8    -0.626246    -0.416104       8
+       9    -0.715567    -0.410354       9
+      10     0.635181     0.355320      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 18.000000
+#! SET iteration  9
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1    -0.042175     0.032213       1
+       2     0.988022     0.892292       2
+       3     0.952455     0.682780       3
+       4     0.081463     0.080647       4
+       5     0.115095     0.274959       5
+       6    -0.894387    -0.548046       6
+       7    -0.815592    -0.492420       7
+       8    -0.140542    -0.385486       8
+       9    -0.155619    -0.382050       9
+      10     0.718466     0.395670      10
+#!-------------------
+
+
+#! FIELDS idx_phi ves1.gradient ves1.aver_gradient index
+#! SET time 20.000000
+#! SET iteration  10
+#! SET type LinearBasisSet
+#! SET ndimensions  1
+#! SET ncoeffs_total  11
+#! SET shape_phi  11
+       0     0.000000     0.000000       0
+       1    -0.204695     0.008523       1
+       2     0.965411     0.899604       2
+       3     0.866280     0.701130       3
+       4     0.384645     0.111047       4
+       5     0.518469     0.299310       5
+       6    -0.715888    -0.564830       6
+       7    -0.534349    -0.496613       7
+       8    -0.591051    -0.406043       8
+       9    -0.595595    -0.403405       9
+      10     0.345874     0.390690      10
+#!-------------------
+
+
diff --git a/regtest/ves/rt-opt-averaged-sgd-monitor-aver-grad/plumed.dat b/regtest/ves/rt-opt-averaged-sgd-monitor-aver-grad/plumed.dat
index 71a804221f69fa4bfe898ffbc814bfa51352eeea..f65539b1cfc3c54bfc7c534c04e3b9171908684f 100644
--- a/regtest/ves/rt-opt-averaged-sgd-monitor-aver-grad/plumed.dat
+++ b/regtest/ves/rt-opt-averaged-sgd-monitor-aver-grad/plumed.dat
@@ -27,6 +27,9 @@ OPT_AVERAGED_SGD ...
   FES_OUTPUT=10
   BIAS_OUTPUT=10
   TARGETDIST_AVERAGES_FMT=%12.6f
+  GRADIENT_FILE=gradient.data
+  GRADIENT_OUTPUT=1
+  GRADIENT_FMT=%12.6f
   COMBINED_GRADIENT_FILE=combined_gradient.data
   COMBINED_GRADIENT_OUTPUT=1
   COMBINED_GRADIENT_FMT=%12.6f