Skip to content

[Bug Report] Unintended in-place operation in body_pose_w #4211

@MinchoU

Description

@MinchoU

Describe the bug

In the function body_pose_w of observations.py, the part that subtracts env origins modifies the original tensor with in-place operation.

Steps to reproduce

If I print out the body pose in the function like this

@generic_io_descriptor(observation_type="BodyState", on_inspect=[record_shape, record_dtype, record_body_names]) def body_pose_w( env: ManagerBasedEnv, asset_cfg: SceneEntityCfg = SceneEntityCfg("robot"), ) -> torch.Tensor: """The flattened body poses of the asset w.r.t the env.scene.origin.   Note: Only the bodies configured in :attr:`asset_cfg.body_ids` will have their poses returned.   Args:  env: The environment.  asset_cfg: The SceneEntity associated with this observation.   Returns:  The poses of bodies in articulation [num_env, 7 * num_bodies]. Pose order is [x,y,z,qw,qx,qy,qz].  Output is stacked horizontally per body.  """ # extract the used quantities (to enable type-hinting) asset: Articulation = env.scene[asset_cfg.name] # access the body poses in world frame print(f"BEFORE:{asset.data.body_pose_w[0,0]}") pose = asset.data.body_pose_w[:, asset_cfg.body_ids, :7] pose[..., :3] = pose[..., :3] - env.scene.env_origins.unsqueeze(1) print(f"AFTER:{asset.data.body_pose_w[0,0]}") return pose.reshape(env.num_envs, -1)

The result becomes

BEFORE:tensor([-1.2500, 1.2500, 0.8004, 0.7057, -0.0245, 0.0393, -0.7070], device='cuda:0') AFTER:tensor([-2.5000, 2.5000, 0.8004, 0.7057, -0.0245, 0.0393, -0.7070], device='cuda:0')

This may effect other observation, rewards, terminations or etc during the training. I suggest to change

pose = asset.data.body_pose_w[:, asset_cfg.body_ids, :7] 

to

pose = asset.data.body_pose_w[:, asset_cfg.body_ids, :7].clone() 

Checklist

  • I have checked that there is no similar issue in the repo (required)
  • I have checked that the issue is not in running Isaac Sim itself and is related to the repo

Acceptance Criteria

Add the criteria for which this task is considered done. If not known at issue creation time, you can add this once the issue is assigned.

  • Criteria 1 : Get a reply whether this is intended, and if not fix the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions