Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottower authored Nov 13, 2023
2 parents 213b5fd + e9b4001 commit a67209c
Show file tree
Hide file tree
Showing 28 changed files with 347 additions and 75 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,26 @@ jobs:
env:
SPHINX_GITHUB_CHANGELOG_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3

- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.9'

python-version: '3.11'
- name: Install dependencies
run: pip install -r docs/requirements.txt

- name: Install PettingZoo
run: pip install .[all]

- name: Generate environment docs
run: python docs/_scripts/gen_envs_mds.py

- name: Generate environments display
run: python docs/_scripts/gen_envs_display.py

- name: Build
run: sphinx-build -b dirhtml -v docs _build

- name: Move 404
run: mv _build/404/index.html _build/404.html

- name: Update 404 links
run: python docs/_scripts/move_404.py _build/404.html

- name: Remove .doctrees
run: rm -r _build/.doctrees

- name: Upload to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jobs:
platform: manylinux_x86_64

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Install dependencies
Expand Down
18 changes: 3 additions & 15 deletions .github/workflows/docs-manual-versioning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,37 @@ jobs:
env:
SPHINX_GITHUB_CHANGELOG_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
if: inputs.commit == ''

- uses: actions/checkout@v3
- uses: actions/checkout@v4
if: inputs.commit != ''
with:
ref: ${{ inputs.commit }}

- uses: actions/setup-python@v4
with:
python-version: '3.9'

python-version: '3.11'
- name: Install dependencies
run: pip install -r docs/requirements.txt

- name: Install PettingZoo
run: pip install .[all]

- name: Generate environment docs
run: python docs/_scripts/gen_envs_mds.py

- name: Generate environments display
run: python docs/_scripts/gen_envs_display.py

- name: Build
run: sphinx-build -b dirhtml -v docs _build

- name: Move 404
run: mv _build/404/index.html _build/404.html

- name: Update 404 links
run: python docs/_scripts/move_404.py _build/404.html

- name: Remove .doctrees
run: rm -r _build/.doctrees

- name: Upload to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: _build
target-folder: ${{ inputs.version }}
clean: false

- name: Upload to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
if: inputs.latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
matrix:
group: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
Expand Down
13 changes: 1 addition & 12 deletions .github/workflows/docs-versioning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,31 @@ jobs:
env:
SPHINX_GITHUB_CHANGELOG_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3

- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Get tag
id: tag
uses: dawidd6/action-get-tag@v1
with:
strip_v: true

- name: Install dependencies
run: pip install -r docs/requirements.txt

- name: Install PettingZoo
run: pip install .[all]

- name: Generate environment docs
run: python docs/_scripts/gen_envs_mds.py

- name: Generate environments display
run: python docs/_scripts/gen_envs_display.py

- name: Build
run: sphinx-build -b dirhtml -v docs _build

- name: Move 404
run: mv _build/404/index.html _build/404.html

- name: Update 404 links
run: python docs/_scripts/move_404.py _build/404.html

- name: Remove .doctrees
run: rm -r _build/.doctrees

- name: Upload to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linux-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/linux-tutorials-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
python-version: ['3.8', '3.9', '3.10', '3.11']
tutorial: [Tianshou, CustomEnvironment, CleanRL, SB3/kaz, SB3/waterworld, SB3/connect_four, SB3/test, AgileRL] # TODO: add back Ray once next release after 2.6.2
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies and run tutorials
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/macos-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
macos-test:
runs-on: macos-11
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v3
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.11
- name: Install dependencies
run: |
pip install -e .[all]
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- run: pip install pre-commit
- run: pre-commit --version
- run: pre-commit install
Expand Down
2 changes: 1 addition & 1 deletion docs/content/environment_creation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: Environment Creation
This documentation overviews creating new environments and relevant useful wrappers, utilities and tests included in PettingZoo designed for the creation of new environments.


We will walk through the creation of a simple Rock-Paper-Scissors environment, with example code for both [AEC](/api/aec/) and [Parallel](/api/aec/) environments.
We will walk through the creation of a simple Rock-Paper-Scissors environment, with example code for both [AEC](/api/aec/) and [Parallel](/api/parallel/) environments.

See our [Custom Environment Tutorial](/tutorials/custom_environment/index) for a full walkthrough on creating custom environments, including complex environment logic and illegal action masking.

Expand Down
1 change: 1 addition & 0 deletions pettingzoo/classic/connect_four/connect_four.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ def render(self):
)

if self.render_mode == "human":
pygame.event.pump()
pygame.display.update()
self.clock.tick(self.metadata["render_fps"])

Expand Down
4 changes: 1 addition & 3 deletions pettingzoo/classic/rlcard_envs/rlcard_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ def reset(self, seed=None, options=None):
self.truncations = self._convert_to_dict(
[False for _ in range(self.num_agents)]
)
self.infos = self._convert_to_dict(
[{"legal_moves": []} for _ in range(self.num_agents)]
)
self.infos = self._convert_to_dict([{} for _ in range(self.num_agents)])
self.next_legal_moves = list(sorted(obs["legal_actions"]))
self._last_obs = obs["obs"]

Expand Down
2 changes: 2 additions & 0 deletions pettingzoo/mpe/_mpe_utils/simple_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def step(self, action):
def enable_render(self, mode="human"):
if not self.renderOn and mode == "human":
self.screen = pygame.display.set_mode(self.screen.get_size())
self.clock = pygame.time.Clock()
self.renderOn = True

def render(self):
Expand All @@ -282,6 +283,7 @@ def render(self):
return np.transpose(observation, axes=(1, 0, 2))
elif self.render_mode == "human":
pygame.display.flip()
self.clock.tick(self.metadata["render_fps"])
return

