Repository navigation
[Core] Refactor and cleanup core subpackage for 3.0 [12/N] - #8094
Conversation
|
| file.write(content) | ||
| # convert the revolute joints that match any of the fixed joint patterns | ||
| matched_joints = [joint for joint in revolute_joints if any(re.match(pattern, joint) for pattern in fixed_joints)] | ||
| change_revolute_to_fixed(urdf_path, matched_joints, verbose) |
There was a problem hiding this comment.
change_revolute_to_fixed_regex reads the URDF to find matching joints, then this helper reads it again before writing. That adds file I/O on every call. If another process changes the file between reads, the selected names may no longer match what gets rewritten. Consider reusing the content from the first read.
There was a problem hiding this comment.
Isaac Lab Review Bot
The refactor largely preserves actuator and controller behavior, but the consolidated actuator command setters introduce a string-to-attribute mapping and reflective buffer lookup solely to reduce repetition, contrary to the repository’s preference against packing containers for shortening code.
- Design and architecture: Shared helpers for actuator command writes, OSC damping gains, and Isaac Sim path discovery reduce duplication without changing the traced data flow. However,
_COMMAND_BUFFER_NAMESplus_target_buffer()obscures the direct relationship between each public command setter and its backing buffer; each setter should pass the explicit buffer to the shared helper. - API: Public setter signatures and selector semantics remain unchanged. The DiffIK reset annotation, controller logging changes, regex utility delegation, and mathematical refactors do not introduce an evidenced public API compatibility issue.
- Implementation: The MLP gather preserves the prior history ordering, the DiffIK and OSC rewrites preserve their output shapes and live-buffer aliasing, and the exception simplification is equivalent because
AssertionErrorderives fromException. The actuator command-buffer lookup should be made explicit rather than using the new suffix map andgetattr, improving rename safety and compliance with repository style guidance.
Minor fixes needed. Posted 1 actionable finding inline.
Automated review; human maintainers own approval decisions.
| return mask | ||
| def _target_buffer(self, command_name: str) -> wp.array(dtype=wp.float32): | ||
| """Return the raw command buffer for ``command_name``.""" | ||
| return getattr(self._collection, f"_joint_{_COMMAND_BUFFER_NAMES[command_name]}_target") |
There was a problem hiding this comment.
🔵 Suggestion · Implementation — Reflective lookup replaces explicit command buffer argument
_target_buffer resolves _joint_pos_target / _joint_vel_target / _joint_effort_target via getattr with an f-string keyed by the new _COMMAND_BUFFER_NAMES map, while the removed helpers took the buffer as a parameter. The repository style rule says not to add packing containers or reflective access just to shorten code: the buffer names are no longer greppable and a rename fails at runtime rather than statically. Pass the buffer explicitly from each setter into _set_index/_set_mask.
|
run-ci |
|
Backported to |
# Description Part 12 of the core cleanup split from #7949. This PR covers `isaaclab.actuators` and `isaaclab.controllers`. It is rebased onto the current `develop` and ports only the parts of the original cleanup that still apply there. **Actuators** - `ActuatorCollection`: - Iterates the shared `_JOINT_PROPERTY_KEYS` tuple (same order) instead of repeating the key list. - Inlines the one-line `_resolve_joint_property` wrapper. - `_joint_indices_as_wp` now reuses `_joint_indices_as_torch`. - The six `ActuatorTargetCommand.set_{position,velocity,effort}_{index,mask}` methods share `_set_index` / `_set_mask`. Selector resolution, shape checks, kernels and command staging are unchanged. - `DCMotor`: removed the unused `_zeros_effort` buffer. - `DelayedPDActuator`: removed the unused `_ALL_INDICES` tensor, and `reset` now loops over the three delay buffers. - Newton adapter: `defaultdict` is now imported at module level. **Controllers** - `DifferentialIKController`: - Compacted `_compute_delta_joint_pos`: IK params are read once, `.mT` is used, and there is a single `unsqueeze`/`squeeze`. - Removed the duplicated `ee_quat_des` write in position mode. - Fixed a docstring typo. - `OperationalSpaceController`: the three copies of the `2 * sqrt(kp) * zeta` damping-gain formula now share `_critically_damped_gains`. The gains are still written in place, so `_frame_matrices` and the LEAPP export annotator keep referencing the live buffer. - `PinkIKController`: - Calls `set_target_from_configuration` directly instead of through `getattr`. - Builds joint-name mismatches with a comprehension. - `except (AssertionError, Exception)` is now `except Exception`. - Logs solver failures with `logger.warning` instead of `print`. - The explicit `None` checks and their `ValueError`s are kept. - `RmpFlowController`: logs the URDF path with `logger.info` instead of `print`, and selects active and watched joints with combined indexing (`all_pos[i, idx]` instead of `all_pos[i][idx]`). - `controllers.utils`: - `change_revolute_to_fixed_regex` resolves the matching joints and delegates to `change_revolute_to_fixed`. - The `ISAAC_PATH` lookup shared by the RMPFlow and lula discovery helpers is now `_isaac_path()`. **Not ported from #7949** - Deprecated limit-alias refactors in `_compat`, `ActuatorBase`, and `ImplicitActuator`: these paths will be removed. - DCMotor clip compaction: `develop` has since reworked `_clip_effort` to take `joint_vel`. - OSC rotation and identity-frame changes: `develop` already covers them. - Removal of Pink IK's `None` checks: it would turn `ValueError` into `TypeError`. ## Type of change - Refactor, plus one user-visible logging change (`print` → `logging` in Pink IK and RMPFlow). ## Verification - Bitwise equivalence against `develop` (same seeded inputs run through both source trees, compared with `torch.equal` including dtype and shape): **566 outputs, 0 differences**, on CPU and CUDA. Covered: - `DifferentialIKController.set_command` + `compute` for all 5 IK methods × pose/position × absolute/relative, batch sizes 1, 64, 512 and 4096, 6–9 joints, including near-singular and rank-deficient Jacobians; plus `_compute_delta_joint_pos` with 3- and 6-row Jacobians. - `OperationalSpaceController` init gains, `set_command` (task and root-frame gains) and `compute` torques in fixed, variable_kp and variable impedance modes, with and without inertial decoupling, gravity compensation and null-space control. `_motion_d_gains_task` stays the same tensor object. - `ActuatorTargetCommand` position/velocity/effort index setters (full and selected) and mask setters. - Performance against `develop` (median of 5 alternating runs; 4096 envs): IK `compute` (all methods), OSC `set_command` (all modes), and the target-command setters are within run-to-run noise on CPU and CUDA (ratios 0.96–1.04; a dedicated 10-run setter benchmark gave matching medians of ~53.6 µs CPU / ~17.0 µs CUDA). - Tests: - `source/isaaclab/test/actuators`, `test_articulation_iface.py`, `test_joint_impedance.py`, `test_local_frame_task.py`, `test_null_space_posture_task.py`, `test_pink_ik_components.py`: pass. When these files run in one process, 3 `test_action_gravity_compensation_with_migrated_robot_configs[...GR1T2_HIGH_PD_CFG]` cases fail on `develop` and on this branch alike; they pass when run on their own. - `test_controller_utils.py` (22), `test_differential_ik.py` (40), `test_operational_space.py` (47), `test_pink_ik.py` (19 passed, 1 skipped): pass. - `test_newton_actuators_newton.py` (38) and `test_newton_actuators_physx.py` (35): pass. - `ruff check` and `ruff format` are clean. ## Checklist - [x] I have read and understood the contribution guidelines - [x] I have run the `pre-commit` checks with `./isaaclab.sh --format` - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] I have added a changelog fragment ## Release backport - [x] <!-- backport-active-release --> Backport this pull request to the active release branch after it merges into `develop` (cherry picked from commit 85dad89)
Description
Part 12 of the core cleanup split from #7949. This PR covers
isaaclab.actuatorsandisaaclab.controllers. It is rebased onto the currentdevelopand ports only the parts of the original cleanup that still apply there.Actuators
ActuatorCollection:_JOINT_PROPERTY_KEYStuple (same order) instead of repeating the key list._resolve_joint_propertywrapper._joint_indices_as_wpnow reuses_joint_indices_as_torch.ActuatorTargetCommand.set_{position,velocity,effort}_{index,mask}methods share_set_index/_set_mask. Selector resolution, shape checks, kernels and command staging are unchanged.DCMotor: removed the unused_zeros_effortbuffer.DelayedPDActuator: removed the unused_ALL_INDICEStensor, andresetnow loops over the three delay buffers.defaultdictis now imported at module level.Controllers
DifferentialIKController:_compute_delta_joint_pos: IK params are read once,.mTis used, and there is a singleunsqueeze/squeeze.ee_quat_deswrite in position mode.OperationalSpaceController: the three copies of the2 * sqrt(kp) * zetadamping-gain formula now share_critically_damped_gains. The gains are still written in place, so_frame_matricesand the LEAPP export annotator keep referencing the live buffer.PinkIKController:set_target_from_configurationdirectly instead of throughgetattr.except (AssertionError, Exception)is nowexcept Exception.logger.warninginstead ofprint.Nonechecks and theirValueErrors are kept.RmpFlowController: logs the URDF path withlogger.infoinstead ofprint, and selects active and watched joints with combined indexing (all_pos[i, idx]instead ofall_pos[i][idx]).controllers.utils:change_revolute_to_fixed_regexresolves the matching joints and delegates tochange_revolute_to_fixed.ISAAC_PATHlookup shared by the RMPFlow and lula discovery helpers is now_isaac_path().Not ported from #7949
_compat,ActuatorBase, andImplicitActuator: these paths will be removed.develophas since reworked_clip_effortto takejoint_vel.developalready covers them.Nonechecks: it would turnValueErrorintoTypeError.Type of change
print→loggingin Pink IK and RMPFlow).Verification
develop(same seeded inputs run through both source trees, compared withtorch.equalincluding dtype and shape): 566 outputs, 0 differences, on CPU and CUDA. Covered:DifferentialIKController.set_command+computefor all 5 IK methods × pose/position × absolute/relative, batch sizes 1, 64, 512 and 4096, 6–9 joints, including near-singular and rank-deficient Jacobians; plus_compute_delta_joint_poswith 3- and 6-row Jacobians.OperationalSpaceControllerinit gains,set_command(task and root-frame gains) andcomputetorques in fixed, variable_kp and variable impedance modes, with and without inertial decoupling, gravity compensation and null-space control._motion_d_gains_taskstays the same tensor object.ActuatorTargetCommandposition/velocity/effort index setters (full and selected) and mask setters.develop(median of 5 alternating runs; 4096 envs): IKcompute(all methods), OSCset_command(all modes), and the target-command setters are within run-to-run noise on CPU and CUDA (ratios 0.96–1.04; a dedicated 10-run setter benchmark gave matching medians of ~53.6 µs CPU / ~17.0 µs CUDA).source/isaaclab/test/actuators,test_articulation_iface.py,test_joint_impedance.py,test_local_frame_task.py,test_null_space_posture_task.py,test_pink_ik_components.py: pass. When these files run in one process, 3test_action_gravity_compensation_with_migrated_robot_configs[...GR1T2_HIGH_PD_CFG]cases fail ondevelopand on this branch alike; they pass when run on their own.test_controller_utils.py(22),test_differential_ik.py(40),test_operational_space.py(47),test_pink_ik.py(19 passed, 1 skipped): pass.test_newton_actuators_newton.py(38) andtest_newton_actuators_physx.py(35): pass.ruff checkandruff formatare clean.Checklist
pre-commitchecks with./isaaclab.sh --formatRelease backport
develop