Skip to content

refactor: split motion tracking common modules#697

Open
caozx1110 wants to merge 4 commits into
mainfrom
refactor/motion-tracking-common-modules
Open

refactor: split motion tracking common modules#697
caozx1110 wants to merge 4 commits into
mainfrom
refactor/motion-tracking-common-modules

Conversation

@caozx1110

Copy link
Copy Markdown
Collaborator

Summary

  • Extract shared motion-tracking owner modules for config, reset planning, domain randomization, rewards, observations, terminations, transforms, motion loading, and numba acceleration.
  • Route G1 tracking/flip/box profiles and X2 flip tracking through the common engine while keeping task-owned profile classes and Hydra task owner YAML behavior.
  • Add focused reward/config/loader/numba tests for the extracted common modules and preserve numpy/numba parity coverage.

Impact

  • Keeps backend-specific behavior behind backend/config owner boundaries; task selection remains via task=<task>/<backend>.
  • Reduces g1/tracking.py to a thin compatibility/profile entrypoint and moves hot-path reward/observation math into testable common modules.
  • Reward hooks now consume 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

@caozx1110 caozx1110 requested a review from TATP-233 as a code owner July 9, 2026 15:29
Copilot AI review requested due to automatic review settings July 9, 2026 15:29

Copilot AI left a comment

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.

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

  • MotionTrackingNumbaAccelerator was renamed to be robot-agnostic, but the result dataclasses returned by compute() / compute_update_state() are still named G1MotionTrackingNumbaResult / G1MotionTrackingNumbaUpdateStateResult. This is inconsistent for a common module 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)

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.

Work: 拆分 G1MotionTrackingEnv 职责边界与配置化常量

2 participants