Repository navigation
Add direct environment reset hook - #6510
AntoineRichard merged 2 commits into
Conversation
Allow direct tasks with backend-native mask reset support to bypass dynamic reset-index compaction while preserving the existing indexed reset behavior by default.
Greptile SummaryThis PR adds a direct-environment reset hook for mask-native reset implementations. The main changes are:
Confidence Score: 4/5The new override path needs fixes before merging. A
source/isaaclab/isaaclab/envs/direct_rl_env.py Important Files Changed
Reviews (1): Last reviewed commit: "Add direct environment reset hook" | Re-trigger Greptile |
| self.extras["final_obs"] = terminal_obs | ||
| self._reset_idx(reset_env_ids) | ||
| reset_env_ids = self._reset_envs_from_buffer() | ||
| if reset_env_ids is not None and len(reset_env_ids) > 0: |
There was a problem hiding this comment.
When a mask-native override resets environments and returns None, this branch skips the post-reset rerender loop even if RTX sensors and reset rerenders are enabled. The later _get_observations() call can then read stale pre-reset sensor buffers for same-step autoreset observations.
There was a problem hiding this comment.
Fixed in b5c94d0. A mask-native override that returns None now raises when RTX reset rerenders are required, preventing the step from returning stale sensor observations. Such overrides must delegate to the default indexed path for this configuration, and the hook docstring now states that restriction.
| def _reset_envs_from_buffer(self) -> torch.Tensor | None: | ||
| """Reset environments marked in the reset buffer. | ||
|
|
||
| The default implementation compacts the reset mask into environment indices. CUDA | ||
| environments synchronize while determining the dynamic output size of | ||
| ``torch.Tensor.nonzero``. Tasks with backend-native mask reset support may | ||
| override this hook and return None to avoid that synchronization. | ||
|
|
||
| Returns: | ||
| Reset environment indices, or None when an override completed reset | ||
| processing without materializing host-visible indices. | ||
| """ |
There was a problem hiding this comment.
Final Observation Becomes Optional
The hook contract allows an override to complete reset processing and return None, but the default hook also owns the compute_final_obs side effect. A native reset override that only performs the mask reset can therefore skip self.extras["final_obs"], so same-step autoreset consumers receive a missing or stale terminal observation.
There was a problem hiding this comment.
Fixed in b5c94d0. A mask-native override that returns None now raises when compute_final_obs is enabled, so terminal-observation capture cannot be silently skipped. Such overrides must delegate to the default indexed path for this configuration, and the hook docstring now states that restriction.
Reject synchronization-free reset overrides when terminal observations or RTX reset rerenders require compact reset indices. This prevents overrides from silently skipping same-step autoreset behavior.
# Description Adds a protected DirectRLEnv reset hook that preserves the existing indexed reset behavior by default while allowing backend-native task implementations to complete reset processing from a device mask without materializing dynamic reset indices on the host. CUDA torch.nonzero compaction requires determining a dynamic output size and can synchronize the stream. The hook isolates that policy decision without changing existing DirectRLEnv task semantics. ManagerBasedRLEnv is intentionally not included. Its scene, event, recorder, curriculum, observation, action, reward, command, and termination reset contracts currently require compact environment IDs, so adding the same hook there would not yet provide a synchronization-free path. This is one focused slice of superseded Draft PR isaac-sim#6509 and is independent of benchmark PR isaac-sim#6474. ## Type of change - New feature (non-breaking protected extension point) ## Validation - ./isaaclab.sh -p tools/changelog/cli.py check develop - ./isaaclab.sh -f before commit - ./isaaclab.sh -f after commit and before push - The source change was exercised by the original focused CPU/CUDA validation before the PR split; new test files are intentionally omitted from this slice. ## Checklist - [x] I have read and understood the contribution guidelines - [x] I have run the pre-commit checks with ./isaaclab.sh --format - [x] Documentation changes are not required for this protected hook - [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 added a changelog fragment for the touched package - [x] My name already exists in CONTRIBUTORS.md
Description
Adds a protected DirectRLEnv reset hook that preserves the existing indexed reset behavior by default while allowing backend-native task implementations to complete reset processing from a device mask without materializing dynamic reset indices on the host.
CUDA torch.nonzero compaction requires determining a dynamic output size and can synchronize the stream. The hook isolates that policy decision without changing existing DirectRLEnv task semantics.
ManagerBasedRLEnv is intentionally not included. Its scene, event, recorder, curriculum, observation, action, reward, command, and termination reset contracts currently require compact environment IDs, so adding the same hook there would not yet provide a synchronization-free path.
This is one focused slice of superseded Draft PR #6509 and is independent of benchmark PR #6474.
Type of change
Validation
Checklist