From fc6042f3e6695d13906e0791356425e3e990442a Mon Sep 17 00:00:00 2001 From: Mayank Mittal <12863862+Mayankm96@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:36:36 +0100 Subject: [PATCH] Fixes order of logging metrics and sampling commands in command manager (#1352) # Description In the command manager, we were logging the metrics after resampling the commands. This leads to incorrect logging of metrics when inside the `resample` call, the metrics tensors get reset. This MR fixes the order to make sure the bug doesn't happen. ## 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` - [x] 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: Kelly Guo Co-authored-by: Kelly Guo Co-authored-by: Kelly Guo --- .../extensions/omni.isaac.lab/config/extension.toml | 2 +- source/extensions/omni.isaac.lab/docs/CHANGELOG.rst | 9 +++++++++ .../omni/isaac/lab/managers/command_manager.py | 13 ++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/source/extensions/omni.isaac.lab/config/extension.toml b/source/extensions/omni.isaac.lab/config/extension.toml index 2adec264fa..4b44b9a4bd 100644 --- a/source/extensions/omni.isaac.lab/config/extension.toml +++ b/source/extensions/omni.isaac.lab/config/extension.toml @@ -1,7 +1,7 @@ [package] # Note: Semantic Versioning is used: https://semver.org/ -version = "0.29.2" +version = "0.29.3" # Description title = "Isaac Lab framework for Robot Learning" diff --git a/source/extensions/omni.isaac.lab/docs/CHANGELOG.rst b/source/extensions/omni.isaac.lab/docs/CHANGELOG.rst index 9265c744bd..0dfdb83c2e 100644 --- a/source/extensions/omni.isaac.lab/docs/CHANGELOG.rst +++ b/source/extensions/omni.isaac.lab/docs/CHANGELOG.rst @@ -1,6 +1,15 @@ Changelog --------- +0.29.3 (2024-12-16) +~~~~~~~~~~~~~~~~~~~ + +Fixed +^^^^^ + +* Fixed ordering of logging and resamping in the command manager, where we were logging the metrics after resampling the commands. This leads to incorrect logging of metrics when inside the resample call, the metrics tensors get reset. + + 0.29.2 (2024-12-16) ~~~~~~~~~~~~~~~~~~~ diff --git a/source/extensions/omni.isaac.lab/omni/isaac/lab/managers/command_manager.py b/source/extensions/omni.isaac.lab/omni/isaac/lab/managers/command_manager.py index 0c50e7a00d..2e1a414ba0 100644 --- a/source/extensions/omni.isaac.lab/omni/isaac/lab/managers/command_manager.py +++ b/source/extensions/omni.isaac.lab/omni/isaac/lab/managers/command_manager.py @@ -132,10 +132,7 @@ def reset(self, env_ids: Sequence[int] | None = None) -> dict[str, float]: # resolve the environment IDs if env_ids is None: env_ids = slice(None) - # set the command counter to zero - self.command_counter[env_ids] = 0 - # resample the command - self._resample(env_ids) + # add logging metrics extras = {} for metric_name, metric_value in self.metrics.items(): @@ -143,6 +140,12 @@ def reset(self, env_ids: Sequence[int] | None = None) -> dict[str, float]: extras[metric_name] = torch.mean(metric_value[env_ids]).item() # reset the metric value metric_value[env_ids] = 0.0 + + # set the command counter to zero + self.command_counter[env_ids] = 0 + # resample the command + self._resample(env_ids) + return extras def compute(self, dt: float): @@ -175,8 +178,8 @@ def _resample(self, env_ids: Sequence[int]): Args: env_ids: The list of environment IDs to resample. """ - # resample the time left before resampling if len(env_ids) != 0: + # resample the time left before resampling self.time_left[env_ids] = self.time_left[env_ids].uniform_(*self.cfg.resampling_time_range) # increment the command counter self.command_counter[env_ids] += 1