|
30 | 30 | from pxr import Gf, PhysxSchema, Sdf, Usd, UsdPhysics, UsdUtils |
31 | 31 |
|
32 | 32 | import isaaclab.sim as sim_utils |
| 33 | +from isaaclab.utils.dict import to_flat_dict |
33 | 34 | from isaaclab.utils.logger import configure_logging |
34 | 35 | from isaaclab.utils.version import get_isaac_sim_version |
35 | 36 |
|
|
41 | 42 | logger = logging.getLogger(__name__) |
42 | 43 |
|
43 | 44 |
|
44 | | -def to_flat_dict(input_dict: dict[str, Any], delimiter: str = ".") -> dict[str, Any]: |
45 | | - """A simple method to transform a nested dict with key strings into a flat dict |
46 | | - where keys are separated with a given delimiter. For example, if the input dictionary |
47 | | - is {"foo": "bar", "spam": {"egg": "ham"}}, and the delimiter is ".", then the output |
48 | | - would be {"foo": "bar", "spam.egg": "ham"} |
49 | | -
|
50 | | - Args: |
51 | | - input_dict (dict[str, Any]): Input dictionary with string keys, potentially nested. |
52 | | - delimiter (str, optional): Delimiter for concatenating keys. Defaults to ".". |
53 | | -
|
54 | | - Returns: |
55 | | - dict[str, Any]: Output flattened dictionary with nested keys. |
56 | | - """ |
57 | | - out_dict = {} |
58 | | - for key, value in input_dict.items(): |
59 | | - # If we have a dict inside the current value, we need to flatten it. |
60 | | - if isinstance(value, dict): |
61 | | - inner_flattened_dict = to_flat_dict(value, delimiter) |
62 | | - # Recursively combine parent key with inner flattened directory. |
63 | | - for inner_key, inner_value in inner_flattened_dict.items(): |
64 | | - out_dict[f"{key}{delimiter}{inner_key}"] = inner_value |
65 | | - # If we are already flat, keep as is. |
66 | | - else: |
67 | | - out_dict[key] = value |
68 | | - return out_dict |
69 | | - |
70 | | - |
71 | 45 | class SimulationContext(_SimulationContext): |
72 | 46 | """A class to control simulation-related events such as physics stepping and rendering. |
73 | 47 |
|
|
0 commit comments