Skip to content

Make MuJoCo IK restarts topology-aware and reproducible #69

Description

@siddhss5

Summary

The unseeded restart logic added in #68 improves MuJoCo differential-IK coverage, but its restart distribution is not yet generic over the joint-space contract and is not connected to the examples' reproducibility seed.

There are two related gaps:

  1. Intersecting every joint's limits with [-pi, pi] can produce an empty interval and crash. The one-turn heuristic is also meaningful only for revolute joints, not prismatic joints.
  2. MuJoCoIKSolver defaults to an entropy-seeded private generator, so an example run with a fixed --seed does not fully determine the MuJoCo fallback's IK samples.

Found in the post-merge audit of #68.

Reproduction: empty restart interval

The current code computes:

lo = np.maximum(lower, -np.pi)
hi = np.minimum(upper, np.pi)
self._rng.uniform(lo, hi)

For a valid finite interval such as [4, 5], this gives lo=4 and hi=pi, then raises:

ValueError: high - low < 0

This was reproduced directly with MuJoCoIKSolver(..., joint_limits=(full(6, 4), full(6, 5)), restarts=1).

The same construction is conceptually wrong for a slide joint because radians and a one-turn window have no meaning for a prismatic coordinate.

Reproducibility gap

MuJoCoIKSolver(seed=None) creates an independently entropy-seeded generator. Both examples accept --seed, but their build_ik_solver helpers do not pass that value into the MuJoCo solver. Consequently, the planner's sampling may be seeded while unseeded IK restarts are not.

This issue does not require changing the generic IKSolver protocol. Explicit constructor seeding is sufficient for now, provided the examples propagate their user-visible seed and the documentation states that a stateful stochastic backend must be seeded separately from CBiRRT.plan.

Proposed solution

Topology-aware restart bounds

Construct a nonempty sampling interval inside each joint's actual admissible domain:

  • For a finite revolute joint, a window of width at most 2*pi may be used, but anchor it at an admissible reference such as the current configuration clamped into the joint limits. Intersecting that window with the limits is then guaranteed nonempty.
  • For a finite prismatic joint, sample from its finite interval or use a separately documented translational restart policy. Do not apply [-pi, pi].
  • For a genuinely continuous revolute joint, sample a single representative window centered at the current configuration.
  • Never synthesize invalid lo > hi bounds.

Use MuJoCo's joint type and limited/unlimited metadata rather than inferring topology only from numeric ranges.

Deterministic construction

  • Preserve the existing explicit seed constructor argument.
  • Pass the examples' --seed into the MuJoCo fallback constructor.
  • Verify that two equivalently initialized solvers with the same seed generate the same restart sequence and results.
  • Keep seeded solve(pose, q_init=...) unchanged and free of random restarts.

Tests

  • A finite revolute interval disjoint from [-pi, pi], such as [4, 5], does not raise and every restart lies inside the limits.
  • A prismatic joint uses a dimensionally appropriate interval and never applies the revolute one-turn rule.
  • Mixed finite and continuous joints produce valid restart configurations.
  • The same explicit solver seed produces the same restart initializations.
  • Different explicit seeds can produce different initializations.
  • The examples' --seed is forwarded to the MuJoCo fallback.
  • A supplied q_init still performs exactly one deterministic solve.
  • Existing UR5e fallback tests remain green.

Acceptance criteria

Related: #65, #68.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions