Skip to content

Commit

Permalink
Implemented state/serialize/hash in SciUnit base class
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerkin committed Oct 26, 2017
1 parent 5e675c2 commit d16cc84
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions sciunit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from copy import copy
from datetime import datetime
from fnmatch import fnmatchcase
import json
try:
from io import StringIO
except ImportError:
Expand Down Expand Up @@ -42,6 +43,7 @@ def log(*args, **kwargs):
output = f.getvalue()
display(HTML(output))


class SciUnit(object):
"""Abstract base class for models, tests, and scores."""
def __init__(self):
Expand All @@ -61,6 +63,22 @@ def __getstate__(self):
del state[key]
return state

@property
def state(self):
return self.__getstate__()

@property
def hash(self):
"""A unique numeric identifier of the current model state"""
state = self.state
result = dict_hash(state)
return result

def serialize(self):
state = self.state
result = json.dumps(state)
return result


class Model(SciUnit):
"""Abstract base class for sciunit models."""
Expand Down Expand Up @@ -119,11 +137,6 @@ def check_params(self):
"""
pass

@property
def state(self):
"""A unique numeric identifier of the current model state"""
return dict_hash(self.__dict__)

def __str__(self):
return '%s' % self.name

Expand Down

0 comments on commit d16cc84

Please sign in to comment.