Skip to content

Commit 036efb2

Browse files
Add opt-in runtime detector for wp.quatf .torch reads
ProxyArray now reads the WARN_ON_TORCH_QUATF_ACCESS environment variable on every .torch access. When set to "1", any read of a wp.quatf-typed ProxyArray emits a UserWarning that points at the caller's source line (stacklevel=2) and explains that the Isaac Lab quaternion convention changed from (w, x, y, z) in 2.x to (x, y, z, w) in 3.x. The detector is silent by default; users opt in during migration with `export WARN_ON_TORCH_QUATF_ACCESS=1`, walk through the warning sites, then unset for production runs. The dtype check is cached on construction so the .torch read path stays a constant-time check; only ProxyArrays wrapping wp.quatf arrays even consult the env var. Documents the new tool in the Isaac Lab 3.0 migration guide as a runtime complement to the source-level Quaternion Finder Tool, and adds four unit tests (env unset, env=1 on quatf, env=1 on non-quatf, env=0 on quatf) under test_proxy_array.
1 parent a00a0a3 commit 036efb2

4 files changed

Lines changed: 151 additions & 0 deletions

File tree

‎docs/source/migration/migrating_to_isaaclab_3-0.rst‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,56 @@ Best Practices for Migration
889889

890890
6. **Check documentation** - Update any docs or comments that mention quaternion format.
891891

892+
893+
Using the Runtime Quaternion Access Detector
894+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
895+
896+
The quaternion finder tool above covers hard-coded values in source files,
897+
but it cannot see quaternions that are *read* from asset/sensor data at
898+
runtime. For those, Isaac Lab ships a
899+
runtime detector hook on :class:`~isaaclab.utils.warp.ProxyArray` that flags
900+
every ``.torch`` access on a ``wp.quatf``-typed property and points at the
901+
exact call site. Use it after the source-level migration to catch the cases
902+
the finder tool can't reach.
903+
904+
Enable it by setting an environment variable before launching your script:
905+
906+
.. code-block:: bash
907+
908+
export WARN_ON_TORCH_QUATF_ACCESS=1
909+
./isaaclab.sh -p my_script.py
910+
911+
Every read of ``.torch`` on a ``ProxyArray`` whose underlying ``wp.array`` has
912+
dtype ``wp.quatf`` then emits a :class:`UserWarning` with the message:
913+
914+
.. code-block:: text
915+
916+
Reading .torch on a wp.quatf-typed ProxyArray. The Isaac Lab quaternion
917+
convention changed from (w, x, y, z) in 2.x to (x, y, z, w) in 3.x. If
918+
your code assumes the old order, this is likely the source of incorrect
919+
rotations. Unset WARN_ON_TORCH_QUATF_ACCESS to silence this warning.
920+
921+
The warning's traceback points at the exact line that performed the access
922+
(via ``stacklevel=2``), so you can walk through the matches in your code and
923+
confirm each one uses the new ``(x, y, z, w)`` order.
924+
925+
Typical workflow:
926+
927+
1. Run a representative scene or task with the env var set.
928+
2. Triage every warning location — check whether the call site assumes
929+
``(w, x, y, z)`` (Lab 2.x) or ``(x, y, z, w)`` (Lab 3.x).
930+
3. Migrate the call sites that still expect the old order.
931+
4. Re-run with the env var still set; the warnings should be gone (or only
932+
come from intentionally-handled call sites).
933+
5. Unset the env var for production runs — the detector adds an
934+
``os.environ`` lookup per ``.torch`` access, which is cheap but not free.
935+
936+
The detector covers only ``ProxyArray.torch`` reads. Direct accesses on the
937+
underlying ``wp.array`` (via ``ProxyArray.warp``) are not flagged, because
938+
warp uses ``(x, y, z, w)`` natively and so a warp-side read is unaffected
939+
by the convention change.
940+
941+
892942
API Changes
893943
~~~~~~~~~~~
894944

