Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use env.render() to visualize environment transitions frame by frame? #54

Open
dantp-ai opened this issue Apr 9, 2023 · 2 comments

Comments

@dantp-ai
Copy link

dantp-ai commented Apr 9, 2023

rng = jax.random.PRNGKey(0)
rng, key_reset, key_act, key_step = jax.random.split(rng, 4)

# Instantiate the environment & its settings.
env, env_params = gymnax.make('FourRooms-misc')

# Reset the environment.
obs, state = env.reset(key_reset, env_params)

while True:
    # Sample a random action.
    action = env.action_space(env_params).sample(key_act)

    # Perform the step transition.
    n_obs, n_state, reward, done, _ = env.step(key_step, state, action, env_params)
    print(f"action: {action}, reward: {reward}, done: {done}")
    env.render(n_state, env_params)

I tried this simple example. The matplotlib figure is never shown. It is stuck and never opens.

Follow-up: Why is gymnax using matplotlib for rendering and not pygame (as gym) ?

@dantp-ai
Copy link
Author

dantp-ai commented Apr 9, 2023

P.S. I understand that I can use the Visualizer to animate a sequence of transitions, but that seems like an overhead when you just want to get the agent's view during interaction with the environment.

@nathanjzhao
Copy link

Curious about this as well. I tried running the visualizer script and it doesn't seem to visualize anything but rewards + steps. Not the environment itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants