Skip to content

Commit 10b2289

Browse files
authored
Enable metrics in policy_runner script (#103)
## Summary Policy runner reports metrics results depending on the task ## Detailed description - Fix data_class assertion when importing path differs - Add compute_metric() in to policy_runner.py
1 parent 2b917b8 commit 10b2289

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

isaac_arena/examples/policy_runner.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,19 @@ def main():
3838
# app. Given current SimulationAppContext setup, use lazy import to handle policy-related
3939
# deps inside create_policy() function to bringup sim app.
4040
policy, num_steps = create_policy(args_cli)
41+
# NOTE(xinjieyao, 2025-10-07): lazy import to prevent app stalling caused by omni.kit
42+
from isaac_arena.metrics.metrics import compute_metrics
4143

4244
for _ in tqdm.tqdm(range(num_steps)):
4345
with torch.inference_mode():
4446
actions = policy.get_action(env, obs)
4547
obs, _, terminated, truncated, _ = env.step(actions)
4648
if terminated.any() or truncated.any():
4749
obs, _ = env.reset()
50+
51+
metrics = compute_metrics(env)
52+
print(f"Metrics: {metrics}")
53+
4854
# Close the environment.
4955
env.close()
5056

isaac_arena/metrics/metrics.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ def get_metric_recorder_dataset_path(env: ManagerBasedRLEnv) -> pathlib.Path:
8787
Returns:
8888
The path to the dataset for the metric recorder.
8989
"""
90-
assert env.cfg.recorders.dataset_file_handler_class_type == HDF5DatasetFileHandler
90+
# Check if the dataset file handler is HDF5DatasetFileHandler
91+
# Use class name comparison instead of direct equality to handle different import contexts
92+
handler_class = env.cfg.recorders.dataset_file_handler_class_type
93+
assert (
94+
handler_class.__name__ == HDF5DatasetFileHandler.__name__
95+
), f"Expected HDF5DatasetFileHandler, got {handler_class.__name__}"
9196
return pathlib.Path(env.cfg.recorders.dataset_export_dir_path) / pathlib.Path(
9297
env.cfg.recorders.dataset_filename + ".hdf5"
9398
)

isaac_arena/metrics/success_rate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def compute_metric_from_recording(self, recorded_metric_data: list[np.ndarray])
7777
which the environment was successful.
7878
"""
7979
num_demos = len(recorded_metric_data)
80+
if num_demos == 0:
81+
return 0.0
8082
all_demos_success_flags = np.concatenate(recorded_metric_data)
8183
assert all_demos_success_flags.ndim == 1
8284
assert all_demos_success_flags.shape[0] == num_demos

0 commit comments

Comments
 (0)