Skip to content

Set seed for string testing - #5709

Merged
pbarejko merged 1 commit into
isaac-sim:developfrom
pbarejko:fix-non-determinisitc-strnig-shuffling
May 20, 2026
Merged

pbarejko merged 1 commit into
isaac-sim:developfrom
pbarejko:fix-non-determinisitc-strnig-shuffling

Conversation

@pbarejko

Copy link
Copy Markdown
Collaborator

Description

Following test can occasionally fail when we get very unlucky when shuffled list will be the same as original.

source/isaaclab/test/utils/test_string.py::test_resolve_matching_names_with_joint_name_strings

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
List any dependencies that are required for this change.

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (existing functionality will not work without user modification)
  • Documentation update

Screenshots

Please attach before and after screenshots of the change if applicable.

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels May 20, 2026

@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

Summary

This PR fixes a test flakiness issue in test_resolve_matching_names_with_joint_name_strings by seeding the random number generator used for shuffling.

Analysis

Problem Being Solved:
The test uses random.shuffle() to randomize a list of 6 joint names before passing them to resolve_matching_names(). With 6 elements, there's a 1/720 (~0.14%) probability that the shuffle produces the exact same order as the original list, causing the assertion names_list != query_list to fail spuriously.

The Fix:

  • Creates a local random.Random(0) instance with a fixed seed
  • Uses the seeded RNG for shuffling instead of global random.shuffle()

Review Notes

✅ Correctness: The fix is appropriate. Using a seeded local RNG ensures deterministic test behavior while still exercising the "shuffled input" code path.

✅ Best Practice: Creating a local Random instance rather than calling random.seed(0) globally is the right approach—it avoids polluting the global RNG state that other tests might depend on.

✅ Test Coverage: The test continues to validate that resolve_matching_names() correctly handles inputs in arbitrary order and returns results in target ordering (not query ordering).

✅ Changelog: The .skip changelog fragment appropriately marks this as a test-only change that won't appear in user-facing release notes.

Minor Observation

The seed value 0 will produce a consistent shuffle, but it's worth verifying that this particular shuffle does result in a different order than the original query_list. Given the implementation, seed 0 should produce a valid permutation—the probability of still landing on identity is negligible with a good PRNG.

Verdict

Clean, minimal fix for a real (if rare) test flakiness issue. No concerns.


Automated review by Isaac Lab Review Bot

@greptile-apps

greptile-apps Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a low-probability (~1/720) flaky test caused by random.shuffle occasionally producing the same ordering it started with, which would then fail the assert names_list != query_list guard. The fix replaces the call to the global random.shuffle with a seeded random.Random(0).shuffle, making the permutation deterministic on every run.

  • The seeded RNG guarantees the shuffled query_list is never accidentally equal to the sorted names_list (which is what the assertion checks), turning a probabilistic test into a fully deterministic one.
  • A .skip-suffixed changelog fragment is added to document the change without creating a user-facing changelog entry.

Confidence Score: 5/5

Safe to merge — the change is test-only, eliminates a real flakiness, and introduces no production code modifications.

Both changed files are test infrastructure. The two-line edit swaps a non-deterministic shuffle for a seeded one, directly fixing the documented flakiness without altering production behavior.

No files require special attention.

Important Files Changed

Filename Overview
source/isaaclab/test/utils/test_string.py Replaces global random.shuffle with a seeded random.Random(0).shuffle to make the joint-name shuffle test deterministic and eliminate a ~1/720 flakiness window.
source/isaaclab/changelog.d/pbarejko-test-string-shuffle-seed.skip Changelog fragment describing the test-only fix; marked .skip so it does not produce a user-facing changelog entry.

Sequence Diagram

sequenceDiagram
    participant T as Test
    participant RNG as random.Random(seed=0)
    participant F as resolve_matching_names()

    T->>RNG: shuffle(query_list)
    Note over RNG: Deterministic permutation<br/>— never equals names_list
    RNG-->>T: query_list (shuffled, fixed order)
    T->>F: resolve_matching_names(query_list, robot_joint_names)
    F-->>T: (index_list, names_list) sorted by robot_joint_names
    T->>T: "assert names_list != query_list ✓"
    T->>T: "assert index_list == [0,1,4,5,8,9] ✓"
    T->>T: "assert names_list == expected ✓"
Loading

Reviews (1): Last reviewed commit: "Set seed for string testing" | Re-trigger Greptile

@pbarejko
pbarejko requested a review from kellyguo11 May 20, 2026 18:42
@pbarejko
pbarejko merged commit b25f2b5 into isaac-sim:develop May 20, 2026
64 of 65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants