Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 363873279
  • Loading branch information
qstanczyk committed Mar 19, 2021
1 parent cae99ca commit 02defa8
Show file tree
Hide file tree
Showing 60 changed files with 249 additions and 226 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Expand Up @@ -5,6 +5,10 @@ should not change, as modifications made to the environment are either
new features or backward compatible bug fixes. We will maintain vX branches
pointing at the most recent vX.Y.

v2.9
- Drop hard dependency on Tensorflow.
- Make installation easier, support for Ubuntu 20.04.

v2.8
- Added support for hardware accelerated headless rendering.
- Minor fixes for the issues reported by Kaggle contestants.
Expand Down
8 changes: 2 additions & 6 deletions Dockerfile
@@ -1,6 +1,5 @@
ARG DOCKER_BASE
FROM $DOCKER_BASE
ARG DEVICE

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get --no-install-recommends install -yq git cmake build-essential \
Expand All @@ -9,11 +8,8 @@ RUN apt-get update && apt-get --no-install-recommends install -yq git cmake buil
libdirectfb-dev libst-dev mesa-utils xvfb x11vnc \
libsdl-sge-dev python3-pip

RUN python3 -m pip install --upgrade pip setuptools
RUN pip3 install --use-feature=2020-resolver --no-cache-dir psutil dm-sonnet==1.*
RUN pip list | grep 'tensorflow ' || pip3 install --use-feature=2020-resolver --no-cache-dir tensorflow==1.15.*
RUN python3 -m pip install --upgrade pip setuptools psutil

RUN pip3 install --use-feature=2020-resolver --no-cache-dir git+https://github.com/openai/baselines.git@master
COPY . /gfootball
RUN cd /gfootball && pip3 install --use-feature=2020-resolver .
RUN cd /gfootball && python3 -m pip install .
WORKDIR '/gfootball'
19 changes: 19 additions & 0 deletions Dockerfile_examples
@@ -0,0 +1,19 @@
ARG DOCKER_BASE
FROM $DOCKER_BASE
ARG DEVICE

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get --no-install-recommends install -yq git cmake build-essential \
libgl1-mesa-dev libsdl2-dev \
libsdl2-image-dev libsdl2-ttf-dev libsdl2-gfx-dev libboost-all-dev \
libdirectfb-dev libst-dev mesa-utils xvfb x11vnc \
libsdl-sge-dev python3-pip

RUN python3 -m pip install --upgrade pip setuptools
RUN pip3 install --no-cache-dir psutil dm-sonnet==1.*
RUN pip list | grep 'tensorflow ' || pip3 install --no-cache-dir tensorflow==1.15.*

RUN pip3 install --no-cache-dir git+https://github.com/openai/baselines.git@master
COPY . /gfootball
RUN cd /gfootball && pip3 install .
WORKDIR '/gfootball'
18 changes: 10 additions & 8 deletions README.md
Expand Up @@ -40,6 +40,8 @@ Instructions are available [here](gfootball/doc/docker.md).
sudo apt-get install git cmake build-essential libgl1-mesa-dev libsdl2-dev \
libsdl2-image-dev libsdl2-ttf-dev libsdl2-gfx-dev libboost-all-dev \
libdirectfb-dev libst-dev mesa-utils xvfb x11vnc libsdl-sge-dev python3-pip
python3 -m pip install --upgrade pip setuptools psutil
```

#### Mac OS X
Expand All @@ -57,7 +59,7 @@ brew install sdl sdl_image sdl_mixer sdl_ttf portmidi

#### 2a. From PyPi package
```
pip3 install gfootball
python3 -m pip install gfootball
```

#### 2b. Installing from sources using GitHub repository
Expand All @@ -77,7 +79,7 @@ source football-env/bin/activate
The last step is to build the environment:

```
pip3 install .
python3 -m pip install .
```
This command can run for a couple of minutes, as it compiles the C++ environment in the background.

Expand All @@ -102,20 +104,20 @@ To quit the game press Ctrl+C in the terminal.
* [Multi-agent support](gfootball/doc/multi_agent.md)
* [Running in docker](gfootball/doc/docker.md)
* [Saving replays, logs, traces](gfootball/doc/saving_replays.md)
* [Imitation Learning](gfootball/doc/imitation.md)

## Training agents to play GRF

### Run training
In order to run TF training, install additional dependencies
(or alternatively use provided [Docker image](gfootball/doc/docker.md)):
In order to run TF training, you need to install additional dependencies

- Update PIP, so that tensorflow 1.15 is available: `python3 -m pip install --upgrade pip setuptools`
- TensorFlow: `pip3 install tensorflow==1.15.*` or
`pip3 install tensorflow-gpu==1.15.*`, depending on whether you want CPU or
- TensorFlow: `python3 -m pip install tensorflow==1.15.*` or
`python3 -m pip install tensorflow-gpu==1.15.*`, depending on whether you want CPU or
GPU version;
- Sonnet: `pip3 install dm-sonnet==1.*`;
- Sonnet: `python3 -m pip install dm-sonnet==1.*`;
- OpenAI Baselines:
`pip3 install git+https://github.com/openai/baselines.git@master`.
`python3 -m pip install git+https://github.com/openai/baselines.git@master`.

