Skip to content

Commit e51d8d6

Browse files
use bharats suggestion
1 parent 7a8cdce commit e51d8d6

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/simsopt/_core/graph_optimizable.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,6 @@ def __init__(self,
519519
objects are identified automatically. Doesn't work with
520520
funcs_in with a property decorator
521521
"""
522-
self.hash = None
523522
self._dofs = DOFs(x0,
524523
names,
525524
np.logical_not(fixed) if fixed is not None else None,
@@ -531,6 +530,8 @@ def __init__(self,
531530
# instances of same class
532531
self._id = ImmutableId(next(self.__class__._ids))
533532
self.name = self.__class__.__name__ + str(self._id.id)
533+
hash_str = hashlib.sha256(self.name.encode('utf-8')).hexdigest()
534+
self.hash = int(hash_str, 16) % 10**32 # 32 digit int as hash
534535
self._children = set() # This gets populated when the object is passed
535536
# as argument to another Optimizable object
536537
self.return_fns = WeakKeyDefaultDict(list) # Store return fn's required by each child
@@ -583,9 +584,6 @@ def __str__(self):
583584
return self.name
584585

585586
def __hash__(self) -> int:
586-
if self.hash is None:
587-
hash_str = hashlib.sha256(self.name.encode('utf-8')).hexdigest()
588-
self.hash = int(hash_str, 16) % 10**32 # 32 digit int as hash
589587
return self.hash
590588

591589
def __eq__(self, other: Optimizable) -> bool:

0 commit comments

Comments
 (0)