diff --git a/.gitignore b/.gitignore index 59fa333..3e8be67 100644 --- a/.gitignore +++ b/.gitignore @@ -553,7 +553,7 @@ celerybeat.pid *.sage.py # Environments -# .env +# .environment .env/ .venv/ env/ diff --git a/README.md b/README.md index 4ee9508..94635bd 100644 --- a/README.md +++ b/README.md @@ -80,36 +80,35 @@ General: level_name: rooms # 'double', 'large', 'simple', ... ``` ... or create your own , maybe with the help of [asciiflow.com](https://asciiflow.com/#/). -Be sure to use '#' as Walls, '-' as free (walkable) Floor-Tiles, 'D' for Doors. -Custom Entites (define you own) may bring their own "Symbol" +Make sure to use `#` as [Walls](mfg_package/environment/entity/wall_floor.py), `-` as free (walkable) [Floor](mfg_package/environment/entity/wall_floor.py)-Tiles, `D` for [Walls](./modules/doors/entities.py). +Other Entites (define you own) may bring their own `Symbols` #### Entites -Entites are either [Objects](./environment/entity/object.py) for tracking stats or env. [Entity](./environment/entity/entity.py) which can interact. +Entites, either [Objects](mfg_package/environment/entity/object.py) for tracking stats +or env. [Entity](mfg_package/environment/entity/entity.py) which can interact. Abstract Entities are provided. #### Groups -[Groups](./environment/groups/objects.py) are entity Sets that provide administrative access to all group members. -All [Entites](./environment/entity/global_entities.py) are available at runtime as EnvState property. +[Groups](mfg_package/environment/groups/objects.py) are entity Sets that provide administrative access to all group members. +All [Entites](mfg_package/environment/entity/global_entities.py) are available at runtime as EnvState property. #### Rules -[Rules](./environment/entity/object.py) define how the environment behaves on micro-scale. -Each of the hookes ('on_init', 'pre-step', 'on_step', 'post_step', 'on_done') +[Rules](mfg_package/environment/entity/object.py) define how the environment behaves on micro-scale. +Each of the hookes (`on_init`, `pre_step`, `on_step`, '`post_step`', `on_done`) provide env-access to implement customn logic, calculate rewards, or gather information. +![Hooks](./images/Hooks_FIKS.png) - - -[Results](./environment/entity/object.py) provide a way to return 'rule' evaluations such as rewards and state reports +[Results](mfg_package/environment/entity/object.py) provide a way to return `rule` evaluations such as rewards and state reports back to the environment. #### Assets -Make sure to bring your own assets for each Entity, that is living in the Gridworld, the 'Renderer' relies on it. +Make sure to bring your own assets for each Entity living in the Gridworl as the `Renderer` relies on it. PNG-files (transparent background) of square aspect-ratio should do the job, in general. -
- | -
- + +     + diff --git a/algorithms/marl/__init__.py b/algorithms/marl/__init__.py deleted file mode 100644 index 7c39bb0..0000000 --- a/algorithms/marl/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -from algorithms.marl.base_ac import BaseActorCritic -from algorithms.marl.iac import LoopIAC -from algorithms.marl.snac import LoopSNAC -from algorithms.marl.seac import LoopSEAC -from algorithms.marl.mappo import LoopMAPPO -from algorithms.marl.memory import MARLActorCriticMemory \ No newline at end of file diff --git a/images/Hooks_FIKS.png b/images/Hooks_FIKS.png new file mode 100644 index 0000000..e594c66 Binary files /dev/null and b/images/Hooks_FIKS.png differ diff --git a/algorithms/static/__init__.py b/mfg_package/__init__.py similarity index 100% rename from algorithms/static/__init__.py rename to mfg_package/__init__.py diff --git a/algorithms/__init__.py b/mfg_package/algorithms/__init__.py similarity index 100% rename from algorithms/__init__.py rename to mfg_package/algorithms/__init__.py diff --git a/mfg_package/algorithms/marl/__init__.py b/mfg_package/algorithms/marl/__init__.py new file mode 100644 index 0000000..7319373 --- /dev/null +++ b/mfg_package/algorithms/marl/__init__.py @@ -0,0 +1 @@ +from mfg_package.algorithms.marl.memory import MARLActorCriticMemory \ No newline at end of file diff --git a/algorithms/marl/base_ac.py b/mfg_package/algorithms/marl/base_ac.py similarity index 97% rename from algorithms/marl/base_ac.py rename to mfg_package/algorithms/marl/base_ac.py index c7675b4..b9a1709 100644 --- a/algorithms/marl/base_ac.py +++ b/mfg_package/algorithms/marl/base_ac.py @@ -2,8 +2,8 @@ import torch from typing import Union, List, Dict import numpy as np from torch.distributions import Categorical -from algorithms.marl.memory import MARLActorCriticMemory -from algorithms.utils import add_env_props, instantiate_class +from mfg_package.algorithms.marl.memory import MARLActorCriticMemory +from mfg_package.algorithms.utils import add_env_props, instantiate_class from pathlib import Path import pandas as pd from collections import deque @@ -18,7 +18,7 @@ class Names: HIDDEN_ACTOR = 'hidden_actor' HIDDEN_CRITIC = 'hidden_critic' AGENT = 'agent' - ENV = 'env' + ENV = 'environment' N_AGENTS = 'n_agents' ALGORITHM = 'algorithm' MAX_STEPS = 'max_steps' @@ -172,7 +172,7 @@ class BaseActorCritic: eps_rew += torch.tensor(reward) results.append(eps_rew.tolist() + [sum(eps_rew).item()] + [episode]) episode += 1 - agent_columns = [f'agent#{i}' for i in range(self.cfg['env']['n_agents'])] + agent_columns = [f'agent#{i}' for i in range(self.cfg['environment']['n_agents'])] results = pd.DataFrame(results, columns=agent_columns + ['sum', 'episode']) results = pd.melt(results, id_vars=['episode'], value_vars=agent_columns + ['sum'], value_name='reward', var_name='agent') return results diff --git a/algorithms/marl/example_config.yaml b/mfg_package/algorithms/marl/example_config.yaml similarity index 100% rename from algorithms/marl/example_config.yaml rename to mfg_package/algorithms/marl/example_config.yaml diff --git a/algorithms/marl/iac.py b/mfg_package/algorithms/marl/iac.py similarity index 90% rename from algorithms/marl/iac.py rename to mfg_package/algorithms/marl/iac.py index 8b2c2ef..30c1656 100644 --- a/algorithms/marl/iac.py +++ b/mfg_package/algorithms/marl/iac.py @@ -1,9 +1,9 @@ import torch -from algorithms.marl.base_ac import BaseActorCritic, nms -from algorithms.utils import instantiate_class +from mfg_package.algorithms.marl.base_ac import BaseActorCritic, nms +from mfg_package.algorithms.utils import instantiate_class from pathlib import Path from natsort import natsorted -from algorithms.marl.memory import MARLActorCriticMemory +from mfg_package.algorithms.marl.memory import MARLActorCriticMemory class LoopIAC(BaseActorCritic): diff --git a/algorithms/marl/mappo.py b/mfg_package/algorithms/marl/mappo.py similarity index 92% rename from algorithms/marl/mappo.py rename to mfg_package/algorithms/marl/mappo.py index c7a7f43..5796b65 100644 --- a/algorithms/marl/mappo.py +++ b/mfg_package/algorithms/marl/mappo.py @@ -1,10 +1,9 @@ -from algorithms.marl.base_ac import Names as nms -from algorithms.marl import LoopSNAC -from algorithms.marl.memory import MARLActorCriticMemory -import random +from mfg_package.algorithms.marl.base_ac import Names as nms +from mfg_package.algorithms.marl.snac import LoopSNAC +from mfg_package.algorithms.marl.memory import MARLActorCriticMemory import torch from torch.distributions import Categorical -from algorithms.utils import instantiate_class +from mfg_package.algorithms.utils import instantiate_class class LoopMAPPO(LoopSNAC): diff --git a/algorithms/marl/memory.py b/mfg_package/algorithms/marl/memory.py similarity index 100% rename from algorithms/marl/memory.py rename to mfg_package/algorithms/marl/memory.py diff --git a/algorithms/marl/networks.py b/mfg_package/algorithms/marl/networks.py similarity index 100% rename from algorithms/marl/networks.py rename to mfg_package/algorithms/marl/networks.py diff --git a/algorithms/marl/seac.py b/mfg_package/algorithms/marl/seac.py similarity index 92% rename from algorithms/marl/seac.py rename to mfg_package/algorithms/marl/seac.py index be572a5..2d1b790 100644 --- a/algorithms/marl/seac.py +++ b/mfg_package/algorithms/marl/seac.py @@ -1,8 +1,8 @@ import torch from torch.distributions import Categorical -from algorithms.marl.iac import LoopIAC -from algorithms.marl.base_ac import nms -from algorithms.marl.memory import MARLActorCriticMemory +from mfg_package.algorithms.marl.iac import LoopIAC +from mfg_package.algorithms.marl.base_ac import nms +from mfg_package.algorithms.marl.memory import MARLActorCriticMemory class LoopSEAC(LoopIAC): diff --git a/algorithms/marl/snac.py b/mfg_package/algorithms/marl/snac.py similarity index 91% rename from algorithms/marl/snac.py rename to mfg_package/algorithms/marl/snac.py index f0ff01d..6b685c4 100644 --- a/algorithms/marl/snac.py +++ b/mfg_package/algorithms/marl/snac.py @@ -1,5 +1,5 @@ -from algorithms.marl.base_ac import BaseActorCritic -from algorithms.marl.base_ac import nms +from mfg_package.algorithms.marl.base_ac import BaseActorCritic +from mfg_package.algorithms.marl.base_ac import nms import torch from torch.distributions import Categorical from pathlib import Path diff --git a/algorithms/static/TSP_base_agent.py b/mfg_package/algorithms/static/TSP_base_agent.py similarity index 97% rename from algorithms/static/TSP_base_agent.py rename to mfg_package/algorithms/static/TSP_base_agent.py index eabd99d..f0db93b 100644 --- a/algorithms/static/TSP_base_agent.py +++ b/mfg_package/algorithms/static/TSP_base_agent.py @@ -6,10 +6,9 @@ import numpy as np import networkx as nx from networkx.algorithms.approximation import traveling_salesman as tsp - -from modules.doors import constants as do -from environment import constants as c -from environment.utils.helpers import MOVEMAP +from mfg_package.modules.doors import constants as do +from mfg_package.environment import constants as c +from mfg_package.utils.helpers import MOVEMAP from abc import abstractmethod, ABC diff --git a/algorithms/static/TSP_dirt_agent.py b/mfg_package/algorithms/static/TSP_dirt_agent.py similarity index 87% rename from algorithms/static/TSP_dirt_agent.py rename to mfg_package/algorithms/static/TSP_dirt_agent.py index ec9e24b..d64fd67 100644 --- a/algorithms/static/TSP_dirt_agent.py +++ b/mfg_package/algorithms/static/TSP_dirt_agent.py @@ -1,6 +1,6 @@ -from algorithms.static.TSP_base_agent import TSPBaseAgent +from mfg_package.algorithms.static.TSP_base_agent import TSPBaseAgent -from modules.clean_up import constants as di +from mfg_package.modules.clean_up import constants as di future_planning = 7 diff --git a/algorithms/static/TSP_item_agent.py b/mfg_package/algorithms/static/TSP_item_agent.py similarity index 94% rename from algorithms/static/TSP_item_agent.py rename to mfg_package/algorithms/static/TSP_item_agent.py index 4b53e00..700ed62 100644 --- a/algorithms/static/TSP_item_agent.py +++ b/mfg_package/algorithms/static/TSP_item_agent.py @@ -1,8 +1,8 @@ import numpy as np -from algorithms.static.TSP_base_agent import TSPBaseAgent +from mfg_package.algorithms.static.TSP_base_agent import TSPBaseAgent -from modules.items import constants as i +from mfg_package.modules.items import constants as i future_planning = 7 inventory_size = 3 diff --git a/algorithms/static/TSP_target_agent.py b/mfg_package/algorithms/static/TSP_target_agent.py similarity index 83% rename from algorithms/static/TSP_target_agent.py rename to mfg_package/algorithms/static/TSP_target_agent.py index 2f10f02..9cae86f 100644 --- a/algorithms/static/TSP_target_agent.py +++ b/mfg_package/algorithms/static/TSP_target_agent.py @@ -1,7 +1,7 @@ -from algorithms.static.TSP_base_agent import TSPBaseAgent +from mfg_package.algorithms.static.TSP_base_agent import TSPBaseAgent -from modules.destinations import constants as d -from modules.doors import constants as do +from mfg_package.modules.destinations import constants as d +from mfg_package.modules.doors import constants as do future_planning = 7 diff --git a/environment/__init__.py b/mfg_package/algorithms/static/__init__.py similarity index 100% rename from environment/__init__.py rename to mfg_package/algorithms/static/__init__.py diff --git a/algorithms/static/random_agent.py b/mfg_package/algorithms/static/random_agent.py similarity index 81% rename from algorithms/static/random_agent.py rename to mfg_package/algorithms/static/random_agent.py index 89e221f..47890c1 100644 --- a/algorithms/static/random_agent.py +++ b/mfg_package/algorithms/static/random_agent.py @@ -1,6 +1,6 @@ from random import randint -from algorithms.static.TSP_base_agent import TSPBaseAgent +from mfg_package.algorithms.static.TSP_base_agent import TSPBaseAgent future_planning = 7 diff --git a/algorithms/utils.py b/mfg_package/algorithms/utils.py similarity index 97% rename from algorithms/utils.py rename to mfg_package/algorithms/utils.py index 39551aa..59e78bd 100644 --- a/algorithms/utils.py +++ b/mfg_package/algorithms/utils.py @@ -56,7 +56,7 @@ def load_yaml_file(path: Path): def add_env_props(cfg): - env = instantiate_class(cfg['env'].copy()) + env = instantiate_class(cfg['environment'].copy()) cfg['agent'].update(dict(observation_size=list(env.observation_space.shape), n_actions=env.action_space.n)) diff --git a/environment/assets/__init__.py b/mfg_package/environment/__init__.py similarity index 100% rename from environment/assets/__init__.py rename to mfg_package/environment/__init__.py diff --git a/environment/actions.py b/mfg_package/environment/actions.py similarity index 93% rename from environment/actions.py rename to mfg_package/environment/actions.py index ac06564..9590edd 100644 --- a/environment/actions.py +++ b/mfg_package/environment/actions.py @@ -1,10 +1,9 @@ import abc from typing import Union -from environment import rewards as r -from environment import constants as c -from environment.utils.helpers import MOVEMAP -from environment.utils.results import ActionResult +from mfg_package.environment import rewards as r, constants as c +from mfg_package.utils.helpers import MOVEMAP +from mfg_package.utils.results import ActionResult class Action(abc.ABC): diff --git a/environment/assets/agent/__init__.py b/mfg_package/environment/assets/__init__.py similarity index 100% rename from environment/assets/agent/__init__.py rename to mfg_package/environment/assets/__init__.py diff --git a/environment/entity/__init__.py b/mfg_package/environment/assets/agent/__init__.py similarity index 100% rename from environment/entity/__init__.py rename to mfg_package/environment/assets/agent/__init__.py diff --git a/environment/assets/agent/adversary.png b/mfg_package/environment/assets/agent/adversary.png similarity index 100% rename from environment/assets/agent/adversary.png rename to mfg_package/environment/assets/agent/adversary.png diff --git a/environment/assets/agent/agent.png b/mfg_package/environment/assets/agent/agent.png similarity index 100% rename from environment/assets/agent/agent.png rename to mfg_package/environment/assets/agent/agent.png diff --git a/environment/assets/agent/agent_collision.png b/mfg_package/environment/assets/agent/agent_collision.png similarity index 100% rename from environment/assets/agent/agent_collision.png rename to mfg_package/environment/assets/agent/agent_collision.png diff --git a/environment/assets/agent/idle.png b/mfg_package/environment/assets/agent/idle.png similarity index 100% rename from environment/assets/agent/idle.png rename to mfg_package/environment/assets/agent/idle.png diff --git a/environment/assets/agent/invalid.png b/mfg_package/environment/assets/agent/invalid.png similarity index 100% rename from environment/assets/agent/invalid.png rename to mfg_package/environment/assets/agent/invalid.png diff --git a/environment/assets/agent/move.png b/mfg_package/environment/assets/agent/move.png similarity index 100% rename from environment/assets/agent/move.png rename to mfg_package/environment/assets/agent/move.png diff --git a/environment/assets/agent/valid.png b/mfg_package/environment/assets/agent/valid.png similarity index 100% rename from environment/assets/agent/valid.png rename to mfg_package/environment/assets/agent/valid.png diff --git a/environment/assets/wall.png b/mfg_package/environment/assets/wall.png similarity index 100% rename from environment/assets/wall.png rename to mfg_package/environment/assets/wall.png diff --git a/environment/constants.py b/mfg_package/environment/constants.py similarity index 100% rename from environment/constants.py rename to mfg_package/environment/constants.py diff --git a/environment/groups/__init__.py b/mfg_package/environment/entity/__init__.py similarity index 100% rename from environment/groups/__init__.py rename to mfg_package/environment/entity/__init__.py diff --git a/environment/entity/agent.py b/mfg_package/environment/entity/agent.py similarity index 84% rename from environment/entity/agent.py rename to mfg_package/environment/entity/agent.py index 841fd03..ec83c0b 100644 --- a/environment/entity/agent.py +++ b/mfg_package/environment/entity/agent.py @@ -1,12 +1,12 @@ from typing import List, Union -from environment import constants as c -from environment.actions import Action -from environment.entity.entity import Entity -from environment.utils.render import RenderEntity -from environment.utils import renderer -from environment.utils.helpers import is_move -from environment.utils.results import ActionResult, Result +from mfg_package.environment import constants as c +from mfg_package.environment.actions import Action +from mfg_package.environment.entity.entity import Entity +from mfg_package.utils.render import RenderEntity +from mfg_package.utils import renderer +from mfg_package.utils.helpers import is_move +from mfg_package.utils.results import ActionResult, Result class Agent(Entity): diff --git a/environment/entity/entity.py b/mfg_package/environment/entity/entity.py similarity index 88% rename from environment/entity/entity.py rename to mfg_package/environment/entity/entity.py index 04f3f77..f95b891 100644 --- a/environment/entity/entity.py +++ b/mfg_package/environment/entity/entity.py @@ -1,12 +1,12 @@ import abc -from environment import constants as c -from environment.entity.object import EnvObject -from environment.utils.render import RenderEntity +from mfg_package.environment import constants as c +from mfg_package.environment.entity.object import EnvObject +from mfg_package.utils.render import RenderEntity class Entity(EnvObject, abc.ABC): - """Full Env Entity that lives on the env Grid. Doors, Items, DirtPile etc...""" + """Full Env Entity that lives on the environment Grid. Doors, Items, DirtPile etc...""" @property def has_position(self): diff --git a/environment/entity/mixin.py b/mfg_package/environment/entity/mixin.py similarity index 100% rename from environment/entity/mixin.py rename to mfg_package/environment/entity/mixin.py diff --git a/environment/entity/object.py b/mfg_package/environment/entity/object.py similarity index 96% rename from environment/entity/object.py rename to mfg_package/environment/entity/object.py index fa44857..e3dfeb8 100644 --- a/environment/entity/object.py +++ b/mfg_package/environment/entity/object.py @@ -1,8 +1,7 @@ -from abc import ABC, abstractmethod from collections import defaultdict from typing import Union -from environment import constants as c +from mfg_package.environment import constants as c class Object: @@ -67,7 +66,7 @@ class Object: class EnvObject(Object): - """Objects that hold Information that are observable, but have no position on the env grid. Inventories etc...""" + """Objects that hold Information that are observable, but have no position on the environment grid. Inventories etc...""" _u_idx = defaultdict(lambda: 0) diff --git a/environment/entity/util.py b/mfg_package/environment/entity/util.py similarity index 89% rename from environment/entity/util.py rename to mfg_package/environment/entity/util.py index 3f861d8..0e242ea 100644 --- a/environment/entity/util.py +++ b/mfg_package/environment/entity/util.py @@ -2,8 +2,8 @@ import math import numpy as np -from environment.entity.mixin import BoundEntityMixin -from environment.entity.object import Object, EnvObject +from mfg_package.environment.entity.mixin import BoundEntityMixin +from mfg_package.environment.entity.object import Object, EnvObject ########################################################################## diff --git a/environment/entity/wall_floor.py b/mfg_package/environment/entity/wall_floor.py similarity index 93% rename from environment/entity/wall_floor.py rename to mfg_package/environment/entity/wall_floor.py index 89ad5b0..7a221cb 100644 --- a/environment/entity/wall_floor.py +++ b/mfg_package/environment/entity/wall_floor.py @@ -2,10 +2,10 @@ from typing import List import numpy as np -from environment import constants as c -from environment.entity.object import EnvObject -from environment.utils.render import RenderEntity -from environment.utils import helpers as h +from mfg_package.environment import constants as c +from mfg_package.environment.entity.object import EnvObject +from mfg_package.utils.render import RenderEntity +from mfg_package.utils import helpers as h class Floor(EnvObject): diff --git a/environment/factory.py b/mfg_package/environment/factory.py similarity index 93% rename from environment/factory.py rename to mfg_package/environment/factory.py index a7251f6..7cc2387 100644 --- a/environment/factory.py +++ b/mfg_package/environment/factory.py @@ -8,13 +8,13 @@ from typing import Union import gymnasium as gym -from environment.utils.level_parser import LevelParser -from environment.utils.observation_builder import OBSBuilder -from environment.utils.config_parser import FactoryConfigParser -from environment.utils import helpers as h -import environment.constants as c +from mfg_package.utils.level_parser import LevelParser +from mfg_package.utils.observation_builder import OBSBuilder +from mfg_package.utils.config_parser import FactoryConfigParser +from mfg_package.utils import helpers as h +import mfg_package.environment.constants as c -from environment.utils.states import Gamestate +from mfg_package.utils.states import Gamestate REC_TAC = 'rec_' @@ -126,7 +126,7 @@ class BaseFactory(gym.Env): # Returns: Reward, Info rewards = defaultdict(lambda: 0.0) - # Gather per agent env rewards and + # Gather per agent environment rewards and # Combine Info dicts into a global one combined_info_dict = defaultdict(lambda: 0.0) for result in chain(tick_results, done_check_results): @@ -171,7 +171,7 @@ class BaseFactory(gym.Env): # noinspection PyGlobalUndefined def render(self, mode='human'): if not self._renderer: # lazy init - from environment.utils.renderer import Renderer + from mfg_package.utils.renderer import Renderer global Renderer self._renderer = Renderer(self.map.level_shape, view_radius=self.conf.pomdp_r, fps=10) diff --git a/environment/logging/__init__.py b/mfg_package/environment/groups/__init__.py similarity index 100% rename from environment/logging/__init__.py rename to mfg_package/environment/groups/__init__.py diff --git a/environment/groups/agents.py b/mfg_package/environment/groups/agents.py similarity index 78% rename from environment/groups/agents.py rename to mfg_package/environment/groups/agents.py index 387a6c2..e1dead4 100644 --- a/environment/groups/agents.py +++ b/mfg_package/environment/groups/agents.py @@ -1,7 +1,6 @@ -from environment.groups.env_objects import EnvObjects -from environment.groups.mixins import PositionMixin -from environment.entity.agent import Agent -import environment.constants as c +from mfg_package.environment.groups.env_objects import EnvObjects +from mfg_package.environment.groups.mixins import PositionMixin +from mfg_package.environment.entity.agent import Agent class Agents(PositionMixin, EnvObjects): diff --git a/environment/groups/env_objects.py b/mfg_package/environment/groups/env_objects.py similarity index 87% rename from environment/groups/env_objects.py rename to mfg_package/environment/groups/env_objects.py index 081d322..b7e8dd5 100644 --- a/environment/groups/env_objects.py +++ b/mfg_package/environment/groups/env_objects.py @@ -1,5 +1,5 @@ -from environment.groups.objects import Objects -from environment.entity.object import EnvObject +from mfg_package.environment.groups.objects import Objects +from mfg_package.environment.entity.object import EnvObject class EnvObjects(Objects): diff --git a/environment/groups/global_entities.py b/mfg_package/environment/groups/global_entities.py similarity index 93% rename from environment/groups/global_entities.py rename to mfg_package/environment/groups/global_entities.py index 7b28d5e..ce530bc 100644 --- a/environment/groups/global_entities.py +++ b/mfg_package/environment/groups/global_entities.py @@ -2,9 +2,8 @@ from collections import defaultdict from operator import itemgetter from typing import Dict -from environment.groups.objects import Objects -from environment.entity.entity import Entity -from environment.utils.helpers import POS_MASK +from mfg_package.environment.groups.objects import Objects +from mfg_package.utils.helpers import POS_MASK class Entities(Objects): diff --git a/environment/groups/mixins.py b/mfg_package/environment/groups/mixins.py similarity index 94% rename from environment/groups/mixins.py rename to mfg_package/environment/groups/mixins.py index 9466165..f61be00 100644 --- a/environment/groups/mixins.py +++ b/mfg_package/environment/groups/mixins.py @@ -1,11 +1,6 @@ -from abc import ABC -from typing import Tuple +from mfg_package.environment import constants as c -import numpy as np - -from environment import constants as c - -from environment.entity.entity import Entity +from mfg_package.environment.entity.entity import Entity # noinspection PyUnresolvedReferences,PyTypeChecker,PyArgumentList diff --git a/environment/groups/objects.py b/mfg_package/environment/groups/objects.py similarity index 98% rename from environment/groups/objects.py rename to mfg_package/environment/groups/objects.py index 5d8cfeb..e284cb9 100644 --- a/environment/groups/objects.py +++ b/mfg_package/environment/groups/objects.py @@ -3,7 +3,7 @@ from typing import List import numpy as np -from environment.entity.object import Object +from mfg_package.environment.entity.object import Object class Objects: diff --git a/environment/groups/utils.py b/mfg_package/environment/groups/utils.py similarity index 83% rename from environment/groups/utils.py rename to mfg_package/environment/groups/utils.py index f3595d5..85f8967 100644 --- a/environment/groups/utils.py +++ b/mfg_package/environment/groups/utils.py @@ -1,14 +1,13 @@ -import numbers -from typing import List, Union, Dict +from typing import List, Union import numpy as np -from environment.groups.env_objects import EnvObjects -from environment.groups.objects import Objects -from environment.groups.mixins import HasBoundedMixin, PositionMixin -from environment.entity.util import PlaceHolder, GlobalPosition -from environment.utils import helpers as h -from environment import constants as c +from mfg_package.environment.groups.env_objects import EnvObjects +from mfg_package.environment.groups.objects import Objects +from mfg_package.environment.groups.mixins import HasBoundedMixin, PositionMixin +from mfg_package.environment.entity.util import GlobalPosition +from mfg_package.utils import helpers as h +from mfg_package.environment import constants as c class Combined(PositionMixin, EnvObjects): diff --git a/environment/groups/wall_n_floors.py b/mfg_package/environment/groups/wall_n_floors.py similarity index 84% rename from environment/groups/wall_n_floors.py rename to mfg_package/environment/groups/wall_n_floors.py index 5a3142f..12b5528 100644 --- a/environment/groups/wall_n_floors.py +++ b/mfg_package/environment/groups/wall_n_floors.py @@ -1,12 +1,10 @@ import random from typing import List -import numpy as np - -from environment import constants as c -from environment.groups.env_objects import EnvObjects -from environment.groups.mixins import PositionMixin -from environment.entity.wall_floor import Wall, Floor +from mfg_package.environment import constants as c +from mfg_package.environment.groups.env_objects import EnvObjects +from mfg_package.environment.groups.mixins import PositionMixin +from mfg_package.environment.entity.wall_floor import Wall, Floor class Walls(PositionMixin, EnvObjects): diff --git a/environment/rewards.py b/mfg_package/environment/rewards.py similarity index 100% rename from environment/rewards.py rename to mfg_package/environment/rewards.py diff --git a/environment/rules.py b/mfg_package/environment/rules.py similarity index 92% rename from environment/rules.py rename to mfg_package/environment/rules.py index 5b4385a..c781294 100644 --- a/environment/rules.py +++ b/mfg_package/environment/rules.py @@ -1,9 +1,8 @@ import abc -from typing import Union, List +from typing import List -from environment.utils.results import Result, TickResult, DoneResult, ActionResult -from environment import constants as c -from environment import rewards as r +from mfg_package.utils.results import TickResult, DoneResult +from mfg_package.environment import rewards as r, constants as c class Rule(abc.ABC): diff --git a/environment/utils/__init__.py b/mfg_package/logging/__init__.py similarity index 100% rename from environment/utils/__init__.py rename to mfg_package/logging/__init__.py diff --git a/environment/logging/envmonitor.py b/mfg_package/logging/envmonitor.py similarity index 92% rename from environment/logging/envmonitor.py rename to mfg_package/logging/envmonitor.py index 40c4bf7..028a739 100644 --- a/environment/logging/envmonitor.py +++ b/mfg_package/logging/envmonitor.py @@ -5,12 +5,12 @@ from typing import Union from gymnasium import Wrapper -from environment.utils.helpers import IGNORED_DF_COLUMNS -from environment.factory import REC_TAC +from mfg_package.utils.helpers import IGNORED_DF_COLUMNS +from mfg_package.environment.factory import REC_TAC import pandas as pd -from plotting.compare_runs import plot_single_run +from mfg_package.plotting.compare_runs import plot_single_run class EnvMonitor(Wrapper): diff --git a/environment/logging/recorder.py b/mfg_package/logging/recorder.py similarity index 96% rename from environment/logging/recorder.py rename to mfg_package/logging/recorder.py index ce58b50..63a4abf 100644 --- a/environment/logging/recorder.py +++ b/mfg_package/logging/recorder.py @@ -4,13 +4,13 @@ from os import PathLike from pathlib import Path from typing import Union +import yaml from gymnasium import Wrapper import numpy as np import pandas as pd -import simplejson -from environment.factory import REC_TAC +from mfg_package.environment.factory import REC_TAC class EnvRecorder(Wrapper): @@ -81,7 +81,7 @@ class EnvRecorder(Wrapper): # cls.out_file.unlink(missing_ok=True) with filepath.open('w') as f: if only_deltas: - from deepdiff import DeepDiff, Delta + from deepdiff import DeepDiff diff_dict = [DeepDiff(t1,t2, ignore_order=True) for t1, t2 in zip(self._recorder_out_list, self._recorder_out_list[1:]) ] @@ -95,7 +95,7 @@ class EnvRecorder(Wrapper): 'header': self.env.summarize_header }) try: - simplejson.dump(out_dict, f, indent=4) + yaml.dump(out_dict, f, indent=4) except TypeError: print('Shit') diff --git a/modules/__init__.py b/mfg_package/modules/__init__.py similarity index 100% rename from modules/__init__.py rename to mfg_package/modules/__init__.py diff --git a/modules/_template/__init__.py b/mfg_package/modules/_template/__init__.py similarity index 100% rename from modules/_template/__init__.py rename to mfg_package/modules/_template/__init__.py diff --git a/modules/_template/constants.py b/mfg_package/modules/_template/constants.py similarity index 100% rename from modules/_template/constants.py rename to mfg_package/modules/_template/constants.py diff --git a/modules/_template/rules.py b/mfg_package/modules/_template/rules.py similarity index 81% rename from modules/_template/rules.py rename to mfg_package/modules/_template/rules.py index fd66718..8710891 100644 --- a/modules/_template/rules.py +++ b/mfg_package/modules/_template/rules.py @@ -1,6 +1,6 @@ from typing import List -from environment.rules import Rule -from environment.utils.results import TickResult, DoneResult +from mfg_package.environment.rules import Rule +from mfg_package.utils.results import TickResult, DoneResult class TemplateRule(Rule): diff --git a/modules/batteries/__init__.py b/mfg_package/modules/batteries/__init__.py similarity index 100% rename from modules/batteries/__init__.py rename to mfg_package/modules/batteries/__init__.py diff --git a/modules/batteries/actions.py b/mfg_package/modules/batteries/actions.py similarity index 79% rename from modules/batteries/actions.py rename to mfg_package/modules/batteries/actions.py index 3f7dacf..eb82eb4 100644 --- a/modules/batteries/actions.py +++ b/mfg_package/modules/batteries/actions.py @@ -1,10 +1,10 @@ from typing import Union -from environment.actions import Action -from environment.utils.results import ActionResult +from mfg_package.environment.actions import Action +from mfg_package.utils.results import ActionResult -from modules.batteries import constants as b, rewards as r -from environment import constants as c +from mfg_package.modules.batteries import constants as b, rewards as r +from mfg_package.environment import constants as c class BtryCharge(Action): diff --git a/modules/batteries/constants.py b/mfg_package/modules/batteries/constants.py similarity index 100% rename from modules/batteries/constants.py rename to mfg_package/modules/batteries/constants.py diff --git a/modules/batteries/entitites.py b/mfg_package/modules/batteries/entitites.py similarity index 85% rename from modules/batteries/entitites.py rename to mfg_package/modules/batteries/entitites.py index 2405b70..1525e03 100644 --- a/modules/batteries/entitites.py +++ b/mfg_package/modules/batteries/entitites.py @@ -1,10 +1,10 @@ -from environment.entity.mixin import BoundEntityMixin -from environment.entity.object import EnvObject -from environment.entity.entity import Entity -from environment import constants as c -from environment.utils.render import RenderEntity +from mfg_package.environment.entity.mixin import BoundEntityMixin +from mfg_package.environment.entity.object import EnvObject +from mfg_package.environment.entity.entity import Entity +from mfg_package.environment import constants as c +from mfg_package.utils.render import RenderEntity -from modules.batteries import constants as b +from mfg_package.modules.batteries import constants as b class Battery(BoundEntityMixin, EnvObject): diff --git a/modules/batteries/groups.py b/mfg_package/modules/batteries/groups.py similarity index 79% rename from modules/batteries/groups.py rename to mfg_package/modules/batteries/groups.py index 3a112b7..134fe18 100644 --- a/modules/batteries/groups.py +++ b/mfg_package/modules/batteries/groups.py @@ -1,6 +1,6 @@ -from environment.groups.env_objects import EnvObjects -from environment.groups.mixins import PositionMixin, HasBoundedMixin -from modules.batteries.entitites import ChargePod, Battery +from mfg_package.environment.groups.env_objects import EnvObjects +from mfg_package.environment.groups.mixins import PositionMixin, HasBoundedMixin +from mfg_package.modules.batteries.entitites import ChargePod, Battery class Batteries(HasBoundedMixin, EnvObjects): diff --git a/modules/batteries/rewards.py b/mfg_package/modules/batteries/rewards.py similarity index 100% rename from modules/batteries/rewards.py rename to mfg_package/modules/batteries/rewards.py diff --git a/modules/batteries/rules.py b/mfg_package/modules/batteries/rules.py similarity index 89% rename from modules/batteries/rules.py rename to mfg_package/modules/batteries/rules.py index dca1f86..387440d 100644 --- a/modules/batteries/rules.py +++ b/mfg_package/modules/batteries/rules.py @@ -1,9 +1,9 @@ from typing import List, Union -from environment.rules import Rule -from environment.utils.results import TickResult, DoneResult +from mfg_package.environment.rules import Rule +from mfg_package.utils.results import TickResult, DoneResult -from environment import constants as c -from modules.batteries import constants as b, rewards as r +from mfg_package.environment import constants as c +from mfg_package.modules.batteries import constants as b, rewards as r class Btry(Rule): diff --git a/modules/clean_up/__init__.py b/mfg_package/modules/clean_up/__init__.py similarity index 100% rename from modules/clean_up/__init__.py rename to mfg_package/modules/clean_up/__init__.py diff --git a/modules/clean_up/actions.py b/mfg_package/modules/clean_up/actions.py similarity index 82% rename from modules/clean_up/actions.py rename to mfg_package/modules/clean_up/actions.py index 300f8dd..5327967 100644 --- a/modules/clean_up/actions.py +++ b/mfg_package/modules/clean_up/actions.py @@ -1,11 +1,11 @@ from typing import Union -from environment.actions import Action -from environment.utils.results import ActionResult +from mfg_package.environment.actions import Action +from mfg_package.utils.results import ActionResult -from modules.clean_up import constants as d, rewards as r +from mfg_package.modules.clean_up import constants as d, rewards as r -from environment import constants as c +from mfg_package.environment import constants as c class CleanUp(Action): diff --git a/modules/clean_up/constants.py b/mfg_package/modules/clean_up/constants.py similarity index 100% rename from modules/clean_up/constants.py rename to mfg_package/modules/clean_up/constants.py diff --git a/modules/clean_up/dirtpiles.png b/mfg_package/modules/clean_up/dirtpiles.png similarity index 100% rename from modules/clean_up/dirtpiles.png rename to mfg_package/modules/clean_up/dirtpiles.png diff --git a/modules/clean_up/entitites.py b/mfg_package/modules/clean_up/entitites.py similarity index 85% rename from modules/clean_up/entitites.py rename to mfg_package/modules/clean_up/entitites.py index 6cae53d..502ca42 100644 --- a/modules/clean_up/entitites.py +++ b/mfg_package/modules/clean_up/entitites.py @@ -1,8 +1,8 @@ from numpy import random -from environment.entity.entity import Entity -from environment.utils.render import RenderEntity -from modules.clean_up import constants as d +from mfg_package.environment.entity.entity import Entity +from mfg_package.utils.render import RenderEntity +from mfg_package.modules.clean_up import constants as d class DirtPile(Entity): diff --git a/modules/clean_up/groups.py b/mfg_package/modules/clean_up/groups.py similarity index 88% rename from modules/clean_up/groups.py rename to mfg_package/modules/clean_up/groups.py index bec4ae4..9ae7a3d 100644 --- a/modules/clean_up/groups.py +++ b/mfg_package/modules/clean_up/groups.py @@ -1,9 +1,9 @@ -from environment.groups.env_objects import EnvObjects -from environment.groups.mixins import PositionMixin -from environment.entity.wall_floor import Floor -from modules.clean_up.entitites import DirtPile +from mfg_package.environment.groups.env_objects import EnvObjects +from mfg_package.environment.groups.mixins import PositionMixin +from mfg_package.environment.entity.wall_floor import Floor +from mfg_package.modules.clean_up.entitites import DirtPile -from environment import constants as c +from mfg_package.environment import constants as c class DirtPiles(PositionMixin, EnvObjects): diff --git a/modules/clean_up/rewards.py b/mfg_package/modules/clean_up/rewards.py similarity index 100% rename from modules/clean_up/rewards.py rename to mfg_package/modules/clean_up/rewards.py diff --git a/modules/clean_up/rule_done_on_all_clean.py b/mfg_package/modules/clean_up/rule_done_on_all_clean.py similarity index 63% rename from modules/clean_up/rule_done_on_all_clean.py rename to mfg_package/modules/clean_up/rule_done_on_all_clean.py index 6ddc621..f82444e 100644 --- a/modules/clean_up/rule_done_on_all_clean.py +++ b/mfg_package/modules/clean_up/rule_done_on_all_clean.py @@ -1,7 +1,7 @@ -from environment import constants as c -from environment.rules import Rule -from environment.utils.results import DoneResult -from modules.clean_up import constants as d, rewards as r +from mfg_package.environment import constants as c +from mfg_package.environment.rules import Rule +from mfg_package.utils.results import DoneResult +from mfg_package.modules.clean_up import constants as d, rewards as r class DirtAllCleanDone(Rule): diff --git a/modules/clean_up/rule_respawn.py b/mfg_package/modules/clean_up/rule_respawn.py similarity index 83% rename from modules/clean_up/rule_respawn.py rename to mfg_package/modules/clean_up/rule_respawn.py index 8da4dca..a460805 100644 --- a/modules/clean_up/rule_respawn.py +++ b/mfg_package/modules/clean_up/rule_respawn.py @@ -1,7 +1,7 @@ -from environment.rules import Rule -from environment.utils.results import TickResult +from mfg_package.environment.rules import Rule +from mfg_package.utils.results import TickResult -from modules.clean_up import constants as d +from mfg_package.modules.clean_up import constants as d class DirtRespawnRule(Rule): diff --git a/modules/clean_up/rule_smear_on_move.py b/mfg_package/modules/clean_up/rule_smear_on_move.py similarity index 76% rename from modules/clean_up/rule_smear_on_move.py rename to mfg_package/modules/clean_up/rule_smear_on_move.py index 5612eda..29c2005 100644 --- a/modules/clean_up/rule_smear_on_move.py +++ b/mfg_package/modules/clean_up/rule_smear_on_move.py @@ -1,9 +1,9 @@ -from environment.rules import Rule -from environment.utils.helpers import is_move -from environment.utils.results import TickResult +from mfg_package.environment.rules import Rule +from mfg_package.utils.helpers import is_move +from mfg_package.utils.results import TickResult -from environment import constants as c -from modules.clean_up import constants as d +from mfg_package.environment import constants as c +from mfg_package.modules.clean_up import constants as d class DirtSmearOnMove(Rule): diff --git a/modules/destinations/__init__.py b/mfg_package/modules/destinations/__init__.py similarity index 100% rename from modules/destinations/__init__.py rename to mfg_package/modules/destinations/__init__.py diff --git a/modules/destinations/actions.py b/mfg_package/modules/destinations/actions.py similarity index 75% rename from modules/destinations/actions.py rename to mfg_package/modules/destinations/actions.py index ae5ac63..d102ddd 100644 --- a/modules/destinations/actions.py +++ b/mfg_package/modules/destinations/actions.py @@ -1,10 +1,10 @@ from typing import Union -from environment.actions import Action -from environment.utils.results import ActionResult +from mfg_package.environment.actions import Action +from mfg_package.utils.results import ActionResult -from modules.destinations import constants as d, rewards as r -from environment import constants as c +from mfg_package.modules.destinations import constants as d, rewards as r +from mfg_package.environment import constants as c class DestAction(Action): diff --git a/modules/destinations/constants.py b/mfg_package/modules/destinations/constants.py similarity index 100% rename from modules/destinations/constants.py rename to mfg_package/modules/destinations/constants.py diff --git a/modules/destinations/destinations.png b/mfg_package/modules/destinations/destinations.png similarity index 100% rename from modules/destinations/destinations.png rename to mfg_package/modules/destinations/destinations.png diff --git a/modules/destinations/entitites.py b/mfg_package/modules/destinations/entitites.py similarity index 84% rename from modules/destinations/entitites.py rename to mfg_package/modules/destinations/entitites.py index 7ed5bfc..f495b25 100644 --- a/modules/destinations/entitites.py +++ b/mfg_package/modules/destinations/entitites.py @@ -1,10 +1,10 @@ from collections import defaultdict -from environment.entity.agent import Agent -from environment.entity.entity import Entity -from environment import constants as c -from environment.utils.render import RenderEntity -from modules.destinations import constants as d +from mfg_package.environment.entity.agent import Agent +from mfg_package.environment.entity.entity import Entity +from mfg_package.environment import constants as c +from mfg_package.utils.render import RenderEntity +from mfg_package.modules.destinations import constants as d class Destination(Entity): diff --git a/modules/destinations/groups.py b/mfg_package/modules/destinations/groups.py similarity index 75% rename from modules/destinations/groups.py rename to mfg_package/modules/destinations/groups.py index 011c28a..c84dfa0 100644 --- a/modules/destinations/groups.py +++ b/mfg_package/modules/destinations/groups.py @@ -1,6 +1,6 @@ -from environment.groups.env_objects import EnvObjects -from environment.groups.mixins import PositionMixin -from modules.destinations.entitites import Destination +from mfg_package.environment.groups.env_objects import EnvObjects +from mfg_package.environment.groups.mixins import PositionMixin +from mfg_package.modules.destinations.entitites import Destination class Destinations(PositionMixin, EnvObjects): diff --git a/modules/destinations/rewards.py b/mfg_package/modules/destinations/rewards.py similarity index 100% rename from modules/destinations/rewards.py rename to mfg_package/modules/destinations/rewards.py diff --git a/modules/destinations/rules.py b/mfg_package/modules/destinations/rules.py similarity index 91% rename from modules/destinations/rules.py rename to mfg_package/modules/destinations/rules.py index bc9c37b..20f3e6a 100644 --- a/modules/destinations/rules.py +++ b/mfg_package/modules/destinations/rules.py @@ -1,10 +1,10 @@ from typing import List, Union -from environment.rules import Rule -from environment.utils.results import TickResult, DoneResult -from environment import constants as c +from mfg_package.environment.rules import Rule +from mfg_package.utils.results import TickResult, DoneResult +from mfg_package.environment import constants as c -from modules.destinations import constants as d, rewards as r -from modules.destinations.entitites import Destination +from mfg_package.modules.destinations import constants as d, rewards as r +from mfg_package.modules.destinations.entitites import Destination class DestinationReach(Rule): diff --git a/modules/doors/__init__.py b/mfg_package/modules/doors/__init__.py similarity index 100% rename from modules/doors/__init__.py rename to mfg_package/modules/doors/__init__.py diff --git a/modules/doors/actions.py b/mfg_package/modules/doors/actions.py similarity index 80% rename from modules/doors/actions.py rename to mfg_package/modules/doors/actions.py index f8a4120..8f0f8b2 100644 --- a/modules/doors/actions.py +++ b/mfg_package/modules/doors/actions.py @@ -1,10 +1,10 @@ from typing import Union -from environment.actions import Action -from environment.utils.results import ActionResult +from mfg_package.environment.actions import Action +from mfg_package.utils.results import ActionResult -from modules.doors import constants as d, rewards as r -from environment import constants as c +from mfg_package.modules.doors import constants as d, rewards as r +from mfg_package.environment import constants as c class DoorUse(Action): diff --git a/modules/doors/constants.py b/mfg_package/modules/doors/constants.py similarity index 100% rename from modules/doors/constants.py rename to mfg_package/modules/doors/constants.py diff --git a/modules/doors/door_closed.png b/mfg_package/modules/doors/door_closed.png similarity index 100% rename from modules/doors/door_closed.png rename to mfg_package/modules/doors/door_closed.png diff --git a/modules/doors/door_open.png b/mfg_package/modules/doors/door_open.png similarity index 100% rename from modules/doors/door_open.png rename to mfg_package/modules/doors/door_open.png diff --git a/modules/doors/entitites.py b/mfg_package/modules/doors/entitites.py similarity index 92% rename from modules/doors/entitites.py rename to mfg_package/modules/doors/entitites.py index 8758cbc..434abbb 100644 --- a/modules/doors/entitites.py +++ b/mfg_package/modules/doors/entitites.py @@ -1,8 +1,8 @@ -from environment.entity.entity import Entity -from environment.utils.render import RenderEntity -from environment import constants as c +from mfg_package.environment.entity.entity import Entity +from mfg_package.utils.render import RenderEntity +from mfg_package.environment import constants as c -from modules.doors import constants as d +from mfg_package.modules.doors import constants as d class DoorIndicator(Entity): diff --git a/modules/doors/groups.py b/mfg_package/modules/doors/groups.py similarity index 73% rename from modules/doors/groups.py rename to mfg_package/modules/doors/groups.py index 8402297..b851e47 100644 --- a/modules/doors/groups.py +++ b/mfg_package/modules/doors/groups.py @@ -1,9 +1,9 @@ from typing import Union -from environment.groups.env_objects import EnvObjects -from environment.groups.mixins import PositionMixin -from modules.doors import constants as d -from modules.doors.entitites import Door +from mfg_package.environment.groups.env_objects import EnvObjects +from mfg_package.environment.groups.mixins import PositionMixin +from mfg_package.modules.doors import constants as d +from mfg_package.modules.doors.entitites import Door class Doors(PositionMixin, EnvObjects): diff --git a/modules/doors/rewards.py b/mfg_package/modules/doors/rewards.py similarity index 100% rename from modules/doors/rewards.py rename to mfg_package/modules/doors/rewards.py diff --git a/modules/doors/rule_door_auto_close.py b/mfg_package/modules/doors/rule_door_auto_close.py similarity index 77% rename from modules/doors/rule_door_auto_close.py rename to mfg_package/modules/doors/rule_door_auto_close.py index 2cd4154..64d80cc 100644 --- a/modules/doors/rule_door_auto_close.py +++ b/mfg_package/modules/doors/rule_door_auto_close.py @@ -1,7 +1,7 @@ -from environment.rules import Rule -from environment import constants as c -from environment.utils.results import TickResult -from modules.doors import constants as d +from mfg_package.environment.rules import Rule +from mfg_package.environment import constants as c +from mfg_package.utils.results import TickResult +from mfg_package.modules.doors import constants as d class DoorAutoClose(Rule): diff --git a/modules/items/__init__.py b/mfg_package/modules/items/__init__.py similarity index 100% rename from modules/items/__init__.py rename to mfg_package/modules/items/__init__.py diff --git a/modules/items/actions.py b/mfg_package/modules/items/actions.py similarity index 86% rename from modules/items/actions.py rename to mfg_package/modules/items/actions.py index 19aa8d7..7d77193 100644 --- a/modules/items/actions.py +++ b/mfg_package/modules/items/actions.py @@ -1,10 +1,10 @@ from typing import Union -from environment.actions import Action -from environment.utils.results import ActionResult +from mfg_package.environment.actions import Action +from mfg_package.utils.results import ActionResult -from modules.items import constants as i, rewards as r -from environment import constants as c +from mfg_package.modules.items import constants as i, rewards as r +from mfg_package.environment import constants as c class ItemAction(Action): diff --git a/modules/items/assets/charge_pod.png b/mfg_package/modules/items/assets/charge_pod.png similarity index 100% rename from modules/items/assets/charge_pod.png rename to mfg_package/modules/items/assets/charge_pod.png diff --git a/modules/items/assets/dropofflocations.png b/mfg_package/modules/items/assets/dropofflocations.png similarity index 100% rename from modules/items/assets/dropofflocations.png rename to mfg_package/modules/items/assets/dropofflocations.png diff --git a/modules/items/assets/items.png b/mfg_package/modules/items/assets/items.png similarity index 100% rename from modules/items/assets/items.png rename to mfg_package/modules/items/assets/items.png diff --git a/modules/items/constants.py b/mfg_package/modules/items/constants.py similarity index 100% rename from modules/items/constants.py rename to mfg_package/modules/items/constants.py diff --git a/modules/items/entitites.py b/mfg_package/modules/items/entitites.py similarity index 89% rename from modules/items/entitites.py rename to mfg_package/modules/items/entitites.py index 052aa54..2381f2f 100644 --- a/modules/items/entitites.py +++ b/mfg_package/modules/items/entitites.py @@ -1,9 +1,9 @@ from collections import deque -from environment.entity.entity import Entity -from environment import constants as c -from environment.utils.render import RenderEntity -from modules.items import constants as i +from mfg_package.environment.entity.entity import Entity +from mfg_package.environment import constants as c +from mfg_package.utils.render import RenderEntity +from mfg_package.modules.items import constants as i class Item(Entity): diff --git a/modules/items/groups.py b/mfg_package/modules/items/groups.py similarity index 87% rename from modules/items/groups.py rename to mfg_package/modules/items/groups.py index 885eead..93cfc2d 100644 --- a/modules/items/groups.py +++ b/mfg_package/modules/items/groups.py @@ -1,11 +1,11 @@ from typing import List -from environment.groups.env_objects import EnvObjects -from environment.groups.objects import Objects -from environment.groups.mixins import PositionMixin, IsBoundMixin, HasBoundedMixin -from environment.entity.wall_floor import Floor -from environment.entity.agent import Agent -from modules.items.entitites import Item, DropOffLocation +from mfg_package.environment.groups.env_objects import EnvObjects +from mfg_package.environment.groups.objects import Objects +from mfg_package.environment.groups.mixins import PositionMixin, IsBoundMixin, HasBoundedMixin +from mfg_package.environment.entity.wall_floor import Floor +from mfg_package.environment.entity.agent import Agent +from mfg_package.modules.items.entitites import Item, DropOffLocation class Items(PositionMixin, EnvObjects): diff --git a/modules/items/rewards.py b/mfg_package/modules/items/rewards.py similarity index 100% rename from modules/items/rewards.py rename to mfg_package/modules/items/rewards.py diff --git a/modules/items/rules.py b/mfg_package/modules/items/rules.py similarity index 91% rename from modules/items/rules.py rename to mfg_package/modules/items/rules.py index 629dd61..43c31cc 100644 --- a/modules/items/rules.py +++ b/mfg_package/modules/items/rules.py @@ -1,10 +1,10 @@ from typing import List -from environment.rules import Rule -from environment import constants as c -from environment.utils.results import TickResult -from modules.items import constants as i -from modules.items.entitites import DropOffLocation +from mfg_package.environment.rules import Rule +from mfg_package.environment import constants as c +from mfg_package.utils.results import TickResult +from mfg_package.modules.items import constants as i +from mfg_package.modules.items.entitites import DropOffLocation class ItemRules(Rule): diff --git a/modules/levels/__init__.py b/mfg_package/modules/levels/__init__.py similarity index 100% rename from modules/levels/__init__.py rename to mfg_package/modules/levels/__init__.py diff --git a/modules/levels/large.txt b/mfg_package/modules/levels/large.txt similarity index 100% rename from modules/levels/large.txt rename to mfg_package/modules/levels/large.txt diff --git a/modules/levels/large_qquad.txt b/mfg_package/modules/levels/large_qquad.txt similarity index 100% rename from modules/levels/large_qquad.txt rename to mfg_package/modules/levels/large_qquad.txt diff --git a/modules/levels/rooms.txt b/mfg_package/modules/levels/rooms.txt similarity index 100% rename from modules/levels/rooms.txt rename to mfg_package/modules/levels/rooms.txt diff --git a/modules/levels/shelves.txt b/mfg_package/modules/levels/shelves.txt similarity index 100% rename from modules/levels/shelves.txt rename to mfg_package/modules/levels/shelves.txt diff --git a/modules/levels/simple.txt b/mfg_package/modules/levels/simple.txt similarity index 100% rename from modules/levels/simple.txt rename to mfg_package/modules/levels/simple.txt diff --git a/modules/machines/__init__.py b/mfg_package/modules/machines/__init__.py similarity index 100% rename from modules/machines/__init__.py rename to mfg_package/modules/machines/__init__.py diff --git a/modules/machines/constants.py b/mfg_package/modules/machines/constants.py similarity index 100% rename from modules/machines/constants.py rename to mfg_package/modules/machines/constants.py diff --git a/modules/machines/entitites.py b/mfg_package/modules/machines/entitites.py similarity index 85% rename from modules/machines/entitites.py rename to mfg_package/modules/machines/entitites.py index e4dbc0d..f4b4a70 100644 --- a/modules/machines/entitites.py +++ b/mfg_package/modules/machines/entitites.py @@ -1,8 +1,8 @@ -from environment.entity.entity import Entity -from environment.utils.render import RenderEntity -from environment import constants as c -from environment.utils.results import TickResult -from modules.machines import constants as m, rewards as r +from mfg_package.environment.entity.entity import Entity +from mfg_package.utils.render import RenderEntity +from mfg_package.environment import constants as c +from mfg_package.utils.results import TickResult +from mfg_package.modules.machines import constants as m, rewards as r class Machine(Entity): diff --git a/modules/machines/groups.py b/mfg_package/modules/machines/groups.py similarity index 55% rename from modules/machines/groups.py rename to mfg_package/modules/machines/groups.py index a2072b1..c2fd3a6 100644 --- a/modules/machines/groups.py +++ b/mfg_package/modules/machines/groups.py @@ -1,6 +1,6 @@ -from environment.groups.env_objects import EnvObjects -from environment.groups.mixins import PositionMixin -from modules.machines.entitites import Machine +from mfg_package.environment.groups.env_objects import EnvObjects +from mfg_package.environment.groups.mixins import PositionMixin +from mfg_package.modules.machines.entitites import Machine class Machines(PositionMixin, EnvObjects): diff --git a/modules/machines/rewards.py b/mfg_package/modules/machines/rewards.py similarity index 100% rename from modules/machines/rewards.py rename to mfg_package/modules/machines/rewards.py diff --git a/modules/machines/rules.py b/mfg_package/modules/machines/rules.py similarity index 69% rename from modules/machines/rules.py rename to mfg_package/modules/machines/rules.py index df94d70..5c89034 100644 --- a/modules/machines/rules.py +++ b/mfg_package/modules/machines/rules.py @@ -1,9 +1,9 @@ from typing import List -from environment.rules import Rule -from environment.utils.results import TickResult, DoneResult -from environment import constants as c -from modules.machines import constants as m -from modules.machines.entitites import Machine +from mfg_package.environment.rules import Rule +from mfg_package.utils.results import TickResult, DoneResult +from mfg_package.environment import constants as c +from mfg_package.modules.machines import constants as m +from mfg_package.modules.machines.entitites import Machine class MachineRule(Rule): diff --git a/plotting/__init__.py b/mfg_package/plotting/__init__.py similarity index 100% rename from plotting/__init__.py rename to mfg_package/plotting/__init__.py diff --git a/plotting/compare_runs.py b/mfg_package/plotting/compare_runs.py similarity index 98% rename from plotting/compare_runs.py rename to mfg_package/plotting/compare_runs.py index 15bb511..4f2e46f 100644 --- a/plotting/compare_runs.py +++ b/mfg_package/plotting/compare_runs.py @@ -6,8 +6,8 @@ from typing import Union, List import pandas as pd -from environment.utils.helpers import IGNORED_DF_COLUMNS -from plotting.plotting import prepare_plot +from mfg_package.utils.helpers import IGNORED_DF_COLUMNS +from mfg_package.plotting.plotting import prepare_plot MODEL_MAP = None diff --git a/plotting/plotting.py b/mfg_package/plotting/plotting.py similarity index 100% rename from plotting/plotting.py rename to mfg_package/plotting/plotting.py diff --git a/studies/__init__.py b/mfg_package/utils/__init__.py similarity index 100% rename from studies/__init__.py rename to mfg_package/utils/__init__.py diff --git a/environment/utils/config_parser.py b/mfg_package/utils/config_parser.py similarity index 92% rename from environment/utils/config_parser.py rename to mfg_package/utils/config_parser.py index ffb27d5..8438902 100644 --- a/environment/utils/config_parser.py +++ b/mfg_package/utils/config_parser.py @@ -4,12 +4,10 @@ from typing import Union import yaml -from environment.groups.global_entities import Entities -from environment.groups.agents import Agents -from environment.entity.agent import Agent -from environment.utils.helpers import locate_and_import_class -from environment import constants as c - +from mfg_package.environment.groups.agents import Agents +from mfg_package.environment.entity.agent import Agent +from mfg_package.utils.helpers import locate_and_import_class +from mfg_package.environment import constants as c DEFAULT_PATH = 'environment' MODULE_PATH = 'modules' @@ -94,6 +92,7 @@ class FactoryConfigParser(object): parsed_actions = list() for action in actions: folder_path = MODULE_PATH if action not in base_env_actions else DEFAULT_PATH + folder_path = (Path(__file__) / '..' / '..' / '..' / folder_path) try: class_or_classes = locate_and_import_class(action, folder_path) except AttributeError: @@ -126,6 +125,7 @@ class FactoryConfigParser(object): for rule in rules: folder_path = MODULE_PATH if rule not in self.default_rules else DEFAULT_PATH + folder_path = (Path(__file__) / '..' / '..' / '..' / folder_path) try: rule_class = locate_and_import_class(rule, folder_path) except AttributeError: diff --git a/environment/utils/helpers.py b/mfg_package/utils/helpers.py similarity index 97% rename from environment/utils/helpers.py rename to mfg_package/utils/helpers.py index 2650729..2ebd033 100644 --- a/environment/utils/helpers.py +++ b/mfg_package/utils/helpers.py @@ -7,7 +7,7 @@ from typing import Union, Dict, List import numpy as np from numpy.typing import ArrayLike -from environment import constants as c +from mfg_package.environment import constants as c """ This file is used for: @@ -212,13 +212,13 @@ def asset_str(agent): def locate_and_import_class(class_name, folder_path: Union[str, PurePath] = ''): """Locate an object by name or dotted path, importing as necessary.""" import sys - sys.path.append("..") + sys.path.append("../../environment") folder_path = Path(folder_path).resolve() module_paths = [x.resolve() for x in folder_path.rglob('*.py') if x.is_file() and '__init__' not in x.name] # possible_package_path = folder_path / '__init__.py' # package = str(possible_package_path) if possible_package_path.exists() else None all_found_modules = list() - package_pos = next(idx for idx, x in enumerate(Path(__file__).resolve().parts) if x == 'environment') + package_pos = next(idx for idx, x in enumerate(Path(__file__).resolve().parts) if x == 'mfg_package') for module_path in module_paths: module_parts = [x.replace('.py', '') for idx, x in enumerate(module_path.parts) if idx >= package_pos] mod = importlib.import_module('.'.join(module_parts)) @@ -227,7 +227,8 @@ def locate_and_import_class(class_name, folder_path: Union[str, PurePath] = ''): 'TickResult', 'ActionResult', 'Action', 'Agent', 'deque', 'BoundEntityMixin', 'RenderEntity', 'TemplateRule', 'defaultdict', 'is_move', 'Objects', 'PositionMixin', 'IsBoundMixin', 'EnvObject', - 'EnvObjects']]) + 'EnvObjects', 'Dict', 'locate_and_import_class', 'yaml', 'Any', + 'inspect']]) try: model_class = mod.__getattribute__(class_name) return model_class diff --git a/environment/utils/level_parser.py b/mfg_package/utils/level_parser.py similarity index 89% rename from environment/utils/level_parser.py rename to mfg_package/utils/level_parser.py index 3f66fbd..f2ad596 100644 --- a/environment/utils/level_parser.py +++ b/mfg_package/utils/level_parser.py @@ -4,10 +4,10 @@ from typing import Dict import numpy as np -from environment.groups.global_entities import Entities -from environment.groups.wall_n_floors import Walls, Floors -from environment.utils import helpers as h -from environment import constants as c +from mfg_package.environment.groups.global_entities import Entities +from mfg_package.environment.groups.wall_n_floors import Walls, Floors +from mfg_package.utils import helpers as h +from mfg_package.environment import constants as c class LevelParser(object): diff --git a/environment/utils/observation_builder.py b/mfg_package/utils/observation_builder.py similarity index 98% rename from environment/utils/observation_builder.py rename to mfg_package/utils/observation_builder.py index 153e11d..d60b144 100644 --- a/environment/utils/observation_builder.py +++ b/mfg_package/utils/observation_builder.py @@ -6,10 +6,10 @@ from typing import Dict, List import numpy as np from numba import njit -from environment.groups.utils import Combined -from environment.utils.states import Gamestate +from mfg_package.environment.groups.utils import Combined +from mfg_package.utils.states import Gamestate -from environment import constants as c +from mfg_package.environment import constants as c class OBSBuilder(object): diff --git a/environment/utils/render.py b/mfg_package/utils/render.py similarity index 100% rename from environment/utils/render.py rename to mfg_package/utils/render.py diff --git a/environment/utils/renderer.py b/mfg_package/utils/renderer.py similarity index 99% rename from environment/utils/renderer.py rename to mfg_package/utils/renderer.py index ea2c9b7..08c68e9 100644 --- a/environment/utils/renderer.py +++ b/mfg_package/utils/renderer.py @@ -9,7 +9,7 @@ import pygame from typing import Tuple, Union import time -from environment.utils.render import RenderEntity +from mfg_package.utils.render import RenderEntity AGENT: str = 'agent' STATE_IDLE: str = 'idle' diff --git a/environment/utils/results.py b/mfg_package/utils/results.py similarity index 91% rename from environment/utils/results.py rename to mfg_package/utils/results.py index 2619ac2..c979ee2 100644 --- a/environment/utils/results.py +++ b/mfg_package/utils/results.py @@ -1,7 +1,7 @@ from typing import Union -from dataclasses import dataclass, asdict +from dataclasses import dataclass -from environment.entity.entity import Entity +from mfg_package.environment.entity.entity import Entity TYPE_VALUE = 'value' TYPE_REWARD = 'reward' diff --git a/environment/utils/states.py b/mfg_package/utils/states.py similarity index 94% rename from environment/utils/states.py rename to mfg_package/utils/states.py index 9ff16f4..45e9dc0 100644 --- a/environment/utils/states.py +++ b/mfg_package/utils/states.py @@ -2,10 +2,10 @@ from typing import List, Dict import numpy as np -from environment.entity.wall_floor import Floor -from environment.rules import Rule -from environment.utils.results import Result -from environment import constants as c +from mfg_package.environment.entity.wall_floor import Floor +from mfg_package.environment.rules import Rule +from mfg_package.utils.results import Result +from mfg_package.environment import constants as c class StepRules: diff --git a/tools.py b/mfg_package/utils/tools.py similarity index 66% rename from tools.py rename to mfg_package/utils/tools.py index fe0305a..f8297ac 100644 --- a/tools.py +++ b/mfg_package/utils/tools.py @@ -2,11 +2,12 @@ import importlib import inspect from os import PathLike from pathlib import Path +from typing import Union import yaml -from environment import constants as c -from environment.utils.helpers import locate_and_import_class +from mfg_package.environment import constants as c +from mfg_package.utils.helpers import locate_and_import_class ACTION = 'Action' GENERAL = 'General' @@ -20,10 +21,9 @@ EXCLUDED = ['identifier', 'args', 'kwargs', 'Move', class ConfigExplainer: - def __init__(self, base_path: PathLike = 'environment', - module_path: PathLike = 'modules'): - self.module_path = Path(module_path) - self.base_path = Path(base_path) + def __init__(self, custom_path: Union[None, PathLike] = None): + self.base_path = Path(__file__).parent.parent.resolve() + self.custom_path = custom_path self.searchspace = [ACTION, GENERAL, ENTITIES, OBSERVATIONS, RULES, ASSETS] def explain_module(self, class_to_explain): @@ -33,8 +33,10 @@ class ConfigExplainer: def _load_and_compare(self, compare_class, paths): conf = {} + package_pos = next(idx for idx, x in enumerate(Path(__file__).resolve().parts) if x == 'mfg_package') for module_path in paths: - mods = importlib.import_module('.'.join([x.replace('.py', '') for x in module_path.parts])) + module_parts = [x.replace('.py', '') for idx, x in enumerate(module_path.parts) if idx >= package_pos] + mods = importlib.import_module('.'.join(module_parts)) for key in mods.__dict__.keys(): if key not in EXCLUDED and not key.startswith('_'): mod = mods.__getattribute__(key) @@ -45,7 +47,7 @@ class ConfigExplainer: pass return conf - def save_actions(self, output_conf_file: PathLike = Path('quickstart') / 'explained_actions.yml'): + def save_actions(self, output_conf_file: PathLike = Path('../../quickstart') / 'explained_actions.yml'): self._save_to_file(self.get_entities(), output_conf_file, ACTION) def get_actions(self): @@ -56,14 +58,14 @@ class ConfigExplainer: # TODO: Print to file! return actions - def save_entities(self, output_conf_file: PathLike = Path('quickstart') / 'explained_entities.yml'): + def save_entities(self, output_conf_file: PathLike = Path('../../quickstart') / 'explained_entities.yml'): self._save_to_file(self.get_entities(), output_conf_file, ENTITIES) def get_entities(self): entities = self._get_by_identifier(ENTITIES) return entities - def save_rules(self, output_conf_file: PathLike = Path('quickstart') / 'explained_rules.yml'): + def save_rules(self, output_conf_file: PathLike = Path('../../quickstart') / 'explained_rules.yml'): self._save_to_file(self.get_entities(), output_conf_file, RULES) def get_rules(self): @@ -77,21 +79,31 @@ class ConfigExplainer: names = [c.ALL, c.COMBINED, c.SELF, c.OTHERS, "Agent['ExampleAgentName']"] for key, val in self.get_entities().items(): try: - e = locate_and_import_class(key)(level_shape=(0, 0), pomdp_r=0).obs_pairs + e = locate_and_import_class(key, self.base_path)(level_shape=(0, 0), pomdp_r=0).obs_pairs except TypeError: e = [key] + except AttributeError as err: + if self.custom_path is not None: + try: + e = locate_and_import_class(key, self.base_path)(level_shape=(0, 0), pomdp_r=0).obs_pairs + except TypeError: + e = [key] + else: + raise err names.extend(e) return names def _get_by_identifier(self, identifier): entities_base_cls = locate_and_import_class(identifier, self.base_path) - module_paths = [x for x in self.base_path.rglob('*.py') if x.is_file() and '__init__' not in x.name] + module_paths = [x.resolve() for x in self.base_path.rglob('*.py') if x.is_file() and '__init__' not in x.name] found_entities = self._load_and_compare(entities_base_cls, module_paths) - module_paths = [x for x in self.module_path.rglob('*.py') if x.is_file() and '__init__' not in x.name] - found_entities.update(self._load_and_compare(entities_base_cls, module_paths)) + if self.custom_path is not None: + module_paths = [x.resolve() for x in self.custom_path.rglob('*.py') if x.is_file() + and '__init__' not in x.name] + found_entities.update(self._load_and_compare(entities_base_cls, module_paths)) return found_entities - def save_all(self, output_conf_file: PathLike = Path('quickstart') / 'explained.yml'): + def save_all(self, output_conf_file: PathLike = Path('../../quickstart') / 'explained.yml'): self._save_to_file(self.get_all(), output_conf_file, 'ALL') def get_all(self): diff --git a/environment/utils/utility_classes.py b/mfg_package/utils/utility_classes.py similarity index 100% rename from environment/utils/utility_classes.py rename to mfg_package/utils/utility_classes.py diff --git a/quickstart/combine_and_monitor_rerun.py b/quickstart/combine_and_monitor_rerun.py index 58cfe6b..6675867 100644 --- a/quickstart/combine_and_monitor_rerun.py +++ b/quickstart/combine_and_monitor_rerun.py @@ -96,7 +96,7 @@ if __name__ == '__main__': max_seed = 0 # Define this folder combinations_path = Path('combinations') - # Those are all differently trained combinations of mdoels, env and parameters + # Those are all differently trained combinations of mdoels, environment and parameters for combination in (x for x in combinations_path.iterdir() if x.is_dir()): # These are all the models for this specific combination for model_run in (x for x in combination.iterdir() if x.is_dir()): @@ -108,7 +108,7 @@ if __name__ == '__main__': # Those are all available seeds for seed_run in (x for x in model_run.iterdir() if x.is_dir()): max_seed = max(int(seed_run.name.split('_')[0]), max_seed) - # Read the env configuration from ROM + # Read the environment configuration from ROM with next(seed_run.glob('env_params.json')).open('r') as f: env_kwargs = simplejson.load(f) available_runs_kwargs[seed_run.name] = env_kwargs diff --git a/quickstart/init.py b/quickstart/init.py new file mode 100644 index 0000000..32e27fb --- /dev/null +++ b/quickstart/init.py @@ -0,0 +1,14 @@ +import os +import shutil +from pathlib import Path + +from mfg_package.utils.tools import ConfigExplainer + +if __name__ == '__main__': + print('Retrieving available options...') + ce = ConfigExplainer() + cwd = Path(os.getcwd()) + ce.save_all(cwd / 'full_config.yaml') + template_path = Path(__file__) / 'mfg_package' / 'modules' / '_template' + shutil.copytree(template_path, cwd) + print() diff --git a/quickstart/single_agent_train_battery_target_env.py b/quickstart/single_agent_train_battery_target_env.py index aef2ce6..ba8a6d5 100644 --- a/quickstart/single_agent_train_battery_target_env.py +++ b/quickstart/single_agent_train_battery_target_env.py @@ -35,9 +35,9 @@ Welcome to this quick start file. Here we will see how to: 1. Setup parameters for the environments (dirt-factory). 2. Setup parameters for the agent training (SB3: PPO) and save metrics. Run the training. - 3. Save env and agent for later analysis. + 3. Save environment and agent for later analysis. 4. Load the agent from drive - 5. Rendering the env with a run of the trained agent. + 5. Rendering the environment with a run of the trained agent. 6. Plot metrics """ @@ -64,14 +64,14 @@ if __name__ == '__main__': # Define property object parameters. - # 'ObservationProperties' are for specifying how the agent sees the env. + # 'ObservationProperties' are for specifying how the agent sees the environment. obs_props = ObservationProperties(render_agents=AgentRenderOptions.NOT, # Agents won`t be shown in the obs at all omit_agent_self=True, # This is default additional_agent_placeholder=None, # We will not take care of future agent frames_to_stack=3, # To give the agent a notion of time pomdp_r=2 # the agent view-radius ) - # 'MovementProperties' are for specifying how the agent is allowed to move in the env. + # 'MovementProperties' are for specifying how the agent is allowed to move in the environment. move_props = MovementProperties(allow_diagonal_movement=True, # Euclidean style (vertices) allow_square_movement=True, # Manhattan (edges) allow_no_op=False) # Pause movement (do nothing) @@ -94,7 +94,7 @@ if __name__ == '__main__': multi_charge = False, ) - # These are the EnvKwargs for initializing the env class, holding all former parameter-classes + # These are the EnvKwargs for initializing the environment class, holding all former parameter-classes # TODO: Comments factory_kwargs = dict(n_agents=1, max_steps=400, @@ -149,8 +149,8 @@ if __name__ == '__main__': model.learn(total_timesteps=int(train_steps), callback=[env_monitor_callback, env_recorder_callback]) ######################################################### - # 3. Save env and agent for later analysis. - # Save the trained Model, the monitor (env measures) and the env parameters + # 3. Save environment and agent for later analysis. + # Save the trained Model, the monitor (environment measures) and the environment parameters model.named_observation_space = env_factory.named_observation_space model.named_action_space = env_factory.named_action_space model.save(model_save_path) @@ -176,10 +176,10 @@ if __name__ == '__main__': model_cls = next(val for key, val in h.MODEL_MAP.items() if key in policy_path.parent.name) # Load the agent agent model = model_cls.load(policy_path / 'model.zip', device='cpu') - # Load old env kwargs + # Load old environment kwargs with next(policy_path.glob(env_params_json)).open('r') as f: env_kwargs = simplejson.load(f) - # Make the env stop ar collisions + # Make the environment stop ar collisions # (you only want to have a single collision per episode hence the statistics) env_kwargs.update(done_at_collision=True) diff --git a/quickstart/single_agent_train_dest_env.py b/quickstart/single_agent_train_dest_env.py index ee22dfb..c54f15a 100644 --- a/quickstart/single_agent_train_dest_env.py +++ b/quickstart/single_agent_train_dest_env.py @@ -34,9 +34,9 @@ Welcome to this quick start file. Here we will see how to: 1. Setup parameters for the environments (dest-factory). 2. Setup parameters for the agent training (SB3: PPO) and save metrics. Run the training. - 3. Save env and agent for later analysis. + 3. Save environment and agent for later analysis. 4. Load the agent from drive - 5. Rendering the env with a run of the trained agent. + 5. Rendering the environment with a run of the trained agent. 6. Plot metrics """ @@ -63,14 +63,14 @@ if __name__ == '__main__': # Define property object parameters. - # 'ObservationProperties' are for specifying how the agent sees the env. + # 'ObservationProperties' are for specifying how the agent sees the environment. obs_props = ObservationProperties(render_agents=AgentRenderOptions.NOT, # Agents won`t be shown in the obs at all omit_agent_self=True, # This is default additional_agent_placeholder=None, # We will not take care of future agent frames_to_stack=3, # To give the agent a notion of time pomdp_r=2 # the agent view-radius ) - # 'MovementProperties' are for specifying how the agent is allowed to move in the env. + # 'MovementProperties' are for specifying how the agent is allowed to move in the environment. move_props = MovementProperties(allow_diagonal_movement=True, # Euclidean style (vertices) allow_square_movement=True, # Manhattan (edges) allow_no_op=False) # Pause movement (do nothing) @@ -85,7 +85,7 @@ if __name__ == '__main__': spawn_mode = DestModeOptions.DONE, ) - # These are the EnvKwargs for initializing the env class, holding all former parameter-classes + # These are the EnvKwargs for initializing the environment class, holding all former parameter-classes # TODO: Comments factory_kwargs = dict(n_agents=1, max_steps=400, @@ -139,8 +139,8 @@ if __name__ == '__main__': model.learn(total_timesteps=int(train_steps), callback=[env_monitor_callback, env_recorder_callback]) ######################################################### - # 3. Save env and agent for later analysis. - # Save the trained Model, the monitor (env measures) and the env parameters + # 3. Save environment and agent for later analysis. + # Save the trained Model, the monitor (environment measures) and the environment parameters model.named_observation_space = env_factory.named_observation_space model.named_action_space = env_factory.named_action_space model.save(model_save_path) @@ -166,10 +166,10 @@ if __name__ == '__main__': model_cls = next(val for key, val in h.MODEL_MAP.items() if key in policy_path.parent.name) # Load the agent agent model = model_cls.load(policy_path / 'model.zip', device='cpu') - # Load old env kwargs + # Load old environment kwargs with next(policy_path.glob(env_params_json)).open('r') as f: env_kwargs = simplejson.load(f) - # Make the env stop ar collisions + # Make the environment stop ar collisions # (you only want to have a single collision per episode hence the statistics) env_kwargs.update(done_at_collision=True) diff --git a/quickstart/single_agent_train_dirt_env.py b/quickstart/single_agent_train_dirt_env.py index b713e59..4718240 100644 --- a/quickstart/single_agent_train_dirt_env.py +++ b/quickstart/single_agent_train_dirt_env.py @@ -34,9 +34,9 @@ Welcome to this quick start file. Here we will see how to: 1. Setup parameters for the environments (dirt-factory). 2. Setup parameters for the agent training (SB3: PPO) and save metrics. Run the training. - 3. Save env and agent for later analysis. + 3. Save environment and agent for later analysis. 4. Load the agent from drive - 5. Rendering the env with a run of the trained agent. + 5. Rendering the environment with a run of the trained agent. 6. Plot metrics """ @@ -63,14 +63,14 @@ if __name__ == '__main__': # Define property object parameters. - # 'ObservationProperties' are for specifying how the agent sees the env. + # 'ObservationProperties' are for specifying how the agent sees the environment. obs_props = ObservationProperties(render_agents=AgentRenderOptions.NOT, # Agents won`t be shown in the obs at all omit_agent_self=True, # This is default additional_agent_placeholder=None, # We will not take care of future agent frames_to_stack=3, # To give the agent a notion of time pomdp_r=2 # the agent' view-radius ) - # 'MovementProperties' are for specifying how the agent is allowed to move in the env. + # 'MovementProperties' are for specifying how the agent is allowed to move in the environment. move_props = MovementProperties(allow_diagonal_movement=True, # Euclidean style (vertices) allow_square_movement=True, # Manhattan (edges) allow_no_op=False) # Pause movement (do nothing) @@ -87,7 +87,7 @@ if __name__ == '__main__': max_spawn_ratio=0.05, dirt_smear_amount=0.0) - # These are the EnvKwargs for initializing the env class, holding all former parameter-classes + # These are the EnvKwargs for initializing the environment class, holding all former parameter-classes # TODO: Comments factory_kwargs = dict(n_agents=1, max_steps=400, @@ -141,8 +141,8 @@ if __name__ == '__main__': model.learn(total_timesteps=int(train_steps), callback=[env_monitor_callback, env_recorder_callback]) ######################################################### - # 3. Save env and agent for later analysis. - # Save the trained Model, the monitor (env measures) and the env parameters + # 3. Save environment and agent for later analysis. + # Save the trained Model, the monitor (environment measures) and the environment parameters model.named_observation_space = env_factory.named_observation_space model.named_action_space = env_factory.named_action_space model.save(model_save_path) @@ -168,10 +168,10 @@ if __name__ == '__main__': model_cls = next(val for key, val in h.MODEL_MAP.items() if key in policy_path.parent.name) # Load the agent model = model_cls.load(policy_path / 'model.zip', device='cpu') - # Load old env kwargs + # Load old environment kwargs with next(policy_path.glob(env_params_json)).open('r') as f: env_kwargs = simplejson.load(f) - # Make the env stop ar collisions + # Make the environment stop ar collisions # (you only want to have a single collision per episode hence the statistics) env_kwargs.update(done_at_collision=True) diff --git a/quickstart/single_agent_train_item_env.py b/quickstart/single_agent_train_item_env.py index 9355f14..e8bd9eb 100644 --- a/quickstart/single_agent_train_item_env.py +++ b/quickstart/single_agent_train_item_env.py @@ -34,9 +34,9 @@ Welcome to this quick start file. Here we will see how to: 1. Setup parameters for the environments (item-factory). 2. Setup parameters for the agent training (SB3: PPO) and save metrics. Run the training. - 3. Save env and agent for later analysis. + 3. Save environment and agent for later analysis. 4. Load the agent from drive - 5. Rendering the env with a run of the trained agent. + 5. Rendering the environment with a run of the trained agent. 6. Plot metrics """ @@ -62,14 +62,14 @@ if __name__ == '__main__': # 1. Setup parameters for the environments (item-factory). # # Define property object parameters. - # 'ObservationProperties' are for specifying how the agent sees the env. + # 'ObservationProperties' are for specifying how the agent sees the environment. obs_props = ObservationProperties(render_agents=AgentRenderOptions.NOT, # Agents won`t be shown in the obs at all omit_agent_self=True, # This is default additional_agent_placeholder=None, # We will not take care of future agent frames_to_stack=3, # To give the agent a notion of time pomdp_r=2 # the agent view-radius ) - # 'MovementProperties' are for specifying how the agent is allowed to move in the env. + # 'MovementProperties' are for specifying how the agent is allowed to move in the environment. move_props = MovementProperties(allow_diagonal_movement=True, # Euclidean style (vertices) allow_square_movement=True, # Manhattan (edges) allow_no_op=False) # Pause movement (do nothing) @@ -84,7 +84,7 @@ if __name__ == '__main__': max_agent_inventory_capacity = 5, # How many items are needed until the agent inventory is full) ) - # These are the EnvKwargs for initializing the env class, holding all former parameter-classes + # These are the EnvKwargs for initializing the environment class, holding all former parameter-classes # TODO: Comments factory_kwargs = dict(n_agents=1, max_steps=400, @@ -137,8 +137,8 @@ if __name__ == '__main__': model.learn(total_timesteps=int(train_steps), callback=[env_monitor_callback, env_recorder_callback]) ######################################################### - # 3. Save env and agent for later analysis. - # Save the trained Model, the monitor (env measures) and the env parameters + # 3. Save environment and agent for later analysis. + # Save the trained Model, the monitor (environment measures) and the environment parameters model.named_observation_space = env_factory.named_observation_space model.named_action_space = env_factory.named_action_space model.save(model_save_path) @@ -164,10 +164,10 @@ if __name__ == '__main__': model_cls = next(val for key, val in h.MODEL_MAP.items() if key in policy_path.parent.name) # Load the agent agent model = model_cls.load(policy_path / 'model.zip', device='cpu') - # Load old env kwargs + # Load old environment kwargs with next(policy_path.glob(env_params_json)).open('r') as f: env_kwargs = simplejson.load(f) - # Make the env stop ar collisions + # Make the environment stop ar collisions # (you only want to have a single collision per episode hence the statistics) env_kwargs.update(done_at_collision=True) diff --git a/reload_agent.py b/reload_agent.py index 71c2677..0b2e43c 100644 --- a/reload_agent.py +++ b/reload_agent.py @@ -2,13 +2,12 @@ import warnings from pathlib import Path import yaml -from stable_baselines3 import PPO -from environment.factory import BaseFactory -from environment.logging.envmonitor import EnvMonitor -from environment.logging.recorder import EnvRecorder +from mfg_package.environment.factory import BaseFactory +from mfg_package.logging.envmonitor import EnvMonitor +from mfg_package.logging.recorder import EnvRecorder -from modules.doors import constants as d +from mfg_package.modules.doors import constants as d warnings.filterwarnings('ignore', category=FutureWarning) warnings.filterwarnings('ignore', category=UserWarning) @@ -32,7 +31,7 @@ if __name__ == '__main__': this_model = out_path / 'model.zip' - model_cls = PPO # next(val for key, val in h.MODEL_MAP.items() if key in out_path.parent.name) + model_cls = None # next(val for key, val in h.MODEL_MAP.items() if key in out_path.parent.name) models = [model_cls.load(this_model)] try: # Legacy Cleanups diff --git a/setup.py b/setup.py index 7b8f847..4cc8313 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,10 @@ setup(name='Marl-Factory-Grid', 'simulation', 'emergence', 'gymnasium', - 'environment' + 'environment', + 'deepdiff', + 'natsort', + ], classifiers=[ 'Development Status :: 4 - Beta',