From 6b59061bd9f15a730cb87922b723692e1b122017 Mon Sep 17 00:00:00 2001 From: Bo Marchman Date: Wed, 28 Feb 2018 17:27:56 -0500 Subject: [PATCH] Make model hashes deterministic Strings included in the hash are randomly salted, breaking caching between different runs. See https://docs.python.org/3/reference/datamodel.html#object.__hash__ --- pyphi/models/actual_causation.py | 2 +- pyphi/models/cuts.py | 2 +- pyphi/models/mechanism.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyphi/models/actual_causation.py b/pyphi/models/actual_causation.py index a590c8876..2ac3faad7 100644 --- a/pyphi/models/actual_causation.py +++ b/pyphi/models/actual_causation.py @@ -177,7 +177,7 @@ def __eq__(self, other): return self.ria == other.ria def __hash__(self): - return hash(('CausalLink', self._ria)) + return hash(self._ria) def __bool__(self): """An |CausalLink| is ``True`` if |alpha > 0|.""" diff --git a/pyphi/models/cuts.py b/pyphi/models/cuts.py index af1f5cd8c..e3e8dec74 100644 --- a/pyphi/models/cuts.py +++ b/pyphi/models/cuts.py @@ -122,7 +122,7 @@ def __eq__(self, other): return self.indices == other.indices def __hash__(self): - return hash(('NullCut', self.indices)) + return hash(self.indices) class Cut(namedtuple('Cut', ['from_nodes', 'to_nodes']), _CutBase): diff --git a/pyphi/models/mechanism.py b/pyphi/models/mechanism.py index cf2a644a0..7efe1d195 100644 --- a/pyphi/models/mechanism.py +++ b/pyphi/models/mechanism.py @@ -235,7 +235,7 @@ def __eq__(self, other): return self.ria == other.ria def __hash__(self): - return hash(('MICE', self._ria)) + return hash(self._ria) def to_json(self): return {'ria': self.ria}