Files
UniversalTrain-ai/tasks/paths.py
T
chenlin d5e9004f6c
Checks / Layout, translation and Colab checks (push) Has been cancelled
Checks / Ruff (push) Has been cancelled
Checks / Framework tests (native backend, CPU) (push) Has been cancelled
Checks / Portable Rust controller (push) Has been cancelled
docs: add AI agent workflow guide and clean up residual single-robot references
2026-11-05 11:52:07 +08:00

62 lines
2.0 KiB
Python

"""Fixed paths inside the repository.
A module of its own so that "where the repository root is" is derived exactly
once. Scattered `Path(__file__).resolve().parents[N]` expressions go wrong when a
file moves, and **raise nothing** -- they simply point at a directory that does
not exist, and only blow up when something tries to read from it.
"""
from __future__ import annotations
from pathlib import Path
#: The repository root. This file lives in `tasks/`, hence one level up.
REPO_ROOT: Path = Path(__file__).resolve().parents[1]
#: The model asset root. One subdirectory per robot asset.
ASSETS_DIR: Path = REPO_ROOT / "assets"
#: The training log root directory name. Relative to the **current working
#: directory** rather than the repository root, matching mjlab's `--log-root`
#: semantics: training started elsewhere puts its logs there.
LOGS_DIRNAME = "logs"
#: Placeholder for the `<model>` segment when a task registers no assets, keeping
#: the directory depth constant so that globs like `logs/*/<task>/` always match.
NO_MODEL = "no_model"
def log_root_for(asset: Path | str | None) -> str:
"""Return `logs/<model>` using the stem of the selected model file.
The training entry point appends the task ID and timestamp. Keeping the
model as its own segment separates runs against different assets.
"""
model = Path(asset).stem if asset else NO_MODEL
return f"{LOGS_DIRNAME}/{model}"
#: Directory name for a task's kept exports, inside the task's own directory.
OUT_DIRNAME = "out"
def out_dir_for(task_id: str) -> Path:
"""Return the default export parent directory for a task.
Robot IDs map directly to `tasks/<robot_id>/out/`. Dots separate path
segments in custom task IDs. The export entry point adds a timestamp and
records the original checkpoint in the layout.
"""
return REPO_ROOT / "tasks" / Path(*task_id.split(".")) / OUT_DIRNAME
__all__ = [
"ASSETS_DIR",
"LOGS_DIRNAME",
"NO_MODEL",
"OUT_DIRNAME",
"REPO_ROOT",
"log_root_for",
"out_dir_for",
]