Skip to content

Commit

Permalink
Make meltingpot/python the root package.
Browse files Browse the repository at this point in the history
Instead of `from meltingpot.python.x import y` you should now just use `from meltingpot.x import y`.

PiperOrigin-RevId: 547748440
Change-Id: Iddb6254e0eccf38229e202ef34a6f980818ac4ff
  • Loading branch information
jagapiou authored and copybara-github committed Jul 13, 2023
1 parent 7bf2f74 commit f387f13
Show file tree
Hide file tree
Showing 149 changed files with 466 additions and 464 deletions.
20 changes: 10 additions & 10 deletions docs/substrate_tutorial/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ By the end, your game will look like this:

## Getting started

The code for this tutorial is in `meltingpot/docs/substrate_tutorial`, and you
The code for this tutorial is in `meltingpot/examples/tutorial/harvest`, and you
can try it out like this:

<code class="lang-shell"><pre>
Expand All @@ -30,25 +30,25 @@ UnboundLocalError: local variable 'game_display' referenced before assignment
```

make sure you are including the `-- --observation WORLD.RGB` parameter in your
command. The reson for this is that the empty substrate only has two
command. The reason for this is that the empty substrate only has two
observations: `WORLD.RGB` and `WORLD.TEXT`. We will add more later on, including
the default per-player `RGB` one.

### Fully working example

If you just want to skip ahead and look at the finished game, simply change the
import in
[`play_harvest.py`](https://github.com/deepmind/meltingpot/tree/main/meltingpot/substrate_tutorial/harvest/play_harvest.py)
[`play_harvest.py`](https://github.com/deepmind/meltingpot/tree/main/meltingpot/examples/tutorial/harvest/play_harvest.py)
from

```python
from meltingpot.tutorial.harvest.configs.environment import harvest as game
from .configs.environment import harvest as game
```

to

```python
from meltingpot.tutorial.harvest.configs.environment import harvest_finished as game
from .configs.environment import harvest_finished as game
```

and launch as desired:
Expand All @@ -72,7 +72,7 @@ us, at least, have an avatar that we can move around.

The first thing to do is to set our number of players to 1 and add the
individual observation to the config in
[`harvest.py`](https://github.com/deepmind/meltingpot/tree/main/meltingpot/substrate_tutorial/harvest/configs/environment/harvest.py):
[`harvest.py`](https://github.com/deepmind/meltingpot/tree/main/meltingpot/examples/tutorial/harvest/configs/environment/harvest.py):

```python
config.num_players = 1
Expand Down Expand Up @@ -209,7 +209,7 @@ the `lab2d_settings` part of the config. In the end, they should look like this:
config.substrate.lab2d_settings = {
"levelName": "harvest",
"levelDirectory":
"meltingpot/substrate_tutorial/harvest/levels",
"meltingpot/examples/tutorial/harvest/levels",
"maxEpisodeLengthFrames": 100,
"numPlayers": 1,
"spriteSize": 8,
Expand Down Expand Up @@ -272,7 +272,7 @@ We have some useful sprites in the
Let's import it (don't forget to add the dependency):

```python
from meltingpot.python.utils.substrates import shapes
from meltingpot.utils.substrates import shapes
```

