Repository navigation
Fixes CI errors where the PresetCfg is never resolved when running tests - #4801
Conversation
Greptile SummaryThis PR fixes an Key changes:
Confidence Score: 3/5
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["gym.make() / parse_env_cfg()"] --> B["load_cfg_from_registry()"]
B --> C{"Is cfg a dict?"}
C -- Yes --> D["raise RuntimeError"]
C -- No --> E["resolve_preset_defaults(cfg)"]
E --> F{"cfg is PresetCfg?"}
F -- Yes --> G["get cfg.default"]
G --> H{"default is not None?"}
H -- Yes --> I["return resolve_preset_defaults(default)\n(recurse until non-PresetCfg)"]
H -- No --> J["return cfg as-is"]
F -- No --> K["Iterate __dataclass_fields__"]
K --> L{"field is PresetCfg?"}
L -- Yes --> M["setattr(cfg, name, default)\nresolve_preset_defaults(default)\n⚠️ return value discarded"]
L -- No --> N["resolve_preset_defaults(value)\n(recurse into nested configclass)"]
M --> O["return cfg"]
N --> O
I --> P["Resolved concrete cfg"]
J --> P
O --> P
P --> Q["cfg.sim.device = device\ncfg.scene.num_envs = num_envs\n..."]
Q --> R["Return cfg to caller"]
Last reviewed commit: afaffee |
| # resolve PresetCfg fields (e.g. physics) to their default values | ||
| from isaaclab_tasks.utils.hydra import _resolve_preset_defaults | ||
|
|
||
| _resolve_preset_defaults(cfg) |
There was a problem hiding this comment.
_resolve_preset_defaults is documented to return "the (possibly replaced) cfg if the root itself is a PresetCfg." Every other call site in hydra.py captures this return value:
env_cfg = _resolve_preset_defaults(env_cfg)
if agent_cfg is not None:
agent_cfg = _resolve_preset_defaults(agent_cfg)Here the return value is discarded. If the root config itself is a PresetCfg (e.g., CartpolePhysicsCfg as described in the PR), the resolved default will be returned but cfg will remain the raw PresetCfg object. Then cfg.sim.device = device on the next line will fail because PresetCfg does not have a .sim attribute. The fix is to capture the return value:
| _resolve_preset_defaults(cfg) | |
| cfg = _resolve_preset_defaults(cfg) |
| @@ -149,6 +149,11 @@ def parse_env_cfg( | |||
| 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 | |||
There was a problem hiding this comment.
This in-function import creates a circular dependency: hydra.py already imports from parse_cfg.py at module level (line 41). While the lazy import defers the ImportError until parse_env_cfg is called, it introduces fragile coupling.
More critically, hydra.py unconditionally raises an ImportError at module load if hydra-core is not installed (lines 31–36). This means parse_env_cfg — a general-purpose utility function — will now fail with a Hydra-specific error in any environment where hydra-core is absent, even if the caller never intended to use Hydra.
Consider refactoring _resolve_preset_defaults into a shared utility module (e.g., preset_utils.py) that neither parse_cfg.py nor hydra.py depends on, to break the circular dependency and remove the Hydra installation requirement from parse_env_cfg.
4374e59 to
afaffee
Compare
Additional Comments (1)
When a nested Consider a doubly-nested case: After execution:
The fix is to capture and apply the return value: Current tests only cover non- |
…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]>
Description
Some task configs like CartpolePhysicsCfg are PresetCfg that wrap multiple physics backends (physx, newton). It gets resolved to its default field when going through the Hydra pipeline (_resolve_preset_defaults), but when creating environments directly via gym.make() (as the test does), the PresetCfg is never resolved — so SimulationContext sees a PresetCfg object instead of an actual PhysxCfg with a class_type attribute.
Type of change
Checklist
pre-commitchecks with./isaaclab.sh --formatconfig/extension.tomlfileCONTRIBUTORS.mdor my name already exists there