Repository navigation
Record custom per-episode values, including values tracked every step - #1468
cvolkcvolk merged 55 commits into
Conversation
5891872 to
61e7a64
Compare
39964e0 to
2e5910b
Compare
2e5910b to
1722b54
Compare
61e7a64 to
d6326cc
Compare
3c9f1da to
64d9ec8
Compare
f96fd97 to
44d41b2
Compare
64d9ec8 to
e48c10e
Compare
[Medium impact] The PR changes the shared episode-results contract used by Arena evaluations. The PR appears safe to merge, with a non-blocking fix recommended for deferred class-based terms. Findings
SummaryTasks and environments can now add named values to each episode’s results, including values collected across its steps.
One non-blocking issue remains: the hook check cannot read a class whose creation is deferred until simulation starts. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
T[Task terms] --> B[Environment builder]
E[Environment terms] --> B
B --> M[Episode recorder manager]
S[Control step] --> U[Update term state]
U --> M
F[Episode finishes] --> M
M --> J[Core fields and named term results in JSONL]
R[New episode starts] --> C[Clear selected term state]
Reviews (1) · Last reviewed commit: "Move per-episode recording docs into the..." · Reviewed by Greptile |
🤖 Isaac Lab-Arena Review BotSummaryThis PR lets tasks add episode recorder terms through Findings🔵 Improvement: docs/pages/arena_in_your_repo/external_tasks_and_embodiments.rst:85: The new section and the task concepts section each point to the other for 🔵 Improvement: isaaclab_arena/recording/episode_recorder_manager.py:125: 🔵 Improvement: isaaclab_arena/tests/test_episode_recorder.py:60: This is a copy of the example's Test Coverage and CI CostFor this commit, CI skipped the "Run tests" and "Run tests with subprocess" jobs; only pre-commit ran. So the test suite hasn't run in CI on these changes. The only test evidence I could see is the local runs listed in the PR description. In VerdictMinor fixes needed |
44d41b2 to
70560c0
Compare
28c83de to
8f712b4
Compare
d51e767 to
335e28a
Compare
| return make_configclass("TerminationsCfg", termination_fields)() | ||
|
|
||
| def _build_episode_recorders_cfg(self, extra_terms: dict[str, EpisodeRecorderTermCfg] | None = None) -> object: | ||
| def _build_episode_recorders_cfg(self, environment_terms: dict[str, EpisodeRecorderTermCfg]) -> object: |
There was a problem hiding this comment.
Are recorders only come from a Python environment?
Tasks can't add them and graph or Experiment YAML has no field for them, so agent-generated environments can't record custom values.
Could TaskBase get a hook for default recorders, and could YAML add them by name?
There was a problem hiding this comment.
EpisodeRecorderTerm only adds post_step() to Isaac Lab's ManagerTermBase, so a class term is a term that updates every step; a value that only needs the end of the episode is a function term. Mark post_step() and __call__ abstract, as Isaac Lab does for ActionTerm and CommandTerm. A missing or misspelled method now fails when the term is created instead of being skipped without an error. The manager no longer checks which class terms override post_step(): it never changed whether the per-step hook is added, because no env without task progress has a class term that leaves it out. post_step() and has_post_step_terms use all class terms. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
post_step(env) gave a class term two handles to the same env, the argument and self._env. reset(env_ids) and Isaac Lab's recorder term hooks use self._env, so post_step() takes no argument now. Only __call__ takes env, because function and class terms share that call. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
The comment said the hook is added whenever task progress or an episode recorder term needs per-step updates. In evaluation runs the success term already advances task progress every step, so task progress needs the hook only when that term is missing, as in Isaac Lab's replay_demos.py. Say so, and that the hook makes Isaac Lab compute the observations twice per step. Both TODOs now also say that Isaac Lab #8822 is on Isaac Lab main, not on the release/3.0.0 branch Arena pins, so the hook stays until Arena moves to an Isaac Lab release that includes it. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
No task returned terms from TaskBase.get_episode_recorder_terms(); only unit tests used it. The example adds both of its terms through IsaacLabArenaEnvironment(episode_recorder_terms=...), because its task does not know the object. Two routes for the same thing made it unclear which to use. Remove get_episode_recorder_terms(), the composite task's _subtask_<i> forwarding, and the builder's task_terms argument. Adding the task hook back later breaks nobody; removing it after a release would. The "Recording your own values" docs move from the task concepts page to the environment concepts page and show the environment route. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Terms had to return a dict because their outputs used to be merged into
the top level of the record. Each term now has its own key, so the rule
only made a single value read "object_peak_speed": {"peak_speed": 0.83}
and kept it from being a sensitivity analysis outcome, which reads
top-level numbers and booleans.
A term now returns any JSON value, such as a number or a dict. NaN and
infinity are still rejected. Both example terms return a plain number.
Signed-off-by: Clemens Volk <cvolk@nvidia.com>
After a physics blow-up, a term like ObjectPeakSpeed returns NaN. The manager raised inside env.step(), which failed the Run and stopped the remaining Runs unless continue_on_error was set. A NaN from an unstable simulation is data about that episode, not a bug in the term. The manager now writes each NaN or infinite float as null and warns with the term name, env id, and episode. An output that is not JSON at all is still an error, because that is a bug in the term. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
a3fc94b to
bcb641f
Compare
335e28a to
9bf4a95
Compare
ObjectPeakSpeed lived in the advanced external environment example. The follow-up PR has Arena's own tasks record it, so it belongs next to the other recording code. It moves to isaaclab_arena/recording/object_terms.py, the example imports it, and the docs include it from there. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
The environment concepts page repeated, in a long section, what the external tasks page shows with a worked example. Remove the section and keep the external tasks page as the one place: it gets the anchor the other pages link to and two sentences on what the episode results hold, what a term returns, and that NaN is written as null. The author-environment skill points there. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
isaaclab_arena/terms is where Arena keeps ready-made terms that tasks and environments pick from, such as events.py and the HDF5 recorder terms in recorders.py. The episode recorder terms are the same kind of library, so object_terms.py in the recording package becomes isaaclab_arena/terms/episode_recorders.py. The recording package keeps the manager and the built-in terms that every episode records. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
#1456 deletes ObjectPeakSpeedExceededRateMetric, which the goal-pose, gear-insertion, assembly, and place-upright tasks used: it read the object's velocity at every step back from the HDF5 file and counted an episode if the speed ever went above 0.5 m/s. ObjectPeakSpeed, moved into isaaclab_arena.terms in #1468, records that peak speed per episode. The four tasks return it as object_peak_speed for the object they used for the metric. The old rate is the share of episodes above 0.5. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Keep one short paragraph on the external tasks page that names the example's two terms and shows what a line holds, and drop the two literalinclude blocks. The authoring skill points to the example. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
object's position at every step back from the HDF5 file. Its measurement moves into ObjectDisplacement, a class-based episode recorder term: post_step() tracks the largest distance the object got from where it was after the episode's first step, and the episode's line records that distance in metres. The definition stays the same: motion during the first control step does not count, an object moved and put back still counts, and deformables use their mean node position. The old rate is the share of episodes whose distance is above 0.02 m, and a different threshold can be applied later without a new run. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
way to add their own: a value that belongs to the task, like how far the picked object moved, would have to be added by every environment that uses the task. #1456 deletes the task-level metrics that used to do this. TaskBase.get_episode_recorder_terms() is back, along with the composite task's _subtask_<i> naming and the builder's task_terms argument. PickAndPlaceTask uses it to record object_displacement for its picked object, so every pick-and-place episode line has it. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
close-door tasks used: it read the door's openness at every step back from the HDF5 file and counted an episode if the openness ever got more than min_openness_change away from the reset openness. OpennessChange is a class-based episode recorder term that records the largest change of the openness from the reset openness, as a fraction of the joint range. RotateRevoluteJointTask returns it as openness_change, so every open-door and close-door episode line has it. The old rate is the share of episodes above 0.05. Without a reset openness, the reference is 0, where the reset event leaves the joint; the old metric could not handle that case. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
#1456 deletes ObjectPeakSpeedExceededRateMetric, which the goal-pose, gear-insertion, assembly, and place-upright tasks used: it read the object's velocity at every step back from the HDF5 file and counted an episode if the speed ever went above 0.5 m/s. ObjectPeakSpeed, moved into isaaclab_arena.terms in #1468, records that peak speed per episode. The four tasks return it as object_peak_speed for the object they used for the metric. The old rate is the share of episodes above 0.5. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
OpenDoorTask's success check and the openness_change term both measure from the reset openness, and both repeated the fallback to 0 when no reset percentage is given. RotateRevoluteJointTask now resolves it once as reset_openness, and both read that attribute. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Tasks now add terms that environment authors do not see. An environment that adds its own object_displacement while using PickAndPlaceTask got "is used more than once", although it defined the name once. The message now says the name is already used by a built-in or task term. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
torch, pytest and SimpleNamespace do not need the simulator; only the isaaclab_arena.recording imports stay inside the test functions. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
OpennessChange and its openness_change field did not say what moved, and did not point back to revolute_joint_moved_rate, the metric they replace. Rename them to RevoluteJointMovement and revolute_joint_movement, matching object_displacement and object_peak_speed, which already follow the names of their metrics. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Keep one sentence about task terms on the external tasks page and the composite task design note, and drop the task concepts page sentence. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
RotateRevoluteJointTask stored the reset openness twice: as given and with None resolved to 0. The reset event now gets the resolved value, which resets the joint the same way, since rotate_revolute_joint() defaults to 0. Nothing passes None to RotateRevoluteJointEventCfg anymore, so its None branch goes too. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Env 0's first reading equalled the reset openness, so a term that measured from the first reading would also have passed. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
TaskBase.get_episode_recorder_terms() documents the task route, and PickAndPlaceTask shows it in use. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
781aa22
into
cvolk/refactor/delete-hdf5-metrics
#1456 deletes ObjectPeakSpeedExceededRateMetric, which the goal-pose, gear-insertion, assembly, and place-upright tasks used: it read the object's velocity at every step back from the HDF5 file and counted an episode if the speed ever went above 0.5 m/s. ObjectPeakSpeed, moved into isaaclab_arena.terms in #1468, records that peak speed per episode. The four tasks return it as object_peak_speed for the object they used for the metric. The old rate is the share of episodes above 0.5. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
…ts (#1456) Remove the HDF5 metrics and record values about each episode in the episode results instead. Environments and tasks add episode recorder terms, the tasks that had metrics record those values again, and the experiment runner's Run table shows each Run's success rate. This PR combines three reviewed PRs: this one, #1468 and #1739. Their review discussions stay there. ## Why this change? Arena kept results about each episode in two places. The episode results hold one JSON line per episode, which the report, the plots, the KPI exporters and the OSMO output read. The metrics saved data into an HDF5 file during the run, only to print a few numbers afterwards. So success was stored twice, every evaluation wrote an HDF5 file, and a metric took four definitions. The episode results are now the one place for values about an episode, and HDF5 files hold only trajectories and demonstrations. ## What changes? - **Metrics removed:** `isaaclab_arena.metrics`, `TaskBase.get_metrics()`, `env.compute_metrics()` and `ArenaRunResult.metrics`. Without trajectory recording, no HDF5 file is written. - **Run table:** `experiment_runner.py` adds `Recorded Episodes`, `Success Rate` and, for composite tasks, `Subtask Success Rates` columns, computed from the episode results. They replace the printed metrics. - **Episode recorder terms:** an environment adds terms through `episode_recorder_terms`, a task through `get_episode_recorder_terms()`. A term is a function that runs when the episode ends, or an `EpisodeRecorderTerm` class that also updates its value in `post_step()` after every control step. Its result goes into the episode line under the term's name. **Ported task metrics:** | Metric on `main` | Now recorded per episode as | |---|---| | `ObjectDisplacedRateMetric` (`PickAndPlaceTask`) | `object_displacement`, in m | | `RevoluteJointMovedRateMetric` (`OpenDoorTask`, `CloseDoorTask`) | `revolute_joint_movement`, as a fraction of the joint range | | `ObjectPeakSpeedExceededRateMetric` (`GoalPoseTask`, `GearInsertionTask`, `AssemblyTask`, `PlaceUprightTask`) | `object_peak_speed`, in m/s | Arena records the values but no longer computes the old rates. A shared function for them will be added once something in Arena needs one. Breaking changes: - Tasks must drop `get_metrics()`, and code that called `env.compute_metrics()` reads the episode results instead. The metric rates and the policy runner's success rate are no longer printed. - An environment term's result moves under the term's name in the episode line. A class-based term must derive from `EpisodeRecorderTerm` and implement `post_step()`, `reset()` and `__call__(env, env_id)`; it reads its params in `__init__`. - `CoreEpisodeRecorderTermCfg` and `ProgressTrackingRecorder` are removed. The recorder term Arena adds is now `post_step_hook` (`PostStepHookRecorder`), which can go once Arena's Isaac Lab includes isaac-sim/IsaacLab#8822. Three figures still show a "Metrics" box and need to be redrawn: `open_door_task.png`, `arena_env_builder.png` and `isaac_lab_arena_arch_overview.png`. ## Usage example Before: ```python class PickAndPlaceTask(TaskBase): def get_metrics(self) -> list[MetricBase]: return [SuccessRateMetric(), ObjectDisplacedRateMetric(self.pick_up_object)] # Printed as: Metrics: {'num_episodes': 20, 'success_rate': 0.85, 'object_displaced_rate': 0.9} ``` After: ```python class PickAndPlaceTask(TaskBase): def get_episode_recorder_terms(self) -> dict[str, EpisodeRecorderTermCfg]: return { "object_displacement": EpisodeRecorderTermCfg( func=ObjectDisplacement, params={"object_name": self.pick_up_object.name} ) } ``` Each episode line then holds `"object_displacement": 0.031`. The old rate is `sum(record["object_displacement"] > 0.02 for record in records) / len(records)`. ## Validation After combining the three PRs and rebasing onto `main` (26e069e), the 23 related test files pass locally on the GPU (226 tests). See #1468 and #1739 for the earlier runs. Not run: the full test suite and evaluations with real policies. --------- Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Let environments record their own values about each episode, including values that build up while the episode runs. An environment adds an episode recorder term, and each episode's line in the episode results holds the term's output under its name.
This PR is based on #1456, which removes the HDF5 metrics.
Why this change?
The episode results (
episode_results_*.jsonl, one line per finished episode) are what the HTML report, the plots, the KPI exporters and the sensitivity analysis read. With #1456 they become the one place for everything about an episode, and HDF5 files only hold trajectories and demonstrations. The idea is to store raw per-episode values there and let users, or their agents, compute whatever metric they need, instead of Arena predefining metrics.Today that line cannot hold a value that builds up during the episode:
IsaacLabArenaEnvironment(episode_recorder_terms=...), but only with a function that runs when the episode ends. A value that builds up during the episode, such as an object's peak speed or how high it was lifted, cannot be recorded at all.MetricBaseclass) and an HDF5 file that was read back after the run. Users who needed their own measurements, such as how far an object was pulled out, ended up combiningMetricBase, progress tracking and recorder hooks.success, and two terms returning the same key failed only when the first episode ended.What changes?
IsaacLabArenaEnvironment(episode_recorder_terms=...), as onmain. No task needs its own terms today, soTaskBasegets no hook for them; one can be added when a task needs it.EpisodeRecorderTerm. It keeps one value per environment, updates it inpost_step()after every control step, clears it inreset()when an episode starts, and returns the episode's result from__call__()when the episode ends.post_step()and__call__()are abstract, so a missing or misspelled method fails when the term is created. A plain function still works for a value that can be read at the end.EpisodeRecorderManagerwrites the core fields (success,episode_length, and so on) itself, at the top level as before. A duplicate term name fails when the environment is built. A term named like a core field would overwrite it, so it fails when the first episode is recorded. A term returns any JSON value, such as a number or a dict, orNoneto leave itself out. A NaN or infinite value, for example after a physics blow-up, is written asnullwith a warning that names the term, instead of failing the Run.ArenaRecorderManager.record_post_step(). The pinned Isaac Lab calls it only while a recorder term is active, so Arena addsPostStepHookRecorder, a term that records nothing, whenever there is task progress or a class-based episode recorder term. It replacesProgressTrackingRecorder, which did the same and also published the progress snapshot; the environment now publishesenv.extras["progress_tracking"]itself when it advances task progress. Isaac Lab #8822 callsrecord_post_step()every step, so the hook can go once Arena moves to an Isaac Lab release that includes it; it is on Isaac Labmain, not on therelease/3.0.0branch Arena pins.test_post_step_hook_recorder_is_still_neededfails at that point and lists what to remove.isaaclab_arena_examples/external_environments/advanced.py) records two values per episode throughepisode_recorder_terms:record_object_final_height, a function term it defines, andObjectPeakSpeed, a class term inisaaclab_arena/terms/episode_recorders.py, next to Arena's other ready-made terms. Theauthor-environmentskill points to the example for per-episode values.This PR adds no terms to Arena's tasks.
object_peak_speed_exceeded_rateandrevolute_joint_moved_rate, removed in #1456, are not recorded by default; the example records an object's peak speed withObjectPeakSpeed.Episode recorder terms and the tracked events from #1457 do different jobs. A tracked event records when a sequence of predicates happened, inside the
progressfield. An episode recorder term records a value of your own under its name.Breaking changes:
IsaacLabArenaEnvironment(episode_recorder_terms=...)moves from the top level of the line to under the term's name. A term that returns a single number or boolean can still be a sensitivity analysis--outcome, under the term's name; a term that returns a dict cannot.null, with a warning.EpisodeRecorderTermand implementpost_step()and__call__().coreterm (CoreEpisodeRecorderTermCfg) is removed. The manager writes the core fields.ProgressTrackingRecorderandProgressTrackingRecorderCfgare removed. The recorder term Arena adds is now namedpost_step_hook.env.extras["progress_tracking"]keeps its content.Not included: rates or averages of custom values in the report and the console table, and adding terms from the Experiment YAML.
Usage example
The interface in short:
funcis a class derived fromEpisodeRecorderTerm, or a plain functionfunc(env, env_id, ...)that runs once when the episode ends.Before, recording whether the object moved took a metric: an Isaac Lab recorder term that saved the object's velocity at every step into an HDF5 file, its cfg class, a function that computed the rate from the file after the run, and a
MetricBaseclass that tied them together. The task listed it:After,
ObjectPeakSpeed, the class term the example uses, follows the episode and returns one result per episode:The value is updated in place (
out=...) because Arena may run steps insidetorch.inference_mode()and reset outside it.Each line of the episode results then holds the term's result under its name (some fields left out):
{"job_name": "pnp_pi0", "env_id": 0, "episode_in_env": 3, "success": true, "progress": {...}, "object_peak_speed": 0.83}The old rate is a comparison over the lines, and the threshold can change without running the evaluation again:
Validation
Rebased onto the rebased #1456, which is on
main(46c7699).pre-commitpasses. The docs build passes withsphinx-build -W.test_composite_task_base,test_sequential_composite_task,test_object_settling,test_place_upright_task,test_gear_insertion_task,test_open_door,test_close_door,test_external_environment,test_rollout_policy, andtest_trajectory_recording.test_gear_insertion_recording(Newton) andtest_sensitivity_analysis.test_completion_criteria_tracking,test_task_success_from_progress,test_true_for_consecutive_steps,test_tracked_events,test_temporal_predicate_composition), the recorder tests (test_episode_recorder,test_episode_recorder_manager,test_arena_env_builder_episode_recorder_terms,test_recorder_dataset_export,test_arena_recorder_manager,test_episode_limit,test_isaaclab_demo_success,test_isaaclab_interop,test_record_demos), and the task and environment tests that read the published progress (test_composite_task_base,test_sequential_composite_task,test_open_door,test_close_door,test_composite_open_door,test_sequential_open_door,test_object_settling,test_object_on_termination,test_object_control_force_actions,test_object_control_runner,test_deformable_object,test_place_upright_task,test_gear_insertion_task,test_gear_insertion_environment). Intest_gear_insertion_environment, the camera test fails to create its render graph when the whole file runs in one Isaac Sim process; it passes on its own, as it did before these commits.test_external_environmentpasses (3 tests), and a 2-episode zero-action run of the advanced example writes"object_peak_speed": {"peak_speed": ...}on each line.ObjectPeakSpeedand requires a moving box, the docs include the example terms), 27 tests pass intest_episode_recorder_manager(with a new test that builds the manager before the simulation plays; it fails withAttributeErroron the previous code),test_episode_recorder,test_external_environment,test_arena_recorder_manager,test_episode_limit, andtest_arena_env_builder_episode_recorder_terms. The docs build passes.CORE_FIELD_NAMESwith the check at record time, 28 tests pass in the same six files, with a new stand-in test for the replay source record index, andtest_experiment_runnerpasses (14 tests).post_step()and__call__(),post_step(self), terms only from the environment, any JSON value, NaN written asnull), 108 tests pass in 16 files, covering the recorder, task, progress, demo-tool and sensitivity analysis tests, andtest_experiment_runnerpasses (14 tests).pre-commitand the docs build pass.pre-commitpasses, and 169 tests pass in the recorder, task, progress, demo-tool, sensitivity analysis and Run table tests, plustest_experiment_runner(14 tests).