Skip to content

Fixes config resolution when presets are not specified - #4796

Merged
kellyguo11 merged 18 commits into
isaac-sim:developfrom
kellyguo11:fix-tests-0302
Mar 5, 2026
Merged

kellyguo11 merged 18 commits into
isaac-sim:developfrom
kellyguo11:fix-tests-0302

Conversation

@kellyguo11

@kellyguo11 kellyguo11 commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes config resolution for environments that use PresetCfg or presets-dict wrappers (multi-backend selectors for PhysX/Newton) when no Hydra CLI override is provided (e.g. in unit tests).

Core changes:

  • Added resolve_cfg_presets() in configclass.py to recursively resolve preset wrappers to their default variant; called at construction in all three env base classes

  • Replaced the circular-import-prone resolve_preset_defaults call in parse_cfg.py with a local implementation

  • SimulationContext and InteractiveScene now also resolve preset wrappers inline

Bug fixes:

  • Automate tasks: fixed broken file path (was calling os.path.basename() on a remote URL instead of using the return value of retrieve_file_path())

  • dexsuite MDP: moved asset imports under TYPE_CHECKING to fix circular imports

  • rl_games: added DirectMARLEnvCfg to valid cfg type check

Test/infra:

  • Reduced num_envs from 32 → 2 across all environment/sensor tests (faster CI, less GPU memory)

  • Fixed app.name in all .kit files ("Isaac Lab" → "IsaacLab")

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

@kellyguo11
kellyguo11 marked this pull request as draft March 3, 2026 05:42
@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Mar 3, 2026
@greptile-apps

greptile-apps Bot commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes config resolution for environments that use PresetCfg or presets-dict wrappers (multi-backend selectors for PhysX/Newton) when no Hydra CLI override is provided. The core change introduces resolve_cfg_presets() in configclass.py and calls it during __init__ in all three env base classes (DirectRLEnv, DirectMARLEnv, ManagerBasedEnv). Several related fixes are bundled in: a retrieve_file_path return-value bug in the automate task, circular-import fixes in dexsuite MDP files, and RL wrapper validity checks switched from cfg-type to env-instance checks.

Key changes:

  • configclass.py: new public resolve_cfg_presets() recursively resolves both new-style (PresetCfg MRO) and old-style (presets dict) wrappers; exported via __init__.pyi
  • parse_cfg.py: circular-import workaround via local _resolve_presets_to_default() — logic is identical to resolve_cfg_presets(), creating a maintenance-burden duplication
  • interactive_scene.py: inline old-style preset resolution during asset iteration, but missing the new-style PresetCfg MRO check, so new-style wrappers remain unresolved when InteractiveScene is constructed directly
  • simulation_context.py: resolves physics preset using a heuristic (no class_type + has default) rather than the authoritative MRO check used everywhere else
  • parse_cfg.py (parse_env_cfg): handles top-level new-style preset wrapper but has no guard for a top-level old-style preset wrapper, which would surface as an AttributeError rather than a clear resolution error
  • RL wrappers (rl_games, rsl_rl, sb3, skrl): deferred imports and instance-of-env checks replace cfg-type checks — clean improvement; rl_games error message still omits DirectMARLEnv
  • assembly_env.py: retrieve_file_path() return value now used correctly instead of os.path.basename() on the remote URL

Confidence Score: 3/5

  • Mostly safe, but two logic gaps mean new-style PresetCfg wrappers can slip through unresolved in InteractiveScene and old-style top-level wrappers cause AttributeError in parse_env_cfg.
  • The core resolution logic in configclass.py and the three env base classes is correct and well-tested. However, the inline resolution in interactive_scene.py only covers old-style presets (missing new-style PresetCfg MRO check), and parse_env_cfg lacks a guard for a top-level old-style preset wrapper. The simulation_context.py detection heuristic is also fragile. These gaps could cause subtle failures in direct-use scenarios (e.g., unit tests that construct InteractiveScene or call parse_env_cfg with certain config shapes).
  • source/isaaclab/isaaclab/scene/interactive_scene.py, source/isaaclab_tasks/isaaclab_tasks/utils/parse_cfg.py, and source/isaaclab/isaaclab/sim/simulation_context.py need closer attention.

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/utils/configclass.py Adds resolve_cfg_presets(), a clean recursive resolver for both new-style (PresetCfg MRO) and old-style (presets dict) wrapper patterns; exported via __init__.pyi.
source/isaaclab_tasks/isaaclab_tasks/utils/parse_cfg.py Replaces the circular-import-prone resolve_preset_defaults call with local helpers that duplicate resolve_cfg_presets logic; top-level old-style preset guard is missing alongside the new-style guard.
source/isaaclab/isaaclab/scene/interactive_scene.py Adds inline preset resolution for old-style presets-dict wrappers in asset iteration, but omits the symmetric new-style PresetCfg MRO check, leaving new-style wrappers unresolved when InteractiveScene is used directly.
source/isaaclab/isaaclab/sim/simulation_context.py Resolves physics PresetCfg wrapper using a heuristic (no class_type + has default) instead of the consistent MRO-name check used elsewhere, which could false-positive on unrelated configs.
source/isaaclab_rl/isaaclab_rl/rl_games/rl_games.py Switches env validity check from cfg-type to env-instance check and adds DirectMARLEnv support; error message still omits DirectMARLEnv.
source/isaaclab_rl/isaaclab_rl/rsl_rl/vecenv_wrapper.py Removes module-level cfg-type imports; switches env validity check to instance-of-env-class pattern with deferred import; clean change.
source/isaaclab_tasks/isaaclab_tasks/direct/automate/assembly_env.py Fixes the retrieve_file_path bug: return value is now captured and used instead of calling os.path.basename on the remote URL.
source/isaaclab/isaaclab/envs/direct_marl_env.py Calls resolve_cfg_presets(cfg) after validate() in __init__; straightforward and consistent with other env base classes.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Env init or parse_env_cfg] --> B[cfg.validate]
    B --> C[resolve_cfg_presets]
    C --> D{Field is PresetCfg subclass via MRO?}
    D -- Yes --> E[field = field.default]
    D -- No --> F{Field has presets dict with default key?}
    F -- Yes --> G[field = field.presets default]
    F -- No --> H[Recurse into field]
    E --> I[Recurse into resolved field]
    G --> I
    H --> C
    C --> J[Concrete cfg passed to scene and managers]

    K[InteractiveScene direct construction] --> L{asset_cfg has presets dict?}
    L -- Yes --> M[asset_cfg = presets default]
    L -- New-style PresetCfg --> N[Warning: Unresolved - MRO check missing]

    O[SimulationContext] --> P{no class_type AND has default attr?}
    P -- Yes --> Q[physics = physics.default]
    P -- No --> R[Heuristic may false-positive]
Loading

Last reviewed commit: 50b4806

@greptile-apps greptile-apps 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.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@github-actions github-actions Bot added the isaac-sim Related to Isaac Sim team label Mar 3, 2026
kellyguo11 and others added 7 commits March 3, 2026 16:37
…aac-sim#4803)

Conflict in parse_cfg.py: kept HEAD's hydra-import-free PresetCfg
resolution (_is_preset_cfg / _resolve_presets_to_default) to avoid
the circular-import that would arise from importing resolve_preset_defaults
from hydra.py (which itself imports load_cfg_from_registry from parse_cfg).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@kellyguo11 kellyguo11 changed the title Fixes automate tests Fixes config resolution when defaults are not specified Mar 4, 2026
@kellyguo11 kellyguo11 changed the title Fixes config resolution when defaults are not specified Fixes config resolution when presets are not specified Mar 4, 2026
@kellyguo11
kellyguo11 marked this pull request as ready for review March 5, 2026 06:35
@kellyguo11
kellyguo11 merged commit bd40069 into isaac-sim:develop Mar 5, 2026
7 of 11 checks passed
Comment on lines +675 to +680
# Resolve old-style preset wrappers: configclass with a ``presets`` dict and a ``'default'`` key.
# These are multi-backend selector objects (e.g. VelocityEnvContactSensorCfg) that hold several
# alternative asset configs in a dict and are not themselves asset configs.
if hasattr(asset_cfg, "presets") and isinstance(asset_cfg.presets, dict) and "default" in asset_cfg.presets:
asset_cfg = asset_cfg.presets["default"]
setattr(self.cfg, asset_name, asset_cfg)

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.

