Adds newton engine#4761
Conversation
a4d008d to
9dbaa03
Compare
Greptile SummaryThis PR adds the Newton physics engine as an alternative backend to IsaacLab, implementing backend-agnostic abstractions throughout the core framework. The implementation includes a full-featured Key changes:
Issues found:
Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Application Start] --> B[SimulationContext.initialize]
B --> C{Physics Backend?}
C -->|PhysX| D[PhysxManager]
C -->|Newton| E[NewtonManager]
E --> F[NewtonManager.initialize]
F --> G[Configure solver type]
G -->|MuJoCo-Warp| H[SolverMuJoCo]
G -->|XPBD| I[SolverXPBD]
G -->|Featherstone| J[SolverFeatherstone]
H & I & J --> K[start_simulation]
K --> L[Dispatch MODEL_INIT event]
L --> M[Finalize ModelBuilder]
M --> N[Dispatch PHYSICS_READY event]
N --> O{CUDA enabled?}
O -->|Yes| P[Initialize CUDA graph]
O -->|No| Q[Skip graphing]
P & Q --> R[Ready for step loop]
D --> S[PhysX initialization path]
S --> R
R --> T[FactoryBase._get_backend]
T --> U{SimulationContext exists?}
U -->|No| V[CRASH - Missing null check]
U -->|Yes| W[Return backend name]
style V fill:#f66
style E fill:#6f6
style H fill:#6f6
style I fill:#6f6
style J fill:#6f6
Last reviewed commit: 4777b98 |
| """Return active backend name for this factory. | ||
|
|
||
| Falls back to ``"physx"`` for backward compatibility when no simulation | ||
| context is initialized yet. | ||
| """ | ||
| # Import lazily to avoid import cycles at module load time. | ||
| manager_name = SimulationContext.instance().physics_manager.__name__.lower() | ||
| if "newton" in manager_name: | ||
| return "newton" | ||
| if "physx" in manager_name: | ||
| return "physx" | ||
| else: | ||
| raise ValueError(f"Unknown physics manager: {manager_name}") |
There was a problem hiding this comment.
Docstring claims fallback to "physx" when no simulation context exists, but code doesn't implement this. If SimulationContext.instance() returns None (which is possible per the type signature), line 46 will raise AttributeError.
| """Return active backend name for this factory. | |
| Falls back to ``"physx"`` for backward compatibility when no simulation | |
| context is initialized yet. | |
| """ | |
| # Import lazily to avoid import cycles at module load time. | |
| manager_name = SimulationContext.instance().physics_manager.__name__.lower() | |
| if "newton" in manager_name: | |
| return "newton" | |
| if "physx" in manager_name: | |
| return "physx" | |
| else: | |
| raise ValueError(f"Unknown physics manager: {manager_name}") | |
| @classmethod | |
| def _get_backend(cls, *args, **kwargs) -> str: | |
| """Return active backend name for this factory. | |
| Falls back to ``"physx"`` for backward compatibility when no simulation | |
| context is initialized yet. | |
| """ | |
| # Import lazily to avoid import cycles at module load time. | |
| sim_ctx = SimulationContext.instance() | |
| if sim_ctx is None or sim_ctx.physics_manager is None: | |
| return "physx" # Backwards compatibility | |
| manager_name = sim_ctx.physics_manager.__name__.lower() | |
| if "newton" in manager_name: | |
| return "newton" | |
| if "physx" in manager_name: | |
| return "physx" | |
| else: | |
| raise ValueError(f"Unknown physics manager: {manager_name}") |
| newton_world_to_env_id = {} | ||
| for col, env_id in enumerate(env_ids.tolist()): | ||
| # begin a new world context (Newton assigns world ID = col) | ||
| builder.begin_world() | ||
| newton_world_to_env_id[col] = env_id |
There was a problem hiding this comment.
newton_world_to_env_id dict is created but never used. Can be removed.
Additional Comments (1)
|
4880abc to
c4563a2
Compare
c4563a2 to
fe96fcd
Compare
# Description This PR adds newton engine to isaaclab together with backend agnostic syntax this pr happens after lazy import Fixes # (issue) <!-- As a practice, it is recommended to open an issue to have discussions on the proposed pull request. This makes it easier for the community to keep track of what is being developed or added, and if a given feature is demanded by more than one party. --> ## Type of change <!-- As you go through the list, delete the ones that are not applicable. --> - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (existing functionality will not work without user modification) - Documentation update ## Screenshots Please attach before and after screenshots of the change if applicable. <!-- Example: | Before | After | | ------ | ----- | | _gif/png before_ | _gif/png after_ | To upload images to a PR -- simply drag and drop an image while in edit mode and it should upload the image directly. You can then paste that source into the above before/after sections. --> ## Checklist - [ ] 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 - [ ] 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 <!-- As you go through the checklist above, you can mark something as done by putting an x character in it For example, - [x] I have done this task - [ ] I have not done this task -->
## Summary Fix incorrect attribute name `contact_margin` → `gap` on Newton `ShapeConfig` in `NewtonManager.create_builder()`. Newton PR #1732 renamed `contact_margin` to `gap` (broad-phase AABB expansion). The IsaacLab code was never updated, creating a dead attribute that Python silently accepted. The intended 1 cm default shape gap was never applied. ## Newton PR #1732 rename mapping | Old field | New field | Semantics | |-----------|-----------|-----------| | `thickness` | `margin` | Shape surface extension (affects contact forces) | | `contact_margin` | **`gap`** | Broad-phase AABB expansion (detection range only) | | `rigid_contact_margin` | `rigid_gap` | Builder-level default gap (already 0.1) | ## Timeline | Date | Newton | IsaacLab | `contact_margin` valid? | |------|--------|----------|------------------------| | Feb 19 | pin: `51ce35e` (has `contact_margin`) | #4646 adds `contact_margin = 0.01` | Yes | | Feb 24 | **PR #1732 renames `contact_margin` → `gap`** | — | — | | Mar 2 | pin updated to `v0.2.3` (after rename) | #4761 keeps `contact_margin` | **No — broken** | | Mar 9 | — | #4883 removes the line | Removed | | Apr 13 | — | #4822 re-adds `contact_margin` | **No — still broken** | ## Ablation: gap vs margin We conducted an ablation study to understand the impact. Note: `margin` (shape surface extension) is a different field from `gap` (broad-phase range). The original code intended to set `gap`, but setting `margin` also has a significant positive effect on training for rough terrain locomotion. | Setting | `gap` | `margin` | Go1 Reward (300 iter) | Effect | |---------|-------|----------|----------------------|--------| | Dead field (baseline) | 0.1 (default) | 0.0 | ~1.0 | — | | `gap=0.01` only | 0.01 | 0.0 | 0.66 | No training improvement | | `margin=0.01` only | 0.1 (default) | 0.01 | 18.77 | Major improvement | | `gap=0.01` + `margin=0.01` | 0.01 | 0.01 | 16.54 | Similar to margin-only | **This PR fixes the correct field migration** (`contact_margin` → `gap`). The `margin` setting for rough terrain contact quality will be addressed separately in the rough terrain env PR (#5248) via a new `default_shape_margin` config field on `NewtonCfg`. ## Test plan - [x] Verified `contact_margin` is not a field on `ShapeConfig` (Newton 1.1.0.dev0) - [x] Verified `gap` is the correct replacement field per Newton PR #1732 - [x] Confirmed by camevor (Newton developer) - [x] Ablation study: gap alone doesn't change training, so existing tests should pass Co-authored-by: Antoine RICHARD <antoiner@nvidia.com>
Description
This PR adds newton engine to isaaclab together with backend agnostic syntax
this pr happens after lazy import
Fixes # (issue)
Type of change
Screenshots
Please attach before and after screenshots of the change if applicable.
Checklist
pre-commitchecks with./isaaclab.sh --formatconfig/extension.tomlfileCONTRIBUTORS.mdor my name already exists there