Farama-Foundation / MicroRTS-Py

A simple and highly efficient RTS-game-inspired environment for reinforcement learning (formerly Gym-MicroRTS)
MIT License
227 stars 44 forks source link

environment works well but not rendering #3

Closed doganjr closed 4 years ago

doganjr commented 4 years ago

Very well implemented wrapper but I cannot render the environment when I run hello_world.py, it does not produce any errors, environment returns observations. I am running the wrapper on macOS and It renders openai gym environments when I call render() in the loop.

vwxyzjn commented 4 years ago

Hi, glad to know that it is running as intended. This seems to be an issue related to #1, Unfortunately I don’t have a mac so I couldn’t test it out. Were you able to get the video recording working by any chance?

For example, try going to experiment folder and run python ppo.py --capture-video

doganjr commented 4 years ago

After some dependencies have been installed and run "python3 ppo.py --capture-video" I got some error like that:

(base) doganjr:experiments doganjr$ python3 ppo.py --capture-video /Users/doganjr/microrts/maps/10x10/basesWorkers10x10.xml [Lai.rewardfunction.RewardFunctionInterface;@1b68ddbd /Users/doganjr/microrts/maps/10x10/basesWorkers10x10.xml [Lai.rewardfunction.RewardFunctionInterface;@59e5ddf /Users/doganjr/microrts/maps/10x10/basesWorkers10x10.xml [Lai.rewardfunction.RewardFunctionInterface;@536aaa8d /Users/doganjr/microrts/maps/10x10/basesWorkers10x10.xml [Lai.rewardfunction.RewardFunctionInterface;@e320068 Unknown encoder 'libx264' Traceback (most recent call last): File "ppo.py", line 292, in next_obs, rs, ds, infos = envs.step(action.T) File "/Users/doganjr/anaconda3/lib/python3.6/site-packages/stable_baselines3/common/vec_env/base_vec_env.py", line 163, in step return self.step_wait() File "ppo.py", line 119, in step_wait obs, reward, done, info = self.venv.step_wait() File "/Users/doganjr/anaconda3/lib/python3.6/site-packages/stable_baselines3/common/vec_env/dummy_vec_env.py", line 44, in step_wait self.envs[env_idx].step(self.actions[env_idx]) File "/Users/doganjr/anaconda3/lib/python3.6/site-packages/gym/wrappers/monitor.py", line 32, in step done = self._after_step(observation, reward, done, info) File "/Users/doganjr/anaconda3/lib/python3.6/site-packages/gym/wrappers/monitor.py", line 171, in _after_step self.video_recorder.capture_frame() File "/Users/doganjr/anaconda3/lib/python3.6/site-packages/gym/wrappers/monitoring/video_recorder.py", line 116, in capture_frame self._encode_image_frame(frame) File "/Users/doganjr/anaconda3/lib/python3.6/site-packages/gym/wrappers/monitoring/video_recorder.py", line 166, in _encode_image_frame self.encoder.capture_frame(frame) File "/Users/doganjr/anaconda3/lib/python3.6/site-packages/gym/wrappers/monitoring/video_recorder.py", line 304, in capture_frame self.proc.stdin.write(frame.tobytes()) BrokenPipeError: [Errno 32] Broken pipe

vwxyzjn commented 4 years ago

Hmmm that seems to suggest the rendering is not working at all. What’s your jdk/jre version? May be the default one does not come with the graphical packages. See https://stackoverflow.com/questions/32862344/what-is-the-difference-between-openjdk-7-jre-headless-and-openjdk-7-jrejdk

vwxyzjn commented 4 years ago

Another thing that you can look into is to see whether you can build microrts by following instructions here https://github.com/santiontanon/microrts/blob/master/README.md

doganjr commented 4 years ago
Screen Shot 2020-07-08 at 22 14 56

By running hello_world.py, above is what I get. It can be seen that states can be observed without any problem. Unlike the demo.gif you provided nothing pops up. :/

doganjr commented 4 years ago

I have installed the newest versions of JDK and JRE but unfortunately, nothing has changed.

vwxyzjn commented 4 years ago

Could you try running

import gym
import gym_microrts
import time
try:
    env = gym.make("MicrortsGlobalAgentRandomEnemy10x10FrameSkip9-v0")
    env.action_space.seed(0)
    env.reset()
    for i in range(10000):
        print(env.render(mode="rgb_array"))
        time.sleep(0.2)
        obs = env.step(env.action_space.sample())
        if env.step(env.action_space.sample())[2]:
            print("done")
            break
    #env.close()
except Exception as e:
    print(e)
    print(e.stacktrace())

and see if the RGB pixels can be retrieved?

image

Btw your error above has Unknown encoder 'libx264', which can be fixed (see https://stackoverflow.com/questions/9764740/unknown-encoder-libx264)

doganjr commented 4 years ago

I have run the script and get the output that you had on your console. But still no rendering. Here is one interesting fact, even I change the environment(gym.make(change)) it always prints out to console following: "/Users/doganjr/microrts/maps/4x4/baseTwoWorkersMaxResources4x4.xml [Lai.rewardfunction.RewardFunctionInterface;@2f410acf" Is it expected or do you think I have installed the wrapper somehow unproperly?

vwxyzjn commented 4 years ago

That is expected.

Get Outlook for iOShttps://aka.ms/o0ukef


From: Dogan Can Cicek notifications@github.com Sent: Thursday, July 9, 2020 2:57:50 AM To: vwxyzjn/gym-microrts gym-microrts@noreply.github.com Cc: Costa Huang costa.huang@outlook.com; Comment comment@noreply.github.com Subject: Re: [vwxyzjn/gym-microrts] environment works well but not rendering (#3)

I have run the script and get the output that you had on your console. But still no rendering. Here is one interesting fact, even I change the environment(gym.make(change)) it always prints out to console following: "/Users/doganjr/microrts/maps/4x4/baseTwoWorkersMaxResources4x4.xml [Lai.rewardfunction.RewardFunctionInterface;@2f410acf" Is it expected or do you think I have installed the wrapper somehow unproperly?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/vwxyzjn/gym-microrts/issues/3#issuecomment-655939622, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABKMJE356ZIDZAVYALTOBVTR2VS65ANCNFSM4OU3NLTA.

doganjr commented 4 years ago

Hello, I have followed instructions from https://github.com/santiontanon/microrts/blob/master/README.md and when I run FrontEnd.java environment popped up without a problem, I also have created a .jar file by following instructions and run it without a problem, too. But when I try to run the latest version of microrts.jar from console it gives an error as follows: (base) doganjr:microrts doganjr$ java -cp microrts.jar rts.MicroRTS Exception in thread "main" java.io.FileNotFoundException: resources/config.properties (No such file or directory) at java.base/java.io.FileInputStream.open0(Native Method) at java.base/java.io.FileInputStream.open(FileInputStream.java:212) at java.base/java.io.FileInputStream.(FileInputStream.java:154) at java.base/java.io.FileInputStream.(FileInputStream.java:109) at rts.GameSettings.fetchConfig(GameSettings.java:116) Do you have any suggestions, is it a MacOS specific problem ?

doganjr commented 4 years ago
Screen Shot 2020-07-10 at 14 46 29

After I have added imshow and show, I am able to catch Game State Visualizer from your demo.gif but it is still not observable. Maybe the problem is mainly about matplotlib part of the wrapper but I am not completely sure.

vwxyzjn commented 4 years ago

Try the following as a work around, which should give you a recorded video in the video folder.

import gym
import gym_microrts
import time
from gym.wrappers import TimeLimit, Monitor

try:
    env = gym.make("MicrortsGlobalAgentRandomEnemy10x10FrameSkip9-v0")
    env = Monitor(env, f'videos')
    env.action_space.seed(0)
    env.reset()
    for i in range(10000):
        time.sleep(0.2)
        obs = env.step(env.action_space.sample())
        next_obs, reward, done, info = env.step(env.action_space.sample())
        if done:
            print("done")
            break
    #env.close()
except Exception as e:
    print(e)
    print(e.stacktrace())

image

With respect to the game visualizer, try the following command

cd ~/microrts
java -classpath microrts.jar tests.PlayGameWithMouseTest

and see if the game visualizer pops up. If so, it would appear to be a jPype problem. It is quite difficult for me to help with this bug since I do not have a mac unfortunately :(.

vwxyzjn commented 4 years ago

For a lack of response, closing this issue for now.