Skip to content

Reuse shared reset sampling in Franka Pour - #8965

Open
maxkra15 wants to merge 33 commits into
isaac-sim:mainfrom
maxkra15:maximiliank/franka-pour-shared-reset-sampling
Open

maxkra15 wants to merge 33 commits into
isaac-sim:mainfrom
maxkra15:maximiliank/franka-pour-shared-reset-sampling

Conversation

@maxkra15

@maxkra15 maxkra15 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

Move Franka Pour to the shared isaaclab.envs.reset.ResetStateSampler introduced in #8872. The shared sampler records completed outcomes, scores the reset catalog, and draws adaptive starts. Pour owns its task-specific 50% shuffled cyclic replay, playback row selection, and dataset restoration.

Existing reset artifacts and sampler configuration fields continue to work. The task keeps the previous Beta score and weight floor. Startup and unfinished manual resets contribute no outcome. Explicit reset(seed=...) and reset_to(..., seed=...) calls reseed the Pour streams. Rerunning the same seed and reset order reproduces the new sequence. Historical Torch-based runs may draw different rows. The released ResetDatasetSampler remains available during its deprecation period. New consumers should use ResetStateSampler.

Validation

  • 39 focused tests passed across Pour, the shared reset utilities, and the NIST monitor.
  • The registered Franka Pour task passed 20 native CUDA steps with the published reset artifact.
  • Baseline and mutation checks verified that the seed, outcome attribution, replay, and CUDA stream regressions fail when their behavior is broken.
  • Full repository formatting, changelog checks, and the clean documentation build passed.

Long training convergence and hosted CI qualification remain follow-up work.

Integrate upstream main at 6d37745 to keep
the branch current with shared API and dependency changes.

Validate the merged revision with focused checks and all repository
formatting and lint hooks. Remote CI remains separate.
Integrate upstream main at 908e849 to keep
the branch current with shared API and dependency changes.

Validate the merged revision with focused checks and all repository
formatting and lint hooks. Remote CI remains separate.
Integrate upstream main at c498443 while preserving
the branch behavior and source history.

Validate the merged revision with focused checks and the required
repository hooks. Remote CI remains separate.
Collect reusable reset-state catalogs with bounded generation and
task-defined acceptance checks. Reuse the sampler from isaac-sim#8872 to keep
outcome tracking and row selection in one implementation.

Add a sparse Franka cube reference with an immediate commanded goal,
physical reset generation, and per-environment evaluation quotas.
@github-actions github-actions Bot added documentation Improvements or additions to documentation isaac-lab Related to Isaac Lab team labels Nov 7, 2026
@maxkra15
maxkra15 marked this pull request as ready for review November 25, 2026 13:29
@maxkra15
maxkra15 requested a review from a team November 25, 2026 13:29
@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

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

Summary

Franka Pour now uses ResetStateSampler for outcome history and adaptive draws while keeping task-owned playback and exact shuffled cyclic replay.

  • Franka Pour shares adaptive reset scoring while keeping its shuffled replay.
  • The old Pour sampler warns callers to move to the shared sampler.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Selected environments reset] --> B{Playback frozen?}
  B -->|Yes| C[Choose playback rows]
  B -->|No| D[Credit completed outcomes to old rows]
  D --> E[Draw adaptive rows]
  E --> F[Replace reserved draws with cyclic replay]
  C --> G[Copy assigned row IDs to environment]
  F --> G
  G --> H[Restore task state]
Loading

Reviews (1) · Last reviewed commit: "Reuse the shared reset sampler in Franka..." · Reviewed by Greptile

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isaac Lab Review Bot

Needs attention: Scope and over-engineering (3), Compatibility and deprecation (2), Implementation (1), Style consistency (2), Test quality (2). Other reviewed categories look good.

  • PR description: Title and body match the migration; reported validation lacks reset-cost measurements: provide baseline/candidate revisions, workload, hardware, backend, environment/catalog counts, warmup, and reset latency.
  • Design and architecture: Architecture looks good.
  • Scope and over-engineering: Minimal implementation: Extend reset_dataset.py and pour_env.py; keep reset_sampler.py for the functional legacy contract. Collapse duplicate requested-row storage into reset_dataset_row_id, skip unused replay permutations, and write replay slices directly without concatenation. Preserve outcome recording, shared sampling, cyclic replay, playback, and reseeding. No source modules were added. Scope is cohesive; no split recommended.
  • API: API changes look good.
  • Compatibility and deprecation: Breaking changes: Boolean masks become integer environment IDs, causing incorrect selection or out-of-bounds resets; preserve mask selection, and restore the uniform-mode metric value changed without deprecation.
  • Implementation: Sliced resets allocate indices for every environment before selecting a subset; construct only the selected range at the sampler boundary.
  • Style consistency: Added test signatures omit required concrete annotations; annotate helper parameters and returns, and add -> None to the tests.
  • Test quality: The CUDA regression bypasses the repository device mask; parameterize it with test_devices(DeviceScope.CUDA) and use the selected device for its tensors and stream.

