Make AWH bias sharing more flexible
[alexxy/gromacs.git] / src / gromacs / applied_forces / awh / tests / awh_setup.cpp
index edb67b5e51bc72a8d62e9ede3b71739c2c576b5a..48191710152e5b6388359492038f7bf20c288150 100644 (file)
@@ -103,12 +103,14 @@ std::vector<char> awhDimParamSerialized(AwhCoordinateProviderType inputCoordinat
  * \param[in] beta Value for 1/(kB*T).
  * \param[in] inputErrorScaling Factor for initial error scaling.
  * \param[in] dimensionParameterBuffers Buffers containing the dimension parameters.
+ * \param[in] shareGroup share group for, potentially, sharing the bias between simulations
  * \param[in] inputUserData If there is a user provided PMF estimate.
  */
 static std::vector<char> awhBiasParamSerialized(AwhHistogramGrowthType            eawhgrowth,
                                                 double                            beta,
                                                 double                            inputErrorScaling,
                                                 ArrayRef<const std::vector<char>> dimensionParameterBuffers,
+                                                int                               shareGroup,
                                                 bool                              inputUserData)
 {
     int                    ndim                 = dimensionParameterBuffers.size();
@@ -118,7 +120,6 @@ static std::vector<char> awhBiasParamSerialized(AwhHistogramGrowthType
     AwhHistogramGrowthType eGrowth              = eawhgrowth;
     bool                   bUserData            = inputUserData;
     double                 errorInitial         = inputErrorScaling / beta;
-    int                    shareGroup           = 0;
     bool                   equilibrateHistogram = false;
 
     gmx::InMemorySerializer serializer;
@@ -151,6 +152,7 @@ static std::vector<char> awhBiasParamSerialized(AwhHistogramGrowthType
  * \param[in] inputErrorScaling Factor for initial error scaling.
  * \param[in] inputSeed Seed value to use.
  * \param[in] dimensionParameterBuffers Buffers containing the dimension parameters.
+ * \param[in] biasShareGroup share group for, potentially, sharing the bias over simulations
  * \param[in] inputUserData If there is a user provided PMF estimate.
  */
 static std::vector<char> awhParamSerialized(AwhHistogramGrowthType            eawhgrowth,
@@ -159,6 +161,7 @@ static std::vector<char> awhParamSerialized(AwhHistogramGrowthType            ea
                                             double                            inputErrorScaling,
                                             int64_t                           inputSeed,
                                             ArrayRef<const std::vector<char>> dimensionParameterBuffers,
+                                            int                               biasShareGroup,
                                             bool                              inputUserData)
 {
     int              numBias                    = 1;
@@ -180,7 +183,7 @@ static std::vector<char> awhParamSerialized(AwhHistogramGrowthType            ea
 
     auto awhParamBuffer = serializer.finishAndGetBuffer();
     auto awhBiasBuffer  = awhBiasParamSerialized(
-            eawhgrowth, beta, inputErrorScaling, dimensionParameterBuffers, inputUserData);
+            eawhgrowth, beta, inputErrorScaling, dimensionParameterBuffers, biasShareGroup, inputUserData);
 
     awhParamBuffer.insert(awhParamBuffer.end(), awhBiasBuffer.begin(), awhBiasBuffer.end());
 
@@ -200,14 +203,15 @@ AwhTestParameters getAwhTestParameters(AwhHistogramGrowthType            eawhgro
                                        double                            beta,
                                        bool                              useAwhFep,
                                        double                            inputErrorScaling,
-                                       int                               numFepLambdaStates)
+                                       int                               numFepLambdaStates,
+                                       int                               biasShareGroup)
 {
     double  convFactor = 1;
     double  k          = 1000;
     int64_t seed       = 93471803;
 
     auto awhParamBuffer = awhParamSerialized(
-            eawhgrowth, eawhpotential, beta, inputErrorScaling, seed, dimensionParameterBuffers, inputUserData);
+            eawhgrowth, eawhpotential, beta, inputErrorScaling, seed, dimensionParameterBuffers, biasShareGroup, inputUserData);
     gmx::InMemoryDeserializer deserializer(awhParamBuffer, false);
     AwhTestParameters         params(&deserializer);
 
@@ -249,7 +253,7 @@ TEST(SerializationTest, CanSerializeBiasParams)
     auto awhDimBuffer   = awhDimParamSerialized();
     auto awhDimArrayRef = gmx::arrayRefFromArray(&awhDimBuffer, 1);
     auto awhBiasBuffer  = awhBiasParamSerialized(
-            AwhHistogramGrowthType::ExponentialLinear, 0.4, 0.5, awhDimArrayRef, false);
+            AwhHistogramGrowthType::ExponentialLinear, 0.4, 0.5, awhDimArrayRef, 0, false);
     gmx::InMemoryDeserializer deserializer(awhBiasBuffer, false);
     AwhBiasParams             awhBiasParams(&deserializer);
     EXPECT_EQ(awhBiasParams.ndim(), 1);
@@ -281,8 +285,14 @@ TEST(SerializationTest, CanSerializeAwhParams)
 {
     auto awhDimBuffer   = awhDimParamSerialized();
     auto awhDimArrayRef = gmx::arrayRefFromArray(&awhDimBuffer, 1);
-    auto awhParamBuffer = awhParamSerialized(
-            AwhHistogramGrowthType::ExponentialLinear, AwhPotentialType::Convolved, 0.4, 0.5, 1337, awhDimArrayRef, false);
+    auto awhParamBuffer = awhParamSerialized(AwhHistogramGrowthType::ExponentialLinear,
+                                             AwhPotentialType::Convolved,
+                                             0.4,
+                                             0.5,
+                                             1337,
+                                             awhDimArrayRef,
+                                             0,
+                                             false);
     gmx::InMemoryDeserializer deserializer(awhParamBuffer, false);
     AwhParams                 awhParams(&deserializer);
     EXPECT_EQ(awhParams.numBias(), 1);