Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,38 @@ 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
usd_dir = os.path.dirname(usd_path)

# 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)

Expand Down
Loading