Significant concerns. Posted 10 inline findings.

Automated review; human maintainers own approval decisions.

rows = self._sampler._sample_with_uniform_replay(num_envs)
if rows.shape != (num_envs,) or rows.dtype != torch.long:
raise RuntimeError("Adaptive sampler returned invalid reset-row IDs.")
env_ids = torch.as_tensor(env_ids, device=self._device, dtype=torch.long)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Critical · Compatibility — Preserve Boolean reset selections

Casting a Boolean mask to long turns True into environment ID 1; a one-environment all-True reset becomes out of bounds. Convert masks to selected indices before calling the sampler.


self._replay_generator = torch.Generator(device=self._device)
seed = env.cfg.seed if env.cfg.seed is not None else self._replay_generator.seed()
self._replay_fraction = float(sampler_cfg.uniform_fraction) if sampling_mode == "adaptive" else 0.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Warning · Compatibility — Preserve the uniform-mode metric

Uniform mode previously reported the configured uniform_fraction through the sampler metric; this sets that metric to zero. Preserve the existing value during deprecation and report effective replay separately.

seed = env.cfg.seed if env.cfg.seed is not None else self._replay_generator.seed()
self._replay_fraction = float(sampler_cfg.uniform_fraction) if sampling_mode == "adaptive" else 0.0
self._restart_replay(seed)
self._requested_rows = torch.empty_like(env.reset_dataset_row_id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Warning · Scope Complexity — Reuse the existing row buffer

_requested_rows duplicates the task’s per-environment row buffer and requires a forwarding helper. Write requested rows into env.reset_dataset_row_id and pass that buffer to the sampler.

elif self._sampling_mode == "uniform":
rows = torch.randint(self._row_count, (num_envs,), device=self._device)
if isinstance(env_ids, slice):
env_ids = torch.arange(env.num_envs, device=self._device)[env_ids]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Warning · Implementation — Materialize only selected slice indices

A small sliced reset allocates indices for every environment before slicing them. Materialize only the selected range when the sampler needs tensor IDs.

def _restart_replay(self, seed: int) -> None:
self._replay_generator.manual_seed(seed)
self._replay_credit = 0.0
self._replay_order = torch.randperm(self._row_count, device=self._device, generator=self._replay_generator)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Warning · Scope Complexity — Defer the replay permutation

Uniform mode never consumes _replay_order, yet initialization and reseeding shuffle the entire catalog. Create the permutation on the first cyclic assignment; keep reseeding and credit reset.

self._row_count, device=self._device, generator=self._replay_generator
)
self._replay_cursor = 0
self._reset_requested_rows(env_ids[slots], torch.cat(chunks))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Warning · Scope Complexity — Remove replay concatenation

Each replay draw builds chunks and copies them through torch.cat, including single-slice draws. Write cyclic slices directly into the selected request slots, then reset the sampler once.


class ResetDatasetSampler:
"""Sample reset rows using a rolling-success kernel and exact cyclic replay."""
"""Legacy reset sampler for callers using the original task-local API.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Warning · Style Consistency — Restore the sampler behavior docstring

The replacement docstring drops the rolling-history and exact-replay behavior and puts migration advice in code. Describe the current behavior here; keep migration instructions in the changelog.

pytestmark = [pytest.mark.unit, pytest.mark.kitless]


def _make_curriculum(num_envs, row_count, *, device="cpu", **overrides):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Warning · Style Consistency — Annotate the added test functions

The new helper has no parameter or return annotations, and the added tests omit -> None. Add concrete signature annotations as required by the contribution guide.

def test_franka_pour_explicit_reset_seed_restarts_sampling(method):
"""The real public reset methods reseed the task samplers on every explicit seed call."""
count = 8
_, buffers, _ = _make_curriculum(count, row_count=17)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Warning · Test Quality — Remove the unused sampler build

The seed test constructs and discards a curriculum and sampler, then constructs another for the same buffers. Reuse the first curriculum instead.

assert sampler.metrics()["sampler/uniform_replay_fraction"] == pytest.approx(0.5)


@pytest.mark.skipif(not torch.cuda.is_available(), reason="requires a non-default CUDA stream")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Warning · Test Quality — Honor the CUDA device mask

The availability check and hard-coded CUDA device bypass the repository’s test device scope and can select an excluded GPU. Use test_devices(DeviceScope.CUDA) throughout this test.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant