Skip to content

Commit

Permalink
Make model hashes deterministic
Browse files Browse the repository at this point in the history
Strings included in the hash are randomly salted, breaking
caching between different runs. See
https://docs.python.org/3/reference/datamodel.html#object.__hash__
  • Loading branch information
rlmv committed Feb 28, 2018
1 parent 1ade50d commit 6b59061
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyphi/models/actual_causation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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|."""
Expand Down
2 changes: 1 addition & 1 deletion pyphi/models/cuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pyphi/models/mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 6b59061

Please sign in to comment.