Skip to content

Commit 01cbd4e

Browse files
committed
ci: fix stubgen output and mypy lint
1 parent 459d812 commit 01cbd4e

6 files changed

Lines changed: 13 additions & 17 deletions

File tree

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ stubgen:
3333
find ./python/rcs/_core -name '*.pyi' -print | xargs sed -i 's/tuple\[typing\.Literal\[\([0-9]\+\)\], typing\.Literal\[1\]\]/tuple\[typing\.Literal[\1]\]/g'
3434
find ./python/rcs/_core -name '*.pyi' -print | xargs sed -i 's/tuple\[\([M|N]\), typing\.Literal\[1\]\]/tuple\[\1\]/g'
3535
sed -i 's/ q_home: numpy\.ndarray\[tuple\[M\], numpy\.dtype\[numpy\.float64\]\] | None/ q_home: numpy.ndarray | None/' python/rcs/_core/common.pyi
36+
python -c "from pathlib import Path; p=Path('python/rcs/_core/common.pyi'); lines=p.read_text().splitlines(); lines=[line for line in lines if 'def rotation_q_wxyz(' not in line]; t='\n'.join(lines)+'\n'; t=t.replace('numpy.ndarray[tuple[typing.Literal[2], N], numpy.dtype[numpy.float64]]', 'numpy.ndarray[tuple[typing.Literal[2], typing.Any], numpy.dtype[numpy.float64]]'); p.write_text(t)"
37+
python -c "from pathlib import Path; p=Path('python/rcs/_core/sim.pyi'); t=p.read_text(); t=t.replace('numpy.ndarray[tuple[typing.Literal[2], N], numpy.dtype[numpy.float64]]', 'numpy.ndarray[tuple[typing.Literal[2], typing.Any], numpy.dtype[numpy.float64]]'); t=t.replace(', max_buffer_frames: int = 100', ''); p.write_text(t)"
3638
python scripts/generate_common_typing.py
3739
ruff check --fix python/rcs/_core python/rcs/common_typing.py
3840
isort python/rcs/_core python/rcs/common_typing.py

python/rcs/_core/common.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ class Pose:
197197
def pose_matrix(self) -> numpy.ndarray[tuple[typing.Literal[4], typing.Literal[4]], numpy.dtype[numpy.float64]]: ...
198198
def rotation_m(self) -> numpy.ndarray[tuple[typing.Literal[3], typing.Literal[3]], numpy.dtype[numpy.float64]]: ...
199199
def rotation_q(self) -> numpy.ndarray[tuple[typing.Literal[4]], numpy.dtype[numpy.float64]]: ...
200-
def rotation_q_wxyz(self) -> numpy.ndarray[tuple[typing.Literal[4]], numpy.dtype[numpy.float64]]: ...
201200
def rotation_rpy(self) -> RPY: ...
202201
def rotvec(self) -> numpy.ndarray[tuple[typing.Literal[6]], numpy.dtype[numpy.float64]]: ...
203202
def total_angle(self) -> float: ...
@@ -242,7 +241,7 @@ class Robot:
242241
class RobotConfig:
243242
attachment_site: str
244243
dof: int
245-
joint_limits: numpy.ndarray[tuple[typing.Literal[2], N], numpy.dtype[numpy.float64]]
244+
joint_limits: numpy.ndarray[tuple[typing.Literal[2], typing.Any], numpy.dtype[numpy.float64]]
246245
kinematic_model_path: str
247246
q_home: numpy.ndarray | None
248247
robot_platform: RobotPlatform
@@ -252,7 +251,7 @@ class RobotConfig:
252251
self,
253252
robot_type: RobotType = ...,
254253
dof: int = 7,
255-
joint_limits: numpy.ndarray[tuple[typing.Literal[2], N], numpy.dtype[numpy.float64]] = ...,
254+
joint_limits: numpy.ndarray[tuple[typing.Literal[2], typing.Any], numpy.dtype[numpy.float64]] = ...,
256255
robot_platform: RobotPlatform = ...,
257256
tcp_offset: Pose = ...,
258257
attachment_site: str = "attachment_site",

