def _prepare_logger(self, logdir, mode): if logdir is not None: timestamp = utils.get_utcnow_time() logpath = f"{logdir}/" \ f"sampler.{mode}.{self._sampler_id}.{timestamp}" os.makedirs(logpath, exist_ok=True) self.logdir = logpath self.logger = tools.SummaryWriter(logpath) else: self.logdir = None self.logger = None
def get_environment_vars() -> Dict[str, Any]: """ Creates a dictionary with environment variables Returns: dict: environment variables """ result = { "python_version": sys.version, "conda_environment": os.environ.get("CONDA_DEFAULT_ENV", ""), "creation_time": utils.get_utcnow_time(), "sysname": platform.uname()[0], "nodename": platform.uname()[1], "release": platform.uname()[2], "version": platform.uname()[3], "architecture": platform.uname()[4], "user": os.environ.get("USER", ""), "path": os.environ.get("PWD", ""), } with open(os.devnull, "w") as devnull: try: git_branch = subprocess.check_output( "git rev-parse --abbrev-ref HEAD".split(), shell=True, stderr=devnull ).strip().decode("UTF-8") git_local_commit = subprocess.check_output( "git rev-parse HEAD".split(), shell=True, stderr=devnull ) git_origin_commit = subprocess.check_output( f"git rev-parse origin/{git_branch}".split(), shell=True, stderr=devnull ) git = dict( branch=git_branch, local_commit=git_local_commit, origin_commit=git_origin_commit ) result["git"] = _decode_dict(git) except (subprocess.CalledProcessError, FileNotFoundError): pass result = _decode_dict(result) return result
def _prepare_logger(self, logdir): timestamp = utils.get_utcnow_time() logpath = f"{logdir}/trainer.{timestamp}" os.makedirs(logpath, exist_ok=True) self.logger = SummaryWriter(logpath)