Then:

Expand Down
10 changes: 6 additions & 4 deletions gfootball/build_game_engine.sh
Expand Up @@ -12,16 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

LIB_EXTENSION="so"

if [[ "$OSTYPE" == "darwin"* ]] ; then
LIB_EXTENSION="dylib"
fi

N_CORES=$(python -c 'import multiprocessing as mp; print(mp.cpu_count())')
# Take into account # of cores and available RAM for deciding on compilation parallelism.
PARALLELISM=$(python3 -c 'import psutil; import multiprocessing as mp; print(int(max(1,min((psutil.virtual_memory().available/1000000000-1)/0.5, mp.cpu_count()))))')

set -e
# Delete pre-existing version of CMakeCache.txt to make 'pip3 install' work.
# Delete pre-existing version of CMakeCache.txt to make 'python3 -m pip install' work.
rm -f third_party/gfootball_engine/CMakeCache.txt
pushd third_party/gfootball_engine && cmake . && make -j $N_CORES && popd
pushd third_party/gfootball_engine && cmake . && make -j $PARALLELISM && popd
pushd third_party/gfootball_engine && ln -sf libgame.$LIB_EXTENSION _gameplayfootball.so && popd
6 changes: 3 additions & 3 deletions gfootball/colabs/gfootball_example_from_prebuild.ipynb
Expand Up @@ -46,11 +46,11 @@
"!apt-get install libsdl2-gfx-dev libsdl2-ttf-dev\n",
"\n",
"# Make sure that the Branch in git clone and in wget call matches !!\n",
"!git clone -b v2.8 https://github.com/google-research/football.git\n",
"!git clone -b v2.9 https://github.com/google-research/football.git\n",
"!mkdir -p football/third_party/gfootball_engine/lib\n",
"\n",
"!wget https://storage.googleapis.com/gfootball/prebuilt_gameplayfootball_v2.6.so -O football/third_party/gfootball_engine/lib/prebuilt_gameplayfootball.so\n",
"!cd football && GFOOTBALL_USE_PREBUILT_SO=1 pip3 install ."
"!wget https://storage.googleapis.com/gfootball/prebuilt_gameplayfootball_v2.9.so -O football/third_party/gfootball_engine/lib/prebuilt_gameplayfootball.so\n",
"!cd football && GFOOTBALL_USE_PREBUILT_SO=1 python3 -m pip install ."
],
"execution_count": 0,
"outputs": []
Expand Down
4 changes: 2 additions & 2 deletions gfootball/colabs/gfootball_example_from_scratch.ipynb
Expand Up @@ -479,8 +479,8 @@
},
"source": [
"## Make sure to set the correct BRANCH (-b XXX)\n",
"! git clone -b v2.8 https://github.com/google-research/football.git\n",
"! cd football && pip3 install ."
"! git clone -b v2.9 https://github.com/google-research/football.git\n",
"! cd football && python3 -m pip install ."
],
"execution_count": 3,
"outputs": [
Expand Down
10 changes: 3 additions & 7 deletions gfootball/doc/docker.md
Expand Up @@ -21,13 +21,13 @@ command to `/etc/profile` to not worry about it in the future.
### Tensorflow without GPU-training support version

```
docker build --build-arg DOCKER_BASE=ubuntu:18.04 --build-arg DEVICE=cpu . -t gfootball
docker build --build-arg DOCKER_BASE=ubuntu:18.04 --build-arg . -t gfootball
```

### Tensorflow with GPU-training support version

```
docker build --build-arg DOCKER_BASE=tensorflow/tensorflow:1.15.2-gpu-py3 --build-arg DEVICE=gpu . -t gfootball
docker build --build-arg DOCKER_BASE=tensorflow/tensorflow:1.15.2-gpu-py3 . -t gfootball
```

## Start the Docker image
Expand All @@ -50,11 +50,7 @@ For example, to play the game yourself you can run:
python3 -m gfootball.play_game --action_set=full
```

Or you can run a sample PPO2 training with:

```
python3 -m gfootball.examples.run_ppo2
```
To run example PPO2 training you need to install OpenAI Baselines in addition.

## Building a docker image under MacOS

Expand Down
14 changes: 14 additions & 0 deletions gfootball/doc/imitation.md
@@ -0,0 +1,14 @@
# Imitation Learning #

One of the approaches applied by a number of teams participating in the
[Google Research Football competition on Kaggle](https://www.kaggle.com/c/google-football)
was Imitation Learning. Over time as the competition progressed, there were more
and more [game replays](https://www.kaggle.com/c/google-football/leaderboard)
available to train on. If you want to pursue this research direction and need
data to start, Kaggle competition replays are there for you. It is possible
to collect the replays of your interest using [Kaggle API](https://www.kaggle.com/docs/api)
or you can start with an already pre-processed publically available data set.
An example of such a dataset can be found [here](https://www.kaggle.com/dott1718/grf-replays-collection).
It consists of around 5000 replays mainly from the top competition agents.
Replays were converted from the original Kaggle format to reduce the size of
the dataset.
6 changes: 3 additions & 3 deletions gfootball/env/football_action_set_test.py
Expand Up @@ -15,14 +15,14 @@

"""Football action set tests."""

import unittest
from absl.testing import absltest
from gfootball.env import football_action_set
import numpy as np

named_action_from_action_set = football_action_set.named_action_from_action_set


class FootballActionSetTest(unittest.TestCase):
class FootballActionSetTest(absltest.TestCase):

def test_action_from_basic_action_set(self):
action_set = football_action_set.get_action_set({'action_set': 'default'})
Expand Down Expand Up @@ -71,4 +71,4 @@ def test_sticky_actions_have_release(self):


if __name__ == '__main__':
unittest.main()
absltest.main()
2 changes: 1 addition & 1 deletion gfootball/env/football_env_core.py
Expand Up @@ -181,7 +181,7 @@ def step(self, action, extra_data={}):
if self._observation['ball_owned_team'] != -1 and self._observation[
'ball_owned_team'] ^ left_team and controlled_players[
i] == self._observation['ball_owned_player']:
if self._env.waiting_for_game_count < 30:
if bool(self._env.waiting_for_game_count < 30) != bool(left_team):
player_action = football_action_set.action_left
else:
player_action = football_action_set.action_right
Expand Down
6 changes: 3 additions & 3 deletions gfootball/env/football_env_test.py
Expand Up @@ -27,6 +27,7 @@
import random
import threading
import zlib
from absl.testing import absltest

from gfootball.env import config
from gfootball.env import football_action_set
Expand All @@ -36,7 +37,6 @@
import numpy as np
import psutil
from six.moves import range
import unittest

fast_run = False

Expand Down Expand Up @@ -285,7 +285,7 @@ def test___render(self):
for _ in range(10):
o, _, _, _ = env.step(football_action_set.action_right)
hash_value = observation_hash(o, hash_value)
self.assertEqual(hash_value, 18699114)
self.assertEqual(hash_value, 2591249504)
env.close()

def test_dynamic_render(self):
Expand Down Expand Up @@ -686,4 +686,4 @@ def test_restore_after_done(self):


if __name__ == '__main__':
unittest.main(failfast=True)
absltest.main(failfast=True)
7 changes: 4 additions & 3 deletions gfootball/env/observation_rotation_test.py
Expand Up @@ -19,14 +19,15 @@
from __future__ import division
from __future__ import print_function

from absl.testing import absltest

from gfootball.env import config
from gfootball.env import football_action_set
from gfootball.env import observation_rotation
import numpy as np
import tensorflow.compat.v1 as tf


class ObservationRotationTest(tf.test.TestCase):
class ObservationRotationTest(absltest.TestCase):

def testObservationFlipping(self):
cfg = config.Config()
Expand Down Expand Up @@ -78,4 +79,4 @@ def testActionFlipping(self):


if __name__ == '__main__':
tf.test.main()
absltest.main()
8 changes: 4 additions & 4 deletions gfootball/env/script_helpers_test.py
Expand Up @@ -21,18 +21,18 @@

import glob
import os
import unittest
import zlib
from absl.testing import absltest

from gfootball.env import config
from gfootball.env import football_action_set
from gfootball.env import football_env
from gfootball.env import script_helpers
import six.moves.cPickle

test_tmpdir = '/tmp/gfootball_test'


class ScriptHelpersTest(unittest.TestCase):
class ScriptHelpersTest(absltest.TestCase):

def generate_replay(self):
"""Generates replay of an episode."""
Expand Down Expand Up @@ -101,4 +101,4 @@ def test_dump_to_video(self):


if __name__ == '__main__':
unittest.main()
absltest.main()
6 changes: 3 additions & 3 deletions gfootball/env/wrappers_test.py
Expand Up @@ -22,10 +22,10 @@
import os
import gym
import numpy as np
import unittest
from absl.testing import absltest


class SingleAgentWrapperTest(unittest.TestCase):
class SingleAgentWrapperTest(absltest.TestCase):

def test_consistent_observation_and_action(self):
env = gym.make(
Expand Down Expand Up @@ -145,4 +145,4 @@ def test_consistent_observation_and_action_floats(self):
env.close()

if __name__ == '__main__':
unittest.main()
absltest.main()
1 change: 1 addition & 0 deletions gfootball/scenarios/tests/11_vs_11_deterministic.py
Expand Up @@ -19,6 +19,7 @@

from . import *


def build_scenario(builder):
builder.config().game_duration = 3000
builder.config().right_team_difficulty = 0.6
Expand Down
1 change: 1 addition & 0 deletions gfootball/scenarios/tests/11_vs_11_easy_deterministic.py
Expand Up @@ -19,6 +19,7 @@

from . import *


def build_scenario(builder):
builder.config().game_duration = 3000
builder.config().right_team_difficulty = 0.05
Expand Down
1 change: 1 addition & 0 deletions gfootball/scenarios/tests/11_vs_11_hard_deterministic.py
Expand Up @@ -19,6 +19,7 @@

from . import *


def build_scenario(builder):
builder.config().game_duration = 3000
builder.config().right_team_difficulty = 0.95
Expand Down
Expand Up @@ -19,6 +19,7 @@

from . import *


def build_scenario(builder):
builder.config().game_duration = 3000
builder.config().deterministic = True
Expand Down
Expand Up @@ -19,6 +19,7 @@

from . import *


def build_scenario(builder):
builder.config().game_duration = 3000
builder.config().deterministic = False
Expand Down
1 change: 1 addition & 0 deletions gfootball/scenarios/tests/11_vs_4_offence_deterministic.py
Expand Up @@ -19,6 +19,7 @@

from . import *


def build_scenario(builder):
builder.config().game_duration = 400
builder.config().deterministic = True
Expand Down
1 change: 1 addition & 0 deletions gfootball/scenarios/tests/11_vs_4_offence_stochastic.py
Expand Up @@ -19,6 +19,7 @@

from . import *


def build_scenario(builder):
builder.config().game_duration = 400
builder.config().deterministic = False
Expand Down
1 change: 1 addition & 0 deletions gfootball/scenarios/tests/corner_test.py
Expand Up @@ -19,6 +19,7 @@

from . import *


def build_scenario(builder):
builder.config().game_duration = 30
builder.config().deterministic = False
Expand Down

0 comments on commit 02defa8

Please sign in to comment.