From 8aa024e1155af4d29e780addced4ceb634425b5a Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Mon, 4 Jan 2021 18:33:58 -0800 Subject: [PATCH 01/11] try to support python3.9 with cattrs deps --- .github/workflows/pytest.yml | 2 +- ml-agents/setup.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 2fdbccb54e..d4d9aa3f7d 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.6.x, 3.7.x, 3.8.x] + python-version: [3.6.x, 3.7.x, 3.8.x, 3.9.x] steps: - uses: actions/checkout@v2 - name: Set up Python diff --git a/ml-agents/setup.py b/ml-agents/setup.py index 55fcc94467..225dae7fac 100644 --- a/ml-agents/setup.py +++ b/ml-agents/setup.py @@ -67,8 +67,9 @@ def run(self): # https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Installation.md#windows-installing-pytorch 'torch>=1.6.0,<1.8.0;platform_system!="Windows"', "tensorboard>=1.15", - # cattrs 1.1.0 dropped support for python 3.6. - "cattrs>=1.0.0,<1.1.0", + # cattrs 1.1.0 dropped support for python 3.6, but 1.0.0 doesn't work for python 3.9 + "cattrs>=1.0.0,<1.1.0; python_version<'3.7'", + "cattrs>=1.1.0; python_version>='3.7'", "attrs>=19.3.0", 'pypiwin32==223;platform_system=="Windows"', ], From 2384477df4d248f7843a0e997a19c88ab89ade2c Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Mon, 4 Jan 2021 19:28:39 -0800 Subject: [PATCH 02/11] fix weird type errors --- ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py b/ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py index 4a0da710a4..055a688af7 100644 --- a/ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py +++ b/ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py @@ -161,7 +161,7 @@ def proto_from_steps( reward=reward, done=done, id=agent_id, - max_step_reached=max_step_reached, + max_step_reached=bool(max_step_reached), action_mask=agent_mask, observations=observations, ) @@ -190,7 +190,7 @@ def proto_from_steps( reward=reward, done=done, id=agent_id, - max_step_reached=max_step_reached, + max_step_reached=bool(max_step_reached), action_mask=None, observations=final_observations, ) From 1768b869150fb6f4ee99089c558dfaa3bcafa6bc Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Tue, 5 Jan 2021 10:03:27 -0800 Subject: [PATCH 03/11] test fix - cast to np.bool --- ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py b/ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py index 055a688af7..0dbe465439 100644 --- a/ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py +++ b/ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py @@ -1,7 +1,7 @@ import io import numpy as np import pytest -from typing import List, Tuple +from typing import List, Tuple, Any from mlagents_envs.communicator_objects.agent_info_pb2 import AgentInfoProto from mlagents_envs.communicator_objects.observation_pb2 import ( @@ -137,13 +137,14 @@ def proto_from_steps( reward = decision_steps.reward[agent_id_index] done = False max_step_reached = False - agent_mask = None + agent_mask: Any = None if decision_steps.action_mask is not None: - agent_mask = [] # type: ignore + agent_mask = [] for _branch in decision_steps.action_mask: agent_mask = np.concatenate( (agent_mask, _branch[agent_id_index, :]), axis=0 ) + agent_mask = agent_mask.astype(np.bool) observations: List[ObservationProto] = [] for all_observations_of_type in decision_steps.obs: observation = all_observations_of_type[agent_id_index] From 3c0783f0ba5e986e4b1b78f39481db9c743e9758 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Tue, 5 Jan 2021 11:29:49 -0800 Subject: [PATCH 04/11] np.tolist() --- ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py b/ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py index 0dbe465439..d6487e52fa 100644 --- a/ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py +++ b/ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py @@ -144,7 +144,7 @@ def proto_from_steps( agent_mask = np.concatenate( (agent_mask, _branch[agent_id_index, :]), axis=0 ) - agent_mask = agent_mask.astype(np.bool) + agent_mask = agent_mask.astype(np.bool).tolist() observations: List[ObservationProto] = [] for all_observations_of_type in decision_steps.obs: observation = all_observations_of_type[agent_id_index] From 10065a16149311d9736573e392c25cda46b868a5 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Tue, 5 Jan 2021 11:51:42 -0800 Subject: [PATCH 05/11] changelog --- com.unity.ml-agents/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index 8c010edf2c..e7a15658a3 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to #### com.unity.ml-agents / com.unity.ml-agents.extensions (C#) #### ml-agents / ml-agents-envs / gym-unity (Python) +- python 3.9 is now supported and tested. (#4821) ### Bug Fixes #### com.unity.ml-agents (C#) From c4b88954a429ed8557944eb2be7996c73f6373a5 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Fri, 8 Jan 2021 18:09:04 -0800 Subject: [PATCH 06/11] newest pytest --- test_requirements.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test_requirements.txt b/test_requirements.txt index 1a3d424ec2..165edb1e67 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,5 +1,5 @@ # Test-only dependencies should go here, not in setup.py -pytest>4.0.0,<6.0.0 -pytest-cov==2.6.1 -pytest-xdist==1.34.0 +pytest>=6.2.1 +pytest-cov==2.10.1 +pytest-xdist==2.2.0 From 52baf8139d62219467f0b49a9b4b0abd638e4904 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Fri, 29 Jan 2021 15:14:14 -0800 Subject: [PATCH 07/11] pytest version and verbose --- .github/workflows/pytest.yml | 2 +- test_requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index d4d9aa3f7d..0f1f1fd1e5 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -50,7 +50,7 @@ jobs: pip freeze > pip_versions-${{ matrix.python-version }}.txt cat pip_versions-${{ matrix.python-version }}.txt - name: Run pytest - run: pytest --cov=ml-agents --cov=ml-agents-envs --cov=gym-unity --cov-report html --junitxml=junit/test-results-${{ matrix.python-version }}.xml -p no:warnings + run: pytest -v --cov=ml-agents --cov=ml-agents-envs --cov=gym-unity --cov-report html --junitxml=junit/test-results-${{ matrix.python-version }}.xml -p no:warnings - name: Upload pytest test results uses: actions/upload-artifact@v2 with: diff --git a/test_requirements.txt b/test_requirements.txt index 165edb1e67..b44bf0f95a 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,5 +1,5 @@ # Test-only dependencies should go here, not in setup.py -pytest>=6.2.1 +pytest>=6.2.2 pytest-cov==2.10.1 pytest-xdist==2.2.0 From 1dd2143a8ad0f8aebf55703d995462d3d477e00d Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Fri, 29 Jan 2021 16:05:14 -0800 Subject: [PATCH 08/11] pytest -s --- .github/workflows/pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 0f1f1fd1e5..97897d9225 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -50,7 +50,7 @@ jobs: pip freeze > pip_versions-${{ matrix.python-version }}.txt cat pip_versions-${{ matrix.python-version }}.txt - name: Run pytest - run: pytest -v --cov=ml-agents --cov=ml-agents-envs --cov=gym-unity --cov-report html --junitxml=junit/test-results-${{ matrix.python-version }}.xml -p no:warnings + run: pytest -v -s --cov=ml-agents --cov=ml-agents-envs --cov=gym-unity --cov-report html --junitxml=junit/test-results-${{ matrix.python-version }}.xml -p no:warnings - name: Upload pytest test results uses: actions/upload-artifact@v2 with: From 412cdc558bbdf80e7db3cb7c4dfd5cdc247b6bc7 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Sun, 31 Jan 2021 14:48:36 -0800 Subject: [PATCH 09/11] close environments to avoid errors on shutdown --- ml-agents-envs/mlagents_envs/tests/test_envs.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ml-agents-envs/mlagents_envs/tests/test_envs.py b/ml-agents-envs/mlagents_envs/tests/test_envs.py index 43e3a67561..138ac6d983 100755 --- a/ml-agents-envs/mlagents_envs/tests/test_envs.py +++ b/ml-agents-envs/mlagents_envs/tests/test_envs.py @@ -45,6 +45,7 @@ def test_port_defaults( ) env = UnityEnvironment(file_name=file_name, worker_id=0, base_port=base_port) assert expected == env._port + env.close() @mock.patch("mlagents_envs.env_utils.launch_executable") @@ -57,6 +58,7 @@ def test_log_file_path_is_set(mock_communicator, mock_launcher): args = env._executable_args() log_file_index = args.index("-logFile") assert args[log_file_index + 1] == "./some-log-folder-path/Player-0.log" + env.close() @mock.patch("mlagents_envs.env_utils.launch_executable") From 47db1384ecaef00affcb17531798bea5f276e566 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Wed, 3 Mar 2021 14:08:13 -0800 Subject: [PATCH 10/11] fix cattrs range --- ml-agents/setup.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ml-agents/setup.py b/ml-agents/setup.py index 225dae7fac..3b5e6881bc 100644 --- a/ml-agents/setup.py +++ b/ml-agents/setup.py @@ -3,6 +3,7 @@ from setuptools import setup, find_packages from setuptools.command.install import install +from mlagents.plugins import ML_AGENTS_STATS_WRITER import mlagents.trainers VERSION = mlagents.trainers.__version__ @@ -64,21 +65,27 @@ def run(self): "protobuf>=3.6", "pyyaml>=3.1.0", # Windows ver. of PyTorch doesn't work from PyPi. Installation: - # https://github.com/Unity-Technologies/ml-agents/blob/master/docs/Installation.md#windows-installing-pytorch + # https://github.com/Unity-Technologies/ml-agents/blob/main/docs/Installation.md#windows-installing-pytorch 'torch>=1.6.0,<1.8.0;platform_system!="Windows"', "tensorboard>=1.15", # cattrs 1.1.0 dropped support for python 3.6, but 1.0.0 doesn't work for python 3.9 - "cattrs>=1.0.0,<1.1.0; python_version<'3.7'", - "cattrs>=1.1.0; python_version>='3.7'", + # Since there's no version that supports both, we have to draw the line somwehere. + "cattrs<1.1.0; python_version<'3.8'", + "cattrs>=1.1.0; python_version>='3.8'", "attrs>=19.3.0", 'pypiwin32==223;platform_system=="Windows"', + "importlib_metadata; python_version<'3.8'", ], python_requires=">=3.6.1", entry_points={ "console_scripts": [ "mlagents-learn=mlagents.trainers.learn:main", "mlagents-run-experiment=mlagents.trainers.run_experiment:main", - ] + ], + # Plugins - each plugin type should have an entry here for the default behavior + ML_AGENTS_STATS_WRITER: [ + "default=mlagents.plugins.stats_writer:get_default_stats_writers" + ], }, cmdclass={"verify": VerifyVersionCommand}, ) From 2d74876c2cc28ae84f90473a568f258bf52c5169 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Wed, 3 Mar 2021 14:14:46 -0800 Subject: [PATCH 11/11] changelog --- com.unity.ml-agents/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index 79d10169cd..97d41000d6 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to #### com.unity.ml-agents / com.unity.ml-agents.extensions (C#) #### ml-agents / ml-agents-envs / gym-unity (Python) - The `encoding_size` setting for RewardSignals has been deprecated. Please use `network_settings` instead. (#4982) +- The `cattrs` version dependency was updated to allow `>=1.1.0` on Python 3.8 or higher. (#4821) + ### Bug Fixes #### com.unity.ml-agents (C#) #### ml-agents / ml-agents-envs / gym-unity (Python)