Skip to content
Open
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
2 changes: 1 addition & 1 deletion scripts/demos/pick_and_place.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def _get_dones(self) -> tuple[torch.Tensor, torch.Tensor]:
cube_to_target_x_dist = self.cube.data.root_pos_w[:, 0] - self.target_pos[:, 0] - self.scene.env_origins[:, 0]
cube_to_target_y_dist = self.cube.data.root_pos_w[:, 1] - self.target_pos[:, 1] - self.scene.env_origins[:, 1]
cube_to_target_z_dist = self.cube.data.root_pos_w[:, 2] - self.target_pos[:, 2] - self.scene.env_origins[:, 2]
cube_to_target_distance = torch.norm(
cube_to_target_distance = torch.linalg.norm(
torch.stack((cube_to_target_x_dist, cube_to_target_y_dist, cube_to_target_z_dist), dim=1), dim=1
)
self.target_reached = cube_to_target_distance < 0.3
Expand Down
2 changes: 1 addition & 1 deletion scripts/tutorials/03_envs/create_cube_base_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def main():
# step env
obs, _ = env.step(target_position)
# print mean squared position error between target and current position
error = torch.norm(obs["policy"] - target_position).mean().item()
error = torch.linalg.norm(obs["policy"] - target_position).mean().item()
print(f"[Step: {count:04d}]: Mean position error: {error:.4f}")
# update counter
count += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def command(self) -> torch.Tensor:

def _update_metrics(self):
# logs data
self.metrics["error_pos_2d"] = torch.norm(self.pos_command_w[:, :2] - self.robot.data.root_pos_w[:, :2], dim=1)
self.metrics["error_pos_2d"] = torch.linalg.norm(
self.pos_command_w[:, :2] - self.robot.data.root_pos_w[:, :2], dim=1
)
self.metrics["error_heading"] = torch.abs(wrap_to_pi(self.heading_command_w - self.robot.data.heading_w))

def _resample_command(self, env_ids: Sequence[int]):
Expand Down
4 changes: 2 additions & 2 deletions source/isaaclab/isaaclab/envs/mdp/commands/pose_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def _update_metrics(self):
self.robot.data.body_pos_w[:, self.body_idx],
self.robot.data.body_quat_w[:, self.body_idx],
)
self.metrics["position_error"] = torch.norm(pos_error, dim=-1)
self.metrics["orientation_error"] = torch.norm(rot_error, dim=-1)
self.metrics["position_error"] = torch.linalg.norm(pos_error, dim=-1)
self.metrics["orientation_error"] = torch.linalg.norm(rot_error, dim=-1)

