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. : ))

@Mayankm96
Copy link
Contributor

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?

Yes, i think it makes sense to become more strong-type if the type is known already.

Why couldn't we do the check and construct indices during init construction instead?

We do the checks for findding joint indices when resolving scene entities. Do you mean the check in the event term itself?

@louislelay
Copy link
Contributor Author

louislelay commented Sep 5, 2025

Hey @ooctipus and @Mayankm96, thanks for the feedback!

I’ve updated the code to make the checks type-explicit and raise on unexpected types. I’ll run tests once my current training job finishes and let you know when it’s ready for review again. Edit: it's good to me :)

On the second point: I agree with Octi, moving the joint index resolution to __init__ makes sense since it stays stable during training and avoids extra work each step.

@louislelay
Copy link
Contributor Author

I tested it and accepted your changes @Mayankm96, aside from the init vs call thingy the rest is good to me!

@github-actions github-actions bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Sep 11, 2025
@Mayankm96 Mayankm96 merged commit 649ad88 into isaac-sim:main Sep 11, 2025
1 check passed
@ooctipus
Copy link
Collaborator

ooctipus commented Sep 13, 2025

@louislelay

- global_indices = actuator_indices = torch.tensor(self.asset_cfg.joint_ids, device=self.asset.device)
+ global_indices = torch.tensor(self.asset_cfg.joint_ids, device=self.asset.device)

ahh we are now missing actuator_indices and can cause error because it is not defined
I will submit an PR to fix this

kellyguo11 pushed a commit that referenced this pull request Sep 15, 2025
# Description

This PR fixes an issue introduced in #3251 , which accidentally deleted
actuator_indices in the case where `asset_cfg.joint_id` is not a `slice`
and `actuator.joint_indices` is a `slice`

## Type of change

<!-- As you go through the list, delete the ones that are not
applicable. -->

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

## Screenshots

Please attach before and after screenshots of the change if applicable.

<!--
Example:

| Before | After |
| ------ | ----- |
| _gif/png before_ | _gif/png after_ |

To upload images to a PR -- simply drag and drop an image while in edit
mode and it should upload the image directly. You can then paste that
source into the above before/after sections.
-->

## Checklist

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->
kellyguo11 pushed a commit that referenced this pull request Sep 18, 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:

```bash
/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

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] 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
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Signed-off-by: Louis LE LAY <[email protected]>
Co-authored-by: ooctipus <[email protected]>
Co-authored-by: Mayank Mittal <[email protected]>
kellyguo11 pushed a commit that referenced this pull request Sep 18, 2025
This PR fixes an issue introduced in #3251 , which accidentally deleted
actuator_indices in the case where `asset_cfg.joint_id` is not a `slice`
and `actuator.joint_indices` is a `slice`

<!-- As you go through the list, delete the ones that are not
applicable. -->

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

Please attach before and after screenshots of the change if applicable.

<!--
Example:

| Before | After |
| ------ | ----- |
| _gif/png before_ | _gif/png after_ |

To upload images to a PR -- simply drag and drop an image while in edit
mode and it should upload the image directly. You can then paste that
source into the above before/after sections.
-->

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->
@louislelay louislelay deleted the fix/tensor-construction-events branch September 19, 2025 08:18
ooctipus added a commit to ooctipus/IsaacLab that referenced this pull request Sep 20, 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:

```bash
/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

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] 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
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Signed-off-by: Louis LE LAY <[email protected]>
Co-authored-by: ooctipus <[email protected]>
Co-authored-by: Mayank Mittal <[email protected]>
ooctipus added a commit to ooctipus/IsaacLab that referenced this pull request Sep 20, 2025
…-sim#3447)

This PR fixes an issue introduced in isaac-sim#3251 , which accidentally deleted
actuator_indices in the case where `asset_cfg.joint_id` is not a `slice`
and `actuator.joint_indices` is a `slice`

<!-- As you go through the list, delete the ones that are not
applicable. -->

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

Please attach before and after screenshots of the change if applicable.

<!--
Example:

| Before | After |
| ------ | ----- |
| _gif/png before_ | _gif/png after_ |

To upload images to a PR -- simply drag and drop an image while in edit
mode and it should upload the image directly. You can then paste that
source into the above before/after sections.
-->

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->
hougantc-nvda pushed a commit to hougantc-nvda/IsaacLab that referenced this pull request Oct 22, 2025
…-sim#3447)

# Description

This PR fixes an issue introduced in isaac-sim#3251 , which accidentally deleted
actuator_indices in the case where `asset_cfg.joint_id` is not a `slice`
and `actuator.joint_indices` is a `slice`

## Type of change

<!-- As you go through the list, delete the ones that are not
applicable. -->

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

## Screenshots

Please attach before and after screenshots of the change if applicable.

<!--
Example:

| Before | After |
| ------ | ----- |
| _gif/png before_ | _gif/png after_ |

To upload images to a PR -- simply drag and drop an image while in edit
mode and it should upload the image directly. You can then paste that
source into the above before/after sections.
-->

## Checklist

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->
george-nehma pushed a commit to george-nehma/IsaacLab-Dreamerv3 that referenced this pull request Oct 24, 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:

```bash
/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

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] 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
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------

Signed-off-by: Louis LE LAY <[email protected]>
Co-authored-by: ooctipus <[email protected]>
Co-authored-by: Mayank Mittal <[email protected]>
george-nehma pushed a commit to george-nehma/IsaacLab-Dreamerv3 that referenced this pull request Oct 24, 2025
…-sim#3447)

# Description

This PR fixes an issue introduced in isaac-sim#3251 , which accidentally deleted
actuator_indices in the case where `asset_cfg.joint_id` is not a `slice`
and `actuator.joint_indices` is a `slice`

## Type of change

<!-- As you go through the list, delete the ones that are not
applicable. -->

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

## Screenshots

Please attach before and after screenshots of the change if applicable.

<!--
Example:

| Before | After |
| ------ | ----- |
| _gif/png before_ | _gif/png after_ |

To upload images to a PR -- simply drag and drop an image while in edit
mode and it should upload the image directly. You can then paste that
source into the above before/after sections.
-->

## Checklist

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->
hougantc-nvda pushed a commit to hougantc-nvda/IsaacLab that referenced this pull request Oct 24, 2025
…-sim#3447)

This PR fixes an issue introduced in isaac-sim#3251 , which accidentally deleted
actuator_indices in the case where `asset_cfg.joint_id` is not a `slice`
and `actuator.joint_indices` is a `slice`

<!-- As you go through the list, delete the ones that are not
applicable. -->

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

Please attach before and after screenshots of the change if applicable.

<!--
Example:

| Before | After |
| ------ | ----- |
| _gif/png before_ | _gif/png after_ |

To upload images to a PR -- simply drag and drop an image while in edit
mode and it should upload the image directly. You can then paste that
source into the above before/after sections.
-->

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants