def _get_state(self, idx, history_len=1):
        """Compose the state from a number (history_len) of observations"""
        start_idx = idx - history_len + 1

        if start_idx < 0 or np.any(self.dones[start_idx : idx + 1]):
            state = np.zeros(
                (history_len,) + tuple(self.observations.shape[1:]),
                dtype=self.observations.dtype,
            )
            indices = [idx]
            for i in range(history_len - 1):
                next_idx = (idx - i - 1) % self.capacity

                if next_idx >= self.length or self.dones[next_idx]:
                    break
                indices.append(next_idx)
            indices = indices[::-1]
            state[-len(indices) :] = self.observations[indices]
        else:
            state = self.observations[slice(start_idx, idx + 1, 1)]

        return state
Compose the state from a number (history_len) of observations
examples/catalyst_rl/buffer.py