Skip to content

Question about missing preserve_order option in joint target lookup #922

Closed

Description

@CumulusAlpha

Hi,

I noticed that in _find_targets,

def _find_targets(self, cfg: BaseActionCfg) -> tuple[list[int], list[str]]:
"""Find target IDs and names based on transmission type.
Args:
cfg: Action configuration.
Returns:
Tuple of (target_ids, target_names).
"""
if cfg.transmission_type == TransmissionType.JOINT:
return self._entity.find_joints_by_actuator_names(cfg.actuator_names)
elif cfg.transmission_type == TransmissionType.TENDON:
return self._entity.find_tendons(
cfg.actuator_names, preserve_order=cfg.preserve_order
)
elif cfg.transmission_type == TransmissionType.SITE:
return self._entity.find_sites(
cfg.actuator_names, preserve_order=cfg.preserve_order
)
else:
raise ValueError(f"Unknown transmission type: {cfg.transmission_type}")

the JOINT branch calls find_joints_by_actuator_names
def find_joints_by_actuator_names(
self,
actuator_name_keys: str | Sequence[str],
) -> tuple[list[int], list[str]]:
# Collect all actuated joint names.
actuated_joint_names_set = set()
for act in self._actuators:
actuated_joint_names_set.update(act.target_names)
# Filter self.joint_names to only actuated joints, preserving natural order.
actuated_in_natural_order = [
name for name in self.joint_names if name in actuated_joint_names_set
]
# Find joints matching the pattern within actuated joints.
_, matched_joint_names = self.find_joints(
actuator_name_keys, joint_subset=actuated_in_natural_order, preserve_order=False
)
# Map joint names back to entity-local indices (indices into self.joint_names).
name_to_entity_idx = {name: i for i, name in enumerate(self.joint_names)}
joint_ids = [name_to_entity_idx[name] for name in matched_joint_names]
return joint_ids, matched_joint_names
, which internally hardcodes preserve_order=False when calling find_joints. Unlike the TENDON and SITE branches, there doesn’t seem to be a way to pass cfg.preserve_order through.

This makes it impossible to preserve the input order for joint targets, as it is always treated as False.

Is this behavior intentional by design? If so, could you clarify the reasoning behind not supporting preserve_order for joints?

Thanks!

Activity

  1. kevinzakka commented on Apr 17, 2026

    @kevinzakka
    Collaborator

    Yes, it's intentional. find_joints_by_actuator_names forces joint targets into the entity's natural joint order. There's a regression test for this at test_find_joints_by_actuator_names_preserves_natural_order, added after motion tracking broke when actuator-definition order leaked through.

    The reason joints are special (and tendons/sites aren't) is the ONNX exporter. In src/mjlab/rl/exporter_utils.py, the policy metadata writes joint_names in natural order but action_scale in action-dim order. They only stay aligned because joint targets are forced into natural order. If we plumbed preserve_order=True through for joints, enabling it would silently produce an ONNX policy where joint_names and action_scale disagree, and deployment would apply the wrong scale to the wrong joint. Tendons and sites have no equivalent exporter coupling, so preserve_order is safe there.

    So for the JOINT branch, cfg.preserve_order is effectively ignored. That's a doc/guard gap we should fix, either by raising when it's set for joints or by clarifying in the docstring that it only applies to TENDON/SITE. If you have a concrete need for user-controlled joint ordering, happy to track it as a separate issue, since it would also require exporting the action order through ONNX metadata.

  2. added
    question
    on Apr 17, 2026
  3. locked and limited conversation to collaborators on Apr 17, 2026
  4. converted this issue into a discussion #928 on Apr 17, 2026
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

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions