Skip to content

Stop partial resets from adding tracking error to other envs' metrics - #1310

Open
Chr0mium24 wants to merge 1 commit into
mujocolab:mainfrom
Chr0mium24:fix/twist-metrics
Open

Chr0mium24 wants to merge 1 commit into
mujocolab:mainfrom
Chr0mium24:fix/twist-metrics

Conversation

@Chr0mium24

Copy link
Copy Markdown

reset(env_ids=...) calls command_manager.compute(dt=0.0, env_ids=env_ids). Since #1139 that call limits timers and command updates to the reset envs, but CommandTerm.compute still calls _update_metrics() for every env. Most command terms assign their metrics, so the extra refresh is harmless, but UniformVelocityCommand accumulates error_vel_xy and error_vel_yaw with +=, so each partial reset adds one more step of tracking error to every env it did not reset.

To reproduce: Go1 flat with auto_reset=False, step 10 times, then reset(env_ids=[0]). env 1's error_vel_xy goes from 0.03560 to 0.03903 although env 1 was not reset (its time_left is unchanged, as fixed in #1139). In a loop that resets finished envs after each step, every step in which some env finishes counts twice for all the others.

The fix moves the accumulation into a new _accumulate_metrics(env_ids) called from compute() next to _integrate_command, so the reset path only touches the reset envs. I left the base class alone because the other command terms assign their metrics; if you would rather scope _update_metrics by env_ids in CommandTerm itself, I'm happy to change it that way.

test_partial_reset_does_not_accumulate_other_envs_metrics fails on main and passes with the fix; the fast suite passes and ruff, ty and pyright are clean. A changelog entry is included.

reset(env_ids=...) calls command_manager.compute(dt=0.0, env_ids=env_ids), which limits timer and command updates to the reset envs but still refreshes metrics for every env. UniformVelocityCommand accumulates error_vel_xy and error_vel_yaw as running sums, so each partial reset added one more step of tracking error to every env it did not reset. In an auto_reset=False loop that resets finished envs after each step, this counts an extra step for the other envs whenever any env finishes. Move the accumulation into _accumulate_metrics(env_ids), called from compute() next to _integrate_command, so the reset path only touches the reset envs. The base class is unchanged because the other command terms assign their metrics rather than accumulate them.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant