Skip to content

Fix TerrainGenerator with integer sub-terrain proportions - #8075

Merged
StafaH merged 2 commits into
isaac-sim:developfrom
Patrick-SCH03:fix/terrain-generator-integer-proportions
Sep 27, 2026
Merged

StafaH merged 2 commits into
isaac-sim:developfrom
Patrick-SCH03:fix/terrain-generator-integer-proportions

Conversation

@Patrick-SCH03

@Patrick-SCH03 Patrick-SCH03 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

TerrainGenerator normalizes the sub-terrain proportions with

proportions = np.array([sub_cfg.proportion for sub_cfg in self.cfg.sub_terrains.values()])
proportions /= np.sum(proportions)

in both _generate_random_terrains and _generate_curriculum_terrains. When every proportion is an int (for example proportion=1 and proportion=3, which the float annotation accepts and configclass does not convert), the array is int64 and the in-place division raises:

numpy._core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'divide' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'

A single float proportion anywhere avoids it, which is why the in-repo configs (all floats) never hit it.

This builds the array with dtype=float in both places. Integer and float proportions now give identical terrains.

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
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have added a changelog fragment under source/<pkg>/changelog.d/ for every touched package (do not edit CHANGELOG.rst or bump extension.toml — CI handles that)
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

Testing

  • Added test_generation_with_integer_proportions (random and curriculum modes): proportions (1, 3) must produce the same terrain origins and mesh as (1.0, 3.0). Both cases fail on develop with the error above and pass with the fix.
  • The whole test_terrain_generator.py passes locally (CPU, with Isaac Sim imports stubbed out).
  • Ruff v0.14.10 (the pre-commit pin) check and format are clean on the changed files. I ran it directly because the full ./isaaclab.sh --format environment isn't available on my Windows machine.

Release backport

  • Backport this pull request to the active release branch after it merges into develop

The sub-terrain proportions were collected with np.array, which gives an
int64 array when every proportion is an int, and the in-place
normalization then raised UFuncTypeError. Build the array as float so
integer proportions behave like the equivalent floats.

Signed-off-by: Patrick-SCH03 <wwoo5241@gmail.com>
@Patrick-SCH03
Patrick-SCH03 requested a review from a team September 27, 2026 03:08
@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Sep 27, 2026
@greptile-apps

greptile-apps Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Fixes terrain generation when proportions are integers.

The PR appears safe to merge; no actionable issue was identified.

Summary

The PR converts sub-terrain proportions to floats before normalization in both random and curriculum generation, allowing integer proportions. It adds a regression test comparing integer and float configurations and a changelog fragment.

Reviews (1) · Last reviewed commit: "Fix TerrainGenerator with integer sub-te..."

@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

The patch explicitly creates floating-point proportion arrays in both terrain-generation modes, preventing NumPy’s in-place division from failing when every configured proportion is an integer. It includes focused regression coverage and the required changelog fragment.

  • Design and architecture: The conversion remains localized to the private helpers that own proportion normalization and is applied consistently to both random and curriculum generation. This is the smallest change needed and does not alter terrain-selection architecture.
  • API: No public signatures, defaults, or exports change. Integer proportions, already accepted by the configuration surface, now behave like equivalent float proportions. Existing float inputs retain the same normalized float64 representation, and the package changelog records the user-visible fix.
  • Implementation: Both consumers of normalized proportions were traced: random selection through np_rng.choice and curriculum column assignment through np.cumsum. Constructing each array with dtype=float directly resolves the deterministic NumPy casting failure. The parameterized seeded test exercises both paths and compares observable terrain origins and mesh vertices for equivalent integer and float configurations.

No blocking issues. No inline issue met the actionable-evidence threshold; the assessment above records the review feedback.

Automated review; human maintainers own approval decisions.

@StafaH StafaH added the ci:run-docker Trigger the on-demand Docker and GPU CI workflow label Sep 27, 2026
@StafaH
StafaH merged commit b39c274 into isaac-sim:develop Sep 27, 2026
53 checks passed
@isaaclab-bot

isaaclab-bot Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Backported to release/3.0.0 as 824eee0.

isaaclab-bot Bot pushed a commit that referenced this pull request Sep 27, 2026
# Description

`TerrainGenerator` normalizes the sub-terrain proportions with

```python
proportions = np.array([sub_cfg.proportion for sub_cfg in self.cfg.sub_terrains.values()])
proportions /= np.sum(proportions)
```

in both `_generate_random_terrains` and `_generate_curriculum_terrains`.
When every `proportion` is an int (for example `proportion=1` and
`proportion=3`, which the `float` annotation accepts and `configclass`
does not convert), the array is `int64` and the in-place division
raises:

```
numpy._core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'divide' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'
```

A single float proportion anywhere avoids it, which is why the in-repo
configs (all floats) never hit it.

This builds the array with `dtype=float` in both places. Integer and
float proportions now give identical terrains.

## 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)
- [ ] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [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 added a changelog fragment under
`source/<pkg>/changelog.d/` for every touched package (do **not** edit
`CHANGELOG.rst` or bump `extension.toml` — CI handles that)
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

## Testing

- Added `test_generation_with_integer_proportions` (random and
curriculum modes): proportions `(1, 3)` must produce the same terrain
origins and mesh as `(1.0, 3.0)`. Both cases fail on `develop` with the
error above and pass with the fix.
- The whole `test_terrain_generator.py` passes locally (CPU, with Isaac
Sim imports stubbed out).
- Ruff v0.14.10 (the pre-commit pin) `check` and `format` are clean on
the changed files. I ran it directly because the full `./isaaclab.sh
--format` environment isn't available on my Windows machine.

## Release backport

- [x] <!-- backport-active-release --> Backport this pull request to the
active release branch after it merges into `develop`

---------

Signed-off-by: Patrick-SCH03 <wwoo5241@gmail.com>
Co-authored-by: Mustafa Haiderbhai <mhaiderbhai@nvidia.com>

(cherry picked from commit b39c274)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ci:run-docker Trigger the on-demand Docker and GPU CI workflow isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants