Skip to content

Update cattrs dependencies to support python3.9 #4821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Mar 3, 2021
Merged
2 changes: 2 additions & 0 deletions com.unity.ml-agents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions ml-agents-envs/mlagents_envs/tests/test_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These weren't an actual problem, but cause noisy errors about closed handles when the tests shut down.



@mock.patch("mlagents_envs.env_utils.launch_executable")
Expand All @@ -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")
Expand Down
11 changes: 6 additions & 5 deletions ml-agents-envs/mlagents_envs/tests/test_rpc_utils.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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).tolist()
observations: List[ObservationProto] = []
for all_observations_of_type in decision_steps.obs:
observation = all_observations_of_type[agent_id_index]
Expand All @@ -161,7 +162,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,
)
Expand Down Expand Up @@ -190,7 +191,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,
)
Expand Down
6 changes: 4 additions & 2 deletions ml-agents/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def run(self):
# 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.
"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
# 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'",
Expand Down