Skip to content

Adds time-based mdp (observation) functions - #2332

Merged
Mayankm96 merged 13 commits into
isaac-sim:mainfrom
TheIndoorDad:feature/SV/time_observation
Jun 2, 2025
Merged

Mayankm96 merged 13 commits into
isaac-sim:mainfrom
TheIndoorDad:feature/SV/time_observation

Conversation

@TheIndoorDad

Copy link
Copy Markdown
Contributor

Description

As discussed in #2284, I was writing an observation function to pass the time remaining in an episode (in seconds) to an observation term in a Manager-based environment, and found this could not be done without modifying ManagerBasedRLEnv to initialize episode_length_buf before managers are loaded. Here is a summary of changes made:

  • Added initialization of episode_length_buf in :meth:load_managers() of :class:~isaaclab.envs.ManagerBasedRLEnv to make it available for use in mdp functions. Note: existing initialization in :meth:__init__ left in place in case it is needed for other use cases. Potentially redundant? Assess.
  • Added :attr:~isaaclab.envs.ManagerBasedRLEnv.curr_episode_length to :class:~isaaclab.envs.ManagerBasedRLEnv which returns reshaped episode_length_buf so it is visible as an attribute in the documentation.
  • Added time observation functions to ~isaaclab.envs.mdp.observations module, :func:~isaaclab.envs.mdp.observations.current_time_s and :func:~isaaclab.envs.mdp.observations.remaining_time_s.

I'm not certain whether the documentation will be updated automatically or if there are further steps I need to take. When I build the documentation on my machine it is updated, but the outputs are ignored by git. Please let me know if there's anything else I need to do.

I could also use some advice on tests (apologies in advance for my lack of experience here, my background is not in software dev). Locally I modified the Isaac-Velocity-Rough-Anymal-C-v0 task to add the two new observation functions, and began to train a policy in rsl_rl using the provided scripts/reinforcement_learning/rsl_rl/train.py script, and both were available to be viewed and appeared to be working correctly. I tried to run the existing suite of unit tests but it gave me an error I don't understand (see below). I also started to create a new script similar to isaaclab/test/envs/check_manager_based_env_anymal_locomotion.py but that would have required a policy trained using the new observation functions (which I can produce, but wasn't sure if that would be worthwhile since it wouldn't be available to others).

Output when running ./isaaclab.sh -t:

[INFO] Warm starting the simulation app before running tests.                                                                                                                                                                                                                                                                        
ERROR:root:Error warm starting the app: b'2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 16 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 17 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 18 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 19 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 20 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 21 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 22 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 23 belongs to.\nMESA-INTEL: warning: Performance support disabled, consider sysctl dev.i915.perf_stream_paranoid=0\n\n'

Cheers.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist

  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation (maybe?)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works (please advise)
  • 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


# initialize data and constants
# -- init buffers
# TODO: this may be redundant since self.episode_length_buf is now initialized in load_managers() to make it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of moving it to load_managers (which is only for managers and not buffers), maybe it is better to move the buffer initialization further up in the class

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can move it above the super().__init__ call if I change the parameters to be self.cfg.scene.num_envs and self.cfg.sim.device. Seems to be working on my side. I'll make a commit for your review.

return math.ceil(self.max_episode_length_s / self.step_dt)

@property
def curr_episode_length(self) -> torch.Tensor:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

episode_length_buf is a variable you can access outside as it is not a private member. I don't think making a property for it is necessary at this point.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I did this purely so the property would show up as an attribute in the documentation, but if you don't think that's necessary (or there's a better way to do it) I will remove.

@TheIndoorDad TheIndoorDad left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commits to follow with above suggested changes.

return math.ceil(self.max_episode_length_s / self.step_dt)

