def test_construct_path(): assert construct_path(Path("/a"), Path("/b")) == Path("/a") assert construct_path(Path("/a"), Path("~/b")) == Path("/a") assert construct_path(Path("/a"), Path("b")) == Path("/a") assert construct_path(Path("~/a"), Path("~/b")) == Path("~/a").expanduser() assert construct_path(Path("~/a"), Path("/b")) == Path("~/a").expanduser() assert construct_path(Path("~/a"), Path("b")) == Path("~/a").expanduser() assert construct_path(Path("a"), Path("/b")) == Path("/b/a") assert construct_path(Path("a"), Path("~/b")) == Path("~/b/a").expanduser() assert construct_path(Path("a"), Path("b")) == Path("b/a").resolve()
def latest_run_dir(self) -> Optional[Path]: """Path to the log directory for the latest call to ``run()``. Returns ``None`` if ``run()`` has not been called. """ if self._run_id > 0: run_dir = Path(f"run_{self._run_id:03d}") return construct_path(run_dir, self.logdir) else: return None
def create_logdir(self, log_dir: Optional[Union[str, Path]]) -> Path: """Create logdir for the Trainer.""" # Create directory for logs. log_dir = Path(log_dir) if log_dir else None if not log_dir: # Initialize timestamp for identifying this SGD training execution. timestr = datetime.today().strftime("%Y-%m-%d_%H-%M-%S") log_dir = Path(f"sgd_{timestr}") log_dir = construct_path(log_dir, DEFAULT_RESULTS_DIR) log_dir.mkdir(parents=True, exist_ok=True) logger.info(f"Trainer logs will be logged in: {log_dir}") return log_dir
def latest_checkpoint_dir(self) -> Optional[Path]: """Path to the latest checkpoint directory.""" checkpoint_dir = Path("checkpoints") return construct_path(checkpoint_dir, self.run_dir)