Giter Club home page Giter Club logo

pysc2-examples's Introduction

StartCraft II Reinforcement Learning Examples

This example program was built on

Current examples

Minimaps

  • CollectMineralShards with Deep Q Network

CollectMineralShards

Quick Start Guide

1. Get PySC2

PyPI

The easiest way to get PySC2 is to use pip:

$ pip install git+https://github.com/deepmind/pysc2

Also, you have to install baselines library.

$ pip install git+https://github.com/openai/baselines

2. Install StarCraft II

Mac / Win

You have to purchase StarCraft II and install it. Or even the Starter Edition will work.

http://us.battle.net/sc2/en/legacy-of-the-void/

Linux Packages

Follow Blizzard's documentation to get the linux version. By default, PySC2 expects the game to live in ~/StarCraftII/.

3. Download Maps

Download the ladder maps and the mini games and extract them to your StarcraftII/Maps/ directory.

4. Train it!

$ python train_mineral_shards.py --algorithm=a2c

5. Enjoy it!

$ python enjoy_mineral_shards.py

4-1. Train it with DQN

$ python train_mineral_shards.py --algorithm=deepq --prioritized=True --dueling=True --timesteps=2000000 --exploration_fraction=0.2

4-2. Train it with A2C(A3C)

$ python train_mineral_shards.py --algorithm=a2c --num_agents=2 --num_scripts=2 --timesteps=2000000
Description Default Parameter Type
map Gym Environment CollectMineralShards string
log logging type : tensorboard, stdout tensorboard string
algorithm Currently, support 2 algorithms : deepq, a2c a2c string
timesteps Total training steps 2000000 int
exploration_fraction exploration fraction 0.5 float
prioritized Whether using prioritized replay for DQN False boolean
dueling Whether using dueling network for DQN False boolean
lr learning rate (if 0 set random e-5 ~ e-3) 0.0005 float
num_agents number of agents for A2C 4 int
num_scripts number of scripted agents for A2C 4 int
nsteps number of steps for update policy 20 int

pysc2-examples's People

Contributors

chris-chris avatar divyavanmahajan avatar keeeeenw avatar lwneal avatar yilei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pysc2-examples's Issues

TypeError: Can't instantiate abstract class SubprocVecEnv with abstract methods step_async, step_wait

WARNING:tensorflow:From /Users/domore/Documents/deeplearning/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/base.py:198: retry (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.
Instructions for updating:
Use the retry module or similar alternatives.
algorithm : a2c
timesteps : 2000000
exploration_fraction : 0.5
prioritized : True
dueling : True
num_agents : 4
lr : 0.0005
random lr : 0.0005
Traceback (most recent call last):
File "/Users/domore/starcraft/pysc2-examples/train_mineral_shards.py", line 302, in
main()
File "/Users/domore/starcraft/pysc2-examples/train_mineral_shards.py", line 168, in main
env = SubprocVecEnv(FLAGS.num_agents + FLAGS.num_scripts, FLAGS.map)

TypeError: Can't instantiate abstract class SubprocVecEnv with abstract methods step_async, step_wait

replay_mineral.py returns empty output

I'm trying to get replay data from .SC2Replay files by running replay_minerals.py. The program runs successfully but outputs empty arrays and values. I've tried several different replay files. Here is a sample output:

============================================= Summary 10 secs =============================================
Replays: 0, Steps total: 0

Camera move: 0, Select pt: 0, Select rect: 0, Control group: 0

Maps: 0
{}

Races: 0
{}

Unit ids: 0
{}

Valid abilities: 0
{}

Made abilities: 0
{}

Valid actions: 0
{}

Made actions: 0
{}

Crashing replays: 0
[]

Invalid replays: 0
[]
---------------------------------------------- Process stats ----------------------------------------------
[ 0] replay: , replays: 0, steps: 0, game loops: 0, last: launch, 9 s ago

The program then finishes with 0 exit code.

Any ideas of what I should try to get this file to work properly?

It seems dqn can't learn much

I ran the script last night. It started with ~11 mean reward, and ended with ~15.5 mean reward.
I tried to play this mini-game myself, and I could get ~100 score or more.
Deepmind reached ~100 score in their video.
Begin
End

train_mineral_shards.py raises error.

I'm using Python 3.5.3 in macOS with following packages:

git+https://github.com/openai/baselines.git@699919f1cf2527b184f4445a3758a773f333a1ba#egg=baselines
PySC2==1.1

When I run the command:

$ python train_mineral_shards.py 

Error raises:

Traceback (most recent call last):
  File "train_mineral_shards.py", line 51, in <module>
    main()
  File "train_mineral_shards.py", line 24, in main
    visualize=True) as env:
  File "/Users/haje01/.pyenv/versions/pysc2/lib/python3.5/site-packages/pysc2/env/sc2_env.py", line 128, in __init__
    raise ValueError("All arguments must be passed as keyword arguments.")