‎source/isaaclab/docs/CHANGELOG.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ Added
1212
(typically an upstream library config object). Raises
1313
:class:`AttributeError` if the target is missing a declared field, so
1414
upstream renames surface at startup instead of as silent no-ops.
15+
* Added an opt-in runtime detector on :class:`~isaaclab.utils.warp.ProxyArray`
16+
that emits a :class:`UserWarning` with the call site (``stacklevel=2``) on
17+
every ``.torch`` read of a ``wp.quatf``-typed array when the
18+
``WARN_ON_TORCH_QUATF_ACCESS`` environment variable is set to ``"1"``.
19+
Helps users find code that still assumes Isaac Lab 2.x's ``(w, x, y, z)``
20+
quaternion convention after the migration to Isaac Lab 3.x's
21+
``(x, y, z, w)`` convention. Documented in the Isaac Lab 3.0 migration
22+
guide as a complement to the source-level quaternion finder tool.
1523

1624

1725
4.6.19 (2026-04-27)

‎source/isaaclab/isaaclab/utils/warp/proxy_array.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@
1010

1111
from __future__ import annotations
1212

13+
import os
1314
import warnings
1415
from typing import ClassVar
1516

1617
import torch
1718
import warp as wp
1819

20+
_QUATF_ACCESS_WARN_ENV = "WARN_ON_TORCH_QUATF_ACCESS"
21+
"""Environment variable that, when set to ``"1"``, makes :attr:`ProxyArray.torch`
22+
emit a :class:`UserWarning` on every read of a ``wp.quatf``-typed array. Used as a
23+
runtime aid for tracking down call sites that may still assume Isaac Lab 2.x's
24+
``(w, x, y, z)`` quaternion convention after the migration to Isaac Lab 3.x's
25+
``(x, y, z, w)`` convention. See the Isaac Lab 3.0 migration guide for details."""
26+
1927

2028
class ProxyArray:
2129
"""Warp-first array wrapper providing cached zero-copy ``.torch`` and ``.warp`` accessors.
@@ -72,6 +80,9 @@ def __init__(self, wp_array: wp.array) -> None:
7280
# Bypass __setattr__ for the two internal fields — everything else raises.
7381
object.__setattr__(self, "_warp", wp_array)
7482
object.__setattr__(self, "_torch_cache", None)
83+
# Cached once at construction so the .torch read path stays a constant-time
84+
# check; only used when the WARN_ON_TORCH_QUATF_ACCESS env var is set.
85+
object.__setattr__(self, "_is_quatf", wp_array.dtype is wp.quatf)
7586

7687
def __setattr__(self, name: str, value) -> None:
7788
"""Forbid mutation of ProxyArray instances except for the internal torch cache.
@@ -88,6 +99,16 @@ def __setattr__(self, name: str, value) -> None:
8899
" Construct a new ProxyArray instead of mutating an existing one."
89100
)
90101

