Fix Use deterministic hashing algorithm for restorable integrators.
@@ -38,6 +38,7 @@ this program. If not, see <http://www.gnu.org/licenses/>.
import numpy as np
import logging
import re
+import zlib
import simtk.unit
@@ -213,9 +214,18 @@ class RestorableIntegrator(mm.CustomIntegrator,PrettyPrintableIntegrator):
@staticmethod
def _compute_class_hash(integrator_class):
- """Return a numeric hash for the integrator class."""
- # We need to convert to float because some digits may be lost in the conversion
- return float(hash(integrator_class.__name__))
+ """Return a numeric hash for the integrator class.
+
+ The hash will become part of the Integrator serialization,
+ so it is important for it consistent across processes in case
+ the integrator is sent to a remote worker. The hash() built-in
+ function is seeded by the PYTHONHASHSEED environmental variable,
+ so we can't use it here.
+
+ We also need to convert to float because some digits may be
+ lost in the conversion.
+ """
+ return float(zlib.adler32(integrator_class.__name__.encode()))
class ThermostatedIntegrator(RestorableIntegrator):
