Repository: Genesis-Embodied-AI/Genesis
File: genesis/utils/array_class.py (Python)

Code before:
def get_entities_state(solver):
    shape = solver._batch_shape(solver.n_entities_)
    kwargs = {
        "hibernated": V(dtype=gs.ti_int, shape=shape),
    }

    if use_ndarray:
        return StructEntitiesState(**kwargs)
    else:

        @ti.data_oriented
        class ClassEntitiesState:
            def __init__(self):
                for k, v in kwargs.items():
                    setattr(self, k, v)

        return ClassEntitiesState()


# =========================================== StaticRigidSimConfig ===========================================

cache_value = partial(dataclasses.field, metadata={FIELD_METADATA_CACHE_VALUE: True})


@dataclasses.dataclass
class StaticRigidSimDummy:
    para_level: int = cache_value()
    use_hibernation: bool = cache_value()
    use_contact_island: bool = cache_value()
    batch_links_info: bool = cache_value()
    batch_dofs_info: bool = cache_value()
    batch_joints_info: bool = cache_value()
    enable_mujoco_compatibility: bool = cache_value()
    enable_multi_contact: bool = cache_value()
    enable_self_collision: bool = cache_value()
    enable_adjacent_collision: bool = cache_value()
    enable_collision: bool = cache_value()
    box_box_detection: bool = cache_value()
    integrator: int = cache_value()
    sparse_solve: bool = cache_value()
    solver_type: int = cache_value()


def get_static_rigid_sim_dummy(solver):
    kwargs = {
        "para_level": solver.sim._para_level,
        "use_hibernation": getattr(solver, "_use_hibernation", False),
        "use_contact_island": getattr(solver, "_use_contact_island", False),
        "batch_links_info": getattr(solver._options, "batch_links_info", False),
        "batch_dofs_info": getattr(solver._options, "batch_dofs_info", False),
        "batch_joints_info": getattr(solver._options, "batch_joints_info", False),

Review comment (performance):
Why do we have both `StaticRigidSimConfig` and `StaticRigidSimDummy`. We should get rid of the former?

Besides, the name is not quite right. `StaticRigidSimDummy` does not mean anything. What is this class all about? If it is used for kernel caching disambiguation only, then it should rather be called `RigidSimMetadata`, or `RigidSimMetadataCache`. But `dummy` here is just misleading I think.

Code after:
def get_entities_state(solver):
    shape = solver._batch_shape(solver.n_entities_)
    kwargs = {
        "hibernated": V(dtype=gs.ti_int, shape=shape),
    }

    if use_ndarray:
        return StructEntitiesState(**kwargs)
    else:

        @ti.data_oriented
        class ClassEntitiesState:
            def __init__(self):
                for k, v in kwargs.items():
                    setattr(self, k, v)

        return ClassEntitiesState()


# =========================================== StaticRigidSimConfig ===========================================

cache_value = partial(dataclasses.field, metadata={FIELD_METADATA_CACHE_VALUE: True})


@dataclasses.dataclass
class StaticRigidSimCacheKey:
    para_level: int = cache_value()
    use_hibernation: bool = cache_value()
    batch_links_info: bool = cache_value()
    batch_dofs_info: bool = cache_value()
    batch_joints_info: bool = cache_value()
    enable_mujoco_compatibility: bool = cache_value()
    enable_multi_contact: bool = cache_value()
    enable_adjacent_collision: bool = cache_value()
    enable_collision: bool = cache_value()
    box_box_detection: bool = cache_value()
    integrator: int = cache_value()
    sparse_solve: bool = cache_value()
    solver_type: int = cache_value()


def get_static_rigid_sim_cache_key(solver):
    kwargs = {
        "para_level": solver.sim._para_level,
        "use_hibernation": getattr(solver, "_use_hibernation", False),
        "batch_links_info": getattr(solver._options, "batch_links_info", False),
        "batch_dofs_info": getattr(solver._options, "batch_dofs_info", False),
        "batch_joints_info": getattr(solver._options, "batch_joints_info", False),
        "enable_mujoco_compatibility": getattr(solver, "_enable_mujoco_compatibility", False),
        "enable_multi_contact": getattr(solver, "_enable_multi_contact", True),
        "enable_adjacent_collision": getattr(solver, "_enable_adjacent_collision", False),