Skip to content
Open
31 changes: 31 additions & 0 deletions docs/source/api/lab/isaaclab.managers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,40 @@ Curriculum Manager
:members:
:exclude-members: __init__

.. _recorder-capture:

Recorder Manager
----------------

Tasks configure recorder terms to capture the state, controls and other fields their consumers need.
Terms run at pre/post step and reset callbacks; reset callbacks receive slices or indices directly.
Consumers own subsequent processing, replay and learning.

Returning a field path and a batched tensor (or nested dictionary of tensors) retains samples.
For online use without retention, publish the batch on the term and return ``(None, None)``.
Consumers access it through ``env.recorder_manager.get_term(name)`` and copy data before the next capture.
``EXPORT_NONE`` disables file export only; disabling the term removes capture itself.

Fields may have different sample rates. ``buffer_initial_capacity`` sets the initial samples per world
and field; choose it with payload size and episode length in mind. Storage grows without dropping
samples and is reused across resets.

**Observation migration:** RL post-step callbacks run after rewards and terminations, before reset
and observation updates. ``env.obs_buf`` still contains the preceding policy input. Read physical
state from the scene or call ``env.observation_manager.compute_group("recording", update_history=False)``
for current observations. Use a separate noiseless group without history or delay to avoid stale
measurements and additional policy noise draws. History is not advanced, but noise and modifiers still
run. Non-RL environments update their normal observations before post-step capture.

**Storage migration:** ``get_episode(env_id)`` returns an owned tensor snapshot with a leading sample
dimension; reading copies data and may synchronize the device. Modify live recording through
``add_to_episodes`` and ``set_success_to_episodes``, not the snapshot. ``EpisodeData.add()`` and
``pre_export()`` are removed: collect through the manager, or assign completed tensors to
``episode.data``. HDF5 loading and playback keep the same tensor format.

The unused ``RecorderTerm.close(file_path)`` hook is removed. Dataset handlers finalize files;
applications explicitly close any additional resources they own.

.. autoclass:: RecorderManager
:members:
:inherited-members:
Expand Down
9 changes: 5 additions & 4 deletions scripts/imitation_learning/isaaclab_mimic/annotate_demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,16 @@ def annotate_episode_in_manual_mode(

print(f'\tThe episode will be replayed again for re-marking subtask signals for the eef "{eef_name}".\n')

annotated_episode = env.recorder_manager.get_episode(0)
for (
subtask_term_signal_name,
subtask_term_signal_action_index,
) in subtask_term_signal_action_indices.items():
# subtask termination signal is false until subtask is complete, and true afterwards
subtask_signals = torch.ones(len(episode.data["actions"]), dtype=torch.bool)
subtask_signals[:subtask_term_signal_action_index] = False
annotated_episode.add(f"obs/datagen_info/subtask_term_signals/{subtask_term_signal_name}", subtask_signals)
env.recorder_manager.add_to_episodes(
f"obs/datagen_info/subtask_term_signals/{subtask_term_signal_name}", subtask_signals.unsqueeze(0), [0]
)

if args_cli.annotate_subtask_start_signals:
for (
Expand All @@ -529,8 +530,8 @@ def annotate_episode_in_manual_mode(
) in subtask_start_signal_action_indices.items():
subtask_signals = torch.ones(len(episode.data["actions"]), dtype=torch.bool)
subtask_signals[:subtask_start_signal_action_index] = False
annotated_episode.add(
f"obs/datagen_info/subtask_start_signals/{subtask_start_signal_name}", subtask_signals
env.recorder_manager.add_to_episodes(
f"obs/datagen_info/subtask_start_signals/{subtask_start_signal_name}", subtask_signals.unsqueeze(0), [0]
)

return True
Expand Down
22 changes: 22 additions & 0 deletions source/isaaclab/changelog.d/recorder-capture.changed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
* Replaced per-world recorder episode containers with batched field allocations and
independent insertion indices, reusing storage across resets and growing without dropping samples.
* Added :meth:`~isaaclab.managers.RecorderManager.get_term` for direct access to captured batches.
* Preserve slices through recorder reset callbacks and normalize Python sequences to lists so tuple
environment indices work for capture, reset and success updates.
* **Breaking:** Removed the implicit observation computation before RL post-step recorder callbacks.
Physical capture no longer consumes extra observation noise. Custom terms needing observations
of the completed transition must call ``env.observation_manager.compute_group(name, update_history=False)``
explicitly; ``env.obs_buf`` still contains the preceding policy input. Use a noiseless group without
history or delay for current measurements that do not consume policy noise draws.
* **Breaking:** Changed :meth:`~isaaclab.managers.RecorderManager.get_episode` to return an owned
snapshot with tensor leaves. To update live recording, use ``add_to_episodes`` and
``set_success_to_episodes``; do not mutate the snapshot. Set ``buffer_initial_capacity``
to control the initial allocation per field.
* **Breaking:** Removed ``EpisodeData.add()`` and ``pre_export()``. Collection now belongs to
``RecorderManager.add_to_episodes()``; assign nested tensors with leading sample dimensions
to ``EpisodeData.data`` when constructing an episode directly. Playback and HDF5 loading remain supported.
* **Breaking:** Removed the unused ``RecorderTerm.close(file_path)`` hook. Dataset handlers own
file finalization; applications must explicitly close any additional resources they own.

* Documented independent capture, retention and export choices, with task-selected schemas and
consumer-owned processing. Core recorder storage remains independent of task and learning packages.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Kept retained recorder allocations writable after leaving PyTorch inference mode, including
grown buffers and schema changes, so subsequent reset and export can finalize those episodes.
5 changes: 1 addition & 4 deletions source/isaaclab/isaaclab/envs/manager_based_rl_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,7 @@ def step(self, action: torch.Tensor) -> VecEnvStepReturn:
self.reset_time_outs = self.termination_manager.time_outs
self.reward_buf = self.reward_manager.compute(dt=self.step_dt)

if len(self.recorder_manager.active_terms) > 0:
# update observations for recording if needed
self.obs_buf = self.observation_manager.compute()
self.recorder_manager.record_post_step()
self.recorder_manager.record_post_step()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this might be easy to miss. the assumption for pre and post seems different that pre obs is fresh but post is stale. Might prefer to have the behavior aligned to avoid problem. Or a cfg level switch to opt in/out

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

same as above, i think recoder manager put a bit too many hooks into managers, a better appoach would be instead of we expose the hook, we just let user compose the step function, and they can add the record in wherever they think its appropriate. this pr will just mostly be speed up

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.

🟡 Warning · Compatibility — Post-step recorders now see stale observations

Removing the refresh means existing post-step terms reading env.obs_buf silently record the previous step's observations. Gate the new timing behind an opt-in or deprecation cycle covering both env packages.


# -- reset envs that terminated/timed-out and log the episode information
reset_env_ids = self.reset_buf.nonzero(as_tuple=False).squeeze(-1).int()
Expand Down
2 changes: 1 addition & 1 deletion source/isaaclab/isaaclab/envs/mdp/recorders/recorders.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class InitialStateRecorder(RecorderTerm):
"""Recorder term that records the initial state of the environment after reset."""

def record_post_reset(self, env_ids: Sequence[int] | None):
def record_post_reset(self, env_ids: Sequence[int] | slice | None):
def extract_env_ids_values(value):
nonlocal env_ids
if isinstance(value, dict):
Expand Down
Loading
Loading