Skip to content

Commit

Permalink
Merge pull request #71 from liyuan9988/cache-unique-id
Browse files Browse the repository at this point in the history
caching unique id
  • Loading branch information
nishiba authored Jul 25, 2019
2 parents 4cba855 + 136d2ff commit 89d6284
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion gokart/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self, *args, **kwargs):
self._add_configuration(kwargs, 'TaskOnKart')
# 'This parameter is dumped into "workspace_directory/log/task_log/" when this task finishes with success.'
self.task_log = dict()
self.task_unique_id = None
super(TaskOnKart, self).__init__(*args, **kwargs)
self._rerun_state = self.rerun

Expand Down Expand Up @@ -118,7 +119,7 @@ def make_model_target(self,
use_unique_id: bool = True):
"""
Make target for models which generate multiple files in saving, e.g. gensim.Word2Vec, Tensorflow, and so on.
:param relative_file_path: A file path to save.
:param save_function: A function to save a model. This takes a model object and a file path.
:param load_function: A function to load a model. This takes a file path and returns a model object.
Expand Down Expand Up @@ -178,6 +179,10 @@ def dump(self, obj, target: Union[None, str, TargetOnKart] = None) -> None:
self._get_output_target(target).dump(obj)

def make_unique_id(self):
self.task_unique_id = self.task_unique_id or self._make_hash_id()
return self.task_unique_id

def _make_hash_id(self):
def _to_str_params(task):
if isinstance(task, TaskOnKart):
return str(task.make_unique_id())
Expand Down

0 comments on commit 89d6284

Please sign in to comment.