From 61c7e19d0f9e20c50e3d5c56c46f74c088256f38 Mon Sep 17 00:00:00 2001
From: Bar <elhararb@gmail.com>
Date: Tue, 26 Feb 2019 17:19:02 +0200
Subject: [PATCH] execution_env.py - small fix (#160)

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.
---
 distiller/apputils/execution_env.py | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/distiller/apputils/execution_env.py b/distiller/apputils/execution_env.py
index 3663fd6..0c59745 100755
--- a/distiller/apputils/execution_env.py
+++ b/distiller/apputils/execution_env.py
@@ -41,14 +41,16 @@ except ImportError:
 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
     """
@@ -87,17 +89,21 @@ def log_execution_env_state(config_filename=None, logdir=None, gitroot='.'):
     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'):
-- 
GitLab