ValueError: All arguments must be passed as keyword arguments.

Any ideas?

train_defeat_zerglings uses wrong dimensions for q_func

I am not sure how to best address this, but it looks like train_defeat_zerglings (and potentially the Q learning version of train_mineral_shards) are not operational with TF 1.14.

The error is thrown in line 1024 of layers.py

    if conv_dims is not None and conv_dims + 2 != input_rank:
      raise ValueError('Convolution expects input with rank %d, got %d' %
                       (conv_dims + 2, input_rank))

Missing _pywrap_tensorflow_internal

Hello,

I have an issue after installing the project and its prerequisites through Git Shell.

When I run train_mineral_shards.py, I get a bunch of stack traces, and the culprit is an ImportError:
ImportError: No module named '_pywrap_tensorflow_internal'

I 've found a workaround on this and currently working on it, but is there another way to resolve this?

Not sure if incompatible with baselines or bad baselines installation

I'm getting the following error when I run enjoy_mineral_shards. I didn't exactly have a seamless baselines installation, but I think baselines is installed correctly now and not the problem.

C:\Users\Rick\Desktop\pysc2-examples>python enjoy_mineral_shards.py
Traceback (most recent call last):
File "enjoy_mineral_shards.py", line 162, in
main()
File "enjoy_mineral_shards.py", line 55, in main
"mineral_shards.pkl", act_params=act_params)
File "C:\Users\Rick\Desktop\pysc2-examples\deepq_mineral_shards.py", line 93, in load
return ActWrapper.load(path, num_cpu=num_cpu, act_params=act_params)
File "C:\Users\Rick\Desktop\pysc2-examples\deepq_mineral_shards.py", line 44, in load
act = deepq.build_act(**act_params)
File "c:\users\rick\desktop\baselines\baselines\deepq\build_graph.py", line 146, in build_act
observations_ph = make_obs_ph("observation")
File "enjoy_mineral_shards.py", line 46, in make_obs_ph
return U.BatchInput((64, 64), name=name)
AttributeError: module 'baselines.common.tf_util' has no attribute 'BatchInput'
W0204 12:41:43.175422 10984 sc_process.py:183] Killing the process.

Errors after baselines repo latest commit

After cleanups done in baselines repo I am getting new errors while running train_mineral_shards (with enjoy_mineral_shards everything works just fine)

Traceback (most recent call last):
  File "C:/Users/Artur/Documents/PySC2/train/train_mineral_shards.py", line 14, in <module>
    from a2c.policies import CnnPolicy
  File "C:\Users\Artur\Documents\PySC2\train\a2c\policies.py", line 3, in <module>
    from baselines.acktr.utils import conv, fc, dense, conv_to_fc, sample, kl_div
ImportError: cannot import name 'conv'

Process finished with exit code 1

Any help?

show an error when i run train_mineral_shards

show an error when i run train_mineral_shards

File "C:\Anaconda3\lib\site-packages\pysc2\run_configs_init_.py", line 39, in get
if FLAGS.sc2_run_config is None: # Find the highest priority as default.
File "C:\Anaconda3\lib\site-packages\absl\flags_flagvalues.py", line 491, in getattr
raise _exceptions.UnparsedFlagAccessError(error_message)
absl.flags._exceptions.UnparsedFlagAccessError: Trying to access flag --sc2_run_config before flags were parsed.

BatchInput seems to be deprecated in latest openai/baselines

Hi, this is somewhat related to Issue #13 .
As of 3/11/2019, openaI/baselines does not support BatchInput in baselines.deepq.utils anymore.

The change was made in commit 24fe3d6576dd8f4cdd5f017805be689d6fa6be8c May 21, 2018.
It seems like BatchInput has been changed to ObvservationInput.

openai/baselines issue #524 also states this issue, but there were no replies made yet.

Since ObvservationInput only accepts gym spaces, I'm not really sure how to modify enjoy_mineral_shards.py to run on the latest baselines since the code below will not work anymore.

def make_obs_ph(name):
      return U.BatchInput((64, 64), name=name)

I think I should be using a code something like the below, but if I do so I would get another error saying ValueError: Convolution expects input with rank 4, got 2 while building the act.

def make_obs_ph(name):
      U.ObservationInput(Box(low=-32.0, high=32.0, shape=(2,)), name=name)

Thanks in advance!

train mineral shard example is not compatible with baselines library

I can't get started train_minteral_shards.py example. Getting this error:

