Skip to content

Conversation

louislelay
Copy link
Contributor

@louislelay louislelay commented Aug 22, 2025

Description

This PR removes a UserWarning from PyTorch about using torch.tensor() on an existing tensor in events.py. It replaces torch.tensor(actuator.joint_indices, device=asset.device) with .to(device) to avoid unnecessary copies.

Warning mentionned:

/home/spring/IsaacLab/source/isaaclab/isaaclab/envs/mdp/events.py:542: 
UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor). actuator_joint_indices = torch.tensor(actuator.joint_indices, device=asset.device)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@louislelay louislelay requested a review from ooctipus as a code owner August 22, 2025 09:15
@ooctipus
Copy link
Collaborator

@louislelay

So actuator.joint_indices can only be torch.tensor or slice? if that is true maybe add if isinstance(slice), elif isinstance(torch.Tensor), else raise error may be a bit more readable?

On a second note, do you think check the type during call time can be too expensive (I know you didn't write the original function, so no pressure to edit), (◎ ◎)ゞ why couldn't we do the check and construct indices during init construction instead?

Would love to know your thought on it. : ))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants