From 9598da8cde0daddb2ded698049fbdcfb0a2231e9 Mon Sep 17 00:00:00 2001 From: ariel Date: Wed, 7 Feb 2024 14:16:47 +0100 Subject: [PATCH 1/5] Set the mp context more globally --- cogment_lab/process_manager.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cogment_lab/process_manager.py b/cogment_lab/process_manager.py index a47a699..4f5676e 100644 --- a/cogment_lab/process_manager.py +++ b/cogment_lab/process_manager.py @@ -57,7 +57,7 @@ def __init__( user_id: str = "cogment_lab", torch_mode: bool = False, log_dir: str | None = None, - mp_method: str | None = None, + mp_method: str = "spawn", orchestrator_port: int = 9000, datastore_port: int = 9003, ): @@ -67,8 +67,12 @@ def __init__( user_id (str, optional): User ID. Defaults to "cogment_lab". torch_mode (bool, optional): Whether to use PyTorch multiprocessing. Defaults to False. log_dir (str, optional): Directory to store logs. Defaults to "logs". - mp_method (str | None, optional): Multiprocessing method to use. Defaults to None. + mp_method (str, optional): Multiprocessing method to use. Defaults to "spawn". WARNING: Methods other than spawn are likely to not work. Use at your own risk. """ + try: + mp.set_start_method(mp_method) + except RuntimeError: + pass self.processes: dict[ImplName, Process] = {} self.tasks: dict[ImplName, Task] = {} @@ -132,7 +136,7 @@ def _add_process( p = TorchProcess(target=target, args=args) else: - p = self.mp_ctx.Process(target=target, args=args) # type: ignore + p = self.mp_ctx.Process(target=target, args=args, name=f"cogment_lab_{name}") # type: ignore p.start() self.processes[name] = p From 2e84f6f69d8caa67e65834434e53540508deb747 Mon Sep 17 00:00:00 2001 From: ariel Date: Wed, 7 Feb 2024 16:21:35 +0100 Subject: [PATCH 2/5] Missing future import --- cogment_lab/specs/action_space.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cogment_lab/specs/action_space.py b/cogment_lab/specs/action_space.py index 4a31901..21f7aa7 100644 --- a/cogment_lab/specs/action_space.py +++ b/cogment_lab/specs/action_space.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations import gymnasium as gym From 3bfe16cb4f1df093c30b68a29c77918b9adfc3ea Mon Sep 17 00:00:00 2001 From: ariel Date: Wed, 7 Feb 2024 16:24:45 +0100 Subject: [PATCH 3/5] Change dict to Dict (temporary?) --- cogment_lab/core.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cogment_lab/core.py b/cogment_lab/core.py index 6089ce5..f333723 100644 --- a/cogment_lab/core.py +++ b/cogment_lab/core.py @@ -17,7 +17,7 @@ import abc import copy import logging -from typing import Awaitable, Callable, Generic, TypeVar +from typing import Awaitable, Callable, Dict, Generic, TypeVar import cogment import numpy as np @@ -30,14 +30,14 @@ Action = TypeVar("Action") -Actions = dict[str, Action] +Actions = Dict[str, Action] Observation = TypeVar("Observation") -Observations = dict[str, Observation] +Observations = Dict[str, Observation] -Rewards = dict[str, float] +Rewards = Dict[str, float] -Dones = dict[str, bool] +Dones = Dict[str, bool] class State: From f7fc20b4431f291fef11114f91cec35b397b25e5 Mon Sep 17 00:00:00 2001 From: ariel Date: Wed, 7 Feb 2024 16:25:28 +0100 Subject: [PATCH 4/5] Missing future import --- cogment_lab/envs/pettingzoo.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cogment_lab/envs/pettingzoo.py b/cogment_lab/envs/pettingzoo.py index 635989e..e21cd22 100644 --- a/cogment_lab/envs/pettingzoo.py +++ b/cogment_lab/envs/pettingzoo.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import logging from typing import Any, TypedDict From 27ec5a766b6dddc49b5583f4010cc9365cddc8a3 Mon Sep 17 00:00:00 2001 From: Ariel Kwiatkowski Date: Wed, 7 Feb 2024 21:03:51 +0100 Subject: [PATCH 5/5] Update action_space.py --- cogment_lab/specs/action_space.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cogment_lab/specs/action_space.py b/cogment_lab/specs/action_space.py index 21f7aa7..c980257 100644 --- a/cogment_lab/specs/action_space.py +++ b/cogment_lab/specs/action_space.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from __future__ import annotations import gymnasium as gym