102+
@staticmethod
103+
def _quatf_access_warning_enabled() -> bool:
104+
"""Return ``True`` when the ``WARN_ON_TORCH_QUATF_ACCESS`` env var is set to ``"1"``.
105+
106+
Read on every :attr:`torch` access to keep the flag dynamic — a single
107+
``os.environ`` lookup is cheap relative to the warp/torch interop work
108+
that follows.
109+
"""
110+
return os.environ.get(_QUATF_ACCESS_WARN_ENV, "0") == "1"
111+
91112
# ------------------------------------------------------------------
92113
# Core accessors
93114
# ------------------------------------------------------------------
@@ -104,7 +125,24 @@ def torch(self) -> torch.Tensor:
104125
The tensor is created on first access via :func:`warp.to_torch` and cached
105126
for subsequent calls. Since this is a zero-copy view, modifications to the
106127
tensor are visible through the warp array and vice versa.
128+
129+
When the underlying warp array has dtype ``wp.quatf`` and the
130+
``WARN_ON_TORCH_QUATF_ACCESS`` environment variable is set to ``"1"``,
131+
each read emits a :class:`UserWarning` pointing at the call site. This
132+
is a runtime aid for migrating Isaac Lab 2.x code (which used the
133+
``(w, x, y, z)`` quaternion convention) to Isaac Lab 3.x's
134+
``(x, y, z, w)`` convention.
107135
"""
136+
if self._is_quatf and self._quatf_access_warning_enabled():
137+
warnings.warn(
138+
"Reading .torch on a wp.quatf-typed ProxyArray. The Isaac Lab"
139+
" quaternion convention changed from (w, x, y, z) in 2.x to"
140+
" (x, y, z, w) in 3.x. If your code assumes the old order,"
141+
" this is likely the source of incorrect rotations."
142+
f" Unset {_QUATF_ACCESS_WARN_ENV} to silence this warning.",
143+
UserWarning,
144+
stacklevel=2,
145+
)
108146
if self._torch_cache is None:
109147
self._torch_cache = wp.to_torch(self._warp)
110148
return self._torch_cache

‎source/isaaclab/test/utils/warp/test_proxy_array.py‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,61 @@ def test_2d_vec3f_shape(self, device):
169169
assert ta.torch.shape == (4, 5, 3)
170170

171171

172+
class TestProxyArrayQuatfTorchAccessWarning:
173+
"""Tests for the WARN_ON_TORCH_QUATF_ACCESS opt-in runtime detector."""
174+
175+
def test_default_no_warning(self, device, monkeypatch):
176+
"""No env var → quatf .torch access is silent."""
177+
from isaaclab.utils.warp.proxy_array import ProxyArray
178+
179+
monkeypatch.delenv("WARN_ON_TORCH_QUATF_ACCESS", raising=False)
180+
ta = ProxyArray(wp.zeros(4, dtype=wp.quatf, device=device))
181+
with warnings.catch_warnings(record=True) as w:
182+
warnings.simplefilter("always")
183+
_ = ta.torch
184+
assert [x for x in w if issubclass(x.category, UserWarning)] == []
185+
186+
def test_env_set_warns_on_quatf(self, device, monkeypatch):
187+
"""WARN_ON_TORCH_QUATF_ACCESS=1 → quatf .torch read emits a UserWarning at the call site."""
188+
from isaaclab.utils.warp.proxy_array import ProxyArray
189+
190+
monkeypatch.setenv("WARN_ON_TORCH_QUATF_ACCESS", "1")
191+
ta = ProxyArray(wp.zeros(4, dtype=wp.quatf, device=device))
192+
with warnings.catch_warnings(record=True) as w:
193+
warnings.simplefilter("always")
194+
_ = ta.torch # the .torch read on this line is what should be reported
195+
user_warns = [x for x in w if issubclass(x.category, UserWarning)]
196+
assert len(user_warns) == 1
197+
assert "quatf" in str(user_warns[0].message)
198+
assert "(w, x, y, z)" in str(user_warns[0].message)
199+
assert "(x, y, z, w)" in str(user_warns[0].message)
200+
# stacklevel=2 → the warning's filename is this test file, not proxy_array.py
201+
assert user_warns[0].filename == __file__
202+
203+
def test_env_set_does_not_warn_on_non_quatf(self, device, monkeypatch):
204+
"""The detector only fires for wp.quatf — float32 / vec3f / transformf are silent."""
205+
from isaaclab.utils.warp.proxy_array import ProxyArray
206+
207+
monkeypatch.setenv("WARN_ON_TORCH_QUATF_ACCESS", "1")
208+
for dtype in (wp.float32, wp.vec3f, wp.transformf, wp.spatial_vectorf):
209+
ta = ProxyArray(wp.zeros(4, dtype=dtype, device=device))
210+
with warnings.catch_warnings(record=True) as w:
211+
warnings.simplefilter("always")
212+
_ = ta.torch
213+
assert [x for x in w if issubclass(x.category, UserWarning)] == []
214+
215+
def test_env_zero_does_not_warn(self, device, monkeypatch):
216+
"""WARN_ON_TORCH_QUATF_ACCESS=0 → silent (only ``"1"`` enables the detector)."""
217+
from isaaclab.utils.warp.proxy_array import ProxyArray
218+
219+
monkeypatch.setenv("WARN_ON_TORCH_QUATF_ACCESS", "0")
220+
ta = ProxyArray(wp.zeros(4, dtype=wp.quatf, device=device))
221+
with warnings.catch_warnings(record=True) as w:
222+
warnings.simplefilter("always")
223+
_ = ta.torch
224+
assert [x for x in w if issubclass(x.category, UserWarning)] == []
225+
226+
172227
class TestProxyArrayConvenienceProperties:
173228
"""Tests for convenience properties: shape, dtype, device, len, repr."""
174229

0 commit comments

Comments
 (0)