Пример #1
0
def dump_experiment_code(src: pathlib.Path, dst: pathlib.Path) -> None:
    """
    Dumps your experiment code for Config API use cases.

    Args:
        src: source code path
        dst: destination code path
    """
    utcnow = get_utcnow_time()
    dst = dst.joinpath("code")
    dst = dst.joinpath(f"code-{utcnow}") if dst.exists() else dst
    os.makedirs(dst, exist_ok=True)
    dump_python_files(src, dst)
Пример #2
0
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": 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 = {
                "branch": git_branch,
                "local_commit": git_local_commit,
                "origin_commit": git_origin_commit,
            }
            result["git"] = _decode_dict(git)
        except (CalledProcessError, FileNotFoundError):
            pass

    result = _decode_dict(result)
    return result
Пример #3
0
 def _get_logdir(self, config: Dict) -> str:
     timestamp = get_utcnow_time()
     config_hash = get_short_hash(config)
     logdir = f"{timestamp}.{config_hash}"
     return logdir
Пример #4
0
 def _get_run_name(self) -> str:
     timestamp = get_utcnow_time()
     config_hash = get_short_hash(self._config)
     default_name = f"{timestamp}-{config_hash}"
     name = get_by_keys(self._config, "args", "name", default=default_name)
     return name
Пример #5
0
 def _get_run_name(self) -> str:
     timestamp = get_utcnow_time()
     config_hash = get_short_hash(self._config)
     default_name = f"{timestamp}-{config_hash}"
     name = self._config.args.name or default_name
     return name
Пример #6
0
def dump_base_experiment_code(src: pathlib.Path, dst: pathlib.Path):
    utcnow = get_utcnow_time()
    dst_ = dst.joinpath("code")
    dst = dst.joinpath(f"code-{utcnow}") if dst_.exists() else dst_
    os.makedirs(dst, exist_ok=True)
    dump_python_files(src, dst)