@property
def curr_episode_length(self) -> torch.Tensor:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I did this purely so the property would show up as an attribute in the documentation, but if you don't think that's necessary (or there's a better way to do it) I will remove.


# initialize data and constants
# -- init buffers
# TODO: this may be redundant since self.episode_length_buf is now initialized in load_managers() to make it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can move it above the super().__init__ call if I change the parameters to be self.cfg.scene.num_envs and self.cfg.sim.device. Seems to be working on my side. I'll make a commit for your review.

@TheIndoorDad
TheIndoorDad requested a review from Mayankm96 April 25, 2025 18:25
@Mayankm96 Mayankm96 added bug Something isn't working enhancement New feature or request labels May 7, 2025
@Mayankm96 Mayankm96 changed the title Adds time-based mdp (observation) functions. Adds time-based mdp (observation) functions May 7, 2025
@TheIndoorDad

Copy link
Copy Markdown
Contributor Author

Hi @Mayankm96, is there anything else you need me to do to get this PR committed to the main branch? Sorry, I'm just not sure of the process.

Cheers, and thanks for your help.

Comment thread source/isaaclab/config/extension.toml Resolved
@Mayankm96
Mayankm96 merged commit dca126a into isaac-sim:main Jun 2, 2025
fan-ziqi pushed a commit to fan-ziqi/IsaacLab that referenced this pull request Jun 5, 2025
# Description

As discussed in isaac-sim#2284, I was writing an observation function to pass the
time remaining in an episode (in seconds) to an observation term in a
Manager-based environment, and found this could not be done without
modifying `ManagerBasedRLEnv` to initialize `episode_length_buf` before
managers are loaded. Here is a summary of changes made:

* Added initialization of `episode_length_buf` in
:meth:`load_managers()` of :class:`~isaaclab.envs.ManagerBasedRLEnv` to
make it available for use in mdp functions. Note: existing
initialization in :meth:`__init__` left in place in case it is needed
for other use cases. Potentially redundant? Assess.
* Added :attr:`~isaaclab.envs.ManagerBasedRLEnv.curr_episode_length` to
:class:`~isaaclab.envs.ManagerBasedRLEnv` which returns reshaped
``episode_length_buf`` so it is visible as an attribute in the
documentation.
* Added time observation functions to `~isaaclab.envs.mdp.observations`
module, :func:`~isaaclab.envs.mdp.observations.current_time_s` and
:func:`~isaaclab.envs.mdp.observations.remaining_time_s`.

I'm not certain whether the documentation will be updated automatically
or if there are further steps I need to take. When I build the
documentation on my machine it is updated, but the outputs are ignored
by git. Please let me know if there's anything else I need to do.

I could also use some advice on tests (apologies in advance for my lack
of experience here, my background is not in software dev). Locally I
modified the `Isaac-Velocity-Rough-Anymal-C-v0` task to add the two new
observation functions, and began to train a policy in rsl_rl using the
provided `scripts/reinforcement_learning/rsl_rl/train.py` script, and
both were available to be viewed and appeared to be working correctly. I
tried to run the existing suite of unit tests but it gave me an error I
don't understand (see below). I also started to create a new script
similar to
[`isaaclab/test/envs/check_manager_based_env_anymal_locomotion.py`](https://github.com/isaac-sim/IsaacLab/blob/7de6d6fef9424c95fc68dc767af67ffbe0da6832/source/isaaclab/test/envs/check_manager_based_env_anymal_locomotion.py)
but that would have required a policy trained using the new observation
functions (which I can produce, but wasn't sure if that would be
worthwhile since it wouldn't be available to others).

Output when running `./isaaclab.sh -t`:
```
[INFO] Warm starting the simulation app before running tests.                                                                                                                                                                                                                                                                        
ERROR:root:Error warm starting the app: b'2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 16 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 17 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 18 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 19 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 20 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 21 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 22 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 23 belongs to.\nMESA-INTEL: warning: Performance support disabled, consider sysctl dev.i915.perf_stream_paranoid=0\n\n'
```

Cheers.

## Type of change

- New feature (non-breaking change which adds functionality)
- This change requires a documentation update

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation (_maybe_?)
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works (please advise)
- [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

---------

Signed-off-by: TheIndoorDad <[email protected]>
Signed-off-by: Mayank Mittal <[email protected]>
Co-authored-by: Mayank Mittal <[email protected]>
yrh012 pushed a commit to aica-technology/isaac-lab that referenced this pull request Jun 16, 2025
# Description

As discussed in isaac-sim#2284, I was writing an observation function to pass the
time remaining in an episode (in seconds) to an observation term in a
Manager-based environment, and found this could not be done without
modifying `ManagerBasedRLEnv` to initialize `episode_length_buf` before
managers are loaded. Here is a summary of changes made:

* Added initialization of `episode_length_buf` in
:meth:`load_managers()` of :class:`~isaaclab.envs.ManagerBasedRLEnv` to
make it available for use in mdp functions. Note: existing
initialization in :meth:`__init__` left in place in case it is needed
for other use cases. Potentially redundant? Assess.
* Added :attr:`~isaaclab.envs.ManagerBasedRLEnv.curr_episode_length` to
:class:`~isaaclab.envs.ManagerBasedRLEnv` which returns reshaped
``episode_length_buf`` so it is visible as an attribute in the
documentation.
* Added time observation functions to `~isaaclab.envs.mdp.observations`
module, :func:`~isaaclab.envs.mdp.observations.current_time_s` and
:func:`~isaaclab.envs.mdp.observations.remaining_time_s`.

I'm not certain whether the documentation will be updated automatically
or if there are further steps I need to take. When I build the
documentation on my machine it is updated, but the outputs are ignored
by git. Please let me know if there's anything else I need to do.

I could also use some advice on tests (apologies in advance for my lack
of experience here, my background is not in software dev). Locally I
modified the `Isaac-Velocity-Rough-Anymal-C-v0` task to add the two new
observation functions, and began to train a policy in rsl_rl using the
provided `scripts/reinforcement_learning/rsl_rl/train.py` script, and
both were available to be viewed and appeared to be working correctly. I
tried to run the existing suite of unit tests but it gave me an error I
don't understand (see below). I also started to create a new script
similar to
[`isaaclab/test/envs/check_manager_based_env_anymal_locomotion.py`](https://github.com/isaac-sim/IsaacLab/blob/7de6d6fef9424c95fc68dc767af67ffbe0da6832/source/isaaclab/test/envs/check_manager_based_env_anymal_locomotion.py)
but that would have required a policy trained using the new observation
functions (which I can produce, but wasn't sure if that would be
worthwhile since it wouldn't be available to others).

Output when running `./isaaclab.sh -t`:
```
[INFO] Warm starting the simulation app before running tests.                                                                                                                                                                                                                                                                        
ERROR:root:Error warm starting the app: b'2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 16 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 17 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 18 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 19 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 20 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 21 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 22 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 23 belongs to.\nMESA-INTEL: warning: Performance support disabled, consider sysctl dev.i915.perf_stream_paranoid=0\n\n'
```

Cheers.

## Type of change

- New feature (non-breaking change which adds functionality)
- This change requires a documentation update

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation (_maybe_?)
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works (please advise)
- [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

---------

Signed-off-by: TheIndoorDad <[email protected]>
Signed-off-by: Mayank Mittal <[email protected]>
Co-authored-by: Mayank Mittal <[email protected]>
harry-wf-cheung pushed a commit to harry-wf-cheung/IsaacLab-Harry that referenced this pull request Jul 30, 2025
# Description

As discussed in isaac-sim#2284, I was writing an observation function to pass the
time remaining in an episode (in seconds) to an observation term in a
Manager-based environment, and found this could not be done without
modifying `ManagerBasedRLEnv` to initialize `episode_length_buf` before
managers are loaded. Here is a summary of changes made:

* Added initialization of `episode_length_buf` in
:meth:`load_managers()` of :class:`~isaaclab.envs.ManagerBasedRLEnv` to
make it available for use in mdp functions. Note: existing
initialization in :meth:`__init__` left in place in case it is needed
for other use cases. Potentially redundant? Assess.
* Added :attr:`~isaaclab.envs.ManagerBasedRLEnv.curr_episode_length` to
:class:`~isaaclab.envs.ManagerBasedRLEnv` which returns reshaped
``episode_length_buf`` so it is visible as an attribute in the
documentation.
* Added time observation functions to `~isaaclab.envs.mdp.observations`
module, :func:`~isaaclab.envs.mdp.observations.current_time_s` and
:func:`~isaaclab.envs.mdp.observations.remaining_time_s`.

I'm not certain whether the documentation will be updated automatically
or if there are further steps I need to take. When I build the
documentation on my machine it is updated, but the outputs are ignored
by git. Please let me know if there's anything else I need to do.

I could also use some advice on tests (apologies in advance for my lack
of experience here, my background is not in software dev). Locally I
modified the `Isaac-Velocity-Rough-Anymal-C-v0` task to add the two new
observation functions, and began to train a policy in rsl_rl using the
provided `scripts/reinforcement_learning/rsl_rl/train.py` script, and
both were available to be viewed and appeared to be working correctly. I
tried to run the existing suite of unit tests but it gave me an error I
don't understand (see below). I also started to create a new script
similar to
[`isaaclab/test/envs/check_manager_based_env_anymal_locomotion.py`](https://github.com/isaac-sim/IsaacLab/blob/31f3729035b6e2a37797e84295f0a249352a3f82/source/isaaclab/test/envs/check_manager_based_env_anymal_locomotion.py)
but that would have required a policy trained using the new observation
functions (which I can produce, but wasn't sure if that would be
worthwhile since it wouldn't be available to others).

Output when running `./isaaclab.sh -t`:
```
[INFO] Warm starting the simulation app before running tests.                                                                                                                                                                                                                                                                        
ERROR:root:Error warm starting the app: b'2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 16 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 17 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 18 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 19 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 20 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 21 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 22 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 23 belongs to.\nMESA-INTEL: warning: Performance support disabled, consider sysctl dev.i915.perf_stream_paranoid=0\n\n'
```

Cheers.

## Type of change

- New feature (non-breaking change which adds functionality)
- This change requires a documentation update

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation (_maybe_?)
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works (please advise)
- [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

---------

Signed-off-by: TheIndoorDad <[email protected]>
Signed-off-by: Mayank Mittal <[email protected]>
Co-authored-by: Mayank Mittal <[email protected]>
LJones-alt pushed a commit to LJones-alt/IsaacLab-Laura that referenced this pull request Jul 1, 2026
# Description

As discussed in isaac-sim#2284, I was writing an observation function to pass the
time remaining in an episode (in seconds) to an observation term in a
Manager-based environment, and found this could not be done without
modifying `ManagerBasedRLEnv` to initialize `episode_length_buf` before
managers are loaded. Here is a summary of changes made:

* Added initialization of `episode_length_buf` in
:meth:`load_managers()` of :class:`~isaaclab.envs.ManagerBasedRLEnv` to
make it available for use in mdp functions. Note: existing
initialization in :meth:`__init__` left in place in case it is needed
for other use cases. Potentially redundant? Assess.
* Added :attr:`~isaaclab.envs.ManagerBasedRLEnv.curr_episode_length` to
:class:`~isaaclab.envs.ManagerBasedRLEnv` which returns reshaped
``episode_length_buf`` so it is visible as an attribute in the
documentation.
* Added time observation functions to `~isaaclab.envs.mdp.observations`
module, :func:`~isaaclab.envs.mdp.observations.current_time_s` and
:func:`~isaaclab.envs.mdp.observations.remaining_time_s`.

I'm not certain whether the documentation will be updated automatically
or if there are further steps I need to take. When I build the
documentation on my machine it is updated, but the outputs are ignored
by git. Please let me know if there's anything else I need to do.

I could also use some advice on tests (apologies in advance for my lack
of experience here, my background is not in software dev). Locally I
modified the `Isaac-Velocity-Rough-Anymal-C-v0` task to add the two new
observation functions, and began to train a policy in rsl_rl using the
provided `scripts/reinforcement_learning/rsl_rl/train.py` script, and
both were available to be viewed and appeared to be working correctly. I
tried to run the existing suite of unit tests but it gave me an error I
don't understand (see below). I also started to create a new script
similar to
[`isaaclab/test/envs/check_manager_based_env_anymal_locomotion.py`](https://github.com/isaac-sim/IsaacLab/blob/7de6d6fef9424c95fc68dc767af67ffbe0da6832/source/isaaclab/test/envs/check_manager_based_env_anymal_locomotion.py)
but that would have required a policy trained using the new observation
functions (which I can produce, but wasn't sure if that would be
worthwhile since it wouldn't be available to others).

Output when running `./isaaclab.sh -t`:
```
[INFO] Warm starting the simulation app before running tests.                                                                                                                                                                                                                                                                        
ERROR:root:Error warm starting the app: b'2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 16 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 17 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 18 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 19 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 20 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 21 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 22 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 23 belongs to.\nMESA-INTEL: warning: Performance support disabled, consider sysctl dev.i915.perf_stream_paranoid=0\n\n'
```

Cheers.

## Type of change

- New feature (non-breaking change which adds functionality)
- This change requires a documentation update

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation (_maybe_?)
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works (please advise)
- [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

---------

Signed-off-by: TheIndoorDad <[email protected]>
Signed-off-by: Mayank Mittal <[email protected]>
Co-authored-by: Mayank Mittal <[email protected]>
csj-275 pushed a commit to csj-275/IsaacLab that referenced this pull request Jul 8, 2026
# Description

As discussed in isaac-sim#2284, I was writing an observation function to pass the
time remaining in an episode (in seconds) to an observation term in a
Manager-based environment, and found this could not be done without
modifying `ManagerBasedRLEnv` to initialize `episode_length_buf` before
managers are loaded. Here is a summary of changes made:

* Added initialization of `episode_length_buf` in
:meth:`load_managers()` of :class:`~isaaclab.envs.ManagerBasedRLEnv` to
make it available for use in mdp functions. Note: existing
initialization in :meth:`__init__` left in place in case it is needed
for other use cases. Potentially redundant? Assess.
* Added :attr:`~isaaclab.envs.ManagerBasedRLEnv.curr_episode_length` to
:class:`~isaaclab.envs.ManagerBasedRLEnv` which returns reshaped
``episode_length_buf`` so it is visible as an attribute in the
documentation.
* Added time observation functions to `~isaaclab.envs.mdp.observations`
module, :func:`~isaaclab.envs.mdp.observations.current_time_s` and
:func:`~isaaclab.envs.mdp.observations.remaining_time_s`.

I'm not certain whether the documentation will be updated automatically
or if there are further steps I need to take. When I build the
documentation on my machine it is updated, but the outputs are ignored
by git. Please let me know if there's anything else I need to do.

I could also use some advice on tests (apologies in advance for my lack
of experience here, my background is not in software dev). Locally I
modified the `Isaac-Velocity-Rough-Anymal-C-v0` task to add the two new
observation functions, and began to train a policy in rsl_rl using the
provided `scripts/reinforcement_learning/rsl_rl/train.py` script, and
both were available to be viewed and appeared to be working correctly. I
tried to run the existing suite of unit tests but it gave me an error I
don't understand (see below). I also started to create a new script
similar to
[`isaaclab/test/envs/check_manager_based_env_anymal_locomotion.py`](https://github.com/isaac-sim/IsaacLab/blob/31f3729035b6e2a37797e84295f0a249352a3f82/source/isaaclab/test/envs/check_manager_based_env_anymal_locomotion.py)
but that would have required a policy trained using the new observation
functions (which I can produce, but wasn't sure if that would be
worthwhile since it wouldn't be available to others).

Output when running `./isaaclab.sh -t`:
```
[INFO] Warm starting the simulation app before running tests.                                                                                                                                                                                                                                                                        
ERROR:root:Error warm starting the app: b'2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 16 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 17 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 18 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 19 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 20 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 21 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 22 belongs to.\n2025-04-17 18:14:17 [429ms] [Error] [omni.platforminfo.plugin] failed to find the package that core 23 belongs to.\nMESA-INTEL: warning: Performance support disabled, consider sysctl dev.i915.perf_stream_paranoid=0\n\n'
```

Cheers.

## Type of change

- New feature (non-breaking change which adds functionality)
- This change requires a documentation update

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation (_maybe_?)
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works (please advise)
- [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

---------

Signed-off-by: TheIndoorDad <[email protected]>
Signed-off-by: Mayank Mittal <[email protected]>
Co-authored-by: Mayank Mittal <[email protected]>
kellyguo11 pushed a commit that referenced this pull request Sep 3, 2026
…tead of an AttributeError from __del__ (#7373)

# Description

When environment construction fails partway through `__init__`, the
destructor emits a *second*,
misleading traceback ahead of the real failure:

```
Exception ignored in: <function ManagerBasedEnv.__del__ at 0x...>
AttributeError: 'ManagerBasedRLEnv' object has no attribute '_is_closed'
```

`ManagerBasedEnv.__del__` (and the `DirectRLEnv` / `DirectMARLEnv`
equivalents) read `self._is_closed`
unconditionally. That attribute is assigned by
`ManagerBasedEnv.__init__`, but a **subclass may run
fallible setup before delegating to it**: `ManagerBasedRLEnv.__init__`
allocates `episode_length_buf`
and `reset_buf` on `cfg.sim.device` before calling `super().__init__()`.
A CUDA OOM, an invalid device,
or a malformed config raises there, leaving `_is_closed` unset.

The original exception still propagates to the caller — it is not
swallowed. But Python cannot raise
out of `__del__`, so it routes the `AttributeError` to
`sys.unraisablehook`, which prints it on
unbuffered stderr. The spurious traceback therefore lands *first*,
naming a different exception type
at a different location, which is what makes the real failure hard to
find.

This defaults the lookup to `True`, so an environment that never
finished initializing is treated as
already closed and needs no teardown. That matches the existing
contract: `_is_closed = True` is
already the first statement of `ManagerBasedEnv.__init__` for exactly
this reason, and genuine
partial-init cleanup is handled explicitly by the `try/except` around
`_init_sim()` that releases the
`SimulationContext` singleton. Applied to all three env classes, which
share an identical destructor.

**Why not move the allocation after `super().__init__()`?** Manager
construction calls every
observation term once to measure its output shape
(`ManagerBase.__init__` -> `_prepare_terms` ->
`term_cfg.func(env)`), and terms such as
`mdp.observations.current_time_s` read
`env.episode_length_buf`. The early allocation was introduced
deliberately in #2332 for that reason.
Guarding the destructor is the change that does not perturb construction
order.

Fixes NVBugs 6604738. Related: 6591313 (`AssetBase.__del__`) and 6311065
(`direct_rl_env.__del__`) —
both fixed, neither covers this path; `AssetBase` uses a different
attribute (`_is_initialized`).

## Type of change

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

## Release backport

- [x] <!-- backport-active-release --> Backport this pull request to the
active release branch after it merges into `develop`

## Validation

`test_env_destructors.py` gains one parametrized case covering a
partially constructed env. Verified it
fails before the fix and passes after:

| | Result |
| --- | --- |
| Without the fix | `3 failed` — `AttributeError` at
`manager_based_env.py:248` |
| With the fix | `14 passed` (11 existing + 3 new) |

```bash
uv run --extra test python -m pytest source/isaaclab/test/envs/test_env_destructors.py -q
```

## Known gap

This guards `__del__` only. `_is_closed` is also read unguarded in
`close()` at
`manager_based_env.py:605`, `direct_rl_env.py:591`,
`direct_marl_env.py:593`,
`manager_based_rl_env.py:358` and `leapp_deployment_env.py:427`, so
`try: env = ManagerBasedRLEnv(cfg) finally: env.close()` still raises. A
follow-up declaring
`_is_closed: bool = True` as a class attribute would cover every read
site at once.

## 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`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] I have added a changelog fragment under
`source/<pkg>/changelog.d/` for every touched package
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
isaaclab-bot Bot pushed a commit that referenced this pull request Sep 3, 2026
…tead of an AttributeError from __del__ (#7373)

# Description

When environment construction fails partway through `__init__`, the
destructor emits a *second*,
misleading traceback ahead of the real failure:

```
Exception ignored in: <function ManagerBasedEnv.__del__ at 0x...>
AttributeError: 'ManagerBasedRLEnv' object has no attribute '_is_closed'
```

`ManagerBasedEnv.__del__` (and the `DirectRLEnv` / `DirectMARLEnv`
equivalents) read `self._is_closed`
unconditionally. That attribute is assigned by
`ManagerBasedEnv.__init__`, but a **subclass may run
fallible setup before delegating to it**: `ManagerBasedRLEnv.__init__`
allocates `episode_length_buf`
and `reset_buf` on `cfg.sim.device` before calling `super().__init__()`.
A CUDA OOM, an invalid device,
or a malformed config raises there, leaving `_is_closed` unset.

The original exception still propagates to the caller — it is not
swallowed. But Python cannot raise
out of `__del__`, so it routes the `AttributeError` to
`sys.unraisablehook`, which prints it on
unbuffered stderr. The spurious traceback therefore lands *first*,
naming a different exception type
at a different location, which is what makes the real failure hard to
find.

This defaults the lookup to `True`, so an environment that never
finished initializing is treated as
already closed and needs no teardown. That matches the existing
contract: `_is_closed = True` is
already the first statement of `ManagerBasedEnv.__init__` for exactly
this reason, and genuine
partial-init cleanup is handled explicitly by the `try/except` around
`_init_sim()` that releases the
`SimulationContext` singleton. Applied to all three env classes, which
share an identical destructor.

**Why not move the allocation after `super().__init__()`?** Manager
construction calls every
observation term once to measure its output shape
(`ManagerBase.__init__` -> `_prepare_terms` ->
`term_cfg.func(env)`), and terms such as
`mdp.observations.current_time_s` read
`env.episode_length_buf`. The early allocation was introduced
deliberately in #2332 for that reason.
Guarding the destructor is the change that does not perturb construction
order.

Fixes NVBugs 6604738. Related: 6591313 (`AssetBase.__del__`) and 6311065
(`direct_rl_env.__del__`) —
both fixed, neither covers this path; `AssetBase` uses a different
attribute (`_is_initialized`).

## Type of change

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

## Release backport

- [x] <!-- backport-active-release --> Backport this pull request to the
active release branch after it merges into `develop`

## Validation

`test_env_destructors.py` gains one parametrized case covering a
partially constructed env. Verified it
fails before the fix and passes after:

| | Result |
| --- | --- |
| Without the fix | `3 failed` — `AttributeError` at
`manager_based_env.py:248` |
| With the fix | `14 passed` (11 existing + 3 new) |

```bash
uv run --extra test python -m pytest source/isaaclab/test/envs/test_env_destructors.py -q
```

## Known gap

This guards `__del__` only. `_is_closed` is also read unguarded in
`close()` at
`manager_based_env.py:605`, `direct_rl_env.py:591`,
`direct_marl_env.py:593`,
`manager_based_rl_env.py:358` and `leapp_deployment_env.py:427`, so
`try: env = ManagerBasedRLEnv(cfg) finally: env.close()` still raises. A
follow-up declaring
`_is_closed: bool = True` as a class attribute would cover every read
site at once.

## 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`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] I have added a changelog fragment under
`source/<pkg>/changelog.d/` for every touched package
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

(cherry picked from commit d7e6341)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants