Skip to content

Commit 0706d7d

Browse files
committed
chore: lint-clean mjlab/maniskill tasks + make tooling paths portable
Pre-push cleanup of the unpushed mjlab/maniskill/robotwin work so it passes the pre-commit gate and contains no machine-specific paths: - ruff: add docstrings to mjlab task/MDP public API, replace diagnostic print() with loguru log, fix ambiguous unicode, Optional->| None, lambda ->def, warnings.warn stacklevel, np.sqrt default-arg, unused imports. Full pre-commit (ruff + ruff-format + hooks) now passes on all changed files. - tooling: remove 53 hardcoded /home/ghr absolute paths from tools/**; repo root via rootutils, reports dir via ROBOVERSE_REPORTS_DIR (rel fallback), external mjlab via MJLAB_DIR (~/projects/mjlab fallback), conda via $(conda info --base). No library code referenced local paths. Smoke: all edited modules import; mjlab v2 backward-compat 12/12 mujoco + 12/12 newton. No runtime behavior changed.
1 parent e124e60 commit 0706d7d

60 files changed

Lines changed: 370 additions & 172 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

roboverse_pack/robots/mjlab_go1_cfg.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"RL_calf_joint",
2727
)
2828

29+
2930
# Default stance — MUST match mjlab INIT_STATE (go1_constants.py): thigh=0.9,
3031
# calf=-1.8, and asymmetric hips R_hip=+0.1 / L_hip=-0.1. The earlier symmetric
3132
# hip=0.0 here (Newton path never got the r7 ±0.1 fix) gave an unstable stance
@@ -80,5 +81,9 @@ class MjlabGo1Cfg(RobotCfg):
8081
default_joint_positions: dict[str, float] = _GO1_DEFAULTS
8182
default_joint_velocities: dict[str, float] = {n: 0.0 for n in _GO1_JOINTS}
8283
control_type: dict[str, Literal["position", "effort"]] = {n: "position" for n in _GO1_JOINTS}
83-
default_pos: tuple[float, float, float] = (0.0, 0.0, 0.278) # mjlab INIT_STATE height (was 0.42 -> 14cm drop -> collapse)
84+
default_pos: tuple[float, float, float] = (
85+
0.0,
86+
0.0,
87+
0.278,
88+
) # mjlab INIT_STATE height (was 0.42 -> 14cm drop -> collapse)
8489
default_rot: tuple[float, float, float, float] = (1.0, 0.0, 0.0, 0.0)

roboverse_pack/tasks/_passthrough_index.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
def list_passthrough_envs() -> dict[str, list[str]]:
3232
"""Return {benchmark_name: [env_id, ...]} for all currently-registered passthrough envs."""
3333
import gymnasium as gym
34+
3435
out: dict[str, list[str]] = {}
3536
for prefix in PASSTHROUGH_PREFIXES:
3637
bench = prefix.rstrip("/")
@@ -44,9 +45,9 @@ def print_passthrough_summary() -> None:
4445
"""Print a one-line summary per benchmark."""
4546
envs = list_passthrough_envs()
4647
total = sum(len(v) for v in envs.values())
47-
print(f"# RoboVerse Passthrough {total} envs across {len(envs)} benchmarks")
48-
print()
48+
print(f"# RoboVerse Passthrough - {total} envs across {len(envs)} benchmarks") # noqa: T201
49+
print() # noqa: T201
4950
for bench, ids in envs.items():
50-
print(f" {bench:25s} {len(ids):4d} example: {ids[0]}")
51-
print()
52-
print(f" TOTAL {total}")
51+
print(f" {bench:25s} {len(ids):4d} example: {ids[0]}") # noqa: T201
52+
print() # noqa: T201
53+
print(f" TOTAL {total}") # noqa: T201

roboverse_pack/tasks/dm_control/_passthrough.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
from typing import Any
66

77
import numpy as np
8+
from loguru import logger as log
89

910

1011
def register_dm_control_passthrough(prefix: str = "DMControl/") -> list[str]:
1112
"""Register all dm_control suite tasks under DMControl/<domain>-<task> namespace."""
1213
from gymnasium.envs.registration import register, registry
14+
1315
import dm_control.suite as suite
16+
1417
registered = []
1518
failed = []
1619
for domain, task in suite.ALL_TASKS:
@@ -28,7 +31,7 @@ def register_dm_control_passthrough(prefix: str = "DMControl/") -> list[str]:
2831
except Exception as e:
2932
failed.append((ns_id, str(e)))
3033
if failed:
31-
print(f"[dm_control_passthrough] {len(failed)} failures")
34+
log.warning(f"[dm_control_passthrough] {len(failed)} failures")
3235
return registered
3336

3437

@@ -43,18 +46,24 @@ class _DMControlGymWrapper(gym.Env):
4346
def __init__(self, domain: str, task: str, **kwargs):
4447
super().__init__()
4548
from dm_control import suite
46-
self._env = suite.load(domain_name=domain, task_name=task,
47-
visualize_reward=kwargs.pop("visualize_reward", False))
49+
50+
self._env = suite.load(
51+
domain_name=domain, task_name=task, visualize_reward=kwargs.pop("visualize_reward", False)
52+
)
4853
spec = self._env.observation_spec()
4954
# Concatenate all obs into a single Box (typical practice for dm_control)
5055
import gymnasium as gym
56+
5157
self._obs_keys = sorted(spec.keys())
5258
obs_dim = sum(int(np.prod(spec[k].shape)) for k in self._obs_keys)
5359
self.observation_space = gym.spaces.Box(low=-np.inf, high=np.inf, shape=(obs_dim,), dtype=np.float32)
5460
a_spec = self._env.action_spec()
55-
self.action_space = gym.spaces.Box(low=a_spec.minimum.astype(np.float32),
56-
high=a_spec.maximum.astype(np.float32),
57-
shape=a_spec.shape, dtype=np.float32)
61+
self.action_space = gym.spaces.Box(
62+
low=a_spec.minimum.astype(np.float32),
63+
high=a_spec.maximum.astype(np.float32),
64+
shape=a_spec.shape,
65+
dtype=np.float32,
66+
)
5867
self._domain = domain
5968
self._task = task
6069

@@ -63,7 +72,6 @@ def _flatten_obs(self, obs):
6372

6473
def reset(self, *, seed=None, options=None):
6574
if seed is not None:
66-
import dm_control.rl.control as ctl # for seeding if available
6775
self._env.task.random.seed(seed)
6876
ts = self._env.reset()
6977
return self._flatten_obs(ts.observation), {}

roboverse_pack/tasks/gym_robotics/_passthrough.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66

77

88
def _ensure_imported():
9-
import gymnasium_robotics
109
import gymnasium as gym
10+
import gymnasium_robotics
11+
1112
gym.register_envs(gymnasium_robotics)
1213
return gymnasium_robotics
1314

1415

1516
def register_gymnasium_robotics_passthrough(prefix: str = "GymRobotics/") -> list[str]:
1617
"""Register all gymnasium-robotics envs under GymRobotics/<env_id> namespace."""
1718
from gymnasium.envs.registration import register, registry
19+
1820
_ensure_imported()
1921
import gymnasium as gym
2022

@@ -47,4 +49,5 @@ def register_gymnasium_robotics_passthrough(prefix: str = "GymRobotics/") -> lis
4749
def _make_env(base_id: str, **kwargs: Any):
4850
_ensure_imported()
4951
import gymnasium as gym
52+
5053
return gym.make(base_id, **kwargs)

roboverse_pack/tasks/maniskill/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def _auto_import_submodules() -> None:
3232
# Auto-register ManiSkill 3 envs under ManiSkill3/<env_id> namespace
3333
try:
3434
from roboverse_pack.tasks.maniskill._passthrough_v3 import register_maniskill3_passthrough
35+
3536
register_maniskill3_passthrough()
3637
except Exception:
3738
pass # mani_skill not installed or registration issue

roboverse_pack/tasks/maniskill/_dense_rl.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DenseRLResetMixin:
2626
"""Randomized resets (cube on table + goal pose) without demo data."""
2727

2828
cube_z: float = 0.02
29-
xy_range: float = 0.1 # object xy ~ uniform[-xy_range, xy_range]
29+
xy_range: float = 0.1 # object xy ~ uniform[-xy_range, xy_range]
3030
goal_z_range: tuple[float, float] = (0.02, 0.02) # on-table by default
3131
reset_seed: int = 0
3232
# Dense RL tasks generate their own randomized initial states, so they
@@ -35,7 +35,7 @@ class DenseRLResetMixin:
3535

3636
# Skip ManiskillBaseTask's demo-trajectory download — call BaseTaskEnv
3737
# directly so the dense task doesn't depend on replay data.
38-
def __init__(self, scenario, device=None) -> None: # noqa: D401
38+
def __init__(self, scenario, device=None) -> None:
3939
BaseTaskEnv.__init__(self, scenario, device)
4040

4141
def _get_initial_states(self) -> list[dict]:
@@ -55,13 +55,15 @@ def u(lo: float, hi: float) -> float:
5555
objs: dict[str, dict] = {}
5656
for name in obj_names:
5757
if "goal" in name.lower():
58-
pos = torch.tensor([u(-self.xy_range, self.xy_range),
59-
u(-self.xy_range, self.xy_range),
60-
u(*self.goal_z_range)], dtype=torch.float32)
58+
pos = torch.tensor(
59+
[u(-self.xy_range, self.xy_range), u(-self.xy_range, self.xy_range), u(*self.goal_z_range)],
60+
dtype=torch.float32,
61+
)
6162
else: # cube / manipuland — rest on the table surface
62-
pos = torch.tensor([u(-self.xy_range, self.xy_range),
63-
u(-self.xy_range, self.xy_range),
64-
self.cube_z], dtype=torch.float32)
63+
pos = torch.tensor(
64+
[u(-self.xy_range, self.xy_range), u(-self.xy_range, self.xy_range), self.cube_z],
65+
dtype=torch.float32,
66+
)
6567
objs[name] = {"pos": pos, "rot": torch.tensor([1.0, 0.0, 0.0, 0.0])}
6668
states.append({
6769
"objects": objs,

roboverse_pack/tasks/maniskill/_passthrough_v3.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717
from __future__ import annotations
1818

1919
import os
20-
from typing import Any, Optional
20+
from typing import Any
21+
22+
from loguru import logger as log
2123

2224

2325
def _ensure_maniskill_imported():
2426
"""Triggers ManiSkill envs registration."""
2527
os.environ.setdefault("MUJOCO_GL", "egl")
2628
import mani_skill
27-
import mani_skill.envs # noqa: F401 — triggers env registry side-effect
29+
import mani_skill.envs
30+
2831
return mani_skill
2932

3033

@@ -35,6 +38,7 @@ def list_maniskill3_envs() -> list[str]:
3538
"""Return all ManiSkill 3-registered env IDs (after triggering import)."""
3639
_ensure_maniskill_imported()
3740
import gymnasium as gym
41+
3842
ids = []
3943
for spec in gym.envs.registry.values():
4044
ep = spec.entry_point
@@ -50,17 +54,19 @@ def register_maniskill3_passthrough(prefix: str = "ManiSkill3/") -> list[str]:
5054
Idempotent. Returns list of registered (or already-present) env ids.
5155
"""
5256
from gymnasium.envs.registration import register, registry
53-
_ensure_maniskill_imported()
54-
import gymnasium as gym
5557

58+
_ensure_maniskill_imported()
5659
# Find all mani_skill envs. ManiSkill 3 wraps with functools.partial(mani_skill.envs.make).
5760
# Identify by the additional_wrappers field which references mani_skill, or by name pattern.
5861
import functools
62+
63+
import gymnasium as gym
64+
5965
base_ids = []
6066
for spec in list(gym.envs.registry.values()):
6167
is_ms = False
6268
# 1. Check additional_wrappers (ManiSkill always wraps with MSTimeLimit)
63-
for w in (getattr(spec, "additional_wrappers", None) or []):
69+
for w in getattr(spec, "additional_wrappers", None) or []:
6470
if "mani_skill" in str(getattr(w, "entry_point", "")):
6571
is_ms = True
6672
break
@@ -82,21 +88,22 @@ def register_maniskill3_passthrough(prefix: str = "ManiSkill3/") -> list[str]:
8288
try:
8389
register(
8490
id=ns_id,
85-
entry_point=f"roboverse_pack.tasks.maniskill._passthrough_v3:_make_maniskill_env",
91+
entry_point="roboverse_pack.tasks.maniskill._passthrough_v3:_make_maniskill_env",
8692
kwargs={"base_id": base_id},
8793
)
8894
registered.append(ns_id)
8995
except Exception as e:
9096
failed.append((ns_id, str(e)))
9197
if failed:
92-
print(f"[maniskill_passthrough] {len(failed)} registration failures:")
98+
log.warning(f"[maniskill_passthrough] {len(failed)} registration failures:")
9399
for ns_id, err in failed[:3]:
94-
print(f" {ns_id}: {err}")
100+
log.warning(f" {ns_id}: {err}")
95101
return registered
96102

97103

98104
def _make_maniskill_env(base_id: str, **kwargs: Any):
99105
"""Factory for namespaced env — just gym.make the underlying base id."""
100106
_ensure_maniskill_imported()
101107
import gymnasium as gym
108+
102109
return gym.make(base_id, **kwargs)

roboverse_pack/tasks/maniskill/lift_peg_upright.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def reset(self, states=None, env_ids=None):
6363
# ``compute_dense_reward`` (mani_skill/envs/tasks/tabletop/lift_peg_upright.py).
6464
# ---------------------------------------------------------------------------
6565

66-
_LP_HALF_LENGTH = 0.12 # peg_length / 2 — target z when upright
67-
_LP_HALF_WIDTH = 0.025 # peg_widdth / 2 — rest height lying flat
66+
_LP_HALF_LENGTH = 0.12 # peg_length / 2 — target z when upright
67+
_LP_HALF_WIDTH = 0.025 # peg_widdth / 2 — rest height lying flat
6868
_LP_TCP_OFFSET = (0.0, 0.0, 0.10312)
6969
_LP_UPRIGHT_COS = float(torch.cos(torch.tensor(0.08))) # ManiSkill 0.08 rad tol
7070

roboverse_pack/tasks/maniskill/pick_cube_v1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class PickCubeV1DenseTask(DenseRLResetMixin, PickCubeV1Task):
129129

130130
def _reward(self, env_states):
131131
import torch
132+
132133
from metasim.utils.math import quat_rotate
133134

134135
rs = env_states.robots["franka"]

roboverse_pack/tasks/maniskill/pick_single_ycb.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ class PickSingleYcbDenseTask(DenseRLResetMixin, _PickSingleYcbBaseTask):
6666
goal_z_range = (0.10, 0.30)
6767
scenario = ScenarioCfg(
6868
objects=[
69-
PrimitiveCubeCfg(name="obj", size=(0.04, 0.04, 0.04), mass=0.02,
70-
physics=PhysicStateType.RIGIDBODY, color=(1.0, 0.5, 0.0)),
71-
PrimitiveSphereCfg(name="goal_site", radius=0.025,
72-
physics=PhysicStateType.XFORM, color=(0.0, 1.0, 0.0)),
69+
PrimitiveCubeCfg(
70+
name="obj", size=(0.04, 0.04, 0.04), mass=0.02, physics=PhysicStateType.RIGIDBODY, color=(1.0, 0.5, 0.0)
71+
),
72+
PrimitiveSphereCfg(name="goal_site", radius=0.025, physics=PhysicStateType.XFORM, color=(0.0, 1.0, 0.0)),
7373
],
7474
robots=["franka"],
7575
)

0 commit comments

Comments
 (0)