Repository navigation
[Warp] Part 3a/9: Resolve Warp selections on SceneEntityCfg and hold the env origins in a Warp array #8856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Warp] Part 3a/9: Resolve Warp selections on SceneEntityCfg and hold the env origins in a Warp array #8856
Changes from all commits
b7bb82b
eb3aeac
d76f8a6
256ca44
fdcb395
a6d8a97
86cfd8d
8c38925
3d3ccf5
f8115f6
2724709
ef26a72
97665ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| * Added the ``joint_ids_wp`` and ``body_ids_wp`` fields to :class:`~isaaclab.managers.SceneEntityCfg`: ``int32`` | ||
| Warp arrays of the resolved joint and body indices, in the order of ``joint_ids`` and ``body_ids``, for Warp terms. | ||
| The new :meth:`~isaaclab.managers.SceneEntityCfg.resolve_warp_ids`, which the Warp managers call after | ||
| :meth:`~isaaclab.managers.SceneEntityCfg.resolve`, fills them; :meth:`~isaaclab.managers.SceneEntityCfg.resolve`, | ||
| ``joint_ids`` and ``body_ids`` are unchanged. Copies of the configuration, :func:`copy.deepcopy` included, share | ||
| them; ``to_dict`` stores them as lists, and a pickled configuration leaves them out (``None``) until | ||
| :meth:`~isaaclab.managers.SceneEntityCfg.resolve_warp_ids` runs again. | ||
| * Added :attr:`~isaaclab.scene.InteractiveScene.env_origins_wp` and | ||
| :attr:`~isaaclab.terrains.TerrainImporter.env_origins_wp`, the ``wp.vec3f`` Warp array that holds the environment | ||
| origins, for Warp code. ``env_origins`` stays a :class:`torch.Tensor`, now a view of that array: assigning | ||
| ``TerrainImporter.env_origins`` writes the new origins into it, so an earlier view of either stays current. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,13 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import MISSING | ||
| import copy | ||
| from dataclasses import MISSING, field | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| import numpy as np | ||
| import torch | ||
| import warp as wp | ||
|
|
||
| from ..utils import configclass | ||
|
|
||
|
|
@@ -123,6 +126,22 @@ class for more details. | |
|
|
||
| """ | ||
|
|
||
| joint_ids_wp: wp.array | None = field(default=None, metadata={"copy": False}) | ||
| """The selected joints as an ``int32`` Warp array of indices, in the order of :attr:`joint_ids`. | ||
| Defaults to None. | ||
|
|
||
| Filled by :meth:`resolve_warp_ids` for the Warp terms; torch terms read :attr:`joint_ids`. | ||
| :func:`~isaaclab.utils.clone`, :func:`~isaaclab.utils.replace` and :func:`copy.deepcopy` share it. | ||
| """ | ||
|
|
||
| body_ids_wp: wp.array | None = field(default=None, metadata={"copy": False}) | ||
| """The selected bodies as an ``int32`` Warp array of indices, in the order of :attr:`body_ids`. | ||
| Defaults to None. | ||
|
|
||
| Filled by :meth:`resolve_warp_ids` for the Warp terms; torch terms read :attr:`body_ids`. | ||
| :func:`~isaaclab.utils.clone`, :func:`~isaaclab.utils.replace` and :func:`copy.deepcopy` share it. | ||
| """ | ||
|
|
||
| def resolve(self, scene: InteractiveScene): | ||
| """Resolves the scene entity and converts the joint and body names to indices. | ||
|
|
||
|
|
@@ -156,6 +175,25 @@ def resolve(self, scene: InteractiveScene): | |
| # convert object collection names to indices based on regex | ||
| self._resolve_object_collection_names(scene) | ||
|
|
||
| def resolve_warp_ids(self, scene: InteractiveScene): | ||
| """Fill :attr:`joint_ids_wp` and :attr:`body_ids_wp` with the selected indices, in selection order. | ||
|
|
||
| The Warp managers call it after :meth:`resolve` for their terms; torch terms do not need it. | ||
| A slice expands over the entity's joints or bodies (the sensors of a contact sensor) and a negative index | ||
| wraps, as in torch indexing. | ||
|
|
||
| Args: | ||
| scene: The interactive scene instance. | ||
| """ | ||
| entity = scene[self.name] | ||
| if hasattr(entity, "num_joints"): | ||
| self.joint_ids_wp = wp.array( | ||
| np.arange(entity.num_joints, dtype=np.int32)[self.joint_ids], device=scene.device | ||
| ) | ||
| num_bodies = entity.num_sensors if hasattr(entity, "num_sensors") else getattr(entity, "num_bodies", None) | ||
| if num_bodies is not None: | ||
| self.body_ids_wp = wp.array(np.arange(num_bodies, dtype=np.int32)[self.body_ids], device=scene.device) | ||
|
|
||
| def finalize(self, device: str) -> None: | ||
| """Move resolved index selections to the device. | ||
|
|
||
|
|
@@ -172,6 +210,28 @@ def finalize(self, device: str) -> None: | |
| if not isinstance(indices, (slice, torch.Tensor)): | ||
| setattr(self, name, torch.tensor(indices, dtype=torch.long, device=device)) | ||
|
|
||
| def __deepcopy__(self, memo: dict) -> SceneEntityCfg: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Warning · Style Consistency — Order deepcopy with dunder members deepcopy follows public lifecycle methods, contrary to the prescribed class-member order. Move it before resolve and finalize.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left where it is: member order only, no behaviour change.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Warning · Style Consistency — Order the new dunder method deepcopy follows ordinary public methods, contrary to the prescribed class-member order. Move it before resolve and finalize.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left where it is: member order only, no behaviour change. |
||
| """Deep-copy every field, ``init=False`` ones included. | ||
|
|
||
| The Warp ids are shared: a Warp array cannot be deep-copied. | ||
| """ | ||
| memo[id(self)] = copied = copy.copy(self) | ||
| for name, value in vars(self).items(): | ||
| if not isinstance(value, wp.array): | ||
| setattr(copied, name, copy.deepcopy(value, memo)) | ||
| return copied | ||
|
|
||
| def __copy__(self) -> SceneEntityCfg: | ||
| """Copy every field; the copy shares the Warp ids.""" | ||
| copied = object.__new__(type(self)) | ||
| copied.__dict__.update(vars(self)) | ||
| return copied | ||
|
|
||
| def __getstate__(self) -> dict: | ||
| """Pickle without the Warp ids, which a Warp array cannot be: they unpickle as None, and | ||
| :meth:`resolve_warp_ids` fills them again.""" | ||
| return {**vars(self), "joint_ids_wp": None, "body_ids_wp": None} | ||
|
|
||
| def _resolve_joint_names(self, scene: InteractiveScene): | ||
| # convert joint names to indices based on regex | ||
| if self.joint_names is not None or self.joint_ids != slice(None): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| * Changed the Warp joint penalties ``joint_torques_l2``, ``joint_vel_l1``, ``joint_vel_l2``, ``joint_acc_l2``, | ||
| ``joint_deviation_l1`` and ``joint_pos_limits``, and the termination ``joint_pos_out_of_manual_limit``, to loop over | ||
| the selected joints in the order of ``joint_ids``. A joint selected twice now counts twice, as in the torch terms. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| * **Breaking:** Removed the Warp subclass ``isaaclab_experimental.managers.SceneEntityCfg``; the name now resolves to | ||
| :class:`isaaclab.managers.SceneEntityCfg`, whose ``joint_ids_wp`` and ``body_ids_wp`` the Warp managers fill. Its | ||
| ``joint_mask`` and ``from_stable`` are removed: Warp terms loop over ``joint_ids_wp``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Warning · Api — Invalidate replaced Warp selections
replace() shares resolved Warp arrays while allowing joint_ids or body_ids to change. The replacement can report one selection and execute another. Clear derived IDs when selection fields change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved by 0a297ba (#8856): the Warp managers fill
joint_ids_wpandbody_ids_wpright after everyresolve(), so a replaced selection gets its own ids when it is resolved.