Skip to content

Cherry pick OMPE-94619: Fix non-deterministic test_noise failures (#5732) - #5755

Merged
pbarejko merged 1 commit into
isaac-sim:release/3.0.0-beta2from
jmart-nv:jmart/cherry-test-noise-beta2
May 22, 2026
Merged

pbarejko merged 1 commit into
isaac-sim:release/3.0.0-beta2from
jmart-nv:jmart/cherry-test-noise-beta2

Conversation

@jmart-nv

Copy link
Copy Markdown
Contributor

Description

Cherry pick PR #5732:

torch.rand can return exact 0 per its [0, 1) contract (~1 in 2^25 on CUDA). The scale-branch of test_noise recovers the scale factor and noise contribution by dividing noisy_data / data. Since data was generated via torch.rand, this produces NaN about ~1 in 1000 test runs (0.1% of the time.) This can be deterministically reproduced by feeding it a seed of 1981.

This change fixes the test by switching data to torch.ones for the scale branch in all three noise tests so noisy_data is the noise term directly. There is no need to recover the scale factor and noise contribution separately. The internal rand_like call inside noise_cfg.func is still exercised and measured, which is the goal of the test.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

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 (N/A - test change only)
  • 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

# Description

`torch.rand` can return exact 0 per its [0, 1) contract (~1 in 2^25 on
CUDA). The scale-branch of test_noise recovers the scale factor and
noise contribution by dividing `noisy_data / data`. Since `data` was
generated via `torch.rand`, this produces NaN about ~1 in 1000 test runs
(0.1% of the time.) This can be deterministically reproduced by feeding
it a seed of 1981.

This change fixes the test by switching `data` to `torch.ones` for the
scale branch in all three noise tests so `noisy_data` is the noise term
directly. There is no need to recover the scale factor and noise
contribution separately. The internal `rand_like` call inside
`noise_cfg.func` is still exercised and measured, which is the goal of
the test.

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Checklist

- [x] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation *(N/A -
test change only)*
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

Co-authored-by: Kelly Guo <[email protected]>
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label May 22, 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 is a well-crafted cherry-pick that fixes a non-deterministic test failure in test_noise.py. The root cause is correctly identified: torch.rand can return exact 0 per its [0, 1) contract, causing division by zero when the op="scale" tests recover noise by dividing noisy_data / data.

Analysis

Root Cause Understanding ✅

  • torch.rand on CUDA has ~1 in 2^25 chance of returning exactly 0
  • With 10000 samples × 3 columns × multiple parametrized runs, this manifests ~0.1% of the time
  • The seed 1981 deterministically reproduces this failure

Fix Correctness ✅
The fix is elegant and minimal:

  1. Uses torch.ones instead of torch.rand only for op="scale" tests
  2. This eliminates division-by-zero while preserving test coverage
  3. The rand_like call inside noise_cfg.func is still exercised
  4. op="add" and op="abs" continue using random data as intended

Code Changes

  • All three test functions (test_gaussian_noise, test_uniform_noise, test_constant_noise) apply the same pattern
  • The conditional logic is clean and well-commented
  • Simplifies result calculation by combining scale and abs branches (both now use noisy_data directly)

Testing Considerations

  • The test still validates the noise functions' statistical properties (mean, std, min, max)
  • Device placement assertions are preserved
  • The parametrized test matrix remains intact

CI Status

Most checks are still pending, but pre-commit and changelog checks have passed. The core logic change is test-only and low-risk.

Verdict

Looks good! This is a clean, well-documented fix for a legitimate flaky test issue. The change is minimal, targeted, and maintains full test coverage of the noise functions.


🔬 Reviewed by Isaac Lab Review Bot | Automated code review

@greptile-apps

greptile-apps Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This cherry-pick fixes a non-deterministic test failure in test_noise.py caused by torch.rand occasionally returning exact 0 on CUDA (per its [0, 1) contract), which made the scale-branch assertions divide by zero and produce NaN. The fix switches data to torch.ones only for the scale op across all three test functions and collapses the now-redundant division branches into the same direct noisy_data read used by abs.

  • Root-cause fix (test_gaussian_noise, test_uniform_noise, test_constant_noise): data = torch.ones(...) when op == "scale" removes the 0/0 risk while keeping the internal rand_like/randn_like call inside the noise function fully exercised.
  • Branch simplification: the elif op == "scale" division blocks are replaced with elif op == "scale" or op == "abs" reading noisy_data directly — mathematically equivalent because noisy_data / 1 == noisy_data.
  • Changelog fragment: a .skip file is added so the test-only change does not generate a user-facing changelog entry.

Confidence Score: 5/5

Safe to merge — the change is confined to test helpers and a changelog fragment, with no modifications to production noise functions.

The root cause (torch.rand returning 0 causing a NaN on division) is correctly addressed by using torch.ones for the scale branch. The merged scale/abs verification path is mathematically equivalent because dividing by 1 is a no-op. All three test functions are updated consistently, and the internal rand_like/randn_like calls inside the noise implementations remain exercised.

No files require special attention.

Important Files Changed

Filename Overview
source/isaaclab/test/utils/test_noise.py Switches data tensor from torch.rand to torch.ones for the 'scale' op in all three noise tests, eliminating the 0/0=NaN failure; merges scale/abs verification branches since both now read noisy_data directly. Logic is correct in all three test functions.
source/isaaclab/changelog.d/jmart-test-noise.skip New changelog fragment (.skip extension signals it won't generate a user-facing entry) describing the test-only fix. Content is accurate and complete.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["test_*_noise(device, noise_device, op)"] --> B{op == 'scale'?}
    B -- Yes --> C["data = torch.ones(10000, 3)"]
    B -- No --> D["data = torch.rand(10000, 3)"]
    C --> E["noisy_data = noise_cfg.func(data, cfg)"]
    D --> E
    E --> F{op branch}
    F -- add --> G["result = noisy_data - data"]
    F -- "scale or abs" --> H["result = noisy_data directly"]
    G --> I["assert result ≈ expected noise params"]
    H --> I
    style C fill:#d4edda,stroke:#28a745
    style H fill:#d4edda,stroke:#28a745
Loading

Reviews (1): Last reviewed commit: "OMPE-94619: Fix non-deterministic test_n..." | Re-trigger Greptile

@pbarejko
pbarejko merged commit 854b6e0 into isaac-sim:release/3.0.0-beta2 May 22, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants