Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python error, no results on the internet openai-gym

import gym
env = gym.make("FrozenLake-v1")
env.reset()
env.render()
env.step(1)
env.render()
Something went wrong with pygame. This should never happen.
  File "C:\Users\ardgn\OneDrive\Belgeler\GitHub\Kutuphaneler-cheatsheets\GYMLibraryOPENAI", line 7, in <module>
    env.render()

This is the error I get when I use the above code

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Code works for me if I add render_mode="human"

import gym

env = gym.make("FrozenLake-v1", render_mode="human")
env.reset()

env.render()
env.step(1)
env.render()

without render_mode="human" (or render_mode="rgb_array") it doesn’t initiate Surface in PyGame in line here, and this makes problem.

And this displays text "Something went wrong with pygame. This should never happen."

        if self.window_surface is None:
            pygame.init()

            if mode == "human":
                pygame.display.init()
                pygame.display.set_caption("Frozen Lake")
                self.window_surface = pygame.display.set_mode(self.window_size)
            elif mode == "rgb_array":
                self.window_surface = pygame.Surface(self.window_size)

        assert (
            self.window_surface is not None
        ), "Something went wrong with pygame. This should never happen."

BTW:

I see that mode "human" also runs render() automatically in every step() and reset()

def step(self, a):
    transitions = self.P[self.s][a]
    i = categorical_sample([t[0] for t in transitions], self.np_random)
    p, s, r, t = transitions[i]
    self.s = s
    self.lastaction = a

    if self.render_mode == "human":
        self.render()
    return (int(s), r, t, False, {"prob": p})

def reset(
    self,
    *,
    seed: Optional[int] = None,
    options: Optional[dict] = None,
):
    super().reset(seed=seed)
    self.s = categorical_sample(self.initial_state_distrib, self.np_random)
    self.lastaction = None

    if self.render_mode == "human":
        self.render()
    return int(self.s), {"prob": 1}

EDIT:

Code from some tutorials – it uses render_mode="human".

import gym

env = gym.make("FrozenLake-v1", render_mode="human")

observation, info = env.reset()

for _ in range(1000):
    observation, reward, terminated, truncated, info = env.step(env.action_space.sample())

    if terminated or truncated:
        observation, info = env.reset()

env.close()    
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use