Repository: Genesis-Embodied-AI/Genesis
File: genesis/engine/scene.py (Python)

Code before:
        """
        Notes:
        - When using gpu
            - for non-batched env, we only parallelize certain loops that have big loop size
            - for batched env, we parallelize all loops
        - When using cpu, we serialize everything.
            - This is emprically as fast as parallel loops even with big batchsize (tested up to B=10000), because invoking multiple cpu processes cannot utilize all cpu usage.
            - In order to exploit full cpu power, users are encouraged to launch multiple processes manually, and each will use a single cpu thred.
        """
        if gs.backend == gs.cpu:
            self._para_level = gs.PARA_LEVEL.NEVER
        elif self.n_envs == 0:
            self._para_level = gs.PARA_LEVEL.PARTIAL
        else:
            self._para_level = gs.PARA_LEVEL.ALL

    @gs.assert_built
    def reset(self, state: SimState | None = None, envs_idx=None):
        """
        Resets the scene to its initial state.

        Parameters
        ----------
        state : SimState | None
            The state to reset the scene to. If None, the scene will be reset to its initial state.
            If this is given, the scene's registerered initial state will be updated to this state.
        envs_idx : None | array_like, optional
            The indices of the environments. If None, all environments will be considered. Defaults to None.
        """
        self._reset(state, envs_idx=envs_idx)

    def _reset(self, state: SimState | None = None, *, envs_idx=None):
        if self._is_built:
            if state is None:
                state = self._init_state
            else:
                assert isinstance(state, SimState), "state must be a SimState object"
                self._init_state = state
            self._sim.reset(state, envs_idx)
        else:
            self._init_state = self._get_state()

        self._t = 0
        self._forward_ready = True
        self._reset_grad()

        # TODO: sets _t = -1; not sure this is env isolation safe
        self._visualizer.reset()

        # TODO: sets _next_particle = 0; not sure this is env isolation safe
        for emitter in self._emitters:

Review comment (bug):
`gs.logger.debug(f"Resetting Scene ~~~<{self._uid}>~~~.")`

Code after:
        """
        Notes:
        - When using gpu
            - for non-batched env, we only parallelize certain loops that have big loop size
            - for batched env, we parallelize all loops
        - When using cpu, we serialize everything.
            - This is emprically as fast as parallel loops even with big batchsize (tested up to B=10000), because invoking multiple cpu processes cannot utilize all cpu usage.
            - In order to exploit full cpu power, users are encouraged to launch multiple processes manually, and each will use a single cpu thred.
        """
        if gs.backend == gs.cpu:
            self._para_level = gs.PARA_LEVEL.NEVER
        elif self.n_envs == 0:
            self._para_level = gs.PARA_LEVEL.PARTIAL
        else:
            self._para_level = gs.PARA_LEVEL.ALL

    @gs.assert_built
    def reset(self, state: SimState | None = None, envs_idx=None):
        """
        Resets the scene to its initial state.

        Parameters
        ----------
        state : SimState | None
            The state to reset the scene to. If None, the scene will be reset to its initial state.
            If this is given, the scene's registerered initial state will be updated to this state.
        envs_idx : None | array_like, optional
            The indices of the environments. If None, all environments will be considered. Defaults to None.
        """
        gs.logger.debug(f"Resetting Scene ~~~<{self._uid}>~~~.")
        self._reset(state, envs_idx=envs_idx)

    def _reset(self, state: SimState | None = None, *, envs_idx=None):
        if self._is_built:
            if state is None:
                state = self._init_state
            else:
                assert isinstance(state, SimState), "state must be a SimState object"
                self._init_state = state
            self._sim.reset(state, envs_idx)
        else:
            self._init_state = self._get_state()

        self._t = 0
        self._forward_ready = True
        self._reset_grad()

        # TODO: sets _t = -1; not sure this is env isolation safe
        self._visualizer.reset()

        # TODO: sets _next_particle = 0; not sure this is env isolation safe