Skip to content

Add SequentialSampler - #1517

Merged
cvolkcvolk merged 2 commits into
mainfrom
cvolkcvolk/feature/sequential-sampler
Oct 25, 2026
Merged

cvolkcvolk merged 2 commits into
mainfrom
cvolkcvolk/feature/sequential-sampler

Conversation

@cvolkcvolk

@cvolkcvolk cvolkcvolk commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

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/variations draw their values at random. ChoiceSampler picks 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?

  • New SequentialSampler and SequentialSamplerCfg in isaaclab_arena/variations/sequential_sampler.py. sample(num_samples, choices, start_index=...) returns num_samples consecutive items from start_index, starting over after the last item. The sampler keeps no state, so the result depends only on the arguments.
  • Like ChoiceSampler, it returns replayed rows when a replay sampler supplies them, checks that they belong to choices, and notifies listeners. It draws no random numbers, so the generator does not affect it.

Usage example

sampler = SequentialSamplerCfg().build()
registry_name = sampler.sample(1, ["cracker_box", "sugar_box", "mustard_bottle"], start_index=rebuild_index)[0]

Validation

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]>
@greptile-apps

greptile-apps Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no actionable issues were found.

Summary

Adds SequentialSampler and SequentialSamplerCfg for drawing items in order and wrapping after the last item.

  • Sequential sampling returns choices in order and starts over at the end.

Reviews (1) · Last reviewed commit: "Add SequentialSampler" · Reviewed by Greptile

@arena-review-bot

Copy link
Copy Markdown
Contributor

🤖 Isaac Lab-Arena Review Bot

Summary

This PR adds SequentialSampler, which returns the items of a per-call choices list in order and wraps around after the last item. Like ChoiceSampler, it supports recording and replay. It exists so that the asset selection in #1458 can spawn the k-th asset on rebuild k. The sampler code is correct. Two things need attention: the sampler stores a position that its only caller overwrites before every draw, and the one test of set_position() passes even if set_position() does nothing.

Design, Boundaries & Scope

SequentialSampler keeps _position, advances it after every live draw, and leaves it unchanged on a replayed draw. Its only caller, AssetSelectionVariation._realize_at_build_time in #1458, calls set_position(rebuild_index) right before each sample(1, ...). Each rebuild also creates a new variation and sampler, and VariationBase.apply_cfg rebuilds the sampler again. So the stored position always starts at 0 and covers at most one draw. The auto-advance and the replay rule only matter in this PR's tests. Passing the start index to sample() would remove that state; details are in the inline comment.

Findings

🟡 Warning: isaaclab_arena/variations/sequential_sampler.py:37: The sampler stores a position that its only caller sets before every draw. Could sample() take a keyword-only start_index instead?

🟡 Warning: isaaclab_arena/tests/test_recorded_variation_samples.py:234: The two earlier draws already leave the position at 1, and set_position(4) also wraps to index 1, so the assertion passes even if set_position() does nothing. Using set_position(5) and expecting ["c"] makes the check able to fail.

Test Coverage and CI Cost

The 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.

Verdict

Minor fixes needed

@peterd-NV peterd-NV left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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]>
cvolkcvolk added a commit that referenced this pull request Oct 25, 2026
cvolkcvolk added a commit that referenced this pull request Oct 25, 2026
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]>
@cvolkcvolk
cvolkcvolk enabled auto-merge (squash) October 25, 2026 20:44
@cvolkcvolk
cvolkcvolk merged commit 6b27eb3 into main Oct 25, 2026
22 of 23 checks passed
cvolkcvolk added a commit that referenced this pull request Oct 26, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants