Repository navigation
Add SequentialSampler - #1517
Conversation
ChoiceSampler draws an item of a list at random. Asset selection (#1458) also needs to take the items of a list in order, one per rebuild, and to record and replay them like any other variation sample. SequentialSampler returns the items of a per-call list in order from a position it keeps, starting over after the last item. Like ChoiceSampler, it returns replayed rows when a replay sampler supplies them, checks that they belong to the list, and notifies listeners. Signed-off-by: Clemens Volk <[email protected]>
Signed-off-by: Clemens Volk <[email protected]>
[Low impact] The PR appears safe to merge; no actionable issues were found. SummaryAdds
Reviews (1) · Last reviewed commit: "Add SequentialSampler" · Reviewed by Greptile |
🤖 Isaac Lab-Arena Review BotSummaryThis PR adds Design, Boundaries & Scope
Findings🟡 Warning: 🟡 Warning: Test Coverage and CI CostThe new tests are plain Python and don't need a SimulationApp, so they add almost no CI time. At this head, Pre-commit and the docs build passed, "Run tests (native uv, source)" was skipped, and the image builds were still running. I didn't see a check that ran the new tests, so I can't confirm they pass in CI. VerdictMinor fixes needed |
peterd-NV
left a comment
There was a problem hiding this comment.
Thanks, looks good. One note on the test that I think should have the bot review suggested change applied and one minor non blocking note.
SequentialSampler kept a position, advanced it after each draw and reduced it modulo the length of the last list. Its only caller sets the position right before every draw, and each rebuild builds a new sampler anyway, so the stored position mattered only in tests, and reusing a sampler with lists of different lengths shifted where the next list started. sample() now takes a keyword-only start_index and returns num_samples consecutive items from it, so the result depends only on the arguments. The order test checks start indices that each give a different item, so it fails if the index is ignored. Signed-off-by: Clemens Volk <[email protected]>
Signed-off-by: Clemens Volk <[email protected]>
The selection only swaps the spawn configuration, so the scene runs validate_simulation_cfg() of the declared object, not of the selected asset. Selecting a Newton-only gear in a PhysX build therefore passed validation. Reject candidates whose class defines its own validate_simulation_cfg(), with a TODO to run that check instead. Also pass the rebuild index to SequentialSampler as start_index, now that #1517 no longer keeps a position. Signed-off-by: Clemens Volk <[email protected]>
Add a disabled `asset_selection` variation to every rigid `Object`, so an Experiment Run can spawn a different registered asset in each rebuild. To support it, build the task contact sensors and the default task description after the selection, so they match the selected asset, and name the `pick_and_place_maple_table` objects `pick_up_object` and `destination_location`, so their variation keys stay the same whichever asset they spawn. ## Why this change? Lighting, HDR maps, camera poses and object mass are variations: an experiment turns them on, the seed decides their values, every episode row records them, and recorded variation replay repeats them. The pick-up object is not. An environment fixes it in code or with an option such as `pick_up_object`, so comparing objects takes one Run per object, and the object is not seeded, recorded or replayed like the variations. `RigidObjectSet` varies objects across the environments of one build, but it does not record which object an environment got, and `supports_recorded_placement()` turns off placement recording for a build that contains one. ## What changes? - Every rigid `Object` except a `RigidObjectSet` gets a disabled `asset_selection` variation, a `RigidAssetSelectionVariation`. When enabled, each build spawns one of its `registry_names` in all environments. Rebuild k takes the k-th name, using `SequentialSampler` from #1517, or a random one with `sampler_cfg.random_choice: true`. A name listed twice is selected more often. Each build checks every name but constructs only the selected one. - The selection runs before placement, so placement and the task's contact sensors use the selected asset. Episode rows record the name, and recorded variation replay spawns it again. A replay record with placement samples must include the value of every enabled build-time variation that sets the new `changes_object_geometry` flag, which `RigidAssetSelectionVariation` does. - The selected name becomes the object's `registry_name`, and the default descriptions of `PickAndPlaceTask` and `AssemblyTask` name it. - `Scene.validate_simulation_cfg()` runs the check of the asset a selection spawns, through the new `Asset.get_spawned_asset()`. A selected Newton-only gear fails a PhysX build, and a declared gear that selects a PhysX asset passes one. - The Experiment Runner passes the rebuild index to `ArenaEnvBuilder`. A warning for in-order selections with fewer rebuilds than names follows in #1520. - The `swap_objects` Run of `getting_started_experiment.yaml` selects its pick-up object from a list, one per build, and the variations docs cover it in the build-time explanation and the table of variations. Breaking changes: - `PickAndPlaceTask`, `ObjectInTask` and `SortMultiObjectTask` build their contact sensors in `get_scene_cfg()`. `scene_config`, `make_scene_cfg()` and `SortMultiObjectTask.pick_up_object_contact_sensor_list` are removed. - `PickAndPlaceTask.task_description` and `AssemblyTask.task_description` hold only a description passed to the constructor. Call `get_task_description()` for the generated one. - The `pick_and_place_maple_table` object names change, and with them their variation keys, scene entity names and placement keys. Variation overrides, replay files and HDF5 demos recorded on main with the old names need the new ones. - Variations that override `configure_at_build_time(seed, variation_key)` must also accept `rebuild_index`, because `ArenaEnvBuilder` now passes it. Limitations: - Only the spawn configuration, the simulation check and `registry_name` change. The object keeps its declared class's `scale`, `spawn_cfg_addon` and other methods. - An unknown name, or one whose class declares another object type, fails in the first build. A name the physics backend cannot simulate, or one whose type is known only after construction, such as an embodiment, fails when a rebuild selects it. - Outside the Experiment Runner, for example in `record_demos.py`, every build is rebuild 0, so in-order selection spawns the first name. - The descriptions of `GearInsertionTask` and `PlaceUprightTask` still name the declared asset, and a `SimReadyUsdObject` is described as `simready_usd_object`. - Metrics cover all selected objects together. Group episode rows by `pick_up_object.asset_selection` for per-object results. - A hand-written `language_instruction` applies to every rebuild. - A `bounding_box` override fails the build when the selection is enabled. - An `ObjectReference` into a selected object still reads the declared asset's `usd_path`. ## Usage example Before, one Run per object: ```yaml runs: rubiks_cube: environment: type: pick_and_place_maple_table pick_up_object: rubiks_cube_hot3d_robolab mustard_bottle: environment: type: pick_and_place_maple_table pick_up_object: mustard_bottle_hot3d_robolab ``` The object is set outside the variation system, so: - the seed, the episode rows' `variations` and recorded variation replay do not cover it; - objects cannot be drawn from a list, in order or at random; - every object needs its own Run. After, one Run that spawns another object in each rebuild (the `swap_objects` Run of `getting_started_experiment.yaml`, which takes the rest of the environment from `shared`): ```yaml runs: swap_objects: environment: destination_location: wooden_bowl_hot3d_robolab num_rebuilds: 3 rollout_limit: num_episodes: 3 variations: pick_up_object.asset_selection.enabled: true pick_up_object.asset_selection.registry_names: [mustard_bottle_hot3d_robolab, orange_01_fruits_veggies_robolab, rubiks_cube_hot3d_robolab] ``` Set `pick_up_object.asset_selection.sampler_cfg.random_choice: true` to draw a name at random in each build instead. ## Validation - On ce7302e, the getting-started Experiment loading tests pass in the local container. On d8596bf, so did the selection tests that run without simulation and `test_recorded_variation_samples.py`. - On d3623d0, the plain Python tests pass in the local container: the selection tests that run without simulation, `test_run_execution.py`, `test_recorded_variation_samples.py` and `test_variation_base.py`. - On 3588692, before the merge of main, 102 related tests pass in the local container, including the Experiment Runner rebuild and replay subprocess tests. The asset selection example experiment of that commit records the three objects in order over rebuilds 0 to 2. - The simulation tests cannot run locally after the merge of main: the local Docker image predates #1481, and Isaac Lab 3.0 fails to import with its warp 1.16.0. CI runs the full suite. --------- Signed-off-by: Clemens Volk <[email protected]>
Add
SequentialSampler, a sampler that returns consecutive items of a list from a given start index, starting over after the last item.Why this change?
The samplers in
isaaclab_arena/variationsdraw their values at random.ChoiceSamplerpicks a random item of a list. Asset selection (#1458) also needs to take a list in order, so that rebuild k of an Experiment Run spawns the k-th asset. Taking the item through a sampler keeps it recorded and replayed like any other variation sample.What changes?
SequentialSamplerandSequentialSamplerCfginisaaclab_arena/variations/sequential_sampler.py.sample(num_samples, choices, start_index=...)returnsnum_samplesconsecutive items fromstart_index, starting over after the last item. The sampler keeps no state, so the result depends only on the arguments.ChoiceSampler, it returns replayed rows when a replay sampler supplies them, checks that they belong tochoices, and notifies listeners. It draws no random numbers, so the generator does not affect it.Usage example
Validation
pre-commitpasses on the changed files.test_recorded_variation_samples.pyandtest_variation_recorder.pypass in the local container on Make an object's asset a repeatable variation #1458's branch, which has the same three files (at 9a2955f).