Skip to content

Adds reward groups to the reward manager - #729

Closed
Dhoeller19 wants to merge 2 commits into
mainfrom
feature/reward_groups
Closed

Dhoeller19 wants to merge 2 commits into
mainfrom
feature/reward_groups

Conversation

@Dhoeller19

Copy link
Copy Markdown

Description

This MR ports the code from @lorenwel and adds the concept of reward groups to the code. In the manager-based workflow, the reward terms can now be grouped together, where the computations for different groups can be done independently. This is useful in multi-agents scenarios, where you have to compute different rewards for different agents.

The reward manager still supports the previous case where no groups are defined.

Type of change

  • New feature (non-breaking change which adds functionality)

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

@lorenwel lorenwel mentioned this pull request Jul 25, 2024
3 of 7 tasks
@lorenwel

Copy link
Copy Markdown
Contributor

Thanks for porting and cleaning this up.
I just checked this PR against our internal up-to-date version of #221 and just judging by the git diff, there doesn't seem to be a functional difference.
So all good from my side.

Comment on lines +267 to +269
"""


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.

Suggested change
"""
"""
pass

Comment on lines 45 to +48

For backwards compatibility, the reward manager also supports the old configuration format without
groups.

@Mayankm96 Mayankm96 Jul 26, 2024 •

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.

Better to keep the note in a separate directive.

Suggested change
For backwards compatibility, the reward manager also supports the old configuration format without
groups.
.. note::
For backwards compatibility, the reward manager also supports the old configuration format without
groups. In this case, the :meth:`compute` returns a tensor instead of a dictionary of tensors.


Returns:
The net reward signal of shape (num_envs,).
A dictionary containing the net reward signal of shape (num_envs,) for each group.

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.

We return a tensor when user doesn't set things up. We should throw proper deprecation warnings to the user so that they adapt.

Both the docstring here in the return and also in the class docs need to be fixed.

Comment on lines +228 to 235
def set_term_cfg(self, term_name: str, cfg: RewardTermCfg, group_name: str = DEFAULT_GROUP_NAME):
"""Sets the configuration of the specified term into the manager.

Args:
group_name: The name of the reward group.
term_name: The name of the reward term.
cfg: The configuration for the reward term.

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.

Ordering of the args don't match.

@Mayankm96 Mayankm96 left a comment

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.

Minor comments related to breaking changes. Also need to adapt the unit tests.

Comment on lines +251 to 252
group_name: The name of the reward group.
term_name: The name of the reward term.

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.

Same here.

def active_terms(self) -> list[str]:
"""Name of active reward terms."""
return self._term_names
def active_terms(self) -> dict[str, list[str]]:

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.

Breaking? This should return a list if it is only one group?

from omni.isaac.lab.envs import ManagerBasedRLEnv


DEFAULT_GROUP_NAME = "reward"

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.

If this is only for internal usage in the class then I suggest marking it with an underscore.

@Mayankm96 Mayankm96 added the enhancement New feature or request label Aug 2, 2024
@pascal-roth pascal-roth added the dev team Issue or pull request created by the dev team label Aug 28, 2024
@bikcrum

bikcrum commented Feb 21, 2025 •

Copy link
Copy Markdown
Contributor

@lorenwel @Mayankm96 @jsmith-bdai

I appreciate the effort in implementing this feature. I’ve been using it for my manager-based multi-agent setup, and it has been quite helpful.

I have a suggestion: it might be beneficial to extend this to the termination manager as well. Specifically, accessing termination_manager.terminated and termination_manager.timeout should return a dictionary. While timeout will remain the same across agents due to a single episode length, the terminated signal is crucial for identifying which specific agent or robot has met all termination conditions.

This change would enable computing returns more accurately. Currently, a single tensor indicates termination for all agents, even if only one agent has terminated, introducing potential bias in return calculations. However, this wouldn’t require modifying the logic for computing done in the manager-based RL environment, it would still be true if at least one agent has been terminated.

Overall, this feature would be particularly useful for correctly computing returns in multi-agent scenarios. Let me know your thoughts!

@kellyguo11 kellyguo11 closed this Aug 27, 2025
@kellyguo11
kellyguo11 deleted the feature/reward_groups branch August 27, 2025 00:19

@isaaclab-review-bot isaaclab-review-bot Bot left a comment •

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.

Re-review after force push (583a264)

Previous bot review (4380685018) was lost during force push. Posting fresh findings that complement @Mayankm96's existing feedback.

Issues Found

  1. Variable shadowing in _prepare_terms — The inner loop reuses group_cfg_items as a variable name (line ~302), which shadows the outer for group_name, group_cfg in group_cfg_items: loop iterator. While Python's for semantics mean this won't cause a runtime bug (the iterator is already captured), it's confusing and a maintenance hazard. Consider renaming the inner variable to term_cfg_items or inner_cfg_items.

  2. has_groups detection may include dunder/internal attrs — all(isinstance(cfg, RewardGroupCfg) for _, cfg in cfg_items) iterates over __dict__.items() which for configclass objects could include internal attributes. If any non-RewardGroupCfg internal attr is present, has_groups will be False even when the user intended groups. Consider filtering to exclude items starting with _.

  3. Logging key change is a silent breaking change — "Episode Reward/" → "Episode_Reward/" (underscore vs space). This will break downstream dashboards/plotting scripts that key on the old format. Either keep the old format for the non-grouped case, or document this explicitly as a breaking change.

Minor Nits (non-blocking)

  • The compute() return type annotation dict[str, torch.Tensor] | torch.Tensor is correct but consider a @overload pair for better type-checker support.
  • Nice work on the backwards compatibility path — the has_groups toggle is a clean approach.

Update (583a264): No new commits since last review. PR is now closed. Previous concerns (variable shadowing, has_groups detection, logging key change) remain as noted above — no further action needed from the bot.


Update (2026-06-08): Re-review triggered for commit 3e67c1cb but the PR HEAD is still at 583a264 (the previously reviewed SHA). The PR remains closed. No new changes to review.


Update (2026-06-08, commit 6699cf71): Re-review triggered but the referenced commit (6699cf71) does not exist in this repository. PR HEAD remains at 583a264 and the PR is still closed (not merged). No new changes to review.


Update (2026-06-08, commit 5447928b): Re-review triggered but the referenced commit (5447928b) does not exist on this PR. PR HEAD remains at 583a264 and the PR is still closed. No new changes to review.


Update (2026-06-08, commit 9eea5fc2): Re-review triggered but the referenced commit (9eea5fc2) does not exist on this PR. PR HEAD remains at 583a264 and the PR is still closed (not merged). No new changes to review.


Update (2026-06-08, commit 36b993c4): Re-review triggered but the referenced commit (36b993c45b0e6133a90b1dfd404ab119ddf54947) does not exist in this repository. PR HEAD remains at 583a264 and the PR is still closed (not merged). No new changes to review.


Update (2026-06-10, commit 89cdc1be): Re-review triggered but the referenced commit (89cdc1be6d3d3d3b7dcc7ec8f5d5139e7d0c8500) does not exist in this repository. PR HEAD remains at 583a264 and the PR is still closed (not merged). No new changes to review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev team Issue or pull request created by the dev team enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants