Skip to content

Fix Newton Contacts losing pipeline properties on capacity growth - #9092

Merged
hujc7 merged 4 commits into
isaac-sim:mainfrom
elle-miller:fix/newton-contacts-preserve-pipeline-props
Nov 20, 2026
Merged

hujc7 merged 4 commits into
isaac-sim:mainfrom
elle-miller:fix/newton-contacts-preserve-pipeline-props

Conversation

@elle-miller

@elle-miller elle-miller commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

TL;DR: When a simulation needs more contacts than Newton estimates by default, Isaac Lab allocates a new contact buffer without enabling per-contact stiffness. Newton still generates hydroelastic contact points across the iso-surface, but discards every triangle's pressure-derived stiffness, so MuJoCo Warp silently falls back to uniform rigid contact parameters across the whole link instead of using the hydroelastic pressure law.

In NewtonBackend._allocate_contacts(), when required > self.contacts.rigid_contact_max in non-deterministic mode, Isaac Lab constructs a bare Contacts(...) instead of rebuilding CollisionPipeline and calling self.collision_pipeline.contacts(). Doing so silently drops pipeline-configured state—including per_contact_shape_properties=True (rigid_contact_stiffness, rigid_contact_damping, rigid_contact_friction), contact_matching and its implicit sort buffers (related to #7783), contact_report, soft-contact buffers, and CONTACT custom attributes.

This PR removes the bare Contacts(...) fallback so CollisionPipeline is rebuilt with rigid_contact_max=required and self.collision_pipeline.contacts() is used in both determinism modes.

Fixes # (issue)
Related to #7783.

Type of change

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

Reproduction

Dropping a hydroelastic box (kh = 5e5 vs 5e7) onto a hydroelastic ground plane (kh = 1e9) with MJWarpSolverCfg(use_mujoco_contacts=False, nconmax=12000) in default non-deterministic mode:

Standalone reproduction script (kit-less)
import newton
import numpy as np
import warp as wp
from isaaclab_newton.physics import MJWarpSolverCfg, NewtonBackend, NewtonBackendCfg, NewtonCfg


def run_case(box_kh: float):
    builder = newton.ModelBuilder(gravity=(0.0, 0.0, -9.81))
    mesh = newton.Mesh.create_box(0.05, 0.05, 0.05, compute_inertia=False)
    ground_mesh = newton.Mesh.create_box(0.25, 0.25, 0.05, compute_inertia=False)
    mesh.build_sdf(margin=0.005, max_resolution=32)
    ground_mesh.build_sdf(margin=0.005, max_resolution=32)

    builder.begin_world()
    body = builder.add_body(xform=wp.transform(wp.vec3(0.0, 0.0, 0.025), wp.quat_identity()))
    builder.add_shape_mesh(
        body,
        mesh=mesh,
        cfg=newton.ModelBuilder.ShapeConfig(is_hydroelastic=True, kh=box_kh, density=2000.0, margin=0.0, gap=0.0),
    )
    builder.add_shape_mesh(
        -1,
        xform=wp.transform(wp.vec3(0.0, 0.0, -0.025), wp.quat_identity()),
        mesh=ground_mesh,
        cfg=newton.ModelBuilder.ShapeConfig(is_hydroelastic=True, kh=1.0e9, margin=0.0, gap=0.0),
    )
    builder.end_world()

    cfg = NewtonCfg(solver_cfg=MJWarpSolverCfg(use_mujoco_contacts=False, nconmax=12000), num_substeps=4)
    cfg.solver_cfg.class_type.prepare_builder(cfg.solver_cfg, builder)
    backend = NewtonBackend(NewtonBackendCfg(physics_cfg=cfg, device="cuda:0"), builder, dt=1.0 / 60.0)
    backend.init_solver()
    backend.capture = None
    backend.actuators_active = True

    for _ in range(30):
        backend.step()

    c = backend.contacts
    nc = int(c.rigid_contact_count.numpy()[0])
    k_med = float(np.median(c.rigid_contact_stiffness.numpy()[:nc])) if c.rigid_contact_stiffness is not None and nc else 0.0
    mjw = backend.solver.mjw_data
    na = int(mjw.nacon.numpy().ravel()[0])
    tc_med = float(np.median(mjw.contact.solref.numpy()[:na, 0])) if na else 0.0
    z = float(backend.state_0.body_q.numpy()[0, 2])
    return bool(c.per_contact_shape_properties), c.rigid_contact_stiffness is not None, nc, k_med, tc_med, z


for kh in (5.0e5, 5.0e7):
    props, stiff, nc, k_med, tc_med, z = run_case(kh)
    print(f"kh={kh:.0e}: per_contact_shape_properties={props}  stiffness_array={stiff}  contacts={nc}  k_med={k_med:.1f} N/m  mjw_solref_tc={tc_med:.5f} s  box_z={z:.6f} m")

Before:

kh=5e+05: per_contact_shape_properties=False  stiffness_array=False  contacts=25  k_med=0.0 N/m  mjw_solref_tc=0.02000 s  box_z=0.074982 m
kh=5e+07: per_contact_shape_properties=False  stiffness_array=False  contacts=20  k_med=0.0 N/m  mjw_solref_tc=0.02000 s  box_z=0.075024 m

After:

kh=5e+05: per_contact_shape_properties=True  stiffness_array=True  contacts=27  k_med=114.2 N/m  mjw_solref_tc=0.59181 s  box_z=0.029917 m
kh=5e+07: per_contact_shape_properties=True  stiffness_array=True  contacts=24  k_med=18332.4 N/m  mjw_solref_tc=0.04671 s  box_z=0.074870 m

Testing

  • pytest source/isaaclab_newton/test/physics/test_newton_manager.py --noconftest -q: 64 passed (including test_deterministic_collision_pipeline_grows_with_the_solver_contact_capacity and the new test_hydroelastic_contacts_keep_per_contact_stiffness_when_nconmax_grows)
  • isaaclab --format (all pre-commit hooks: ruff, ruff-format, codespell, license header, RST, changelog fragment): passed
  • python tools/changelog/cli.py check main --include-worktree: passed

Checklist

Docker and GPU tests run on demand. Push the commits you want tested, then
comment run-ci on the pull request.

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with uv run isaaclab --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have validated the changed behavior with focused coverage and applied the test-audit criteria to any test changes
  • I have added a changelog fragment under source/<pkg>/changelog.d/ for every touched package (do not edit CHANGELOG.rst or bump package versions — CI handles that)
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@elle-miller
elle-miller requested a review from a team November 18, 2026 21:53
@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Nov 18, 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

Needs attention: Style consistency (2), Test quality (2). Other reviewed categories look good.

  • PR description: The title matches the allocation fix and supplied reproduction; correct Testing’s claim that the hydroelastic test has nondeterministic parametrization, and shorten the repeated field-loss explanation while preserving the reproduction and template sections.
  • Design and architecture: Architecture looks good.
  • Scope and over-engineering: No over-engineering issues.
  • API: API changes look good.
  • Compatibility and deprecation: No breaking changes identified.
  • Implementation: Implementation looks good.
  • Style consistency: The new hydroelastic test lacks required signature annotations; annotate device as str and add -> None.
  • Test quality: The new mock rows fail on the baseline because model=None cannot supply contact attributes, not because stiffness is lost; remove those rows and retain the real hydroelastic regression.

Minor fixes needed. Posted 4 inline findings.

Automated review; human maintainers own approval decisions.

"""Contact allocation can rebuild the pipeline but must leave solver output allocation to its caller."""
@pytest.mark.parametrize(
"deterministic_mode",
[wp.DeterministicMode.GPU_TO_GPU, wp.DeterministicMode.NOT_GUARANTEED],

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.

🟡 Warning · Test Quality — Remove nondeterministic mock rows

These rows fail before the fix because model=None cannot supply requested contact attributes to bare Contacts, not because properties are lost. The hydroelastic test owns that regression; retain the existing deterministic rows.

assert observable_requests == []


@pytest.mark.parametrize("device", test_devices(DeviceScope.CUDA))

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.

🟡 Warning · Test Quality — Mark the regression kitless

This test runs without Isaac Sim, but the file has no kitless marker, so text-based kitless CI selection misses it. Add pytest.mark.kitless directly to the test.



@pytest.mark.parametrize("device", test_devices(DeviceScope.CUDA))
def test_hydroelastic_contacts_keep_per_contact_stiffness_when_nconmax_grows(device):

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.

🟡 Warning · Style Consistency — Annotate the new test

The new function omits parameter and return annotations required by the contribution guide. Annotate device as str and add -> None.

assert backend.contacts.rigid_contact_max == 12000
assert backend.contacts.per_contact_shape_properties is True
assert backend.contacts.rigid_contact_stiffness is not None
nc = int(backend.contacts.rigid_contact_count.numpy()[0])

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.

🟡 Warning · Style Consistency — Name the contact count

The new nc abbreviation obscures the measured contact count and conflicts with the guide’s descriptive-name rule. Rename it contact_count.

@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

The PR rebuilds CollisionPipeline when the solver needs more contact storage, preserving pipeline-configured contact properties.

  • Growing contact capacity keeps pipeline settings attached.

No new actionable issues were found in the changes since the previous review. Tests were not run during this review.

Reviews (2) · Last reviewed commit: "Build hydroelastic test SDFs on the para..." · Reviewed by Greptile

@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

Needs attention: Style consistency (2), Test quality (1). Other reviewed categories look good.

  • PR description: Testing incorrectly claims hydroelastic determinism parametrization; name only the capacity test, condense repeated branch and #7783 explanations, and retain the reproduction and reported validation.
  • Design and architecture: Architecture looks good.
  • Scope and over-engineering: No over-engineering issues.
  • API: API changes look good.
  • Compatibility and deprecation: No breaking changes identified.
  • Implementation: Implementation looks good.
  • Style consistency: Both changed test signatures lack guide-required parameter and return annotations; add concrete types and -> None.
  • Test quality: The standalone hydroelastic regression lacks pytest.mark.kitless, excluding it from marker-based kitless CI; add the marker while retaining distinct physical and allocation-contract coverage.

Minor fixes needed. Posted 3 inline findings.

Automated review; human maintainers own approval decisions.

assert observable_requests == []


@pytest.mark.parametrize("device", test_devices(DeviceScope.CUDA))

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.

🟡 Warning · Test Quality — Mark the regression kitless

This standalone Newton test needs no Isaac Sim, but the file lacks a kitless marker and marker-based CI will not select it. Mark the new test pytest.mark.kitless.



@pytest.mark.parametrize("device", test_devices(DeviceScope.CUDA))
def test_hydroelastic_contacts_keep_per_contact_stiffness_when_nconmax_grows(device):

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.

🟡 Warning · Style Consistency — Annotate changed test signatures

Both changed test functions omit parameter and return annotations required by the contribution guide. Add concrete parameter types and -> None.


@pytest.mark.parametrize("device", test_devices(DeviceScope.CUDA))
def test_hydroelastic_contacts_keep_per_contact_stiffness_when_nconmax_grows(device):
"""Hydroelastic SDF contacts must retain per-contact stiffness arrays when nconmax exceeds auto-estimate."""

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.

🟡 Warning · Style Consistency — Remove redundant test docstring

The docstring repeats the test name and assertions without explaining a constraint. Remove it rather than maintain a second description of the same contract.

@AntoineRichard

Copy link
Copy Markdown
Collaborator

run-ci

@isaaclab-bot isaaclab-bot Bot added ci:run-docker Trigger the on-demand Docker and GPU CI workflow and removed ci:run-docker Trigger the on-demand Docker and GPU CI workflow labels Nov 19, 2026

@maxkra15 maxkra15 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.

Rebuilding through the pipeline preserves the contact properties- lg

@hujc7
hujc7 merged commit a733031 into isaac-sim:main Nov 20, 2026
58 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.

4 participants