Skip to content

Fix MockSensorContact to match Newton's nested sensing_objs structure#4925

Merged
kellyguo11 merged 2 commits intoisaac-sim:developfrom
ooctipus:zhengyuz/fix-mock-contact-sensor-nested-structure
Mar 11, 2026
Merged

Fix MockSensorContact to match Newton's nested sensing_objs structure#4925
kellyguo11 merged 2 commits intoisaac-sim:developfrom
ooctipus:zhengyuz/fix-mock-contact-sensor-nested-structure

Conversation

@ooctipus
Copy link
Copy Markdown
Collaborator

@ooctipus ooctipus commented Mar 10, 2026

Description

the test is using old newton contact sensor api, and new api only accepts nested list structure.

Fixes #4908

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 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 Mar 10, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 10, 2026

Greptile Summary

This PR fixes MockNewtonContactSensor so that sensing_objs and counterparts use the nested list[list[tuple[int, int]]] structure that Newton's real SensorContact API returns, matching the double-loop flattening ([obj for world_objs in ... for obj in world_objs]) introduced in PR #4883's ContactSensor._create_buffers. The previous flat list[tuple] caused a TypeError: cannot unpack non-iterable int object when the outer loop tried to iterate over tuples directly.

  • Changed self.sensing_objs from [(i, 1) for i in range(n)] to [[(i, 1) for i in range(n)]] — a single-world outer wrapper around the existing flat list
  • Same change applied to self.counterparts
  • The type annotations are updated correspondingly (list[list[tuple[int, int]]])
  • The mock correctly models a single-world scenario, which is sufficient for the unit test use-case

Confidence Score: 5/5

  • This PR is safe to merge — it is a minimal, targeted mock fix with no production code changes.
  • The change is a single-file, two-line fix to a test mock. It correctly aligns the mock's data structure with the real Newton API (list[list[tuple]]), which is exactly what the _create_buffers double-loop flattening expects. No logic changes are made to production code, and the fix is verified by reading both the mock and the consumer code in contact_sensor.py.
  • No files require special attention.

Important Files Changed

Filename Overview
source/isaaclab_newton/isaaclab_newton/test/mock_interfaces/mock_newton.py Wraps sensing_objs and counterparts in an outer list to match Newton's list[list[tuple]] structure, fixing TypeError when ContactSensor._create_buffers runs its double-loop flattening.

Sequence Diagram

sequenceDiagram
    participant Test as Unit Test
    participant Mock as MockNewtonContactSensor
    participant CS as ContactSensor._create_buffers()

    Test->>Mock: MockNewtonContactSensor(num_sensing_objs, num_counterparts)
    Note over Mock: sensing_objs = [[(i,1) for i in range(n)]]<br/>counterparts = [[(i,1) for i in range(m)]]

    Test->>CS: _create_buffers()
    CS->>Mock: contact_view.sensing_objs
    Mock-->>CS: list[list[tuple[int,int]]]
    CS->>CS: flat_sensing = [obj for world_objs in sensing_objs for obj in world_objs]
    Note over CS: Double-loop flattening works correctly

    CS->>Mock: contact_view.counterparts
    Mock-->>CS: list[list[tuple[int,int]]]
    CS->>CS: flat_counterparts = [obj for world_objs in counterparts for obj in world_objs]
    Note over CS: Double-loop flattening works correctly

    CS-->>Test: Buffers initialized successfully
Loading

Last reviewed commit: 94e5969

@ooctipus ooctipus force-pushed the zhengyuz/fix-mock-contact-sensor-nested-structure branch from 94e5969 to ade524c Compare March 10, 2026 23:30
@ooctipus ooctipus requested a review from AntoineRichard March 10, 2026 23:31
@ooctipus ooctipus force-pushed the zhengyuz/fix-mock-contact-sensor-nested-structure branch from ade524c to 6b8218d Compare March 10, 2026 23:51
@kellyguo11 kellyguo11 merged commit 22f118d into isaac-sim:develop Mar 11, 2026
13 of 15 checks passed
daniela-hase pushed a commit to daniela-hase/IsaacLab that referenced this pull request Mar 30, 2026
…isaac-sim#4925)

# Description

the test is using old newton contact sensor api, and new api only
accepts nested list structure.

Fixes isaac-sim#4908

## 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
- [x] 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
- [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

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