Skip to content

Commit

Permalink
smallab 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
octopuscabbage committed Dec 23, 2021
1 parent 74a0094 commit ee84b3b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def read(fname):

setup(
name="smallab",
version="2.0.0",
version="2.1.0",
url='https://github.com/octopuscabbage/smallab',
packages=find_packages(),
install_requires=required,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def load_most_recent(self, experiment:ExperimentBase, name, specification):
location = get_partial_save_directory(name, specification,experiment)
checkpoints = self._get_time_sorted_checkpoints(name, specification,experiment)
if checkpoints == []:
logging.getLogger("smallab.{id}.checkpoint".format(id=specification_id)).info("No checkpoints available")
logging.getLogger(experiment.get_logger_name()).info("No checkpoints available")
return
# checkpoints = reversed(checkpoints)
able_to_load_checkpoint = False
Expand All @@ -84,14 +84,14 @@ def load_most_recent(self, experiment:ExperimentBase, name, specification):
used_checkpoint = checkpoint
break
except:
logging.getLogger("smallab.{id}.checkpoint".format(id=specification_id)).warning(
logging.getLogger(experiment.get_logger_name()).warning(
"Unable to load checkpoint {chp}".format(chp=checkpoint), exc_info=True)
if not able_to_load_checkpoint:
logging.getLogger("smallab.{id}.checkpoint".format(id=specification_id)).warning(
logging.getLogger(experiment.get_logger_name()).warning(
"All checkpoints corrupt".format(id=specification_id))
return
else:
logging.getLogger("smallab.{id}.checkpoint".format(id=specification_id)).info(
logging.getLogger(experiment.get_logger_name()).info(
"Successfully loaded checkpoint {chp}".format(chp=used_checkpoint))
return partial_experiment

Expand Down Expand Up @@ -121,18 +121,20 @@ def _save_checkpoint(self, save_data, name, specification):
experiment_name = experiment.get_name(specification)
checkpoint_name = str(datetime.datetime.now())
try:
start_checkpoint_time = time.time()
location = get_partial_save_directory(name, specification,experiment)
os.makedirs(location, exist_ok=True)
# TODO make sure a checkpoint with this name doesn't already exist
with open(os.path.join(location, checkpoint_name + ".pkl"), "wb") as f:
dill.dump(save_data, f)
logging.getLogger("smallab.{id}.checkpoint".format(id=experiment_name)).info(
"Succesfully checkpointed {chp}".format(chp=checkpoint_name))
checkpointing_time = time.time() - start_checkpoint_time
logging.getLogger(experiment.get_logger_name()).info(
"Succesfully checkpointed {chp} in {dt}s".format(chp=checkpoint_name,dt=round(checkpointing_time,2)))
checkpoints = os.listdir(location)
if len(checkpoints) > self.rolled_backups:
checkpoints = self._get_time_sorted_checkpoints(name, specification,experiment)
os.remove(os.path.join(location, str(checkpoints[0]) + ".pkl"))
except:
logging.getLogger("smallab.{id}.checkpoint".format(id=experiment_name)).warning(
logging.getLogger(experiment.get_logger_name()).warning(
"Unsuccesful checkpoint {chp}".format(chp=checkpoint_name),
exc_info=True)
7 changes: 7 additions & 0 deletions smallab/name_helper/dict.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
import json

def dict2name(dictionary):
return '_'.join(['{0}-{1}'.format(k, v) for k, v in dictionary.items()])


def hash_dict(dictionary):
return str(hash(json.dumps(dictionary)))

0 comments on commit ee84b3b

Please sign in to comment.