From e7ac67d35a44991ee96ec05e6f4a0dcafeaef4de Mon Sep 17 00:00:00 2001 From: UWLab BOT Date: Tue, 27 Jan 2026 16:24:38 -0800 Subject: [PATCH] Prepares pre-merge --- .../manipulation/reset_states/mdp/events.py | 3 +-- .../reset_states/mdp/terminations.py | 11 +------- .../manipulation/reset_states/mdp/utils.py | 27 +++++++++++++++++-- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/source/uwlab_tasks/uwlab_tasks/manager_based/manipulation/reset_states/mdp/events.py b/source/uwlab_tasks/uwlab_tasks/manager_based/manipulation/reset_states/mdp/events.py index ed754d1..edeeb79 100644 --- a/source/uwlab_tasks/uwlab_tasks/manager_based/manipulation/reset_states/mdp/events.py +++ b/source/uwlab_tasks/uwlab_tasks/manager_based/manipulation/reset_states/mdp/events.py @@ -1017,8 +1017,7 @@ def __init__(self, cfg: EventTermCfg, env: ManagerBasedEnv): # Load all datasets self.datasets = [] num_states = [] - rank = int(os.getenv("RANK", "0")) - download_dir = os.path.join(tempfile.gettempdir(), f"rank_{rank}") + download_dir = utils.get_temp_dir() for dataset_file in dataset_files: # Handle both local files and URLs local_file_path = retrieve_file_path(dataset_file, download_dir=download_dir) diff --git a/source/uwlab_tasks/uwlab_tasks/manager_based/manipulation/reset_states/mdp/terminations.py b/source/uwlab_tasks/uwlab_tasks/manager_based/manipulation/reset_states/mdp/terminations.py index 23f1188..1ee8ce2 100644 --- a/source/uwlab_tasks/uwlab_tasks/manager_based/manipulation/reset_states/mdp/terminations.py +++ b/source/uwlab_tasks/uwlab_tasks/manager_based/manipulation/reset_states/mdp/terminations.py @@ -373,9 +373,6 @@ def __init__(self, cfg: TerminationTermCfg, env: ManagerBasedEnv): self.insertive_object_cfg = cfg.params.get("insertive_object_cfg") self.insertive_object = env.scene[self.insertive_object_cfg.name] - insertive_metadata = utils.read_metadata_from_usd_directory(self.insertive_object.cfg.spawn.usd_path) - - self.insertive_target_mesh_path = insertive_metadata.get("target_mesh_path") self.enable_visualization = cfg.params.get("enable_visualization", False) # Initialize OBB computation cache and compute OBBs once @@ -397,13 +394,7 @@ def __init__(self, cfg: TerminationTermCfg, env: ManagerBasedEnv): def _compute_object_obbs(self): """Compute OBB for insertive object and convert to body frame.""" # Get prim path (use env 0 as template) - insertive_base_path = self.insertive_object.cfg.prim_path.replace(".*", "0", 1) - - # Determine object prim path - use specific mesh if provided - if self.insertive_target_mesh_path is not None: - insertive_prim_path = f"{insertive_base_path}/{self.insertive_target_mesh_path}" - else: - insertive_prim_path = insertive_base_path + insertive_prim_path = self.insertive_object.cfg.prim_path.replace(".*", "0", 1) # Compute OBB in world frame using Isaac Sim's built-in functions insertive_centroid_world, insertive_axes_world, insertive_half_extents = bounds_utils.compute_obb( diff --git a/source/uwlab_tasks/uwlab_tasks/manager_based/manipulation/reset_states/mdp/utils.py b/source/uwlab_tasks/uwlab_tasks/manager_based/manipulation/reset_states/mdp/utils.py index 7d33275..83e784e 100644 --- a/source/uwlab_tasks/uwlab_tasks/manager_based/manipulation/reset_states/mdp/utils.py +++ b/source/uwlab_tasks/uwlab_tasks/manager_based/manipulation/reset_states/mdp/utils.py @@ -304,6 +304,30 @@ def temporary_seed(seed: int, restore_numpy: bool = True, restore_python: bool = random.setstate(py_state) +def get_temp_dir(rank: int | None = None) -> str: + """Get a user/job-specific temporary directory under /tmp/uwlab/. + + Creates a directory structure that avoids conflicts between users and jobs: + /tmp/uwlab/{uid}/{job_id}/{rank}/ + + Args: + rank: Process rank (defaults to RANK env var or 0) + + Returns: + Path to the temporary directory (created if it doesn't exist) + """ + if rank is None: + rank = int(os.getenv("RANK", "0")) + + uid = os.getuid() + job_id = os.getenv("SLURM_JOB_ID") or os.getenv("PBS_JOBID") or "local" + + download_dir = os.path.join("/tmp", "uwlab", str(uid), str(job_id), f"rank_{rank}") + os.makedirs(download_dir, mode=0o700, exist_ok=True) + + return download_dir + + def read_metadata_from_usd_directory(usd_path: str) -> dict: """Read metadata from metadata.yaml in the same directory as the USD file.""" # Get the directory containing the USD file @@ -311,8 +335,7 @@ def read_metadata_from_usd_directory(usd_path: str) -> dict: # Look for metadata.yaml in the same directory metadata_path = os.path.join(usd_dir, "metadata.yaml") - rank = int(os.getenv("RANK", "0")) - download_dir = os.path.join(tempfile.gettempdir(), f"rank_{rank}") + download_dir = get_temp_dir() with open(retrieve_file_path(metadata_path, download_dir=download_dir)) as f: metadata_file = yaml.safe_load(f)