Skip to content
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

Fix meta link path and jitscript regressions from latest PRs #1125

Merged
merged 5 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions omnigibson/controllers/joint_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from omnigibson.macros import create_module_macros
from omnigibson.utils.backend_utils import _compute_backend as cb
from omnigibson.utils.backend_utils import add_compute_function
from omnigibson.utils.python_utils import assert_valid_key
from omnigibson.utils.python_utils import assert_valid_key, torch_compile
from omnigibson.utils.ui_utils import create_module_logger

# Create module logger
Expand Down Expand Up @@ -307,7 +307,7 @@ def command_dim(self):
return len(self.dof_idx)


@th.compile
@torch_compile
def _compute_joint_torques_torch(
u: th.Tensor,
mm: th.Tensor,
Expand Down
14 changes: 12 additions & 2 deletions omnigibson/object_states/particle_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,21 @@ def overlap_callback(hit):
"height": 1.0,
"size": 1.0,
}
mesh_prim_path = f"{self.link.prim_path}/visuals/mesh_0"

# Create a primitive shape if it doesn't already exist
# See if the mesh exists at the latest dataset's target location
mesh_prim_path = f"{self.link.prim_path}/visuals/mesh_0"
pre_existing_mesh = lazy.omni.isaac.core.utils.prims.get_prim_at_path(mesh_prim_path)

# If not, see if it exists in the legacy format's location
# TODO: Remove this after new dataset release
if not pre_existing_mesh:
mesh_prim_path = f"{self.link.prim_path}/mesh_0"
pre_existing_mesh = lazy.omni.isaac.core.utils.prims.get_prim_at_path(mesh_prim_path)

# Create a primitive mesh neither option exists
if not pre_existing_mesh:
mesh_prim_path = f"{self.link.prim_path}/visuals/mesh_0"

# Projection mesh params must be specified in order to determine scalings
assert self._projection_mesh_params is not None, (
f"Must specify projection_mesh_params for {self.obj.name}'s {self.__class__.__name__} "
Expand Down
11 changes: 10 additions & 1 deletion omnigibson/object_states/toggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,19 @@ def _initialize(self):
# Make sure this object is not cloth
assert self.obj.prim_type != PrimType.CLOTH, f"Cannot create ToggledOn state for cloth object {self.obj.name}!"

# See if the mesh exists at the latest dataset's target location
mesh_prim_path = f"{self.link.prim_path}/visuals/mesh_0"
pre_existing_mesh = lazy.omni.isaac.core.utils.prims.get_prim_at_path(mesh_prim_path)
# Create a primitive mesh if it doesn't already exist

# If not, see if it exists in the legacy format's location
# TODO: Remove this after new dataset release
if not pre_existing_mesh:
mesh_prim_path = f"{self.link.prim_path}/mesh_0"
pre_existing_mesh = lazy.omni.isaac.core.utils.prims.get_prim_at_path(mesh_prim_path)

# Create a primitive mesh neither option exists
if not pre_existing_mesh:
mesh_prim_path = f"{self.link.prim_path}/visuals/mesh_0"
self.scale = m.DEFAULT_SCALE if self.scale is None else self.scale
# Note: We have to create a mesh (instead of a sphere shape) because physx complains about non-uniform
# scaling for non-meshes
Expand Down
32 changes: 31 additions & 1 deletion omnigibson/prims/cloth_prim.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
CLOTH_CONFIGURATIONS = ["default", "settled", "folded", "crumpled"]

# Subsample cloth particle points to boost performance
m.ALLOW_MULTIPLE_CLOTH_MESH_COMPONENTS = False
m.ALLOW_MULTIPLE_CLOTH_MESH_COMPONENTS = True # TODO: Disable after new dataset release
m.N_CLOTH_KEYPOINTS = 1000
m.FOLDING_INCREMENTS = 100
m.CRUMPLING_INCREMENTS = 100
Expand Down Expand Up @@ -1023,3 +1023,33 @@ def reset(self):
if self.initialized:
points_configuration = self._load_config.get("default_point_configuration", "default")
self.reset_points_to_configuration(points_configuration)

@cached_property
def is_meta_link(self):
return False

@cached_property
def meta_link_type(self):
raise ValueError(f"{self.name} is not a meta link")

@cached_property
def meta_link_id(self):
"""The meta link id of this link, if the link is a meta link.

The meta link ID is a semantic identifier for the meta link within the meta link type. It is
used when an object has multiple meta links of the same type. It can be just a numerical index,
or for some objects, it will be a string that can be matched to other meta links. For example,
a stove might have toggle buttons named "left" and "right", and heat sources named "left" and
"right". The meta link ID can be used to match the toggle button to the heat source.
"""
raise ValueError(f"{self.name} is not a meta link")

@cached_property
def meta_link_sub_id(self):
"""The integer meta link sub id of this link, if the link is a meta link.

The meta link sub ID identifies this link as one of the parts of a meta link. For example, an
attachment meta link's ID will be the attachment pair name, and each attachment point that
works with that pair will show up as a separate link with a unique sub ID.
"""
raise ValueError(f"{self.name} is not a meta link")
19 changes: 19 additions & 0 deletions omnigibson/utils/python_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from functools import wraps
from hashlib import md5
from importlib import import_module
import sys

import h5py
import torch as th
Expand Down Expand Up @@ -711,6 +712,24 @@ def __setattr__(self, key, value):
super().__setattr__(key, value)


def torch_compile(func):
"""
Decorator to compile a function with torch.compile on Linux and torch.jit.script on Windows. This is because of poor support for torch.compile on Windows.

Args:
func (function): Function to compile

Returns:
function: Compiled function
"""
# If we're on Windows, return a jitscript option
if sys.platform == "win32":
return th.jit.script(func)
# Otherwise, return a torch.compile option
else:
return th.compile(func)


def nums2array(nums, dim, dtype=th.float32):
"""
Converts input @nums into numpy array of length @dim. If @nums is a single number, broadcasts input to
Expand Down
Loading
Loading