$ python train_mineral_shards.py
Traceback (most recent call last):
File "train_mineral_shards.py", line 14, in
from common.vec_env.subproc_vec_env import SubprocVecEnv
File "D:\devel\repositories\pysc2-examples\common_init_.py", line 1, in
from baselines.common.console_util import *
ImportError: No module named 'baselines.common.console_util'

btw, I am using windows, can't it be problem? I've tried build baselines from repository, but I've failed on atari.py dependency (not very compatible with windows). baselines0.1.4 or lower libraries can be installed using pip, but seem to be not sufficient for example. Please help how to proceed.

when run python enjoy_mineral_shards.py come with error

Hallo , when I run command "python enjoy_mineral_shards.py" in terminal ,the error is:

Traceback (most recent call last):
File "enjoy_mineral_shards.py", line 163, in
main()
File "enjoy_mineral_shards.py", line 39, in main
game_steps_per_episode=steps * step_mul) as env:
File "/home/m/.local/lib/python3.5/site-packages/pysc2/env/sc2_env.py", line 248, in init
raise ValueError("Please specify agent_interface_format.")
ValueError: Please specify agent_interface_format.

Can anyone else can solve it ??? Thanks

test/scripted_test.py

I get the following error:

pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
Error
Traceback (most recent call last):
File "/anaconda3/envs/conda/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
yield
File "/anaconda3/envs/conda/lib/python3.6/unittest/case.py", line 605, in run
testMethod()
File "/Users/donggeun/Downloads/pysc2-examples-master/tests/scripted_test.py", line 33, in test_defeat_zerglings
game_steps_per_episode=self.steps * self.step_mul) as env:
File "/anaconda3/envs/conda/lib/python3.6/site-packages/pysc2/env/sc2_env.py", line 248, in init
raise ValueError("Please specify agent_interface_format.")
ValueError: Please specify agent_interface_format.

DeprecationWarning: screen_size_px and minimap_size_px are deprecated.

Hi! I tried to run the train_mineral_shards.py using pycharm on the windows 7, the error is :
Traceback (most recent call last):
File "D:\Anaconda3\lib\multiprocessing\process.py", line 258, in _bootstrap
self.run()
File "D:\Anaconda3\lib\multiprocessing\process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Administrator.SC-201608140925\Desktop\pysc2-examples-master\common\vec_env\subproc_vec_env.py", line 20, in worker
minimap_size_px=(32, 32)) as env:
File "D:\Anaconda3\lib\site-packages\pysc2\env\sc2_env.py", line 182, in init
"screen_size_px and minimap_size_px are deprecated. Use the feature "
DeprecationWarning: screen_size_px and minimap_size_px are deprecated. Use the feature or rgb variants instead. Make sure to check your observations too since they also switched from screen/minimap to feature and rgb variants.
I hope someone can answer my question, thank you!

Supervised Learning to Predict Win/Loss from Pysc2

Hi,
I was wondering if you have or know of any examples that implemented supervised learning using Starcraft II game data (implimented in section 5 of this paper : StarCraft II: A New Challenge for
Reinforcement Learning). Methods for how the features were generated from game replays or anything of that sort is always appreciated.

Thank you,

Training information

Hi there,

This is more of a question, I'm using your code to train some agents and I would like to generate graphs of their performance rating over time. Is there already a way to do that already or I would need to export the scores at the end of each iteration?

Thanks

ImportError: cannot import name 'mse'

$ python train_mineral_shards.py --algorithm=a2c
/home/guoyoutian/anaconda3/lib/python3.6/site-packages/h5py/init.py:36: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type.
from ._conv import register_converters as _register_converters
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "train_mineral_shards.py", line 15, in
from a2c import a2c
File "/home/guoyoutian/PycharmProjects/pysc2-examples-master/a2c/a2c.py", line 12, in
from baselines.a2c.utils import cat_entropy, mse
ImportError: cannot import name 'mse'

Baselines version problem

What's the baselines' version in this repo?
Baselines have pr so many times, some functions can't work well.

Discord Server for collaboration

We have setup a Discord Server @ see below dedicated for PySC2 collaboration.

  • I should add this is not endorsed by this project and is open to anyone

missing 1 required positional argument: 'map_name'

Hello, I am trying to get the example work in Windows 10. Here is an error which I encountered.

Traceback (most recent call last):
  File "train_mineral_shards.py", line 302, in <module>
    main()
  File "train_mineral_shards.py", line 168, in main
    env = SubprocVecEnv(FLAGS.num_agents + FLAGS.num_scripts, FLAGS.map)
TypeError: __init__() missing 1 required positional argument: 'map_name'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.