Skip to content

Commit db56f66

Browse files
committed
Check recapture and stream order through data in session-read tests
- The native-edit test asserts the read after invalidation captures again. - The stream test queues a copy after the replay and syncs only that stream. - Read the collection link types through one collection; both share a layout.
1 parent f4f6672 commit db56f66

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

‎source/isaaclab_ov/isaaclab_ov/test/fixtures/views/session_reads.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
REPLAY_ONLY = "read_into did not replay its captured session read"
2020
"""Failure of a binding read or a new capture where only the captured plan may serve the read."""
2121

22+
RECAPTURE = "read_into replayed a plan it had to capture again"
23+
"""Failure of a replay where the read must capture a new plan."""
24+
2225

2326
def binding_values(view: OvPhysxView, tensor_type: int) -> wp.array:
2427
"""Read ``tensor_type`` straight from its TensorBinding: the reference a session read must match.
@@ -44,3 +47,12 @@ def replays_only(view: OvPhysxView, tensor_type: int) -> Iterator[None]:
4447
):
4548
yield
4649
assert launch.call_count == 1, REPLAY_ONLY
50+
51+
52+
@contextlib.contextmanager
53+
def captures_again(tensor_type: int) -> Iterator[None]:
54+
"""Fail unless the one ``read_into`` inside captures a new plan of ``tensor_type``, rather than replaying one."""
55+
capture = OvPhysxSessionReads._capture
56+
with patch.object(OvPhysxSessionReads, "_capture", autospec=True, side_effect=capture) as spy:
57+
yield
58+
assert spy.call_count == 1 and spy.call_args.args[1] == tensor_type, RECAPTURE

‎source/isaaclab_ov/test/assets/test_rigid_object.py‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
from collections.abc import Iterator
2424
from dataclasses import dataclass
25-
from unittest.mock import patch
2625

2726
import numpy as np
2827
import pytest
@@ -39,7 +38,7 @@
3938
from isaaclab_ov.assets import RigidObject, RigidObjectCollection # noqa: E402
4039
from isaaclab_ov.physics import OvPhysxCfg # noqa: E402
4140
from isaaclab_ov.sim.views import OvPhysxView # noqa: E402
42-
from isaaclab_ov.test.fixtures.views.session_reads import binding_values, replays_only # noqa: E402
41+
from isaaclab_ov.test.fixtures.views.session_reads import binding_values, captures_again, replays_only # noqa: E402
4342
from ovphysx.types import SimObjectType # noqa: E402
4443

4544
import isaaclab.sim as sim_utils # noqa: E402
@@ -302,8 +301,8 @@ def test_session_reads_after_a_native_structural_edit(device: str) -> None:
302301
"""After ``invalidate_session_reads`` and a body disabled through the native handle, the next read captures again
303302
and reads the binding's values.
304303
305-
It guards the invalidation itself (released plans are captured again, never replayed); with today's ovphysx a plan
306-
captured before this edit also still reads correctly, so it cannot show that the edit needs the invalidation.
304+
With today's ovphysx a plan captured before this edit would still read correctly, so the recapture is asserted
305+
directly: an invalidation that kept the plans fails it.
307306
"""
308307
with build_simulation_context(device=device, sim_cfg=SimulationCfg(physics=OvPhysxCfg(), device=device)) as sim:
309308
cubes = _spawn_cubes("Edited", y_offset=0.0)
@@ -323,7 +322,8 @@ def test_session_reads_after_a_native_structural_edit(device: str) -> None:
323322
for _ in range(5): # the second cube falls
324323
sim.step()
325324
replayed.fill_(-1.0)
326-
view.read_into(TT.RIGID_BODY_POSE, replayed)
325+
with captures_again(TT.RIGID_BODY_POSE):
326+
view.read_into(TT.RIGID_BODY_POSE, replayed)
327327
expected = binding_values(view, TT.RIGID_BODY_POSE)
328328
torch.testing.assert_close(wp.to_torch(replayed), wp.to_torch(expected), atol=0.0, rtol=0.0)
329329
finally:
@@ -475,9 +475,10 @@ def test_session_reads_match_bindings(scene: _RigidScene, tensor_type: int) -> N
475475
"""A session read fills ``read_into`` with the binding's values in the binding's row order."""
476476
for _ in range(3):
477477
scene.sim.step()
478-
# A collection reads LINK_* through its RIGID_BODY_* binding; the cuboid pairs read the rigid-body types.
478+
# A collection reads LINK_* through its RIGID_BODY_* binding (one collection: they share the layout); the cuboid
479+
# pairs read the rigid-body types.
479480
served = {TT.LINK_POSE: TT.RIGID_BODY_POSE, TT.LINK_VELOCITY: TT.RIGID_BODY_VELOCITY}.get(tensor_type)
480-
owners = (scene.fused, scene.stepped) if served else (scene.dynamic, scene.kinematic, scene.spinning)
481+
owners = (scene.fused,) if served else (scene.dynamic, scene.kinematic, scene.spinning)
481482
for owner in owners:
482483
view = owner.root_view
483484
expected = binding_values(view, tensor_type)
@@ -499,13 +500,14 @@ def test_session_read_replays_on_the_callers_stream(scene: _RigidScene, null_str
499500
replayed = wp.zeros_like(expected)
500501
view.read_into(TT.RIGID_BODY_POSE, replayed) # captures the plan
501502
replayed.fill_(-1.0)
503+
copied = wp.zeros_like(expected)
502504
wp.synchronize_device(device)
503505
stream = wp.get_device(device).null_stream if null_stream else wp.Stream(device)
504-
with wp.ScopedStream(stream), patch.object(wp, "capture_launch", wraps=wp.capture_launch) as launch:
506+
with wp.ScopedStream(stream):
505507
view.read_into(TT.RIGID_BODY_POSE, replayed)
506-
assert launch.call_args.kwargs["stream"] is stream
507-
wp.synchronize_device(device)
508-
torch.testing.assert_close(wp.to_torch(replayed), wp.to_torch(expected), atol=0.0, rtol=0.0)
508+
wp.copy(copied, replayed) # queued after the replay on the same stream
509+
wp.synchronize_stream(stream) # only this stream: a replay elsewhere leaves the copy holding -1
510+
torch.testing.assert_close(wp.to_torch(copied), wp.to_torch(expected), atol=0.0, rtol=0.0)
509511

510512

511513
@pytest.mark.parametrize("scene", _CUDA_SCENES, indirect=True)

0 commit comments

Comments
 (0)