refactor: split motion tracking common modules#697
Open
caozx1110 wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the motion-tracking environments by extracting the shared (robot-agnostic) tracking engine into unilab.envs.motion_tracking.common, keeping per-robot/profile modules (G1/X2) as thin registry/profile layers while preserving Hydra task owner behavior and numpy/numba parity coverage.
Changes:
- Introduces a shared motion-tracking engine (
common/tracking.py) plus owner modules for config, reset planning, transforms, terminations, rewards, domain randomization, motion loading/sampling, and the numba accelerator. - Updates G1/X2 motion-tracking env/profile modules to route through the shared engine while retaining legacy symbol imports/aliases where needed.
- Adds/updates focused tests to lock reward math/dispatch and ensure numba parity still holds after the extraction.
Reviewed changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/envs/test_motion_tracking_rewards.py | New guard tests for extracted common reward terms and reward reduction logic. |
| tests/envs/test_motion_loader.py | Updates tests to import the extracted common motion loader/sampler. |
| tests/envs/test_g1_motion_tracking_numba.py | Switches numba accelerator imports to the extracted common implementation. |
| tests/envs/test_env_configs.py | Adjusts imports and expectations for common motion loader/tracking/DR provider names. |
| src/unilab/envs/motion_tracking/x2/flip_tracking.py | Migrates X2 flip tracking to the common config + deploy engine. |
| src/unilab/envs/motion_tracking/g1/tracking.py | Reduces G1 tracking module to registry/profile wrappers + backward-compatible re-exports. |
| src/unilab/envs/motion_tracking/g1/tracking_obs.py | Migrates custom reward terms to the new RewardContext call signature. |
| src/unilab/envs/motion_tracking/g1/motion_box_loader.py | Routes box motion loader dependencies through the extracted common loader types. |
| src/unilab/envs/motion_tracking/g1/flip_tracking.py | Removes duplicated zero-randomization helpers in favor of common equivalents. |
| src/unilab/envs/motion_tracking/g1/box_tracking.py | Updates object reward terms to accept RewardContext consistently with common reward dispatch. |
| src/unilab/envs/motion_tracking/common/init.py | Introduces the common motion-tracking package namespace. |
| src/unilab/envs/motion_tracking/common/config.py | Adds shared dataclass config types + backward-compatible aliases and helpers. |
| src/unilab/envs/motion_tracking/common/motion_loader.py | Extracts shared motion loading/sampling logic (including multi-clip support). |
| src/unilab/envs/motion_tracking/common/reset.py | Extracts reset reference-state construction. |
| src/unilab/envs/motion_tracking/common/transforms.py | Extracts yaw-aligned relative transform updates used by obs/reward/termination. |
| src/unilab/envs/motion_tracking/common/observations.py | Extracts shared observation building and anchor-frame transform writers. |
| src/unilab/envs/motion_tracking/common/terminations.py | Extracts shared termination computation. |
| src/unilab/envs/motion_tracking/common/rewards.py | Extracts shared reward config, context, term functions, and reducer. |
| src/unilab/envs/motion_tracking/common/domain_randomization.py | Extracts the DR reset/observation provider into common owner space. |
| src/unilab/envs/motion_tracking/common/tracking.py | New shared env engine orchestrating step/reset, delegating math to owner modules. |
| src/unilab/envs/motion_tracking/common/numba.py | Renames accelerator to common MotionTrackingNumbaAccelerator and updates messaging. |
| benchmark/benchmark_g1_motion_tracking_numba.py | Updates benchmarking harness to use the extracted common numba accelerator. |
Comments suppressed due to low confidence (1)
src/unilab/envs/motion_tracking/common/numba.py:916
MotionTrackingNumbaAcceleratorwas renamed to be robot-agnostic, but the result dataclasses returned bycompute()/compute_update_state()are still namedG1MotionTrackingNumbaResult/G1MotionTrackingNumbaUpdateStateResult. This is inconsistent for acommonmodule and makes the public surface confusing for non-G1 trackers (e.g. X2). Consider adding MotionTracking-prefixed aliases (or renaming with backward-compatible aliases).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+88
to
+90
| def test_build_reward_functions_matches_numba_term_order(): | ||
| assert set(rewards.build_reward_functions()) == set(numba_mod.TERM_ORDER) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Impact
task=<task>/<backend>.g1/tracking.pyto a thin compatibility/profile entrypoint and moves hot-path reward/observation math into testable common modules.RewardContext, matching the extracted common reward dispatch.Validation
NUMBA_THREADING_LAYER=workqueue make test-all— 1559 passed, 32 skipped, 266 deselected, 1 xfailed.Fixes #135