Repository navigation
Declare semantic inclusion matches and select compact clone worlds #9156
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
Changes from 4 commits
ace1e86
9c7a0f8
75dc866
c763fc3
41f14db
99002df
ec2d14e
e1a6080
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| * Added :attr:`~isaaclab.cloner.InclusionSet.variants` to pin the spawner variant of assets in a clone combination, so | ||
| scenes can list their legal variant-level compositions instead of enumerating the product of all variant counts. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,13 @@ | |
| from isaaclab.assets import AssetBaseCfg, RigidObjectCfg | ||
| from isaaclab.cloner import ( | ||
| CloneCfg, | ||
| InclusionSet, | ||
| ReplicateContext, | ||
| ReplicateSession, | ||
| UsdReplicateContext, | ||
| clone_plan_from_env_0, | ||
| grid_transforms, | ||
| make_valid_clone_combinations, | ||
| ) | ||
| from isaaclab.cloner import path as cloner_path | ||
| from isaaclab.renderers import RenderContext, RendererCfg | ||
|
|
@@ -285,6 +287,28 @@ def test_multi_spawner_creates_concrete_asset_prototypes(simulation, unused_vari | |
| assert all(1 not in ids for _, _, ids in simulation.calls) | ||
|
|
||
|
|
||
| def test_pinned_variants_narrow_a_combination_to_its_unpinned_product(): | ||
| """A pin fixes one asset's variant, also for repeated instances; only unpinned assets multiply.""" | ||
| # Flat prototype rows: robot 0, part 1-3, tool 4-5, lamp 6-7. Unclaimed robot and lamp join every world. | ||
| names, counts = ["robot", "part", "tool", "lamp"], [1, 3, 2, 2] | ||
| combinations = [ | ||
| InclusionSet(assets=["part", "tool"], variants={"part": 2, "tool": 0, "lamp": 0}, weight=3.0), | ||
| InclusionSet(assets=["part", "part", "tool"], variants={"part": 1, "lamp": 1}), | ||
| ] | ||
| worlds, weights = make_valid_clone_combinations(names, counts, combinations) | ||
| # Pinning every multi-variant asset leaves one world carrying the whole weight; the free tool splits the other. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Warning · Style Consistency — Remove assertion-narrating comment The comment repeats the test docstring and narrates the following world and weight assertions. Remove it; the prototype-row mapping above explains the non-obvious numeric IDs. |
||
| assert worlds == ((0, 3, 4, 6), (0, 2, 2, 4, 7), (0, 2, 2, 5, 7)) | ||
| np.testing.assert_array_equal(weights, [3.0, 0.5, 0.5]) | ||
|
|
||
| with pytest.raises(ValueError, match="does not replicate.*'tool'"): | ||
| absent = [InclusionSet(assets=["part"], variants={"tool": 0}), InclusionSet(assets=["tool"])] | ||
| make_valid_clone_combinations(names, counts, absent) | ||
| # A pin is an index into the asset's variants; None does not leave the asset free. | ||
| for variant in (3, -1, None, True): | ||
| with pytest.raises(ValueError, match=f"Cannot pin variant {variant} of 'part'"): | ||
| make_valid_clone_combinations(names, counts, [InclusionSet(assets=["part"], variants={"part": variant})]) | ||
|
|
||
|
|
||
| def test_replicate_session_clears_plan_when_asset_init_fails(simulation): | ||
| """Failed construction releases the plan without dispatching any clone backend.""" | ||
| with pytest.raises(RuntimeError, match="asset boom"): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
|
|
||
| import isaaclab.sim as sim_utils | ||
| from isaaclab.assets import RigidObjectCfg | ||
| from isaaclab.cloner import InclusionSet | ||
| from isaaclab.scene import InteractiveScene, InteractiveSceneCfg | ||
| from isaaclab.sim import build_simulation_context | ||
| from isaaclab.test.utils import DeviceScope, test_devices | ||
|
|
@@ -149,6 +150,38 @@ def test_native_selection_preserves_initial_worlds_and_unused_variant(device: st | |
| torch.testing.assert_close(asset.mesh_variant_ids.torch.cpu(), torch.tensor([2, 1], dtype=torch.int32)) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("device", test_devices(DeviceScope.DEFAULT_CUDA)) | ||
| def test_pinned_clone_combinations_choose_initial_variants(device: str) -> None: | ||
| """Each world starts with the variants its clone combination pins, for reset-time and static spawners.""" | ||
| scene_cfg = _VariantSceneCfg(num_envs=4, env_spacing=2.0) | ||
| third = scene_cfg.object.spawn.assets_cfg[0].copy() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Warning · Style Consistency — Use functional configuration cloning New configuration code should use the guide's functional operations. Replace this added |
||
| third.radius, third.mass_props.mass = 0.06, 27.0 | ||
| scene_cfg.object.spawn.assets_cfg.append(third) | ||
| scene_cfg.fixture = _variant_object() | ||
| scene_cfg.fixture.prim_path = "{ENV_REGEX_NS}/Fixture" | ||
| scene_cfg.fixture.spawn.static = True | ||
| scene_cfg.fixture.init_state.pos = (0.5, 0.0, 0.2) | ||
| # The second combination leaves the fixture free, so it expands into one world prototype per fixture variant. | ||
| scene_cfg.clone_cfg.clone_combinations = [ | ||
| InclusionSet(assets=["object", "fixture"], variants={"object": 2, "fixture": 1}), | ||
| InclusionSet(assets=["object", "fixture"], variants={"object": 0}), | ||
| ] | ||
| sim_cfg = SimulationCfg( | ||
| device=device, | ||
| gravity=(0.0, 0.0, 0.0), | ||
| physics=NewtonCfg(solver_cfg=MJWarpSolverCfg(use_mujoco_contacts=False), use_cuda_graph=False), | ||
| ) | ||
| with build_simulation_context(sim_cfg=sim_cfg) as sim: | ||
| sim._app_control_on_stop_handle = None | ||
| scene = InteractiveScene(scene_cfg) | ||
| sim.register_interactive_scene(scene) | ||
| sim.reset() | ||
| asset, fixture = scene["object"], scene["fixture"] | ||
| torch.testing.assert_close(asset.mesh_variant_ids.torch.cpu(), torch.tensor([2, 2, 0, 0], dtype=torch.int32)) | ||
| torch.testing.assert_close(asset.data.body_mass.torch[:, 0].cpu(), torch.tensor([27.0, 27.0, 1.0, 1.0])) | ||
| torch.testing.assert_close(fixture.data.body_mass.torch[:, 0].cpu(), torch.tensor([8.0, 8.0, 1.0, 8.0])) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("device", test_devices(DeviceScope.DEFAULT_CUDA)) | ||
| @pytest.mark.parametrize( | ||
| "solver_cfg, static", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Warning · Test Quality — Mark the planning test kitless
CI selects kitless files by marker text. This pure-planning test has no kitless marker, so that selection omits it. Add
pytest.mark.kitlessto the test.