google / google/brax

Issue with rendering for VectorGymWrapper

Open
#535 0 comments 0 reactions 1 assignee Claimed by @bridgesign View on GitHub
good first issue
Dominant language
Jupyter Notebook
Stars
3.2k
Forks
349
PR merge metrics
No merged PRs in 30d

Description

It seems that the code for the render function in `brax.envs.wrappers.gym.VectorGymWrapper` is wrong. The code is intended only to render the first environment and not all environments. In case of gym/gymansium, vector envs render all environments at the same time. The error comes on this [line](https://github.com/google/brax/blob/main/brax/envs/wrappers/gym.py#L152)

The issue is that `pipeline_state` does not implement `take`.

The code can be fixed by replacing the line with the following:
```python
def render(self, mode='human'):
if mode == 'rgb_array':
sys, state = self._env.sys, self._state
if state is None:
raise RuntimeError('must call reset or step before rendering')
# Change this line to return (env_num, height, width, 3)
return np.stack([image.render_array(sys, state.take(i).pipeline_state, 256, 256) for i in range(self.num_envs)])
else:
return super().render(mode=mode) # just raise an exception
```
This will return an ndarray with images stacked for each environment.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.