Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Fixed
^^^^^

* Fixed a quadratic path lookup in :class:`~isaaclab.scene_data.SceneDataProvider` transform
mapping that stalled setup at high rigid-body counts (thousands of environments). The
per-item ``list.index`` scan is now an ``O(N)`` dictionary lookup.
14 changes: 9 additions & 5 deletions source/isaaclab/isaaclab/scene_data/scene_data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from __future__ import annotations

import contextlib
import re
from collections import deque
from typing import TYPE_CHECKING, Any
Expand Down Expand Up @@ -210,10 +209,15 @@ def create_mapping(self, paths: list[str | None]) -> wp.array(dtype=wp.int32) |
paths or if no mapping is needed.
"""
if input_paths := self.backend.transform_paths:
mapping = [-1] * len(input_paths)
for i, path in enumerate(input_paths):
with contextlib.suppress(ValueError):
mapping[i] = paths.index(path)
# Build a path -> output-index map once (first occurrence wins, to match
# ``list.index`` semantics), then resolve each input path in O(1). This
# was an O(N^2) ``paths.index(path)`` linear scan per input path -- minutes
# at the ~200k rigid bodies of an 8192-env scene.
path_to_out: dict[str | None, int] = {}
for out_idx, out_path in enumerate(paths):
if out_path not in path_to_out:
path_to_out[out_path] = out_idx
mapping = [path_to_out.get(path, -1) for path in input_paths]
if not np.array_equal(mapping, np.arange(len(input_paths))):
return wp.array(mapping, dtype=wp.int32)
return None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Fixed
^^^^^

* Fixed camera world-pose resolution stalling (and benchmark timeouts) at high environment
counts under the PhysX backend. The Fabric frame view no longer rebuilds a whole-scene
path-to-index map on every environment reset; resolved indices are cached and recomputed
only when the prim selection changes.
Original file line number Diff line number Diff line change
Expand Up @@ -491,22 +491,48 @@ def _refresh_active_bundle_if_needed(self) -> None:
self._rebuild_ro_arrays()

def _rebuild_ro_arrays(self) -> None:
"""Rebuild the four ``_sel_ro``-keyed indexed arrays (children + parents)."""
self._ro_fabric_indices = self._compute_fabric_indices(self._sel_ro)
"""Rebuild the four ``_sel_ro``-keyed indexed arrays (children + parents).

The view->fabric index maps change only when the selection's prim set
changes, but resolving them costs a ``str(Sdf.Path)`` over every prim in
the selection (the whole env hierarchy, ~1.1M prims at 8192 envs). So the
(small) resolved index arrays are recomputed only when the selection size
changes; the indexed-fabric-array wrappers below are always rebuilt since
the underlying buckets may have moved.
"""
n = len(self._sel_ro.GetPaths())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caching on just the length feels fragile. But better caching like computing a hash might make this slow again...

if getattr(self, "_ro_cached_n", None) != n:
# Cache only the tiny resolved indices on the host (a few KB), NOT the
# giant per-selection path->index dict.
self._ro_child_idx_host = self._compute_fabric_indices(self._sel_ro).numpy()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why .numpy() here?

self._ro_parent_idx_host = self._compute_parent_fabric_indices(self._sel_ro).numpy()
self._ro_cached_n = n
# Fresh device arrays each rebuild (do not alias one cached wp.array across

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment

# the churning per-reset wrappers).
self._ro_fabric_indices = wp.array(self._ro_child_idx_host, dtype=wp.int32, device=self._device)
self._ro_parent_fabric_indices = wp.array(self._ro_parent_idx_host, dtype=wp.int32, device=self._device)
self._world_ifa_ro = self._build_indexed_array(self._sel_ro, self._WORLD_MATRIX_NAME, self._ro_fabric_indices)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wny do we create new indices here? Can't we use the cached ones directly?

self._local_ifa_ro = self._build_indexed_array(self._sel_ro, self._LOCAL_MATRIX_NAME, self._ro_fabric_indices)
self._ro_parent_fabric_indices = self._compute_parent_fabric_indices(self._sel_ro)
self._parent_world_ifa_ro = wp.indexedfabricarray(
fa=wp.fabricarray(self._sel_ro, self._WORLD_MATRIX_NAME),
indices=self._ro_parent_fabric_indices,
)

def _rebuild_rw_arrays(self) -> None:
"""Rebuild the four ``_sel_rw``-keyed indexed arrays (children + parents)."""
self._rw_fabric_indices = self._compute_fabric_indices(self._sel_rw)
"""Rebuild the four ``_sel_rw``-keyed indexed arrays (children + parents).

See :meth:`_rebuild_ro_arrays`: the resolved index arrays are recomputed
only when the selection size changes; the wrappers are always rebuilt.
"""
n = len(self._sel_rw.GetPaths())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caching on just the length feels fragile. But better caching like computing a hash might make this slow again...

if getattr(self, "_rw_cached_n", None) != n:
self._rw_child_idx_host = self._compute_fabric_indices(self._sel_rw).numpy()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why numpy() here?

self._rw_parent_idx_host = self._compute_parent_fabric_indices(self._sel_rw).numpy()
self._rw_cached_n = n
self._rw_fabric_indices = wp.array(self._rw_child_idx_host, dtype=wp.int32, device=self._device)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wny do we create new indices here? Can't we use the cached ones directly?

self._rw_parent_fabric_indices = wp.array(self._rw_parent_idx_host, dtype=wp.int32, device=self._device)
self._world_ifa_rw = self._build_indexed_array(self._sel_rw, self._WORLD_MATRIX_NAME, self._rw_fabric_indices)
self._local_ifa_rw = self._build_indexed_array(self._sel_rw, self._LOCAL_MATRIX_NAME, self._rw_fabric_indices)
self._rw_parent_fabric_indices = self._compute_parent_fabric_indices(self._sel_rw)
self._parent_world_ifa_rw = wp.indexedfabricarray(
fa=wp.fabricarray(self._sel_rw, self._WORLD_MATRIX_NAME),
indices=self._rw_parent_fabric_indices,
Expand Down
Loading