From edeb3737e40c44f81520a088aa07ae03db9cda7f Mon Sep 17 00:00:00 2001 From: ggsavin Date: Fri, 25 Aug 2023 10:01:49 -0400 Subject: [PATCH 1/8] fixing custom env tutorial returns bto properly return infos --- .../EnvironmentCreation/tutorial2_adding_game_logic.py | 6 +++++- tutorials/EnvironmentCreation/tutorial3_action_masking.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tutorials/EnvironmentCreation/tutorial2_adding_game_logic.py b/tutorials/EnvironmentCreation/tutorial2_adding_game_logic.py index 5c06a14a9..8ac1450d1 100644 --- a/tutorials/EnvironmentCreation/tutorial2_adding_game_logic.py +++ b/tutorials/EnvironmentCreation/tutorial2_adding_game_logic.py @@ -44,7 +44,11 @@ def reset(self, seed=None, options=None): ) for a in self.agents } - return observations, {} + + # Get dummy infos. Necessary for proper parallel_to_aec conversion + infos = {a: {} for a in self.agents} + + return observations, infos def step(self, actions): # Execute actions diff --git a/tutorials/EnvironmentCreation/tutorial3_action_masking.py b/tutorials/EnvironmentCreation/tutorial3_action_masking.py index b01639f3e..5353aa745 100644 --- a/tutorials/EnvironmentCreation/tutorial3_action_masking.py +++ b/tutorials/EnvironmentCreation/tutorial3_action_masking.py @@ -45,7 +45,11 @@ def reset(self, seed=None, options=None): "prisoner": {"observation": observation, "action_mask": [0, 1, 1, 0]}, "guard": {"observation": observation, "action_mask": [1, 0, 0, 1]}, } - return observations, {} + + # Get dummy infos. Necessary for proper parallel_to_aec conversion + infos = {a: {} for a in self.agents} + + return observations, infos def step(self, actions): # Execute actions From 98427615037631227b51893f524012aa52128601 Mon Sep 17 00:00:00 2001 From: ggsavin Date: Fri, 25 Aug 2023 10:04:15 -0400 Subject: [PATCH 2/8] parallel_to_aec will cause issues in downstream APIs if infos is not properly set in the reset function --- pettingzoo/test/parallel_test.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pettingzoo/test/parallel_test.py b/pettingzoo/test/parallel_test.py index 2ba450a1b..a5cca6e0c 100644 --- a/pettingzoo/test/parallel_test.py +++ b/pettingzoo/test/parallel_test.py @@ -46,8 +46,11 @@ def parallel_api_test(par_env: ParallelEnv, num_cycles=1000): MAX_RESETS = 2 for _ in range(MAX_RESETS): obs, infos = par_env.reset() + assert isinstance(obs, dict) + assert isinstance(infos, dict) assert set(obs.keys()) == (set(par_env.agents)) + assert set(infos.keys()) == (set(par_env.agents)) terminated = {agent: False for agent in par_env.agents} truncated = {agent: False for agent in par_env.agents} live_agents = set(par_env.agents[:]) From d9e6a4548e38fa0f83da8b7b013302299b6864e5 Mon Sep 17 00:00:00 2001 From: ggsavin Date: Fri, 25 Aug 2023 11:23:14 -0400 Subject: [PATCH 3/8] ensuring info keys match observation keys if infos are empty --- pettingzoo/utils/conversions.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pettingzoo/utils/conversions.py b/pettingzoo/utils/conversions.py index 48cf1fadb..ef1010fba 100644 --- a/pettingzoo/utils/conversions.py +++ b/pettingzoo/utils/conversions.py @@ -294,6 +294,11 @@ def action_space(self, agent): def reset(self, seed=None, options=None): self._observations, self.infos = self.env.reset(seed=seed, options=options) + + # Every environment needs to return infos that contain the same keys as the observations + if bool(self.infos) == False: + self.infos = {agent: {} for agent in self._observations.keys()} + self.agents = self.env.agents[:] self._live_agents = self.agents[:] self._actions: Dict[AgentID, Optional[ActionType]] = { From 0969d70a22d2dd70ae8e9095819e7bce39534875 Mon Sep 17 00:00:00 2001 From: ggsavin Date: Fri, 25 Aug 2023 11:31:59 -0400 Subject: [PATCH 4/8] empty infos now warns and uses self.agents to populate keys --- pettingzoo/utils/conversions.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pettingzoo/utils/conversions.py b/pettingzoo/utils/conversions.py index ef1010fba..eafa05056 100644 --- a/pettingzoo/utils/conversions.py +++ b/pettingzoo/utils/conversions.py @@ -294,11 +294,6 @@ def action_space(self, agent): def reset(self, seed=None, options=None): self._observations, self.infos = self.env.reset(seed=seed, options=options) - - # Every environment needs to return infos that contain the same keys as the observations - if bool(self.infos) == False: - self.infos = {agent: {} for agent in self._observations.keys()} - self.agents = self.env.agents[:] self._live_agents = self.agents[:] self._actions: Dict[AgentID, Optional[ActionType]] = { @@ -309,6 +304,12 @@ def reset(self, seed=None, options=None): self.terminations = {agent: False for agent in self.agents} self.truncations = {agent: False for agent in self.agents} self.rewards = {agent: 0 for agent in self.agents} + + # Every environment needs to return infos that contain the same keys as the observations + if bool(self.infos) == False: + warnings.warn("The `infos` dictionary returned by `env.reset` was empty. Agent IDs as keys will be used") + self.infos = {agent: {} for agent in self.agents} + self._cumulative_rewards = {agent: 0 for agent in self.agents} self.new_agents = [] self.new_values = {} From 8644e9f90a2302c709e35039aa28459b5bd19e18 Mon Sep 17 00:00:00 2001 From: ggsavin Date: Fri, 25 Aug 2023 12:25:52 -0400 Subject: [PATCH 5/8] additional condition for infos --- pettingzoo/utils/conversions.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pettingzoo/utils/conversions.py b/pettingzoo/utils/conversions.py index eafa05056..5d7ac0358 100644 --- a/pettingzoo/utils/conversions.py +++ b/pettingzoo/utils/conversions.py @@ -305,11 +305,14 @@ def reset(self, seed=None, options=None): self.truncations = {agent: False for agent in self.agents} self.rewards = {agent: 0 for agent in self.agents} - # Every environment needs to return infos that contain the same keys as the observations - if bool(self.infos) == False: + # Every environment needs to return infos that contain self.agents as their keys + if not self.infos: warnings.warn("The `infos` dictionary returned by `env.reset` was empty. Agent IDs as keys will be used") self.infos = {agent: {} for agent in self.agents} - + elif set(self.infos.keys()) != set(self.agents): + warnings.warn("The `infos` dictionary keys returned by `env.reset` is not equal to the agent IDs listed in `self.agents`. Overwriting with just agent IDs as keys") + self.infos = {agent: {} for agent in self.agents} + self._cumulative_rewards = {agent: 0 for agent in self.agents} self.new_agents = [] self.new_values = {} From 3934466322b7ccd4b1e62b324b988ec0f2ee4429 Mon Sep 17 00:00:00 2001 From: elliottower Date: Fri, 1 Sep 2023 15:31:04 -0400 Subject: [PATCH 6/8] Split env creation tutorials with explanation, update requirements to pz 1.24.1 for new hotfix --- .github/workflows/linux-tutorials-test.yml | 2 +- docs/code_examples/aec_rps_usage.py | 16 ++++++++++++++++ docs/code_examples/parallel_rps.py | 2 ++ docs/code_examples/parallel_rps_usage.py | 11 +++++++++++ docs/content/environment_creation.md | 19 +++++++++++++++++++ docs/index.md | 2 +- .../1-project-structure.md | 0 .../2-environment-logic.md | 0 .../3-action-masking.md | 0 .../4-testing-your-environment.md | 0 .../5-using-your-environment.md | 0 .../index.md | 8 +++++--- pettingzoo/__init__.py | 2 +- pettingzoo/test/parallel_test.py | 1 + pettingzoo/utils/conversions.py | 6 +++--- tutorials/CleanRL/requirements.txt | 2 +- tutorials/CustomEnvironment/requirements.txt | 1 + .../tutorial1_skeleton_creation.py | 0 .../tutorial2_adding_game_logic.py | 4 +++- .../tutorial3_action_masking.py | 2 +- .../tutorial4_testing_the_environment.py | 11 +++++++++++ .../4-TestingTheEnvironment.txt | 0 .../EnvironmentCreation/5-UsingWithAPI.txt | 0 .../EnvironmentCreation/6-UsingWithRL.txt | 0 .../EnvironmentCreation/requirements.txt | 1 - .../tutorial4_testing_the_environment.py | 7 ------- tutorials/Ray/requirements.txt | 7 ++++--- tutorials/SB3/connect_four/requirements.txt | 2 +- tutorials/SB3/kaz/requirements.txt | 2 +- tutorials/SB3/pistonball/requirements.txt | 2 +- tutorials/SB3/test/requirements.txt | 2 +- tutorials/SB3/waterworld/requirements.txt | 2 +- 32 files changed, 86 insertions(+), 28 deletions(-) create mode 100644 docs/code_examples/aec_rps_usage.py create mode 100644 docs/code_examples/parallel_rps_usage.py rename docs/tutorials/{environmentcreation => custom_environment}/1-project-structure.md (100%) rename docs/tutorials/{environmentcreation => custom_environment}/2-environment-logic.md (100%) rename docs/tutorials/{environmentcreation => custom_environment}/3-action-masking.md (100%) rename docs/tutorials/{environmentcreation => custom_environment}/4-testing-your-environment.md (100%) rename docs/tutorials/{environmentcreation => custom_environment}/5-using-your-environment.md (100%) rename docs/tutorials/{environmentcreation => custom_environment}/index.md (53%) create mode 100644 tutorials/CustomEnvironment/requirements.txt rename tutorials/{EnvironmentCreation => CustomEnvironment}/tutorial1_skeleton_creation.py (100%) rename tutorials/{EnvironmentCreation => CustomEnvironment}/tutorial2_adding_game_logic.py (98%) rename tutorials/{EnvironmentCreation => CustomEnvironment}/tutorial3_action_masking.py (99%) create mode 100644 tutorials/CustomEnvironment/tutorial4_testing_the_environment.py delete mode 100644 tutorials/EnvironmentCreation/4-TestingTheEnvironment.txt delete mode 100644 tutorials/EnvironmentCreation/5-UsingWithAPI.txt delete mode 100644 tutorials/EnvironmentCreation/6-UsingWithRL.txt delete mode 100644 tutorials/EnvironmentCreation/requirements.txt delete mode 100644 tutorials/EnvironmentCreation/tutorial4_testing_the_environment.py diff --git a/.github/workflows/linux-tutorials-test.yml b/.github/workflows/linux-tutorials-test.yml index 20ba3000c..dc5600a21 100644 --- a/.github/workflows/linux-tutorials-test.yml +++ b/.github/workflows/linux-tutorials-test.yml @@ -19,7 +19,7 @@ jobs: fail-fast: false matrix: python-version: ['3.8', '3.9', '3.10', '3.11'] - tutorial: ['Tianshou', 'EnvironmentCreation', 'CleanRL', 'SB3/kaz', 'SB3/waterworld', 'SB3/connect_four', 'SB3/test'] # TODO: add back Ray once next release after 2.6.2 + tutorial: ['Tianshou', 'CustomEnvironment', 'CleanRL', 'SB3/kaz', 'SB3/waterworld', 'SB3/connect_four', 'SB3/test'] # TODO: add back Ray once next release after 2.6.2 steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/docs/code_examples/aec_rps_usage.py b/docs/code_examples/aec_rps_usage.py new file mode 100644 index 000000000..ce4f24625 --- /dev/null +++ b/docs/code_examples/aec_rps_usage.py @@ -0,0 +1,16 @@ +import aec_rps + +env = aec_rps.env(render_mode="human") +env.reset(seed=42) + +for agent in env.agent_iter(): + observation, reward, termination, truncation, info = env.last() + + if termination or truncation: + action = None + else: + # this is where you would insert your policy + action = env.action_space(agent).sample() + + env.step(action) +env.close() \ No newline at end of file diff --git a/docs/code_examples/parallel_rps.py b/docs/code_examples/parallel_rps.py index 5d54c6483..383659666 100644 --- a/docs/code_examples/parallel_rps.py +++ b/docs/code_examples/parallel_rps.py @@ -130,6 +130,7 @@ def reset(self, seed=None, options=None): self.num_moves = 0 observations = {agent: NONE for agent in self.agents} infos = {agent: {} for agent in self.agents} + self.state = observations return observations, infos @@ -165,6 +166,7 @@ def step(self, actions): self.agents[i]: int(actions[self.agents[1 - i]]) for i in range(len(self.agents)) } + self.state = observations # typically there won't be any information in the infos, but there must # still be an entry for each agent diff --git a/docs/code_examples/parallel_rps_usage.py b/docs/code_examples/parallel_rps_usage.py new file mode 100644 index 000000000..38949eb78 --- /dev/null +++ b/docs/code_examples/parallel_rps_usage.py @@ -0,0 +1,11 @@ +import parallel_rps + +env = parallel_rps.parallel_env(render_mode="human") +observations, infos = env.reset() + +while env.agents: + # this is where you would insert your policy + actions = {agent: env.action_space(agent).sample() for agent in env.agents} + + observations, rewards, terminations, truncations, infos = env.step(actions) +env.close() diff --git a/docs/content/environment_creation.md b/docs/content/environment_creation.md index f0cb89023..3c5122feb 100644 --- a/docs/content/environment_creation.md +++ b/docs/content/environment_creation.md @@ -5,6 +5,11 @@ 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. + +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. + ## Example Custom Environment This is a carefully commented version of the PettingZoo rock paper scissors environment. @@ -14,6 +19,13 @@ This is a carefully commented version of the PettingZoo rock paper scissors envi :language: python ``` +To interact with your custom AEC environment, use the following code: + +```{eval-rst} +.. literalinclude:: ../code_examples/aec_rps_usage.py + :language: python +``` + ## Example Custom Parallel Environment ```{eval-rst} @@ -21,6 +33,13 @@ This is a carefully commented version of the PettingZoo rock paper scissors envi :language: python ``` +To interact with your custom parallel environment, use the following code: + +```{eval-rst} +.. literalinclude:: ../code_examples/parallel_rps_usage.py + :language: python +``` + ## Using Wrappers A wrapper is an environment transformation that takes in an environment as input, and outputs a new environment that is similar to the input environment, but with some transformation or validation applied. PettingZoo provides [wrappers to convert environments](/api/pz_wrappers) back and forth between the AEC API and the Parallel API and a set of simple [utility wrappers](/api/pz_wrappers) which provide input validation and other convenient reusable logic. PettingZoo also includes [wrappers](/api/supersuit_wrappers) via the SuperSuit companion package (`pip install supersuit`). diff --git a/docs/index.md b/docs/index.md index 69ff05962..cf9613924 100644 --- a/docs/index.md +++ b/docs/index.md @@ -39,7 +39,7 @@ environments/third_party_envs :hidden: :caption: Tutorials -tutorials/environmentcreation/index +tutorials/custom_environment/index tutorials/cleanrl/index tutorials/tianshou/index tutorials/rllib/index diff --git a/docs/tutorials/environmentcreation/1-project-structure.md b/docs/tutorials/custom_environment/1-project-structure.md similarity index 100% rename from docs/tutorials/environmentcreation/1-project-structure.md rename to docs/tutorials/custom_environment/1-project-structure.md diff --git a/docs/tutorials/environmentcreation/2-environment-logic.md b/docs/tutorials/custom_environment/2-environment-logic.md similarity index 100% rename from docs/tutorials/environmentcreation/2-environment-logic.md rename to docs/tutorials/custom_environment/2-environment-logic.md diff --git a/docs/tutorials/environmentcreation/3-action-masking.md b/docs/tutorials/custom_environment/3-action-masking.md similarity index 100% rename from docs/tutorials/environmentcreation/3-action-masking.md rename to docs/tutorials/custom_environment/3-action-masking.md diff --git a/docs/tutorials/environmentcreation/4-testing-your-environment.md b/docs/tutorials/custom_environment/4-testing-your-environment.md similarity index 100% rename from docs/tutorials/environmentcreation/4-testing-your-environment.md rename to docs/tutorials/custom_environment/4-testing-your-environment.md diff --git a/docs/tutorials/environmentcreation/5-using-your-environment.md b/docs/tutorials/custom_environment/5-using-your-environment.md similarity index 100% rename from docs/tutorials/environmentcreation/5-using-your-environment.md rename to docs/tutorials/custom_environment/5-using-your-environment.md diff --git a/docs/tutorials/environmentcreation/index.md b/docs/tutorials/custom_environment/index.md similarity index 53% rename from docs/tutorials/environmentcreation/index.md rename to docs/tutorials/custom_environment/index.md index 36d0a1799..c82348759 100644 --- a/docs/tutorials/environmentcreation/index.md +++ b/docs/tutorials/custom_environment/index.md @@ -1,10 +1,10 @@ --- -title: "Environment Creation" +title: "Custom Environment Tutorial" --- -# Environment Creation Tutorial +# Custom Environment Tutorial -These tutorials walk you though creating a custom environment from scratch, and are recommended as a starting point for anyone new to PettingZoo. +These tutorials walk you though the full process of creating a custom environment from scratch, and are recommended as a starting point for anyone new to PettingZoo. 1. [Project Structure](/tutorials/environmentcreation/1-project-structure.md) @@ -14,6 +14,8 @@ These tutorials walk you though creating a custom environment from scratch, and 4. [Testing Your Environment](/tutorials/environmentcreation/4-testing-your-environment.md) +For a simpler example environment, including both [AEC](/api/aec/) and [Parallel](/api/aec/) implementations, see our [Environment Creation](/content/environment_creation/) documentation. + ```{toctree} :hidden: diff --git a/pettingzoo/__init__.py b/pettingzoo/__init__.py index 9f58764c9..2f20788c1 100644 --- a/pettingzoo/__init__.py +++ b/pettingzoo/__init__.py @@ -12,7 +12,7 @@ os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "hide" -__version__ = "1.24.0" +__version__ = "1.24.1" try: import sys diff --git a/pettingzoo/test/parallel_test.py b/pettingzoo/test/parallel_test.py index a5cca6e0c..4209ba296 100644 --- a/pettingzoo/test/parallel_test.py +++ b/pettingzoo/test/parallel_test.py @@ -130,3 +130,4 @@ def parallel_api_test(par_env: ParallelEnv, num_cycles=1000): if len(live_agents) == 0: break + print("Passed Parallel API test") diff --git a/pettingzoo/utils/conversions.py b/pettingzoo/utils/conversions.py index 5d7ac0358..714086e85 100644 --- a/pettingzoo/utils/conversions.py +++ b/pettingzoo/utils/conversions.py @@ -307,11 +307,11 @@ def reset(self, seed=None, options=None): # Every environment needs to return infos that contain self.agents as their keys if not self.infos: - warnings.warn("The `infos` dictionary returned by `env.reset` was empty. Agent IDs as keys will be used") + warnings.warn("The `infos` dictionary returned by `env.reset` was empty. OverwritingAgent IDs will be used as keys") self.infos = {agent: {} for agent in self.agents} elif set(self.infos.keys()) != set(self.agents): - warnings.warn("The `infos` dictionary keys returned by `env.reset` is not equal to the agent IDs listed in `self.agents`. Overwriting with just agent IDs as keys") - self.infos = {agent: {} for agent in self.agents} + self.infos = {agent: {self.infos.copy()} for agent in self.agents} + warnings.warn(f"The `infos` dictionary returned by `env.reset()` is not valid: must contain keys for each agent defined in self.agents: {self.agents}. Overwriting with current info duplicated for each agent: {self.infos}") self._cumulative_rewards = {agent: 0 for agent in self.agents} self.new_agents = [] diff --git a/tutorials/CleanRL/requirements.txt b/tutorials/CleanRL/requirements.txt index 07894712e..3a9d9bed8 100644 --- a/tutorials/CleanRL/requirements.txt +++ b/tutorials/CleanRL/requirements.txt @@ -1,4 +1,4 @@ -pettingzoo[butterfly,atari,testing]>=1.23.1 +pettingzoo[butterfly,atari,testing]>=1.24.1 SuperSuit>=3.9.0 tensorboard>=2.11.2 torch>=1.13.1 diff --git a/tutorials/CustomEnvironment/requirements.txt b/tutorials/CustomEnvironment/requirements.txt new file mode 100644 index 000000000..9d780a563 --- /dev/null +++ b/tutorials/CustomEnvironment/requirements.txt @@ -0,0 +1 @@ +pettingzoo==1.24.1 diff --git a/tutorials/EnvironmentCreation/tutorial1_skeleton_creation.py b/tutorials/CustomEnvironment/tutorial1_skeleton_creation.py similarity index 100% rename from tutorials/EnvironmentCreation/tutorial1_skeleton_creation.py rename to tutorials/CustomEnvironment/tutorial1_skeleton_creation.py diff --git a/tutorials/EnvironmentCreation/tutorial2_adding_game_logic.py b/tutorials/CustomEnvironment/tutorial2_adding_game_logic.py similarity index 98% rename from tutorials/EnvironmentCreation/tutorial2_adding_game_logic.py rename to tutorials/CustomEnvironment/tutorial2_adding_game_logic.py index 8ac1450d1..a52222815 100644 --- a/tutorials/EnvironmentCreation/tutorial2_adding_game_logic.py +++ b/tutorials/CustomEnvironment/tutorial2_adding_game_logic.py @@ -89,7 +89,6 @@ def step(self, actions): if self.timestep > 100: rewards = {"prisoner": 0, "guard": 0} truncations = {"prisoner": True, "guard": True} - self.agents = [] self.timestep += 1 # Get observations @@ -105,6 +104,9 @@ def step(self, actions): # Get dummy infos (not used in this example) infos = {a: {} for a in self.agents} + if any(terminations.values()) or all(truncations.values()): + self.agents = [] + return observations, rewards, terminations, truncations, infos def render(self): diff --git a/tutorials/EnvironmentCreation/tutorial3_action_masking.py b/tutorials/CustomEnvironment/tutorial3_action_masking.py similarity index 99% rename from tutorials/EnvironmentCreation/tutorial3_action_masking.py rename to tutorials/CustomEnvironment/tutorial3_action_masking.py index 5353aa745..3d70d4893 100644 --- a/tutorials/EnvironmentCreation/tutorial3_action_masking.py +++ b/tutorials/CustomEnvironment/tutorial3_action_masking.py @@ -8,7 +8,7 @@ from pettingzoo import ParallelEnv -class CustomEnvironment(ParallelEnv): +class CustomActionMaskedEnvironment(ParallelEnv): metadata = { "name": "custom_environment_v0", } diff --git a/tutorials/CustomEnvironment/tutorial4_testing_the_environment.py b/tutorials/CustomEnvironment/tutorial4_testing_the_environment.py new file mode 100644 index 000000000..88c6f9b46 --- /dev/null +++ b/tutorials/CustomEnvironment/tutorial4_testing_the_environment.py @@ -0,0 +1,11 @@ +from tutorial3_action_masking import CustomActionMaskedEnvironment +from tutorial2_adding_game_logic import CustomEnvironment + +from pettingzoo.test import parallel_api_test + +if __name__ == "__main__": + env = CustomEnvironment() + parallel_api_test(env, num_cycles=1_000_000) + + env = CustomActionMaskedEnvironment() + parallel_api_test(env, num_cycles=1_000_000) diff --git a/tutorials/EnvironmentCreation/4-TestingTheEnvironment.txt b/tutorials/EnvironmentCreation/4-TestingTheEnvironment.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/tutorials/EnvironmentCreation/5-UsingWithAPI.txt b/tutorials/EnvironmentCreation/5-UsingWithAPI.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/tutorials/EnvironmentCreation/6-UsingWithRL.txt b/tutorials/EnvironmentCreation/6-UsingWithRL.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/tutorials/EnvironmentCreation/requirements.txt b/tutorials/EnvironmentCreation/requirements.txt deleted file mode 100644 index ae5c33767..000000000 --- a/tutorials/EnvironmentCreation/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -pettingzoo==1.23.0 diff --git a/tutorials/EnvironmentCreation/tutorial4_testing_the_environment.py b/tutorials/EnvironmentCreation/tutorial4_testing_the_environment.py deleted file mode 100644 index cbfbf41b2..000000000 --- a/tutorials/EnvironmentCreation/tutorial4_testing_the_environment.py +++ /dev/null @@ -1,7 +0,0 @@ -from tutorial3_action_masking import CustomEnvironment - -from pettingzoo.test import parallel_api_test - -if __name__ == "__main__": - env = CustomEnvironment() - parallel_api_test(env, num_cycles=1_000_000) diff --git a/tutorials/Ray/requirements.txt b/tutorials/Ray/requirements.txt index 62909ce6b..f093df3e2 100644 --- a/tutorials/Ray/requirements.txt +++ b/tutorials/Ray/requirements.txt @@ -1,6 +1,7 @@ -PettingZoo[classic, butterfly]==1.23.1 +PettingZoo[classic,butterfly]>=1.24.1 Pillow>=9.4.0 -ray[rllib]>2.6.2 -SuperSuit==3.8.0 +# note: currently requires nightly release, see https://docs.ray.io/en/latest/ray-overview/installation.html#daily-releases-nightlies +ray[rllib]>2.6.3 +SuperSuit>=3.9.0 torch>=1.13.1 tensorflow-probability>=0.19.0 diff --git a/tutorials/SB3/connect_four/requirements.txt b/tutorials/SB3/connect_four/requirements.txt index 30917f7b2..9af251d02 100644 --- a/tutorials/SB3/connect_four/requirements.txt +++ b/tutorials/SB3/connect_four/requirements.txt @@ -1,3 +1,3 @@ -pettingzoo[classic]>=1.23.1 +pettingzoo[classic]>=1.24.1 stable-baselines3>=2.0.0 sb3-contrib>=2.0.0 diff --git a/tutorials/SB3/kaz/requirements.txt b/tutorials/SB3/kaz/requirements.txt index c0e9ef734..062e612af 100644 --- a/tutorials/SB3/kaz/requirements.txt +++ b/tutorials/SB3/kaz/requirements.txt @@ -1,3 +1,3 @@ -pettingzoo[butterfly]>=1.23.1 +pettingzoo[butterfly]>=1.24.1 stable-baselines3>=2.0.0 supersuit>=3.9.0 diff --git a/tutorials/SB3/pistonball/requirements.txt b/tutorials/SB3/pistonball/requirements.txt index c0e9ef734..062e612af 100644 --- a/tutorials/SB3/pistonball/requirements.txt +++ b/tutorials/SB3/pistonball/requirements.txt @@ -1,3 +1,3 @@ -pettingzoo[butterfly]>=1.23.1 +pettingzoo[butterfly]>=1.24.1 stable-baselines3>=2.0.0 supersuit>=3.9.0 diff --git a/tutorials/SB3/test/requirements.txt b/tutorials/SB3/test/requirements.txt index 838ea192b..bd55ee8ca 100644 --- a/tutorials/SB3/test/requirements.txt +++ b/tutorials/SB3/test/requirements.txt @@ -1,4 +1,4 @@ -pettingzoo[classic]>=1.23.1 +pettingzoo[classic]>=1.24.1 stable-baselines3>=2.0.0 sb3-contrib>=2.0.0 pytest diff --git a/tutorials/SB3/waterworld/requirements.txt b/tutorials/SB3/waterworld/requirements.txt index 0b91a8538..c06122078 100644 --- a/tutorials/SB3/waterworld/requirements.txt +++ b/tutorials/SB3/waterworld/requirements.txt @@ -1,4 +1,4 @@ -pettingzoo[sisl]>=1.23.1 +pettingzoo[sisl]>=1.24.1 stable-baselines3>=2.0.0 supersuit>=3.9.0 pymunk From 105383ad61f002abe9597220aca032aa48382d90 Mon Sep 17 00:00:00 2001 From: elliottower Date: Fri, 1 Sep 2023 15:33:35 -0400 Subject: [PATCH 7/8] pre-commit, add check for GitHub workflows (validate them locally before running on CI) --- .pre-commit-config.yaml | 4 ++++ docs/code_examples/aec_rps_usage.py | 2 +- docs/content/environment_creation.md | 4 ++-- pettingzoo/utils/conversions.py | 11 ++++++++--- .../tutorial4_testing_the_environment.py | 2 +- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 735642935..08174efa7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -75,3 +75,7 @@ repos: additional_dependencies: ["pyright"] args: - --project=pyproject.toml + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.26.3 + hooks: + - id: check-github-workflows diff --git a/docs/code_examples/aec_rps_usage.py b/docs/code_examples/aec_rps_usage.py index ce4f24625..71edc4e73 100644 --- a/docs/code_examples/aec_rps_usage.py +++ b/docs/code_examples/aec_rps_usage.py @@ -13,4 +13,4 @@ action = env.action_space(agent).sample() env.step(action) -env.close() \ No newline at end of file +env.close() diff --git a/docs/content/environment_creation.md b/docs/content/environment_creation.md index 3c5122feb..717c66bc2 100644 --- a/docs/content/environment_creation.md +++ b/docs/content/environment_creation.md @@ -6,9 +6,9 @@ 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/aec/) 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. +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. ## Example Custom Environment diff --git a/pettingzoo/utils/conversions.py b/pettingzoo/utils/conversions.py index 714086e85..589754cb8 100644 --- a/pettingzoo/utils/conversions.py +++ b/pettingzoo/utils/conversions.py @@ -1,3 +1,4 @@ +# pyright: reportGeneralTypeIssues=false import copy import warnings from collections import defaultdict @@ -307,12 +308,16 @@ def reset(self, seed=None, options=None): # Every environment needs to return infos that contain self.agents as their keys if not self.infos: - warnings.warn("The `infos` dictionary returned by `env.reset` was empty. OverwritingAgent IDs will be used as keys") + warnings.warn( + "The `infos` dictionary returned by `env.reset` was empty. OverwritingAgent IDs will be used as keys" + ) self.infos = {agent: {} for agent in self.agents} elif set(self.infos.keys()) != set(self.agents): self.infos = {agent: {self.infos.copy()} for agent in self.agents} - warnings.warn(f"The `infos` dictionary returned by `env.reset()` is not valid: must contain keys for each agent defined in self.agents: {self.agents}. Overwriting with current info duplicated for each agent: {self.infos}") - + warnings.warn( + f"The `infos` dictionary returned by `env.reset()` is not valid: must contain keys for each agent defined in self.agents: {self.agents}. Overwriting with current info duplicated for each agent: {self.infos}" + ) + self._cumulative_rewards = {agent: 0 for agent in self.agents} self.new_agents = [] self.new_values = {} diff --git a/tutorials/CustomEnvironment/tutorial4_testing_the_environment.py b/tutorials/CustomEnvironment/tutorial4_testing_the_environment.py index 88c6f9b46..ac6a867e1 100644 --- a/tutorials/CustomEnvironment/tutorial4_testing_the_environment.py +++ b/tutorials/CustomEnvironment/tutorial4_testing_the_environment.py @@ -1,5 +1,5 @@ -from tutorial3_action_masking import CustomActionMaskedEnvironment from tutorial2_adding_game_logic import CustomEnvironment +from tutorial3_action_masking import CustomActionMaskedEnvironment from pettingzoo.test import parallel_api_test From 79da170f640407f7bf61425a6f0110159f93a1d4 Mon Sep 17 00:00:00 2001 From: elliottower Date: Fri, 1 Sep 2023 17:37:14 -0400 Subject: [PATCH 8/8] Fix version numbers, bump to 1.24.1 for new hotfix --- tutorials/CleanRL/requirements.txt | 2 +- tutorials/CustomEnvironment/requirements.txt | 2 +- tutorials/Ray/requirements.txt | 2 +- tutorials/SB3/connect_four/requirements.txt | 2 +- tutorials/SB3/kaz/requirements.txt | 2 +- tutorials/SB3/pistonball/requirements.txt | 2 +- tutorials/SB3/test/requirements.txt | 2 +- tutorials/SB3/waterworld/requirements.txt | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tutorials/CleanRL/requirements.txt b/tutorials/CleanRL/requirements.txt index 3a9d9bed8..87c5e0a80 100644 --- a/tutorials/CleanRL/requirements.txt +++ b/tutorials/CleanRL/requirements.txt @@ -1,4 +1,4 @@ -pettingzoo[butterfly,atari,testing]>=1.24.1 +pettingzoo[butterfly,atari,testing]>=1.24.0 SuperSuit>=3.9.0 tensorboard>=2.11.2 torch>=1.13.1 diff --git a/tutorials/CustomEnvironment/requirements.txt b/tutorials/CustomEnvironment/requirements.txt index 9d780a563..691bc14a8 100644 --- a/tutorials/CustomEnvironment/requirements.txt +++ b/tutorials/CustomEnvironment/requirements.txt @@ -1 +1 @@ -pettingzoo==1.24.1 +pettingzoo==1.24.0 diff --git a/tutorials/Ray/requirements.txt b/tutorials/Ray/requirements.txt index f093df3e2..3cd41dae8 100644 --- a/tutorials/Ray/requirements.txt +++ b/tutorials/Ray/requirements.txt @@ -1,4 +1,4 @@ -PettingZoo[classic,butterfly]>=1.24.1 +PettingZoo[classic,butterfly]>=1.24.0 Pillow>=9.4.0 # note: currently requires nightly release, see https://docs.ray.io/en/latest/ray-overview/installation.html#daily-releases-nightlies ray[rllib]>2.6.3 diff --git a/tutorials/SB3/connect_four/requirements.txt b/tutorials/SB3/connect_four/requirements.txt index 9af251d02..bf7c59673 100644 --- a/tutorials/SB3/connect_four/requirements.txt +++ b/tutorials/SB3/connect_four/requirements.txt @@ -1,3 +1,3 @@ -pettingzoo[classic]>=1.24.1 +pettingzoo[classic]>=1.24.0 stable-baselines3>=2.0.0 sb3-contrib>=2.0.0 diff --git a/tutorials/SB3/kaz/requirements.txt b/tutorials/SB3/kaz/requirements.txt index 062e612af..01a14c748 100644 --- a/tutorials/SB3/kaz/requirements.txt +++ b/tutorials/SB3/kaz/requirements.txt @@ -1,3 +1,3 @@ -pettingzoo[butterfly]>=1.24.1 +pettingzoo[butterfly]>=1.24.0 stable-baselines3>=2.0.0 supersuit>=3.9.0 diff --git a/tutorials/SB3/pistonball/requirements.txt b/tutorials/SB3/pistonball/requirements.txt index 062e612af..01a14c748 100644 --- a/tutorials/SB3/pistonball/requirements.txt +++ b/tutorials/SB3/pistonball/requirements.txt @@ -1,3 +1,3 @@ -pettingzoo[butterfly]>=1.24.1 +pettingzoo[butterfly]>=1.24.0 stable-baselines3>=2.0.0 supersuit>=3.9.0 diff --git a/tutorials/SB3/test/requirements.txt b/tutorials/SB3/test/requirements.txt index bd55ee8ca..95e118fdd 100644 --- a/tutorials/SB3/test/requirements.txt +++ b/tutorials/SB3/test/requirements.txt @@ -1,4 +1,4 @@ -pettingzoo[classic]>=1.24.1 +pettingzoo[classic]>=1.24.0 stable-baselines3>=2.0.0 sb3-contrib>=2.0.0 pytest diff --git a/tutorials/SB3/waterworld/requirements.txt b/tutorials/SB3/waterworld/requirements.txt index c06122078..87d3b18d7 100644 --- a/tutorials/SB3/waterworld/requirements.txt +++ b/tutorials/SB3/waterworld/requirements.txt @@ -1,4 +1,4 @@ -pettingzoo[sisl]>=1.24.1 +pettingzoo[sisl]>=1.24.0 stable-baselines3>=2.0.0 supersuit>=3.9.0 pymunk