def _resample_command(self, env_ids: Sequence[int]):
# sample new pose targets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def _update_metrics(self):
max_command_step = max_command_time / self._env.step_dt
# logs data
self.metrics["error_vel_xy"] += (
torch.norm(self.vel_command_b[:, :2] - self.robot.data.root_lin_vel_b[:, :2], dim=-1) / max_command_step
torch.linalg.norm(self.vel_command_b[:, :2] - self.robot.data.root_lin_vel_b[:, :2], dim=-1)
/ max_command_step
)
self.metrics["error_vel_yaw"] += (
torch.abs(self.vel_command_b[:, 2] - self.robot.data.root_ang_vel_b[:, 2]) / max_command_step
Expand Down
10 changes: 7 additions & 3 deletions source/isaaclab/isaaclab/envs/mdp/rewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def base_height_l2(
def body_lin_acc_l2(env: ManagerBasedRLEnv, asset_cfg: SceneEntityCfg = SceneEntityCfg("robot")) -> torch.Tensor:
"""Penalize the linear acceleration of bodies using L2-kernel."""
asset: Articulation = env.scene[asset_cfg.name]
return torch.sum(torch.norm(asset.data.body_lin_acc_w[:, asset_cfg.body_ids, :], dim=-1), dim=1)
return torch.sum(torch.linalg.norm(asset.data.body_lin_acc_w[:, asset_cfg.body_ids, :], dim=-1), dim=1)


"""
Expand Down Expand Up @@ -263,7 +263,9 @@ def undesired_contacts(env: ManagerBasedRLEnv, threshold: float, sensor_cfg: Sce
contact_sensor: ContactSensor = env.scene.sensors[sensor_cfg.name]
# check if contact force is above threshold
net_contact_forces = contact_sensor.data.net_forces_w_history
is_contact = torch.max(torch.norm(net_contact_forces[:, :, sensor_cfg.body_ids], dim=-1), dim=1)[0] > threshold
is_contact = (
torch.max(torch.linalg.norm(net_contact_forces[:, :, sensor_cfg.body_ids], dim=-1), dim=1)[0] > threshold
)
# sum over contacts for each environment
return torch.sum(is_contact, dim=1)

Expand All @@ -284,7 +286,9 @@ def contact_forces(env: ManagerBasedRLEnv, threshold: float, sensor_cfg: SceneEn
contact_sensor: ContactSensor = env.scene.sensors[sensor_cfg.name]
net_contact_forces = contact_sensor.data.net_forces_w_history
# compute the violation
violation = torch.max(torch.norm(net_contact_forces[:, :, sensor_cfg.body_ids], dim=-1), dim=1)[0] - threshold
violation = (
torch.max(torch.linalg.norm(net_contact_forces[:, :, sensor_cfg.body_ids], dim=-1), dim=1)[0] - threshold
)
# compute the penalty
return torch.sum(violation.clip(min=0.0), dim=1)

Expand Down
2 changes: 1 addition & 1 deletion source/isaaclab/isaaclab/envs/mdp/terminations.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,5 @@ def illegal_contact(env: ManagerBasedRLEnv, threshold: float, sensor_cfg: SceneE
net_contact_forces = contact_sensor.data.net_forces_w_history
# check if any contact force exceeds the threshold
return torch.any(
torch.max(torch.norm(net_contact_forces[:, :, sensor_cfg.body_ids], dim=-1), dim=1)[0] > threshold, dim=1
torch.max(torch.linalg.norm(net_contact_forces[:, :, sensor_cfg.body_ids], dim=-1), dim=1)[0] > threshold, dim=1
)
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def _update_buffers_impl(self, env_ids: Sequence[int]):
# since this function is called every frame, we can use the difference to get the elapsed time
elapsed_time = self._timestamp[env_ids] - self._timestamp_last_update[env_ids]
# -- check contact state of bodies
is_contact = torch.norm(self._data.net_forces_w[env_ids, :, :], dim=-1) > self.cfg.force_threshold
is_contact = torch.linalg.norm(self._data.net_forces_w[env_ids, :, :], dim=-1) > self.cfg.force_threshold
is_first_contact = (self._data.current_air_time[env_ids] > 0) * is_contact
is_first_detached = (self._data.current_contact_time[env_ids] > 0) * ~is_contact
# -- update the last contact time if body has just become in contact
Expand Down Expand Up @@ -456,7 +456,7 @@ def _debug_vis_callback(self, event):
return
# marker indices
# 0: contact, 1: no contact
net_contact_force_w = torch.norm(self._data.net_forces_w, dim=-1)
net_contact_force_w = torch.linalg.norm(self._data.net_forces_w, dim=-1)
marker_indices = torch.where(net_contact_force_w > self.cfg.force_threshold, 0, 1)
# check if prim is visualized
if self.cfg.track_pose:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def _get_connecting_lines(
lengths: The length of each connecting line. Shape is (N,).
"""
direction = end_pos - start_pos
lengths = torch.norm(direction, dim=-1)
lengths = torch.linalg.norm(direction, dim=-1)
positions = (start_pos + end_pos) / 2

# Get default direction (along z-axis)
Expand All @@ -507,7 +507,7 @@ def _get_connecting_lines(

# Calculate rotation from default direction to target direction
rotation_axis = torch.linalg.cross(default_direction, direction_norm)
rotation_axis_norm = torch.norm(rotation_axis, dim=-1)
rotation_axis_norm = torch.linalg.norm(rotation_axis, dim=-1)

# Handle case where vectors are parallel
mask = rotation_axis_norm > 1e-6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def pinhole_camera_pattern(
transform_vec = torch.tensor([1, -1, -1], device=device).unsqueeze(0).unsqueeze(2)
pix_in_cam_frame = pix_in_cam_frame[:, [2, 0, 1], :] * transform_vec
# normalize ray directions
ray_directions = (pix_in_cam_frame / torch.norm(pix_in_cam_frame, dim=1, keepdim=True)).permute(0, 2, 1)
ray_directions = (pix_in_cam_frame / torch.linalg.norm(pix_in_cam_frame, dim=1, keepdim=True)).permute(0, 2, 1)
# for camera, we always ray-cast from the sensor's origin
ray_starts = torch.zeros_like(ray_directions, device=device)

Expand Down
2 changes: 1 addition & 1 deletion source/isaaclab/isaaclab/utils/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ def sample_gaussian(
if isinstance(mean, float):
if isinstance(size, int):
size = (size,)
return torch.normal(mean=mean, std=std, size=size).to(device=device)
return torch.linalg.normal(mean=mean, std=std, size=size).to(device=device)
else:
return torch.normal(mean=mean, std=std).to(device=device)

Expand Down
4 changes: 2 additions & 2 deletions source/isaaclab/test/controllers/test_differential_ik.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ def _run_ik_controller(
pos_error, rot_error = compute_pose_error(
ee_pos_b, ee_quat_b, ee_pose_b_des[:, 0:3], ee_pose_b_des[:, 3:7]
)
pos_error_norm = torch.norm(pos_error, dim=-1)
rot_error_norm = torch.norm(rot_error, dim=-1)
pos_error_norm = torch.linalg.norm(pos_error, dim=-1)
rot_error_norm = torch.linalg.norm(rot_error, dim=-1)
# desired error (zer)
des_error = torch.zeros_like(pos_error_norm)
# check convergence
Expand Down
10 changes: 5 additions & 5 deletions source/isaaclab/test/controllers/test_operational_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,8 +1617,8 @@ def _check_convergence(
pos_error, rot_error = compute_pose_error(
ee_pose_b[:, 0:3], ee_pose_b[:, 3:7], ee_target_pose_b[:, 0:3], ee_target_pose_b[:, 3:7]
)
pos_error_norm = torch.norm(pos_error * pos_mask, dim=-1)
rot_error_norm = torch.norm(rot_error * rot_mask, dim=-1)
pos_error_norm = torch.linalg.norm(pos_error * pos_mask, dim=-1)
rot_error_norm = torch.linalg.norm(rot_error * rot_mask, dim=-1)
# desired error (zer)
des_error = torch.zeros_like(pos_error_norm)
# check convergence
Expand All @@ -1629,8 +1629,8 @@ def _check_convergence(
pos_error, rot_error = compute_pose_error(
ee_pose_b[:, 0:3], ee_pose_b[:, 3:7], ee_target_pose_b[:, 0:3], ee_target_pose_b[:, 3:7]
)
pos_error_norm = torch.norm(pos_error * pos_mask, dim=-1)
rot_error_norm = torch.norm(rot_error * rot_mask, dim=-1)
pos_error_norm = torch.linalg.norm(pos_error * pos_mask, dim=-1)
rot_error_norm = torch.linalg.norm(rot_error * rot_mask, dim=-1)
# desired error (zer)
des_error = torch.zeros_like(pos_error_norm)
# check convergence
Expand All @@ -1645,7 +1645,7 @@ def _check_convergence(
R_task_b = matrix_from_quat(task_frame_pose_b[:, 3:])
force_target_b[:] = (R_task_b @ force_target_b[:].unsqueeze(-1)).squeeze(-1)
force_error = ee_force_b - force_target_b
force_error_norm = torch.norm(
force_error_norm = torch.linalg.norm(
force_error * force_mask, dim=-1
) # ignore torque part as we cannot measure it
des_error = torch.zeros_like(force_error_norm)
Expand Down
4 changes: 2 additions & 2 deletions source/isaaclab/test/controllers/test_pink_ik.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def verify_errors(errors, test_setup, tolerances):

for hand in ["left", "right"]:
# Check PD controller errors
pd_error_norm = torch.norm(errors[f"{hand}_pd_error"], dim=1)
pd_error_norm = torch.linalg.norm(errors[f"{hand}_pd_error"], dim=1)
torch.testing.assert_close(
pd_error_norm,
zero_tensor,
Expand All @@ -328,7 +328,7 @@ def verify_errors(errors, test_setup, tolerances):
)

# Check IK position errors
pos_error_norm = torch.norm(errors[f"{hand}_pos_error"], dim=1)
pos_error_norm = torch.linalg.norm(errors[f"{hand}_pos_error"], dim=1)
torch.testing.assert_close(
pos_error_norm,
zero_tensor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def main():
# step env
obs, _ = env.step(target_position)
# print mean squared position error between target and current position
error = torch.norm(obs["policy"] - target_position).mean().item()
error = torch.linalg.norm(obs["policy"] - target_position).mean().item()
print(f"[Step: {count:04d}]: Mean position error: {error:.4f}")
# update counter
count += 1
Expand Down
3 changes: 2 additions & 1 deletion source/isaaclab/test/sensors/test_contact_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ def _test_contact_position(shape: RigidObject, sensor: ContactSensor, mode: Cont
[[0.0, 0.0, -shape.cfg.spawn.radius]], device=sensor._data.pos_w.device
)
assert torch.all(
torch.abs(torch.norm(sensor._data.contact_pos_w - contact_position.unsqueeze(1), p=2, dim=-1)) < 1e-2
torch.abs(torch.linalg.norm(sensor._data.contact_pos_w - contact_position.unsqueeze(1), p=2, dim=-1))
< 1e-2
).item()
elif mode == ContactTestMode.NON_CONTACT:
assert torch.all(torch.isnan(sensor._data.contact_pos_w)).item()
Expand Down
4 changes: 2 additions & 2 deletions source/isaaclab/test/utils/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def test_quat_to_and_from_angle_axis(device):
)
torch.testing.assert_close(rot_vec_scipy, rot_vec_value)
axis = math_utils.normalize(rot_vec_value.clone())
angle = torch.norm(rot_vec_value.clone(), dim=-1)
angle = torch.linalg.norm(rot_vec_value.clone(), dim=-1)
q_value = math_utils.quat_unique(math_utils.quat_from_angle_axis(angle, axis))
torch.testing.assert_close(q_rand, q_value)

Expand Down Expand Up @@ -780,7 +780,7 @@ def test_compute_pose_error(device, rot_error_type):
else:
axis_angle = math_utils.quat_box_minus(q02, q01)
axis = math_utils.normalize(axis_angle)
angle = torch.norm(axis_angle, dim=-1)
angle = torch.linalg.norm(axis_angle, dim=-1)

torch.testing.assert_close(
math_utils.quat_unique(math_utils.quat_from_angle_axis(angle, axis)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ def _get_rewards(self) -> torch.Tensor:
first_contact = self._contact_sensor.compute_first_contact(self.step_dt)[:, self._feet_ids]
last_air_time = self._contact_sensor.data.last_air_time[:, self._feet_ids]
air_time = torch.sum((last_air_time - 0.5) * first_contact, dim=1) * (
torch.norm(self._commands[:, :2], dim=1) > 0.1
torch.linalg.norm(self._commands[:, :2], dim=1) > 0.1
)
# undesired contacts
net_contact_forces = self._contact_sensor.data.net_forces_w_history
is_contact = (
torch.max(torch.norm(net_contact_forces[:, :, self._undesired_contact_body_ids], dim=-1), dim=1)[0] > 1.0
torch.max(torch.linalg.norm(net_contact_forces[:, :, self._undesired_contact_body_ids], dim=-1), dim=1)[0]
> 1.0
)
contacts = torch.sum(is_contact, dim=1)
# flat orientation
Expand All @@ -160,7 +161,9 @@ def _get_rewards(self) -> torch.Tensor:
def _get_dones(self) -> tuple[torch.Tensor, torch.Tensor]:
time_out = self.episode_length_buf >= self.max_episode_length - 1
net_contact_forces = self._contact_sensor.data.net_forces_w_history
died = torch.any(torch.max(torch.norm(net_contact_forces[:, :, self._base_id], dim=-1), dim=1)[0] > 1.0, dim=1)
died = torch.any(
torch.max(torch.linalg.norm(net_contact_forces[:, :, self._base_id], dim=-1), dim=1)[0] > 1.0, dim=1
)
return died, time_out

def _reset_idx(self, env_ids: torch.Tensor | None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def _compute_intermediate_values(self, dt):
keypoint_offset.repeat(self.num_envs, 1),
)[1]

self.keypoint_dist = torch.norm(self.keypoints_held - self.keypoints_fixed, p=2, dim=-1).mean(-1)
self.keypoint_dist = torch.linalg.norm(self.keypoints_held - self.keypoints_fixed, p=2, dim=-1).mean(-1)
self.last_update_timestamp = self._robot._data._sim_timestamp

def _get_observations(self):
Expand Down Expand Up @@ -420,7 +420,7 @@ def move_gripper_in_place(self, ctrl_target_gripper_dof_pos):
rot_actions = actions[:, 3:6]

# Convert to quat and set rot target
angle = torch.norm(rot_actions, p=2, dim=-1)
angle = torch.linalg.norm(rot_actions, p=2, dim=-1)
axis = rot_actions / angle.unsqueeze(-1)

rot_actions_quat = torch_utils.quat_from_angle_axis(angle, axis)
Expand Down Expand Up @@ -472,7 +472,7 @@ def _apply_action(self):
self.ctrl_target_fingertip_midpoint_pos = self.fixed_pos_action_frame + pos_error_clipped

# Convert to quat and set rot target
angle = torch.norm(rot_actions, p=2, dim=-1)
angle = torch.linalg.norm(rot_actions, p=2, dim=-1)
axis = rot_actions / angle.unsqueeze(-1)

rot_actions_quat = torch_utils.quat_from_angle_axis(angle, axis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def check_plug_close_to_socket(keypoints_plug, keypoints_socket, dist_threshold,
"""Check if plug is close to socket."""

# Compute keypoint distance between plug and socket
keypoint_dist = torch.norm(keypoints_socket - keypoints_plug, p=2, dim=-1)
keypoint_dist = torch.linalg.norm(keypoints_socket - keypoints_plug, p=2, dim=-1)

# Check if keypoint distance is below threshold
is_plug_close_to_socket = torch.where(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def move_gripper_in_place(self, ctrl_target_gripper_dof_pos):
rot_actions = actions[:, 3:6]

# Convert to quat and set rot target
angle = torch.norm(rot_actions, p=2, dim=-1)
angle = torch.linalg.norm(rot_actions, p=2, dim=-1)
axis = rot_actions / angle.unsqueeze(-1)

rot_actions_quat = torch_utils.quat_from_angle_axis(angle, axis)
Expand Down Expand Up @@ -366,7 +366,7 @@ def _apply_action(self):
self.ctrl_target_fingertip_midpoint_pos = self.fixed_pos_action_frame + pos_error_clipped

# Convert to quat and set rot target
angle = torch.norm(rot_actions, p=2, dim=-1)
angle = torch.linalg.norm(rot_actions, p=2, dim=-1)
axis = rot_actions / angle.unsqueeze(-1)

rot_actions_quat = torch_utils.quat_from_angle_axis(angle, axis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def check_plug_close_to_socket(keypoints_plug, keypoints_socket, dist_threshold,
"""Check if plug is close to socket."""

# Compute keypoint distance between plug and socket
keypoint_dist = torch.norm(keypoints_socket - keypoints_plug, p=2, dim=-1)
keypoint_dist = torch.linalg.norm(keypoints_socket - keypoints_plug, p=2, dim=-1)

# Check if keypoint distance is below threshold
is_plug_close_to_socket = torch.where(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def close_gripper_in_place(self):
rot_actions = actions[:, 3:6]

# Convert to quat and set rot target
angle = torch.norm(rot_actions, p=2, dim=-1)
angle = torch.linalg.norm(rot_actions, p=2, dim=-1)
axis = rot_actions / angle.unsqueeze(-1)

rot_actions_quat = torch_utils.quat_from_angle_axis(angle, axis)
Expand Down Expand Up @@ -276,7 +276,7 @@ def _apply_action(self):
ctrl_target_fingertip_midpoint_pos = fixed_pos_action_frame + pos_error_clipped

# Convert to quat and set rot target
angle = torch.norm(rot_actions, p=2, dim=-1)
angle = torch.linalg.norm(rot_actions, p=2, dim=-1)
axis = rot_actions / angle.unsqueeze(-1)

rot_actions_quat = torch_utils.quat_from_angle_axis(angle, axis)
Expand Down Expand Up @@ -455,14 +455,14 @@ def _get_factory_rew_dict(self, curr_successes):
torch.tensor([1.0, 0.0, 0.0, 0.0], device=self.device).unsqueeze(0).repeat(self.num_envs, 1),
keypoint_offset.repeat(self.num_envs, 1),
)[1]
keypoint_dist = torch.norm(keypoints_held - keypoints_fixed, p=2, dim=-1).mean(-1)
keypoint_dist = torch.linalg.norm(keypoints_held - keypoints_fixed, p=2, dim=-1).mean(-1)

a0, b0 = self.cfg_task.keypoint_coef_baseline
a1, b1 = self.cfg_task.keypoint_coef_coarse
a2, b2 = self.cfg_task.keypoint_coef_fine
# Action penalties.
action_penalty_ee = torch.norm(self.actions, p=2)
action_grad_penalty = torch.norm(self.actions - self.prev_actions, p=2, dim=-1)
action_penalty_ee = torch.linalg.norm(self.actions, p=2)
action_grad_penalty = torch.linalg.norm(self.actions - self.prev_actions, p=2, dim=-1)
curr_engaged = self._get_curr_successes(success_threshold=self.cfg_task.engage_threshold, check_rot=False)

rew_dict = {
Expand Down Expand Up @@ -707,7 +707,7 @@ def randomize_initial_state(self, env_ids):
env_ids=bad_envs,
)
pos_error = torch.linalg.norm(pos_error, dim=1) > 1e-3
angle_error = torch.norm(aa_error, dim=1) > 1e-3
angle_error = torch.linalg.norm(aa_error, dim=1) > 1e-3
any_error = torch.logical_or(pos_error, angle_error)
bad_envs = bad_envs[any_error.nonzero(as_tuple=False).squeeze(-1)]

Expand Down
Loading
Loading