Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
execution_env.py - small fix (#160)
Browse files Browse the repository at this point in the history
Function ```log_execution_env_state``` copies a given configuration file to the logs directory to save all of the details of an experiment.  In some distributed a file copy may fail, so we wrap the copy of the configuration file with a try/except block.
  • Loading branch information
barrh authored and nzmora committed Feb 26, 2019
1 parent 42be146 commit 713fec8
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions distiller/apputils/execution_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@
logger = logging.getLogger("app_cfg")


def log_execution_env_state(config_filename=None, logdir=None, gitroot='.'):
def log_execution_env_state(config_path=None, logdir=None, gitroot='.'):
"""Log information about the execution environment.
It is recommeneded to log this information so it can be used for referencing
at a later time.
File 'config_path' will be copied to directory 'logdir'. A common use-case
is passing the path to a (compression) schedule YAML file. Storing a copy
of the schedule file, with the experiment logs, is useful in order to
reproduce experiments.
Args:
config_filename: filename to store in logdir, if logdir is set
config_path: path to config file, used only when logdir is set
logdir: log directory
git_root: the path to the .git root directory
"""
Expand Down Expand Up @@ -87,17 +89,21 @@ def log_git_state():
log_git_state()
logger.debug("Command line: %s", " ".join(sys.argv))

if (logdir is None) or (config_filename is None):
if (logdir is None) or (config_path is None):
return
# clone configuration files to output directory
configs_dest = os.path.join(logdir, 'configs')
with contextlib.suppress(FileExistsError):
os.makedirs(configs_dest)
if os.path.exists(os.path.join(configs_dest, config_filename)):
if os.path.exists(os.path.join(configs_dest,
os.path.basename(config_path))):
logger.debug('{} already exists in logdir'.format(
os.path.basename(config_filename) or config_filename))
os.path.basename(config_path) or config_path))
else:
shutil.copy(config_filename, configs_dest)
try:
shutil.copy(config_path, configs_dest)
except OSError as e:
logger.debug('Failed to copy of config file: {}'.format(str(e)))


def config_pylogger(log_cfg_file, experiment_name, output_dir='logs'):
Expand Down

0 comments on commit 713fec8

Please sign in to comment.