def draw(self):
Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/mpe/simple_reference/simple_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
| Actions | Discrete/Continuous |
| Parallel API | Yes |
| Manual Control | No |
| Agents | `agents= [adversary_0, agent_0,agent_1]` |
| Agents | `agents= [agent_0, agent_1]` |
| Agents | 3 |
| Action Shape | (5) |
| Action Values | Discrete(5)/Box(0.0, 1.0, (5)) |
Expand Down
6 changes: 4 additions & 2 deletions pettingzoo/sisl/multiwalker/multiwalker.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ def __init__(self, *args, **kwargs):
EzPickle.__init__(self, *args, **kwargs)
self.env = _env(*args, **kwargs)
self.render_mode = self.env.render_mode
self.agents = ["walker_" + str(r) for r in range(self.env.num_agents)]
self.agents = ["walker_" + str(r) for r in range(self.env.n_walkers)]
self.possible_agents = self.agents[:]
self.agent_name_mapping = dict(zip(self.agents, list(range(self.num_agents))))
self.agent_name_mapping = dict(
zip(self.agents, list(range(self.env.n_walkers)))
)
self._agent_selector = agent_selector(self.agents)
# spaces
self.action_spaces = dict(zip(self.agents, self.env.action_space))
Expand Down
9 changes: 3 additions & 6 deletions pettingzoo/sisl/multiwalker/multiwalker_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ def __init__(
self._seed()
self.setup()
self.screen = None
self.agent_list = list(range(self.n_walkers))
self.last_rewards = [0 for _ in range(self.n_walkers)]
self.last_dones = [False for _ in range(self.n_walkers)]
self.last_obs = [None for _ in range(self.n_walkers)]
Expand All @@ -359,15 +358,12 @@ def setup(self):
BipedalWalker(self.world, init_x=sx, init_y=init_y, seed=self.seed_val)
for sx in self.start_x
]
self.num_agents = len(self.walkers)
self.observation_space = [agent.observation_space for agent in self.walkers]
self.action_space = [agent.action_space for agent in self.walkers]

self.package_scale = self.n_walkers / 1.75
self.package_length = PACKAGE_LENGTH / SCALE * self.package_scale

self.total_agents = self.n_walkers

self.prev_shaping = np.zeros(self.n_walkers)
self.prev_package_shaping = 0.0

Expand Down Expand Up @@ -534,7 +530,7 @@ def get_last_rewards(self):
)

def get_last_dones(self):
return dict(zip(self.agent_list, self.last_dones))
return dict(zip(list(range(self.n_walkers)), self.last_dones))

def get_last_obs(self):
return dict(
Expand Down Expand Up @@ -692,7 +688,8 @@ def render(self, close=False):
self.surf = pygame.transform.flip(self.surf, False, True)
self.screen.blit(self.surf, (-self.scroll * render_scale - offset, 0))
if self.render_mode == "human":
pygame.display.flip()
pygame.event.pump()
pygame.display.update()
elif self.render_mode == "rgb_array":
return np.transpose(
np.array(pygame.surfarray.pixels3d(self.screen)), axes=(1, 0, 2)
Expand Down
3 changes: 2 additions & 1 deletion pettingzoo/sisl/pursuit/pursuit_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ def render(self):
new_observation = np.copy(observation)
del observation
if self.render_mode == "human":
pygame.display.flip()
pygame.event.pump()
pygame.display.update()
return (
np.transpose(new_observation, axes=(1, 0, 2))
if self.render_mode == "rgb_array"
Expand Down
3 changes: 2 additions & 1 deletion pettingzoo/sisl/waterworld/waterworld_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,8 @@ def render(self):
del observation

if self.render_mode == "human":
pygame.display.flip()
pygame.event.pump()
pygame.display.update()
return (
np.transpose(new_observation, axes=(1, 0, 2))
if self.render_mode == "rgb_array"
Expand Down
5 changes: 3 additions & 2 deletions pettingzoo/test/parallel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def parallel_api_test(par_env: ParallelEnv, num_cycles=1000):

assert isinstance(obs, dict)
assert isinstance(infos, dict)
assert set(obs.keys()) == (set(par_env.agents))
assert set(infos.keys()) == (set(par_env.agents))
# Note: obs and info dicts must contain all AgentIDs, but can also have other additional keys (e.g., "common")
assert set(par_env.agents).issubset(set(obs.keys()))
assert set(par_env.agents).issubset(set(infos.keys()))
terminated = {agent: False for agent in par_env.agents}
truncated = {agent: False for agent in par_env.agents}
live_agents = set(par_env.agents[:])
Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def last(
) -> tuple[ObsType | None, float, bool, bool, dict[str, Any]]:
"""Returns observation, cumulative reward, terminated, truncated, info for the current agent (specified by self.agent_selection)."""
agent = self.agent_selection
assert agent
assert agent is not None
observation = self.observe(agent) if observe else None
return (
observation,
Expand Down
2 changes: 2 additions & 0 deletions pettingzoo/utils/wrappers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
from pettingzoo.utils.wrappers.base_parallel import BaseParallelWrapper
from pettingzoo.utils.wrappers.capture_stdout import CaptureStdoutWrapper
from pettingzoo.utils.wrappers.clip_out_of_bounds import ClipOutOfBoundsWrapper
from pettingzoo.utils.wrappers.multi_episode_env import MultiEpisodeEnv
from pettingzoo.utils.wrappers.multi_episode_parallel_env import MultiEpisodeParallelEnv
from pettingzoo.utils.wrappers.order_enforcing import OrderEnforcingWrapper
from pettingzoo.utils.wrappers.terminate_illegal import TerminateIllegalWrapper
Loading

0 comments on commit a67209c

Please sign in to comment.