and change our avatar's Appearance `Component` to:
Expand Down Expand Up @@ -501,7 +501,7 @@ character in the ASCII map, and call the prefab `"apple"`.
config.lab2d_settings = {
"levelName": "harvest",
"levelDirectory":
"meltingpot/tutorial/harvest/levels",
"meltingpot/examples/tutorial/harvest/levels",
"maxEpisodeLengthFrames": 100,
"numPlayers": 5,
"spriteSize": 8,
Expand Down Expand Up @@ -720,7 +720,7 @@ First set `config.num_players = 5`. The rest of the changes go in
config.lab2d_settings = {
"levelName": "harvest_finished",
"levelDirectory":
"meltingpot/tutorial/harvest/levels",
"meltingpot/examples/tutorial/harvest/levels",
"maxEpisodeLengthFrames": 1000,
"numPlayers": 5,
"spriteSize": 8,
Expand Down
4 changes: 2 additions & 2 deletions examples/pettingzoo/sb3_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Binary to run Stable Baselines 3 agents on meltingpot substrates."""

import gym
from meltingpot import substrate
import stable_baselines3
from stable_baselines3.common import callbacks
from stable_baselines3.common import torch_layers
Expand All @@ -23,8 +24,7 @@
from torch import nn
import torch.nn.functional as F

from examples.pettingzoo import utils
from meltingpot.python import substrate
from . import utils

device = torch.device("cuda") if torch.cuda.is_available() else torch.device(
"cpu")
Expand Down
4 changes: 2 additions & 2 deletions examples/pettingzoo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

from gym import utils as gym_utils
import matplotlib.pyplot as plt
from meltingpot import substrate
from ml_collections import config_dict
from pettingzoo import utils as pettingzoo_utils
from pettingzoo.utils import wrappers

from examples import utils
from meltingpot.python import substrate
from .. import utils

PLAYER_STR_FORMAT = 'player_{index}'
MAX_CYCLES = 1000
Expand Down
4 changes: 2 additions & 2 deletions examples/rllib/self_play_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

import os

from meltingpot import substrate
import ray
from ray import air
from ray import tune
from ray.rllib.algorithms import ppo
from ray.rllib.policy.policy import PolicySpec

from examples.rllib import utils
from meltingpot.python import substrate
from . import utils


def get_config(
Expand Down
6 changes: 3 additions & 3 deletions examples/rllib/tests/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

from absl.testing import absltest
from gym.spaces import discrete
from meltingpot import substrate
from meltingpot.configs.substrates import commons_harvest_open

from examples.rllib import utils
from meltingpot.python import substrate
from meltingpot.python.configs.substrates import commons_harvest_open
from .. import utils


class MeltingPotEnvTests(absltest.TestCase):
Expand Down
7 changes: 4 additions & 3 deletions examples/rllib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
import dm_env
import dmlab2d
from gym import spaces
from meltingpot import substrate
from meltingpot.utils.policies import policy
from ml_collections import config_dict
import numpy as np
from ray.rllib import algorithms
from ray.rllib.env import multi_agent_env
from ray.rllib.policy.sample_batch import DEFAULT_POLICY_ID

from examples import utils
from meltingpot.python import substrate
from meltingpot.python.utils.policies import policy
from .. import utils


PLAYER_STR_FORMAT = 'player_{index}'

Expand Down
2 changes: 1 addition & 1 deletion examples/rllib/view_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from ray.tune.analysis.experiment_analysis import ExperimentAnalysis
from ray.tune.registry import register_env

from examples.rllib import utils
from . import utils


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""Configuration for finished tutorial level: Harvest."""

from ml_collections import config_dict
from meltingpot.python.utils.substrates import shapes
from meltingpot.utils.substrates import shapes


SPAWN_POINT = {
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial/harvest/play_harvest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from absl import app
from absl import flags

from examples.tutorial.harvest.configs.environment import harvest as game
from meltingpot.python.human_players import level_playing_utils
from .configs.environment import harvest as game
from meltingpot.human_players import level_playing_utils

FLAGS = flags.FLAGS

Expand Down
6 changes: 3 additions & 3 deletions meltingpot/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
# limitations under the License.
"""Melting Pot."""

from meltingpot.python import bot
from meltingpot.python import scenario
from meltingpot.python import substrate
from meltingpot import bot
from meltingpot import scenario
from meltingpot import substrate
16 changes: 8 additions & 8 deletions meltingpot/python/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

import functools

from meltingpot.python import substrate
from meltingpot.python.configs import bots as bot_configs
from meltingpot.python.utils.policies import fixed_action_policy
from meltingpot.python.utils.policies import policy
from meltingpot.python.utils.policies import policy_factory
from meltingpot.python.utils.policies import puppet_policy
from meltingpot.python.utils.policies import saved_model_policy
from meltingpot.python.utils.substrates import specs
from meltingpot import substrate
from meltingpot.configs import bots as bot_configs
from meltingpot.utils.policies import fixed_action_policy
from meltingpot.utils.policies import policy
from meltingpot.utils.policies import policy_factory
from meltingpot.utils.policies import puppet_policy
from meltingpot.utils.policies import saved_model_policy
from meltingpot.utils.substrates import specs

NOOP_BOT_NAME = 'noop_bot'
NOOP_ACTION = 0
Expand Down
4 changes: 2 additions & 2 deletions meltingpot/python/bot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from absl.testing import absltest
from absl.testing import parameterized

from meltingpot.python import bot
from meltingpot.python.testing import bots as test_utils
from meltingpot import bot
from meltingpot.testing import bots as test_utils


@parameterized.named_parameters((name, name) for name in bot.BOTS)
Expand Down
21 changes: 10 additions & 11 deletions meltingpot/python/configs/bots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@

import immutabledict

from meltingpot.python.utils.puppeteers import alternator
from meltingpot.python.utils.puppeteers import clean_up
from meltingpot.python.utils.puppeteers import coins
from meltingpot.python.utils.puppeteers import coordination_in_the_matrix
from meltingpot.python.utils.puppeteers import fixed_goal
from meltingpot.python.utils.puppeteers import gift_refinements
from meltingpot.python.utils.puppeteers import in_the_matrix
from meltingpot.python.utils.puppeteers import puppeteer
from meltingpot.python.utils.puppeteers import running_with_scissors_in_the_matrix
from meltingpot.utils.puppeteers import alternator
from meltingpot.utils.puppeteers import clean_up
from meltingpot.utils.puppeteers import coins
from meltingpot.utils.puppeteers import coordination_in_the_matrix
from meltingpot.utils.puppeteers import fixed_goal
from meltingpot.utils.puppeteers import gift_refinements
from meltingpot.utils.puppeteers import in_the_matrix
from meltingpot.utils.puppeteers import puppeteer
from meltingpot.utils.puppeteers import running_with_scissors_in_the_matrix


def _find_models_root() -> str:
import re # pylint: disable=g-import-not-at-top
return re.sub('meltingpot/python/.*', 'meltingpot/assets/saved_models',
__file__)
return re.sub('meltingpot/.*?$', 'meltingpot/assets/saved_models/', __file__)


MODELS_ROOT = _find_models_root()
Expand Down
4 changes: 2 additions & 2 deletions meltingpot/python/configs/bots/bot_configs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from absl.testing import absltest
from absl.testing import parameterized

from meltingpot.python.configs import bots
from meltingpot.python.configs import substrates
from meltingpot.configs import bots
from meltingpot.configs import substrates


def _subdirs(root):
Expand Down
8 changes: 4 additions & 4 deletions meltingpot/python/configs/scenarios/scenario_configs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
from absl.testing import absltest
from absl.testing import parameterized

from meltingpot.python import bot as bot_factory
from meltingpot.python.configs import bots
from meltingpot.python.configs import scenarios
from meltingpot.python.configs import substrates
from meltingpot import bot as bot_factory
from meltingpot.configs import bots
from meltingpot.configs import scenarios
from meltingpot.configs import substrates

SCENARIO_CONFIGS = scenarios.SCENARIO_CONFIGS
AVAILABLE_BOTS = bot_factory.BOTS
Expand Down
8 changes: 4 additions & 4 deletions meltingpot/python/configs/substrates/allelopathic_harvest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@

from ml_collections import config_dict

from meltingpot.python.utils.substrates import colors
from meltingpot.python.utils.substrates import game_object_utils
from meltingpot.python.utils.substrates import shapes
from meltingpot.python.utils.substrates import specs
from meltingpot.utils.substrates import colors
from meltingpot.utils.substrates import game_object_utils
from meltingpot.utils.substrates import shapes
from meltingpot.utils.substrates import specs

PrefabConfig = game_object_utils.PrefabConfig

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
preferences. arXiv preprint arXiv:2010.09054.
"""

from meltingpot.python.configs.substrates import allelopathic_harvest as base_config
from meltingpot.configs.substrates import allelopathic_harvest as base_config

OPEN_ASCII_MAP = """
333PPPP12PPP322P32PPP1P13P3P3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@

from ml_collections import config_dict

from meltingpot.python.configs.substrates import the_matrix
from meltingpot.python.utils.substrates import colors
from meltingpot.python.utils.substrates import game_object_utils
from meltingpot.python.utils.substrates import shapes
from meltingpot.python.utils.substrates import specs
from meltingpot.configs.substrates import the_matrix
from meltingpot.utils.substrates import colors
from meltingpot.utils.substrates import game_object_utils
from meltingpot.utils.substrates import shapes
from meltingpot.utils.substrates import specs

PrefabConfig = game_object_utils.PrefabConfig

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@

from ml_collections import config_dict

from meltingpot.python.configs.substrates import the_matrix
from meltingpot.python.utils.substrates import colors
from meltingpot.python.utils.substrates import game_object_utils
from meltingpot.python.utils.substrates import shapes
from meltingpot.python.utils.substrates import specs
from meltingpot.configs.substrates import the_matrix
from meltingpot.utils.substrates import colors
from meltingpot.utils.substrates import game_object_utils
from meltingpot.utils.substrates import shapes
from meltingpot.utils.substrates import specs

PrefabConfig = game_object_utils.PrefabConfig

Expand Down
6 changes: 3 additions & 3 deletions meltingpot/python/configs/substrates/boat_race.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@

from ml_collections import config_dict as configdict

from meltingpot.python.utils.substrates import colors
from meltingpot.python.utils.substrates import shapes
from meltingpot.python.utils.substrates import specs
from meltingpot.utils.substrates import colors
from meltingpot.utils.substrates import shapes
from meltingpot.utils.substrates import specs

# Warning: setting `_ENABLE_DEBUG_OBSERVATIONS = True` may cause slowdown.
_ENABLE_DEBUG_OBSERVATIONS = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from ml_collections import config_dict as configdict

from meltingpot.python.configs.substrates import boat_race as base_config
from meltingpot.configs.substrates import boat_race as base_config


def get_config() -> configdict.ConfigDict:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
from ml_collections import config_dict
import networkx as nx

from meltingpot.python.configs.substrates import reaction_graph_utils as graph_utils
from meltingpot.python.utils.substrates import colors
from meltingpot.python.utils.substrates import shapes
from meltingpot.python.utils.substrates import specs
from meltingpot.configs.substrates import reaction_graph_utils as graph_utils
from meltingpot.utils.substrates import colors
from meltingpot.utils.substrates import shapes
from meltingpot.utils.substrates import specs

# Warning: setting `_ENABLE_DEBUG_OBSERVATIONS = True` may cause slowdown.
_ENABLE_DEBUG_OBSERVATIONS = False
Expand Down
Loading

0 comments on commit f387f13

Please sign in to comment.