mani_skill.utils.structs#
Submodules#
- mani_skill.utils.structs.actor
- mani_skill.utils.structs.articulation
- mani_skill.utils.structs.articulation_joint
- mani_skill.utils.structs.base
- mani_skill.utils.structs.decorators
- mani_skill.utils.structs.drive
- mani_skill.utils.structs.link
- mani_skill.utils.structs.pose
- mani_skill.utils.structs.render_camera
- mani_skill.utils.structs.types
Attributes#
Classes#
Wrapper around sapien.Entity objects mixed in with useful properties from the RigidBodyDynamicComponent components |
|
Wrapper around physx.PhysxArticulationJoint objects |
|
Base class of all structs that manage sapien objects on CPU/GPU |
|
A gpu memory configuration dataclass that neatly holds all parameters that configure physx GPU memory for simulation |
|
Wrapper around physx.PhysxArticulationLinkComponent objects |
|
Base class of all structs that manage sapien objects on CPU/GPU |
|
Base class of all structs that manage sapien objects on CPU/GPU |
|
Base class of all structs that manage sapien objects on CPU/GPU |
|
Base class of all structs that manage sapien objects on CPU/GPU |
|
Wrapper around sapien.Pose that supports managing a batch of Poses and flexible creation of them from a variety of |
|
Wrapper around sapien.render.RenderCameraComponent |
|
Simulation configurations for ManiSkill environments |
Package Contents#
- class mani_skill.utils.structs.Actor[source]#
Bases:
mani_skill.utils.structs.base.PhysxRigidDynamicComponentStruct[sapien.Entity]Wrapper around sapien.Entity objects mixed in with useful properties from the RigidBodyDynamicComponent components
At the moment, on GPU and CPU one can query pose, linear velocity, and angular velocity easily
On CPU, more properties are available
- apply_force(force)[source]#
Apply an instantaneous external force to this actor in Newtons to the body’s center of mass. Once called no need to call any gpu_apply_x functions as this handles it for you.
- Parameters:
force (mani_skill.utils.structs.types.Array)
- classmethod create_from_entities(entities, scene, scene_idxs, shared_name=None)[source]#
- Parameters:
entities (list[sapien.Entity])
scene_idxs (torch.Tensor)
shared_name (Optional[str])
- get_collision_meshes(to_world_frame=True, first_only=False)[source]#
Returns the collision mesh of each managed actor object. Note results of this are not cached or optimized at the moment so this function can be slow if called too often. Some actors have no collision meshes, in which case this function returns an empty list.
- Parameters:
to_world_frame (bool) – Whether to transform the collision mesh pose to the world frame
first_only (bool) – Whether to return the collision mesh of just the first actor managed by this object. If True, this also returns a single Trimesh.Mesh object instead of a list. This can be useful for efficiency reasons if you know ahead of time all of the managed actors have the same collision mesh
- Return type:
Union[list[trimesh.Trimesh], trimesh.Trimesh]
- get_first_collision_mesh(to_world_frame=True)[source]#
Returns the collision mesh of the first managed actor object. Note results of this are not cached or optimized at the moment so this function can be slow if called too often. Some actors have no collision meshes, in which case this function returns None
- Parameters:
to_world_frame (bool) – Whether to transform the collision mesh pose to the world frame
- Return type:
Union[trimesh.Trimesh, None]
- hide_visual()[source]#
Hides this actor from view. In CPU simulation the visual body is simply set to visibility 0
For GPU simulation, currently this is implemented by moving the actor very far away as visiblity cannot be changed on the fly. As a result we do not permit hiding and showing visuals of objects with collision shapes as this affects the actual simulation. Note that this operation can also be fairly slow as we need to run px.gpu_apply_rigid_dynamic_data and px.gpu_fetch_rigid_dynamic_data.
- is_static(lin_thresh=0.01, ang_thresh=0.1)[source]#
Checks if this actor is static within the given linear velocity threshold lin_thresh and angular velocity threshold ang_thresh
- classmethod merge(actors, name=None)[source]#
Merge actors together under one view so that they can all be managed by one python dataclass object. This can be useful for e.g. randomizing the asset loaded into a task and being able to do object.pose to fetch the pose of all randomized assets or object.set_pose to change the pose of each of the different assets, despite the assets not being uniform across all sub-scenes.
For example usage of this method, see mani_skill/envs/tasks/pick_single_ycb.py
- Parameters:
actors (list[Actor]) – The actors to merge into one actor object to manage
name (str) – A new name to give the merged actors. If none, the name will default to the first actor’s name
- set_collision_group_bit(group, bit_idx, bit)[source]#
Set’s a specific collision group bit for all collision shapes in all parallel actors
- Parameters:
group (int)
bit_idx (int)
bit (Union[int, bool])
- set_pose(arg1)[source]#
- Parameters:
arg1 (Union[mani_skill.utils.structs.pose.Pose, sapien.Pose])
- Return type:
None
- set_state(state, env_idx=None)[source]#
- Parameters:
state (mani_skill.utils.structs.types.Array)
env_idx (Optional[torch.Tensor])
- property has_collision_shapes#
- initial_pose: mani_skill.utils.structs.pose.Pose = None#
The initial pose of this Actor, as defined when creating the actor via the ActorBuilder. It is necessary to track this pose to ensure the actor is still at the correct pose once gpu system is initialized. It may also be useful to help reset a environment to an initial state without having to manage initial poses yourself
- merged: bool = False#
Whether this object is a view of other actors as a result of Actor.merge
- name: str = None#
- property per_scene_id#
Returns a int32 torch tensor of the actor level segmentation ID for each managed actor object.
- property pose: mani_skill.utils.structs.pose.Pose#
- Return type:
- px_body_type: Literal['kinematic', 'static', 'dynamic'] = None#
- class mani_skill.utils.structs.ArticulationJoint[source]#
Bases:
mani_skill.utils.structs.base.BaseStruct[sapien.physx.PhysxArticulationJoint]Wrapper around physx.PhysxArticulationJoint objects
At the moment, all of the same joints across all sub scenes are restricted to having the same properties as each other
- classmethod create(physx_joints, physx_articulations, scene, scene_idxs, joint_index, active_joint_index=None)[source]#
Creates an object for managing articulation joints in articulations
Note that the properties articulation, child_link, parent_link are by default None as they might not make sense in GPU sim and must be set by user
- Parameters:
physx_joints (list[sapien.physx.PhysxArticulationJoint])
physx_articulations (list[sapien.physx.PhysxArticulation])
scene_idxs (torch.Tensor)
joint_index (torch.Tensor)
active_joint_index (torch.Tensor)
- set_drive_properties(stiffness, damping, force_limit=3.4028234663852886e+38, mode='force')[source]#
- Parameters:
stiffness (float)
damping (float)
force_limit (float)
mode (Literal['force', 'acceleration'])
- set_drive_target(target)[source]#
- Parameters:
target (mani_skill.utils.structs.types.Array)
- Return type:
None
- set_drive_velocity_target(velocity)[source]#
- Parameters:
velocity (mani_skill.utils.structs.types.Array)
- Return type:
None
- set_limits(limits)[source]#
- Parameters:
limits (mani_skill.utils.structs.types.Array)
- Return type:
None
- property _data_index#
- _physx_articulations: list[sapien.physx.PhysxArticulation] = None#
- active_index: torch.Tensor#
index of this joint amongst the active joints
- articulation: mani_skill.utils.structs.articulation.Articulation | None = None#
- child_link: mani_skill.utils.structs.link.Link | None = None#
- property damping: torch.Tensor#
- Return type:
torch.Tensor
- property dof: torch.Tensor#
- Return type:
torch.Tensor
- property drive_mode: list[Literal['force', 'acceleration']]#
typing.Literal[‘force’, ‘acceleration’]
- Type:
type
- Return type:
list[Literal[‘force’, ‘acceleration’]]
- property drive_target: torch.Tensor#
- Return type:
torch.Tensor
- property drive_velocity_target: torch.Tensor#
- Return type:
torch.Tensor
- property force_limit: torch.Tensor#
- Return type:
torch.Tensor
- property friction: torch.Tensor#
- Return type:
torch.Tensor
- property global_pose: mani_skill.utils.structs.pose.Pose#
- Return type:
- index: torch.Tensor#
index of this joint among all joints
- property limits: torch.Tensor#
- Return type:
torch.Tensor
- name: str = None#
- parent_link: mani_skill.utils.structs.link.Link | None = None#
- property pose_in_child#
- property pose_in_parent#
- property qpos#
The qpos of this joint in the articulation
- property qvel#
The qvel of this joint in the articulation
- property stiffness: torch.Tensor#
- Return type:
torch.Tensor
- property type: list[Literal['fixed', 'revolute', 'revolute_unwrapped', 'prismatic', 'free']]#
- Return type:
list[Literal[‘fixed’, ‘revolute’, ‘revolute_unwrapped’, ‘prismatic’, ‘free’]]
- class mani_skill.utils.structs.BaseStruct[source]#
Bases:
Generic[T]Base class of all structs that manage sapien objects on CPU/GPU
- property __maniskill_hash__#
A better hash to use compared to the default frozen dataclass hash. It is tied directly to the only immutable field (the _objs list).
- property _num_objs#
- _objs: list[T]#
list of objects of type T managed by this dataclass. This should not be modified after initialization. The struct hash is dependent on the hash of this list.
- _scene_idxs: torch.Tensor#
a list of indexes parallel to self._objs indicating which sub-scene each of those objects are actually in by index
- property device#
- property px#
The physx system objects managed by this dataclass are working on
- scene: mani_skill.envs.scene.ManiSkillScene#
The ManiSkillScene object that manages the sub-scenes this dataclasses’s objects are in
- class mani_skill.utils.structs.DefaultMaterialsConfig[source]#
-
- dynamic_friction: float = 0.3#
- restitution: float = 0#
- static_friction: float = 0.3#
- class mani_skill.utils.structs.GPUMemoryConfig[source]#
A gpu memory configuration dataclass that neatly holds all parameters that configure physx GPU memory for simulation
- collision_stack_size: int = 4194304#
Increase this if you get ‘Collision stack overflow detected’
- found_lost_aggregate_pairs_capacity: int = 1024#
- found_lost_pairs_capacity: int = 33554432#
- heap_capacity: int = 67108864#
- max_rigid_contact_count: int = 524288#
Increase this if you get ‘Contact buffer overflow detected’
- max_rigid_patch_count: int = 262144#
Increase this if you get ‘Patch buffer overflow detected’
- temp_buffer_capacity: int = 16777216#
overflowing initial allocation size, increase capacity to at least %.’
- Type:
Increase this if you get ‘PxgPinnedHostLinearMemoryAllocator
- total_aggregate_pairs_capacity: int = 1024#
- class mani_skill.utils.structs.Link[source]#
Bases:
mani_skill.utils.structs.base.PhysxRigidBodyComponentStruct[sapien.physx.PhysxArticulationLinkComponent]Wrapper around physx.PhysxArticulationLinkComponent objects
- bbox(filter)[source]#
- Parameters:
filter (Callable[[sapien.physx.PhysxArticulationLinkComponent, sapien.render.RenderShape], bool])
- Return type:
list[trimesh.primitives.Box]
- classmethod create(physx_links, scene, scene_idxs)[source]#
- Parameters:
physx_links (list[sapien.physx.PhysxArticulationLinkComponent])
scene_idxs (torch.Tensor)
- generate_mesh(filter, mesh_name)[source]#
Generates mesh objects (trimesh.Trimesh) for each managed physx link given a filter and saves them to self.meshes[mesh_name] in addition to returning them here.
- Parameters:
filter (Callable[[sapien.physx.PhysxArticulationLinkComponent, sapien.render.RenderShape], bool])
mesh_name (str)
- get_visual_meshes(to_world_frame=True, first_only=False)[source]#
Returns the visual mesh of each managed link object. Note results of this are not cached or optimized at the moment so this function can be slow if called too often
- Parameters:
to_world_frame (bool)
first_only (bool)
- Return type:
list[trimesh.Trimesh]
- set_collision_group_bit(group, bit_idx, bit)[source]#
Set’s a specific collision group bit for all collision shapes in all parallel actors :param group: the collision group to set the bit for. Typically you only need to use group 2 to disable collision checks between links to enable faster simulation. :type group: int :param bit_idx: the bit index to set :type bit_idx: int :param bit: the bit value to set. Must be 1/0 or True/False. :type bit: int | bool
- Parameters:
group (int)
bit_idx (int)
bit (Union[int, bool])
- set_pose(arg1)[source]#
- Parameters:
arg1 (Union[mani_skill.utils.structs.pose.Pose, sapien.Pose])
- Return type:
None
- articulation: mani_skill.utils.structs.Articulation = None#
the articulation that this link is a part of. If this is None, most likely this link object is a view/merged link object in which case there is no one articulation that can be referenced easily
- property index: torch.Tensor#
The indexes of the managed link objects in their respective articulations. NOTE that these do not correspond with position in the qpos and qvel of articulations. For that index use index_q
- Return type:
torch.Tensor
- property is_root: torch.Tensor#
- Return type:
torch.Tensor
- joint: mani_skill.utils.structs.articulation_joint.ArticulationJoint = None#
the joint of which this link is a child of. If this is a view/merged link then this joint is also a view/merged joint
- merged: bool = False#
whether this link is result of Link.merge or not
- meshes: dict[str, list[trimesh.Trimesh]]#
map from user-defined mesh groups (e.g. “handle” meshes for cabinets) to a list of trimesh.Trimesh objects corresponding to each physx link object managed here
- name: str = None#
- property per_scene_id: torch.Tensor#
Returns a int32 torch tensor of the link level segmentation ID for each managed link object.
- Return type:
torch.Tensor
- property pose: mani_skill.utils.structs.pose.Pose#
- Return type:
- property render_shapes#
Returns each managed link objects render shape list (a list of lists)
- class mani_skill.utils.structs.PhysxJointComponentStruct[source]#
Bases:
BaseStruct[T],Generic[T]Base class of all structs that manage sapien objects on CPU/GPU
- pose_in_child: mani_skill.utils.structs.pose.Pose#
- pose_in_parent: mani_skill.utils.structs.pose.Pose#
- class mani_skill.utils.structs.PhysxRigidBaseComponentStruct[source]#
Bases:
BaseStruct[T],Generic[T]Base class of all structs that manage sapien objects on CPU/GPU
- _bodies: list[sapien.physx.PhysxRigidBaseComponent]#
- class mani_skill.utils.structs.PhysxRigidBodyComponentStruct[source]#
Bases:
PhysxRigidBaseComponentStruct[T],Generic[T]Base class of all structs that manage sapien objects on CPU/GPU
- get_net_contact_forces()[source]#
Get the net contact forces on this body. Returns force vector of shape (N, 3) where N is the number of environments, and 3 is the dimension of the force vector itself, representing x, y, and z direction of force.
- get_net_contact_impulses()[source]#
Get the net contact impulses on this body. Returns impulse vector of shape (N, 3) where N is the number of environments, and 3 is the dimension of the impulse vector itself, representing x, y, and z direction of impulse.
- _bodies: list[sapien.physx.PhysxRigidBodyComponent]#
- property _body_data: torch.Tensor#
- Return type:
torch.Tensor
- property _body_data_index#
a list of indexes of each GPU rigid body in the px.cuda_rigid_body_data buffer, one for each element in self._objs
- _body_data_index_internal: slice = None#
- _body_data_name: str#
- property _body_force_query#
- property angular_damping: torch.Tensor#
- Return type:
torch.Tensor
- property angular_velocity: torch.Tensor#
- Return type:
torch.Tensor
- property auto_compute_mass: torch.Tensor#
- Return type:
torch.Tensor
- property cmass_local_pose: mani_skill.utils.structs.pose.Pose#
- Return type:
- property disable_gravity: torch.Tensor#
- Return type:
torch.Tensor
- property linear_damping: torch.Tensor#
- Return type:
torch.Tensor
- property linear_velocity: torch.Tensor#
- Return type:
torch.Tensor
- property mass: torch.Tensor#
- Return type:
torch.Tensor
- property px#
The physx system objects managed by this dataclass are working on
- class mani_skill.utils.structs.PhysxRigidDynamicComponentStruct[source]#
Bases:
PhysxRigidBodyComponentStruct[T],Generic[T]Base class of all structs that manage sapien objects on CPU/GPU
- set_angular_velocity(arg0)[source]#
Set the angular velocity of the dynamic rigid body. :param arg0: The angular velocity to set. Can be of shape (N, 3) where N is the number of managed bodies or (3, ) to apply the same angular velocity to all managed bodies.
- Parameters:
arg0 (mani_skill.utils.structs.types.Array)
- set_linear_velocity(arg0)[source]#
Set the linear velocity of the dynamic rigid body. :param arg0: The linear velocity to set. Can be of shape (N, 3) where N is the number of managed bodies or (3, ) to apply the same linear velocity to all managed bodies.
- Parameters:
arg0 (mani_skill.utils.structs.types.Array)
- set_locked_motion_axes(axes)[source]#
Set some motion axes of the dynamic rigid body to be locked :param axes: list of 6 true/false values indicating whether which of the 6 DOFs of the body is locked.
The order is linear X, Y, Z followed by angular X, Y, Z. If given a single list of length 6, it will be applied to all managed bodies. If given a a batch of shape (N, 6), you can modify the N managed bodies each in batch.
Example
set_locked_motion_axes([True, False, False, False, True, False]) allows the object to move along the X axis and rotate about the Y axis
- Parameters:
axes (mani_skill.utils.structs.types.Array)
- Return type:
None
- _bodies: list[sapien.physx.PhysxRigidDynamicComponent]#
- property angular_velocity: torch.Tensor#
- Return type:
torch.Tensor
- property gpu_index#
- property gpu_pose_index#
- property is_sleeping#
- property linear_velocity: torch.Tensor#
- Return type:
torch.Tensor
- property locked_motion_axes: mani_skill.utils.structs.types.Array#
list[bool]
- Type:
type
- Return type:
mani_skill.utils.structs.types.Array
- class mani_skill.utils.structs.Pose[source]#
Wrapper around sapien.Pose that supports managing a batch of Poses and flexible creation of them from a variety of sources (list, numpy array, sapien.Pose). This pose object will also return information with a batch dimension, even if it is just holding a single position and quaternion.
As a result pose.p and pose.q will return shapes (N, 3) and (N, 4) respectively for N poses being stored. pose.raw_pose stores all the pose data as a single 2D array of shape (N, 7).
All sapien.Pose API are re-implemented in batch mode here to support GPU simulation. E.g. pose multiplication and inverse with
pose_1.inv() * pose_2, or creating transformation matrices withpose_1.to_transformation_matrix()are suppported they same way they are in sapien.Pose.Pose Creation#
To create a batched pose with a given position
pand/or quaternionq, you run:pose = Pose.create_from_pq(p=p, q=q)
pandqcan be a torch tensor, numpy array, and/or list, or None.If
porqhave only 1 value/not batched, then we automatically repeat the value to the batch size of the other given value. For example, ifphas a batch dimension of size > 1, andqhas a batch dimension of size 1 or is a flat list, then the code automatically repeats theqvalue to the batch size ofp. Likewise in the reverse direction the same repeating occurs.If
pandqhave the same batch size, they are stored as so.If
pandqhave no batch dimensions, one is automatically added (e.g.phaving shape (3,) now becomes (1, 3))If
pis None, it is auto filled with zeros.If
qis None, it is auto filled with the [1, 0, 0, 0] quaternion.If you have a sapien.Pose, another Pose object, or a raw pose tensor of shape (N, 7) or (7,) called
x, you can create this Pose object with:pose = Pose.create(x)
If you want a sapien.Pose object instead of this batched Pose, you can do
pose.spto get the sapien.Pose version (which is not batched). Note that this is only permitted if this Pose has a batch size of 1.Pose Indexing#
You can index into a Pose object like numpy/torch arrays to get a new Pose object with the indexed data.
For example if
posehas a batch size of 4, thenpose[0]will be a Pose object with batch size of 1, andpose[1:3]will be a Pose object with batch size of 2.- __mul__(arg0)[source]#
Multiply two poses. Supports multiplying singular poses like sapien.Pose or Pose object with batch size of 1 with Pose objects with batch size > 1.
- classmethod create(pose, device=None)[source]#
Creates a Pose object from a given
pose, which can be a torch tensor, sapien.Pose, list of sapien.Pose, or Pose
- classmethod create_from_pq(p=None, q=None, device=None)[source]#
Creates a Pose object from a given position
pand/or quaternionq- Parameters:
p (Optional[mani_skill.utils.structs.types.Array])
q (Optional[mani_skill.utils.structs.types.Array])
device (Optional[mani_skill.utils.structs.types.Device])
- to(device)[source]#
Move the Pose object to a different device
- Parameters:
device (mani_skill.utils.structs.types.Device)
- to_transformation_matrix()[source]#
Returns the (N, 4, 4) shaped transformation matrix equivalent to this pose
- property device: mani_skill.utils.structs.types.Device#
Torch Device the Pose object is on
- Return type:
mani_skill.utils.structs.types.Device
- property p#
The position of this pose
- property q#
The quaternion of this pose
- raw_pose: torch.Tensor#
- property shape: torch.Size#
Shape of the Pose object
- Return type:
torch.Size
- property sp#
Returns the equivalent sapien pose. Note that this is only permitted if this Pose has a batch size of 1.
- class mani_skill.utils.structs.RenderCamera[source]#
Wrapper around sapien.render.RenderCameraComponent
- classmethod create(render_cameras, scene, mount=None)[source]#
- Parameters:
render_cameras (list[sapien.render.RenderCameraComponent])
scene (Any)
mount (Optional[Union[mani_skill.utils.structs.actor.Actor, mani_skill.utils.structs.link.Link]])
- get_picture(names)[source]#
- Parameters:
names (Union[str, list[str]])
- Return type:
list[torch.Tensor]
- set_perspective_parameters(near, far, fx, fy, cx, cy, skew)[source]#
- Parameters:
near (float)
far (float)
fx (float)
fy (float)
cx (float)
cy (float)
skew (float)
- Return type:
None
- set_property(name, value)[source]#
change properties of the camera. This is not well documented at the moment and is a heavily overloaded function.
At the moment you can do this:
set_property(“toneMapper”, value) where value is 0 (gamma), 1 (sRGB), 2 (filmic) change the color management used. Default is 0 (gamma)
set_property(“exposure”, value) where value is the exposure. Default is 1.0
- Parameters:
name (str)
value (Any)
- Return type:
None
- _cached_extrinsic_matrix: torch.Tensor = None#
- _cached_intrinsic_matrix: torch.Tensor = None#
- _cached_local_pose: mani_skill.utils.structs.pose.Pose = None#
- _cached_model_matrix: torch.Tensor = None#
- property _cuda_buffer#
- _render_cameras: list[sapien.render.RenderCameraComponent]#
- camera_group: sapien.render.RenderCameraGroup = None#
- property cx: float#
- Return type:
float
- property cy: float#
- Return type:
float
- property far: float#
- Return type:
float
- property fovx: float#
- Return type:
float
- property fovy: float#
- Return type:
float
- property fx: float#
- Return type:
float
- property fy: float#
- Return type:
float
- property global_pose: mani_skill.utils.structs.pose.Pose#
- Return type:
- property height: int#
- Return type:
int
- property local_pose: sapien.Pose#
- Return type:
sapien.Pose
- name: str#
- property near: float#
- Return type:
float
- scene: Any#
- property skew: float#
- Return type:
float
- property width: int#
- Return type:
int
- class mani_skill.utils.structs.SceneConfig[source]#
-
- bounce_threshold: float = 2.0#
- contact_offset: float = 0.02#
- cpu_workers: int = 0#
- enable_ccd: bool = False#
- enable_enhanced_determinism: bool = False#
- enable_friction_every_iteration: bool = True#
- enable_pcm: bool = True#
- enable_tgs: bool = True#
- gravity: numpy.ndarray | list[float]#
- rest_offset: float = 0#
- sleep_threshold: float = 0.005#
- solver_position_iterations: int = 15#
- solver_velocity_iterations: int = 1#
- class mani_skill.utils.structs.SimConfig[source]#
Simulation configurations for ManiSkill environments
- control_freq: int = 20#
control frequency (Hz). Every control step (e.g. env.step) contains sim_freq / control_freq physx simulation steps
- default_materials_config: DefaultMaterialsConfig#
- gpu_memory_config: GPUMemoryConfig#
- scene_config: SceneConfig#
- sim_freq: int = 100#
simulation frequency (Hz)
- spacing: float = 5#
Controls the spacing between parallel environments when simulating on GPU in meters. Increase this value if you expect objects in one parallel environment to impact objects within this spacing distance