New-style PresetCfg wrappers not handled in InteractiveScene

The inline preset resolution here only handles the old-style presets dict pattern. If an asset config is wrapped in a new-style PresetCfg subclass (identified via MRO name matching, as used everywhere else in this PR), it will not be resolved here. If InteractiveScene is created directly (e.g. in unit tests) with a new-style preset in a scene field, the wrapper object will be forwarded to asset builders instead of the concrete config.

The check should mirror the pattern used in resolve_cfg_presets() in configclass.py:

# New-style PresetCfg
if any(cls.__name__ == "PresetCfg" for cls in type(asset_cfg).__mro__):
    asset_cfg = asset_cfg.default
    setattr(self.cfg, asset_name, asset_cfg)
# Old-style preset
elif hasattr(asset_cfg, "presets") and isinstance(asset_cfg.presets, dict) and "default" in asset_cfg.presets:
    asset_cfg = asset_cfg.presets["default"]
    setattr(self.cfg, asset_name, asset_cfg)

Comment on lines +147 to +151
# If physics is a PresetCfg wrapper (has a 'default' field but no 'class_type'),
# resolve to the default preset so downstream code always sees a concrete PhysicsCfg.
if not hasattr(self._physics, "class_type") and hasattr(self._physics, "default"):
self._physics = self._physics.default
self.cfg.physics = self._physics

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.

Fragile PresetCfg detection heuristic

The detection relies on the absence of class_type combined with the presence of default:

if not hasattr(self._physics, "class_type") and hasattr(self._physics, "default"):

This is a proxy heuristic rather than the authoritative MRO name check used in resolve_cfg_presets() elsewhere in this PR. Any SimulationCfg-derived config that happens to carry a default attribute but lacks class_type would be silently replaced — which could produce a confusing AttributeError downstream rather than a clear error.

For consistency and robustness, prefer the same detection pattern used in configclass.py:

if any(cls.__name__ == "PresetCfg" for cls in type(self._physics).__mro__):
    self._physics = self._physics.default
    self.cfg.physics = self._physics

Comment on lines +118 to 122
# NOTE: import here (not at module level) to avoid loading heavy env classes before Isaac Sim is initialized.
from isaaclab.envs import DirectMARLEnv, DirectRLEnv, ManagerBasedRLEnv