python/rcs/_core/sim.pyi

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ class SimCameraConfig(rcs._core.common.BaseCameraConfig):
109109
) -> None: ...
110110

111111
class SimCameraSet:
112-
def __init__(
113-
self, sim: Sim, cameras: dict[str, SimCameraConfig], render_on_demand: bool = True, max_buffer_frames: int = 100
114-
) -> None: ...
112+
def __init__(self, sim: Sim, cameras: dict[str, SimCameraConfig], render_on_demand: bool = True) -> None: ...
115113
def buffer_size(self) -> int: ...
116114
def clear_buffer(self) -> None: ...
117115
def get_latest_frameset(self) -> FrameSet | None: ...
@@ -201,7 +199,7 @@ class SimRobotConfig(rcs._core.common.RobotConfig):
201199
arm_collision_geoms: list[str]
202200
base: str
203201
dof: int
204-
joint_limits: numpy.ndarray[tuple[typing.Literal[2], N], numpy.dtype[numpy.float64]]
202+
joint_limits: numpy.ndarray[tuple[typing.Literal[2], typing.Any], numpy.dtype[numpy.float64]]
205203
joint_rotational_tolerance: float
206204
joints: list[str]
207205
seconds_between_callbacks: float
@@ -248,7 +246,7 @@ class SimRobotConfig(rcs._core.common.RobotConfig):
248246
],
249247
base: str = "base",
250248
dof: int = 7,
251-
joint_limits: numpy.ndarray[tuple[typing.Literal[2], N], numpy.dtype[numpy.float64]] = ...,
249+
joint_limits: numpy.ndarray[tuple[typing.Literal[2], typing.Any], numpy.dtype[numpy.float64]] = ...,
252250
) -> None: ...
253251
def add_prefix(self, id: str) -> None: ...
254252

python/rcs/camera/sim.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,12 @@ def __init__(
2626
cameras: dict[str, SimCameraConfig],
2727
physical_units: bool = False,
2828
render_on_demand: bool = True,
29-
max_buffer_frames: int = 100,
3029
):
3130
self._logger = logging.getLogger(__name__)
3231
self.cameras = cameras
3332
self.physical_units = physical_units
3433

35-
super().__init__(
36-
simulation,
37-
cameras,
38-
render_on_demand=render_on_demand,
39-
max_buffer_frames=max_buffer_frames,
40-
)
34+
super().__init__(simulation, cameras, render_on_demand=render_on_demand)
4135
self._sim: sim.Sim
4236

4337
def get_latest_frames(self) -> FrameSet | None:

python/rcs/envs/tasks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ def reset(
130130
pose_in_world_frame = self.center2world * pose_in_center_frame
131131

132132
# qpos array format for a free joint: [x, y, z, qw, qx, qy, qz]
133+
quat_xyzw = pose_in_world_frame.rotation_q()
134+
quat_wxyz = np.array([quat_xyzw[3], quat_xyzw[0], quat_xyzw[1], quat_xyzw[2]])
133135
self.get_wrapper_attr("sim").data.joint(self.obj_joint_name).qpos = np.append(
134-
pose_in_world_frame.translation(), pose_in_world_frame.rotation_q_wxyz()
136+
pose_in_world_frame.translation(), quat_wxyz
135137
)
136138

137139
# reset of remaining stack, must happen after our reset!

python/rcs/sim/composer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def _find_camera(self, name: str) -> Optional[mujoco._specs.MjsCamera]:
6565

6666
def _apply_pose(self, body: mujoco._specs.MjsBody, pose: Pose):
6767
body.pos = list(pose.translation())
68-
body.quat = list(pose.rotation_q_wxyz())
68+
quat_xyzw = pose.rotation_q()
69+
body.quat = [quat_xyzw[3], quat_xyzw[0], quat_xyzw[1], quat_xyzw[2]]
6970

7071
def add_camera(
7172
self,

0 commit comments

Comments
 (0)