Repository navigation
Closed
Labels
questionFurther information is requested
Description
Hi,
I noticed that in _find_targets,
mjlab/src/mjlab/envs/mdp/actions/actions.py
Lines 100 to 120 in 7fcea47
| 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_namesmjlab/src/mjlab/entity/entity.py
Lines 502 to 524 in 7fcea47
| 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 |
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!
Metadata
Metadata
Assignees
Labels
questionFurther information is requested
Activity
kevinzakka commentedon Apr 17, 2026
Yes, it's intentional.
find_joints_by_actuator_namesforces joint targets into the entity's natural joint order. There's a regression test for this attest_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 writesjoint_namesin natural order butaction_scalein action-dim order. They only stay aligned because joint targets are forced into natural order. If we plumbedpreserve_order=Truethrough for joints, enabling it would silently produce an ONNX policy wherejoint_namesandaction_scaledisagree, and deployment would apply the wrong scale to the wrong joint. Tendons and sites have no equivalent exporter coupling, sopreserve_orderis safe there.So for the
JOINTbranch,cfg.preserve_orderis 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 toTENDON/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.