-
Notifications
You must be signed in to change notification settings - Fork 230
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
Watching a replay #22
Comments
SMAC doesn't use the RGB features that are present PySC2 since SMAC uses only feature vectors as observations. Therefore, replays with such "deteriorated graphics" as in pysc2 are not available, unfortunately. Have you tried the following command which is suggested in pymarl repository: python -m pysc2.bin.play --norender --rgb_minimap_size 0 --replay NAME.SC2Replay It works for me on Mac. |
This command works but I don't get the point, it doesn't visualize anything. Is it useful to compute test time indicators or things like that by changing the behaviour of pysc2.bin.play ? |
Which OS are you using? On Mac, it opens an SC2 window and replays the episodes that have been saved. |
I am in an ubuntu docker on a redhat computer. It doesn't show anything, just dumps a few log messages (opening replay, playing the game) until this replay is done playing (I assume). I only have the Linux version of the game (from blizzard repo) installed by the way, I guess I should play the replay from the official game release with wine ? |
Yes, please do that until I take a close look at the Linux version. |
I am also on Linux and had the same problem. What I can do
What I am unable to doReplay a game played on a SMAC map and visualize it, by using the
Since the SMAC tutorial explicitly says to use the My settings
Log of failure
|
The problem is known and I guess fixing it is not easy. I suggest you do the same thing I did, install wine and the official game. You will be able to watch the replays with this version of the game. |
I had a similar issue where I was getting the error on line 305 in pysc2/lib/features.py. The problem is that the code is trying to get a color option that is higher that what exists in the color pallet. In line 304, there is an if statement "if self.clip:" that will clip the values in the variable 'plane' so that this error won't happen. It looks like self.clip was never set to True so the code doesn't actually clip it. My solution was to just set clip to True so that the values are clipped and the indexError does not occur. Not sure if this is the best fix or not but it worked for me. I don't see why you wouldn't always want to clip anyways to prevent this error from happening. |
For future reference, these are the lines. |
Hi there, I have revisited this issue and decided to provide the fix suggested by @nwayt001 (which I have tested and works) in a pysc2 fork of my own. It is only a single commit ahead of v3.0.0 and master, so it should still be compatible with everything. A quick installation can be done like so: pip install git+https://github.com/douglasrizzo/pysc2.git@smac-view I have tested it in a replay file generated by the example agents in the 8m map: python -m pysc2.bin.play --render --replay 8m_replay.SC2Replay |
@douglasrizzo Wonderful, does it work on SMAC envs while using SMAC to training agents? |
@GoingMyWay I don't think so, since the Starcraft2Env provided by SMAC doesn't implement the smac/smac/env/starcraft2/starcraft2.py Lines 1335 to 1337 in a185b70
|
Thanks, sorry for my late reply, these days I am trying to record video the play while evaluating. |
@GoingMyWay my advice would be for you to run the evaluation, save the replay, then replay it either on the game on Windows for the best graphics, or on Linux. Then capture the screen with a screen recorder app. |
Thanks, my laptop is Macbook Pro, I can evaluate the model while training but cannot record the video. If you can share some steps-by-steps guidelines to do video recording, it would be very nice. Or you can make a PR to SMAC, I think it is a very good enhancement for SMAC. |
@douglasrizzo I am using your code, here is my simple code to save the replay import time
import argparse
from smac.env import StarCraft2Env
import numpy as np
def main(args):
env = StarCraft2Env(map_name=args.map_name)
env_info = env.get_env_info()
n_actions = env_info["n_actions"]
n_agents = env_info["n_agents"]
n_episodes = 10
for e in range(n_episodes):
env.reset()
terminated = False
episode_reward = 0
while not terminated:
obs = env.get_obs()
state = env.get_state()
time.sleep(1)
actions = []
for agent_id in range(n_agents):
avail_actions = env.get_avail_agent_actions(agent_id)
avail_actions_ind = np.nonzero(avail_actions)[0]
action = np.random.choice(avail_actions_ind)
actions.append(action)
reward, terminated, _ = env.step(actions)
episode_reward += reward
env.save_replay() # here is the saving replay operation
print("Total reward in episode {} = {}".format(e, episode_reward))
env.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='run demo')
parser.add_argument('--map-name', type=str, default='3m')
args = parser.parse_args()
main(args=args) After running for 1 episode, I got many replay files, how can I merge or save all replays of one episode to one replay file? I found it not possible to do this, the save_replay function saves replays in the previous buffer all episodes. |
@GoingMyWay you don't call |
Thanks, another question is while using SMAC, when I want to evaluate the MARL model for some episode after some training time steps and save the replay of these evaluation episodes. Does it also save the replay of last evaluation? Or does it only save the replay of current evaluation episodes? |
I believe it saves everything between the moment you call |
Looks like it will save all the previous episodes one by one even calling You can try this code and see the output replays import time
import argparse
from smac.env import StarCraft2Env
import numpy as np
def main(args):
env = StarCraft2Env(map_name=args.map_name)
env_info = env.get_env_info()
n_actions = env_info["n_actions"]
n_agents = env_info["n_agents"]
n_episodes = 10
for e in range(n_episodes):
env.reset()
terminated = False
episode_reward = 0
while not terminated:
obs = env.get_obs()
state = env.get_state()
time.sleep(1)
actions = []
for agent_id in range(n_agents):
avail_actions = env.get_avail_agent_actions(agent_id)
avail_actions_ind = np.nonzero(avail_actions)[0]
action = np.random.choice(avail_actions_ind)
actions.append(action)
reward, terminated, _ = env.step(actions)
episode_reward += reward
# save after each episode
env.save_replay() # here is the saving replay operation
print("Total reward in episode {} = {}".format(e, episode_reward))
env.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='run demo')
parser.add_argument('--map-name', type=str, default='3m')
args = parser.parse_args()
main(args=args) |
I am using Starcraft 2 version 5.0.4.
Can the version be a problem? However, I was able to create a replay file using the code above by @GoingMyWay. To replay it I had to use a different code which skips the version checking. |
I had to explicitly call env.save_replay() to create the replay files in the following file:
Otherwise, the replay files are not created. |
Ok. So I was able to play the replay files (in smac env) by modifying the pysc2 play file that skips the version checking. |
@plutonic88 SMAC does not save replays automatically, you do have to call |
I have added a section in the README file on how to save and watch replays. I hope this answers your questions. Please let me know if something is unclear. |
@plutonic88 Hi, you can also use the SC2Switcher to open the replay files without running any Python code. |
@samvelyan I am trying to watch replays generated on Linux through the Windows game. I have a few replays generated on Linux. I was able to install the game using Wine (as mentioned in the SMAC README) and access the replay files from inside the game, but I get an "Unable to open map" error when double clicking the replay, also from inside the game. I'm not sure if I need to provide the SMAC map files to the game. I looked around but it seems the game doesn't have a "Maps" folder to which we can drop the map files to. Any clues? |
but offical version of sc2 is too high now, wine is not work for watching the replay anymore |
I found the issue same like yours, how solve it ? |
The only way to watch a replay on SMAC is to play it from the windows game ? There is no way to watch it with deteriorated graphics as in pysc2 ?
What is the meaning of the "watch a replay" section on README then ?
I tried to naively watch a replay as you do in pysc2 and had the following error:
File "/usr/local/lib/python3.7/site-packages/pysc2/lib/stopwatch.py", line 212, in _stopwatch return func(*args, **kwargs) File "/usr/local/lib/python3.7/site-packages/pysc2/lib/features.py", line 305, in color return self.palette[plane] IndexError: index 1970 is out of bounds for axis 0 with size 1962
The text was updated successfully, but these errors were encountered: