From 87d5eb01ce2b4980bc1c444e2fa72f565bcffc9b Mon Sep 17 00:00:00 2001 From: Kale-ab Date: Thu, 24 Feb 2022 16:12:20 +0200 Subject: [PATCH 1/2] fix: Fix docs build. --- docs/environments.md | 1 - docs/environments/smac.md | 2 +- docs/systems.md | 1 - docs/systems/tf/dial.md | 3 --- docs/systems/tf/qmix.md | 3 --- docs/systems/tf/value_decomposition.md | 3 +++ docs/systems/tf/vdn.md | 3 --- mava/wrappers/flatland.py | 16 ++++++++++++---- mkdocs.yml | 4 +--- 9 files changed, 17 insertions(+), 19 deletions(-) delete mode 100644 docs/environments.md delete mode 100644 docs/systems.md delete mode 100644 docs/systems/tf/dial.md delete mode 100644 docs/systems/tf/qmix.md create mode 100644 docs/systems/tf/value_decomposition.md delete mode 100644 docs/systems/tf/vdn.md diff --git a/docs/environments.md b/docs/environments.md deleted file mode 100644 index dab18da6a..000000000 --- a/docs/environments.md +++ /dev/null @@ -1 +0,0 @@ -::: mava.wrappers diff --git a/docs/environments/smac.md b/docs/environments/smac.md index b7fe85cef..ee1a0d24a 100644 --- a/docs/environments/smac.md +++ b/docs/environments/smac.md @@ -1 +1 @@ -Currently supported through the [PettingZoo Wrapper](pettingzoo). +::: mava.wrappers.smac diff --git a/docs/systems.md b/docs/systems.md deleted file mode 100644 index 16db6b89b..000000000 --- a/docs/systems.md +++ /dev/null @@ -1 +0,0 @@ -::: mava.systems.tf.dial diff --git a/docs/systems/tf/dial.md b/docs/systems/tf/dial.md deleted file mode 100644 index c9ce5f7cc..000000000 --- a/docs/systems/tf/dial.md +++ /dev/null @@ -1,3 +0,0 @@ ---8<-- "mava/systems/tf/dial/README.md" - -::: mava.systems.tf.dial diff --git a/docs/systems/tf/qmix.md b/docs/systems/tf/qmix.md deleted file mode 100644 index 5bc3bd2ca..000000000 --- a/docs/systems/tf/qmix.md +++ /dev/null @@ -1,3 +0,0 @@ ---8<-- "mava/systems/tf/qmix/README.md" - -::: mava.systems.tf.qmix diff --git a/docs/systems/tf/value_decomposition.md b/docs/systems/tf/value_decomposition.md new file mode 100644 index 000000000..39452ab37 --- /dev/null +++ b/docs/systems/tf/value_decomposition.md @@ -0,0 +1,3 @@ +--8<-- "mava/systems/tf/value_decomposition/README.md" + +::: mava.systems.tf.value_decomposition diff --git a/docs/systems/tf/vdn.md b/docs/systems/tf/vdn.md deleted file mode 100644 index 0ad88b42a..000000000 --- a/docs/systems/tf/vdn.md +++ /dev/null @@ -1,3 +0,0 @@ ---8<-- "mava/systems/tf/vdn/README.md" - -::: mava.systems.tf.vdn diff --git a/mava/wrappers/flatland.py b/mava/wrappers/flatland.py index 851f4a58d..66e6bb3e8 100644 --- a/mava/wrappers/flatland.py +++ b/mava/wrappers/flatland.py @@ -22,10 +22,18 @@ import numpy as np from acme import specs from acme.wrappers.gym_wrapper import _convert_to_spec -from flatland.envs.observations import GlobalObsForRailEnv, Node, TreeObsForRailEnv -from flatland.envs.rail_env import RailEnv -from flatland.envs.step_utils.states import TrainState -from flatland.utils.rendertools import AgentRenderVariant, RenderTool + +try: + from flatland.envs.observations import GlobalObsForRailEnv, Node, TreeObsForRailEnv + from flatland.envs.rail_env import RailEnv + from flatland.envs.step_utils.states import TrainState + from flatland.utils.rendertools import AgentRenderVariant, RenderTool +except ModuleNotFoundError: + # Without these types - the docs fail. + # TODO(Kale-ab): Remove this hack. + RailEnv = Any + Node = Any + pass from gym.spaces import Discrete from gym.spaces.box import Box diff --git a/mkdocs.yml b/mkdocs.yml index 64835712c..2baadd049 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -46,9 +46,7 @@ nav: - mad4pg: systems/tf/mad4pg.md - mappo: systems/tf/mappo.md - madqn: systems/tf/madqn.md - - vdn: systems/tf/vdn.md - - qmix: systems/tf/qmix.md - - dial: systems/tf/dial.md + - vdn and qmix: systems/tf/value_decomposition.md - Environments: - General: environments/general.md - Supported Environments: From 67655211c0de5c120a4220f1c5373adcaaac669f Mon Sep 17 00:00:00 2001 From: Kale-ab Date: Thu, 24 Feb 2022 17:01:11 +0200 Subject: [PATCH 2/2] fix: Updated flatland check. --- mava/utils/environments/flatland_utils.py | 29 ++++++++++++++++------- mava/wrappers/flatland.py | 1 - tests/utils/environment_utils_test.py | 10 ++++---- tests/wrappers/wrapper_test.py | 9 ++----- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/mava/utils/environments/flatland_utils.py b/mava/utils/environments/flatland_utils.py index e26cbe788..223a455e0 100644 --- a/mava/utils/environments/flatland_utils.py +++ b/mava/utils/environments/flatland_utils.py @@ -22,7 +22,27 @@ ) from mava.wrappers.flatland import FlatlandEnvWrapper -try: + +def check_flatland_import() -> bool: + """Consistent way to check if flatland has been installed. + + Returns: + whether flatland exists or not. + """ + try: + from flatland.envs.line_generators import sparse_line_generator + + # Delete unused var + del sparse_line_generator + _found_flatland = True + + except ModuleNotFoundError: + _found_flatland = False + return _found_flatland + + +_found_flatland = check_flatland_import() +if _found_flatland: from flatland.envs.line_generators import sparse_line_generator from flatland.envs.malfunction_generators import ( MalfunctionParameters, @@ -33,13 +53,6 @@ from flatland.envs.rail_env import RailEnv from flatland.envs.rail_generators import sparse_rail_generator - _found_flatland = True - -except ModuleNotFoundError: - _found_flatland = False - -if _found_flatland: - def _create_rail_env_with_tree_obs( n_agents: int = 5, x_dim: int = 30, diff --git a/mava/wrappers/flatland.py b/mava/wrappers/flatland.py index 66e6bb3e8..971de0577 100644 --- a/mava/wrappers/flatland.py +++ b/mava/wrappers/flatland.py @@ -33,7 +33,6 @@ # TODO(Kale-ab): Remove this hack. RailEnv = Any Node = Any - pass from gym.spaces import Discrete from gym.spaces.box import Box diff --git a/tests/utils/environment_utils_test.py b/tests/utils/environment_utils_test.py index defa7bca4..28a918418 100644 --- a/tests/utils/environment_utils_test.py +++ b/tests/utils/environment_utils_test.py @@ -18,14 +18,12 @@ import pytest from mava.utils.environments import debugging_utils, pettingzoo_utils +from mava.utils.environments.flatland_utils import check_flatland_import -try: - from mava.utils.environments import flatland_utils +_has_flatland = check_flatland_import() - _has_flatland = True -except (ModuleNotFoundError, ImportError): - _has_flatland = False - pass +if _has_flatland: + from mava.utils.environments import flatland_utils @pytest.mark.parametrize( diff --git a/tests/wrappers/wrapper_test.py b/tests/wrappers/wrapper_test.py index 434888e71..226aca86c 100644 --- a/tests/wrappers/wrapper_test.py +++ b/tests/wrappers/wrapper_test.py @@ -22,16 +22,11 @@ from _pytest.monkeypatch import MonkeyPatch from mava import types +from mava.utils.environments.flatland_utils import check_flatland_import from tests.conftest import EnvSpec, EnvType, Helpers from tests.enums import EnvSource -try: - import flatland # noqa: F401 - - _has_flatland = True -except (ModuleNotFoundError, ImportError): - _has_flatland = False - pass +_has_flatland = check_flatland_import() """ TestEnvWrapper is a general purpose test class that runs tests for environment wrappers. This is meant to flexibily test various environments wrappers.