danaugrs / huskarl

Deep Reinforcement Learning Framework + Algorithms
https://medium.com/@tensorflow/introducing-huskarl-the-modular-deep-reinforcement-learning-framework-e47d4b228dd3
MIT License
414 stars 51 forks source link

Visualization windows remain open #7

Open Ryandry1st opened 5 years ago

Ryandry1st commented 5 years ago

I probably simply do not see the function, but there does not seem to be a way to close the visualized plots once they are open. I attempted using: plt.close() plt.close('all') but neither worked. Also simply attempting to close the window by clicking had no effect. The only way I could close the windows was by closing the entire workspace/killing the process.

Let me know what the proper way is!

junhuang-ifast commented 5 years ago

I had the same problem here. Although the official way to close an environment was to call env.close(), or in the example dqn-cartpole.py dummy_env.close() (i assume), none of these methods worked and the window remained open.

@Ryandry1st have u solved this problem?

Otherwise it would be appreciated if anyone else knows how to solve this? Thanks ! @danaugrs

Ryandry1st commented 5 years ago

I also tried this and found that they did not work. No I do not have a solution, as of right now I have to close the execution window, which is not reasonable. I was mostly just looking into this to check out how the library works so I have not put in serious time for solutions. It also appears that the windows task manager is unable to close the windows too, so it is unlikely that a simple script will be able to.

junhuang-ifast commented 5 years ago

my solution was to go into the Simulationclass directly in simulation.py and add env.close() at the end of the training/test function

For example:

def test(self, max_steps, visualize=True):
        """Test the agent on the environment."""
        self.agent.training = False

        # Create and initialize environment
        env = self.create_env()
        state = env.reset()

        for step in range(max_steps):
            if visualize: env.render()
            action = self.agent.act(state)
            next_state, reward, done, _ = env.step(action)
            state = env.reset() if done else next_state
               env.close()  <------

This closes the window after train/test completes. It's a bit of a workaround but it works