if not isinstance(env.unwrapped, (ManagerBasedRLEnv, DirectRLEnv, DirectMARLEnv)):
raise ValueError(

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.

Stale error message after adding DirectMARLEnv to the check

The isinstance check was extended to include DirectMARLEnv, but the error message still only mentions ManagerBasedRLEnv and DirectRLEnv:

raise ValueError(
    "The environment must be inherited from ManagerBasedRLEnv or DirectRLEnv. Environment type:"
    f" {type(env)}"
)
Suggested change
# NOTE: import here (not at module level) to avoid loading heavy env classes before Isaac Sim is initialized.
from isaaclab.envs import DirectMARLEnv, DirectRLEnv, ManagerBasedRLEnv
if not isinstance(env.unwrapped, (ManagerBasedRLEnv, DirectRLEnv, DirectMARLEnv)):
raise ValueError(
raise ValueError(
"The environment must be inherited from ManagerBasedRLEnv, DirectRLEnv, or DirectMARLEnv."
f" Environment type: {type(env)}"
)

Comment on lines +24 to +65
def _is_preset_cfg(obj: object) -> bool:
"""Return True if *obj* is an instance of a PresetCfg subclass (new typed-field style).

Uses MRO class-name matching so that this module has no dependency on the
hydra-gated ``isaaclab_tasks.utils.hydra`` import path.
"""
return any(cls.__name__ == "PresetCfg" for cls in type(obj).__mro__)


def _is_old_style_preset(obj: object) -> bool:
"""Return True if *obj* is an old-style preset wrapper (has ``presets`` dict with a ``'default'`` key)."""
presets = getattr(obj, "presets", None)
return hasattr(obj, "__dataclass_fields__") and isinstance(presets, dict) and "default" in presets


def _resolve_presets_to_default(cfg: object) -> object:
"""Recursively replace preset wrapper fields with their *default* preset.

Handles two preset patterns used in IsaacLab task configs:

* **New style** (``PresetCfg`` subclass): typed fields where ``default`` is a class attribute.
* **Old style** (``presets`` dict): configclass with ``presets: dict[str, Cfg]`` and a ``'default'`` key.

Both are resolved in-place so the config can be used without a Hydra CLI override (e.g. in tests).
"""
if not hasattr(cfg, "__dataclass_fields__"):
return cfg
for field_name in list(cfg.__dataclass_fields__):
value = getattr(cfg, field_name, None)
if value is None or not hasattr(value, "__dataclass_fields__"):
continue
if _is_preset_cfg(value):
resolved = value.default
setattr(cfg, field_name, resolved)
_resolve_presets_to_default(resolved)
elif _is_old_style_preset(value):
resolved = value.presets["default"]
setattr(cfg, field_name, resolved)
_resolve_presets_to_default(resolved)
else:
_resolve_presets_to_default(value)
return cfg

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.

Duplicate preset-resolution logic between parse_cfg.py and configclass.py

_is_preset_cfg(), _is_old_style_preset(), and _resolve_presets_to_default() here are functionally identical to resolve_cfg_presets() added to configclass.py in this same PR. The duplication is acknowledged in the PR description as a workaround for a circular import, but it creates a maintenance hazard: future changes to the resolution algorithm must be applied in both places.

A lighter alternative would be a deferred import inside _resolve_presets_to_default(), or extracting the resolution logic into a small, import-free utility module that both call sites can import without triggering a cycle. That would eliminate the duplicated logic while keeping the circular-import fix.

Comment on lines 193 to 209
if isinstance(cfg, dict):
raise RuntimeError(f"Configuration for the task: '{task_name}' is not a class. Please provide a class.")

# resolve PresetCfg fields (e.g. physics) to their default values
from isaaclab_tasks.utils.hydra import resolve_preset_defaults

cfg = resolve_preset_defaults(cfg)
# If the top-level cfg is itself a PresetCfg wrapper, resolve to the default preset before
# attempting any attribute access (e.g. cfg.sim, cfg.scene).
if _is_preset_cfg(cfg):
cfg = cfg.default

# Resolve any PresetCfg wrappers to their default preset so the config
# is usable without a Hydra CLI override (e.g. in tests).
# Must happen BEFORE attribute overrides, otherwise overrides on PresetCfg wrapper
# fields (e.g. cfg.scene when scene is a PresetCfg) get discarded when the wrapper
# is replaced by its .default.
_resolve_presets_to_default(cfg)

# simulation device
cfg.sim.device = 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.

Top-level old-style preset not handled before attribute access

_is_preset_cfg(cfg) handles the case where the top-level cfg is a new-style PresetCfg wrapper and resolves it before calling _resolve_presets_to_default(). However, there is no matching guard for the old-style pattern (presets dict with a "default" key). If a top-level task config is itself an old-style preset wrapper, the code will proceed to call _resolve_presets_to_default(cfg) on the wrapper — where the wrapper's fields (e.g. cfg.sim) most likely don't exist — and then reach cfg.sim.device = device (a few lines further down), raising an AttributeError rather than surfacing a clear error.

if _is_preset_cfg(cfg):
    cfg = cfg.default
# Add the symmetric guard for the old-style pattern:
elif _is_old_style_preset(cfg):
    cfg = cfg.presets["default"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working infrastructure isaac-lab Related to Isaac Lab team isaac-sim Related to Isaac Sim team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant