Skip to content

OMPE-94619: Fix non-deterministic test_noise failures.#5732

Merged
pbarejko merged 2 commits into
isaac-sim:developfrom
jmart-nv:jmart/test-noise
May 22, 2026
Merged

OMPE-94619: Fix non-deterministic test_noise failures.#5732
pbarejko merged 2 commits into
isaac-sim:developfrom
jmart-nv:jmart/test-noise

Conversation

@jmart-nv
Copy link
Copy Markdown

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

  • 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

`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.
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label May 21, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 21, 2026

Greptile Summary

This PR fixes a non-deterministic test failure in test_noise.py caused by torch.rand occasionally returning exact 0 on CUDA (~1-in-2^25 per element), which led to 0/0 = NaN when the scale branch divided noisy_data / data to recover the noise factor.

  • For all three noise tests (gaussian, uniform, constant), the scale branch now uses data = torch.ones(...) instead of torch.rand(...). Since scale computes data * noise, using ones makes noisy_data equal to the noise term directly, eliminating the need for the division and producing mathematically equivalent assertions.
  • The elif op == \"scale\" / elif op == \"abs\" arms are unified into a single elif op == \"scale\" or op == \"abs\" branch, reflecting that both now measure noisy_data directly.

Confidence Score: 5/5

Test-only change with no production code modified; the new assertions are mathematically equivalent to the originals.

The fix replaces torch.rand with torch.ones for the scale branch in three tests. The noise model implementations confirm that scale computes data * noise, so with data = ones, noisy_data equals the noise distribution directly — the same quantity the old code recovered via division. All three assertions (Gaussian std/mean, uniform min/max, constant exact-match) remain correct and statistically sound with 10,000 samples.

No files require special attention.

Important Files Changed

Filename Overview
source/isaaclab/test/utils/test_noise.py Fixes NaN-producing division in scale-branch tests by using torch.ones as input data; assertions are mathematically equivalent to the original after removing the division.
source/isaaclab/changelog.d/jmart-test-noise.skip New changelog fragment (.skip extension suppresses changelog entry) documenting the test-only fix for OMPE-94619.

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

Copy link
Copy Markdown

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

Choose a reason for hiding this comment

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

Code Review Summary

Verdict: ✅ Approve

This is a well-crafted fix for a subtle but real flaky test issue. The analysis and solution are both correct.


What This PR Does Well

  1. Root Cause Analysis: Correctly identifies that torch.rand can return exact 0 per its [0, 1) contract, causing noisy_data / data to produce NaN during scale operation testing.

  2. Minimal, Targeted Fix: Rather than adding epsilon guards or try/except blocks, the fix elegantly sidesteps the issue by using torch.ones for scale operations. This is mathematically sound because noisy_data = data * noise_factor simplifies to just noise_factor when data=1.

  3. Preserved Test Coverage: The tests still validate the same noise distribution properties (mean, std, min, max, bias) and the internal rand_like call inside the noise functions is still exercised.

  4. Good Documentation: Comments explain the "why" with ticket reference (OMPE-94619), and the changelog fragment is clear.


Technical Validation

The branch consolidation (elif op == "scale" or op == "abs") is correct because:

  • scale with data=ones: noisy_data = 1 * noise = noise
  • abs: noisy_data = noise (replaces data entirely)

Both result in noisy_data being the pure noise term, so the same verification logic applies.


No blocking issues found. LGTM! 🎉

@kellyguo11 kellyguo11 moved this to Ready to merge in Isaac Lab May 21, 2026
@pbarejko pbarejko merged commit 8f3a960 into isaac-sim:develop May 22, 2026
109 of 122 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to merge to Done in Isaac Lab May 22, 2026
pbarejko pushed a commit that referenced this pull request May 22, 2026
) (#5755)

# 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

- [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 <kellyg@nvidia.com>
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

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants