Making a Custom Environment¶
Setup pre-commit hooks¶
pre-commit install to initialize pre-commit hooks. pip install pre-commit if you don’t have the package.
Create a new environment package in
momaland/envs/Create a new environment class in
momaland/envs/<env_name>/<env_name>.py, this class should extendMOParallelEnvorMOAECEnv. Override the PettingZoo methods (see their documentation). Additionally, you should define a memberself.reward_spacesthat is a dictionary of space specifying the shape of the reward vector of each agent, as well as a methodreward_space(self, agent) -> Spacethat returns the reward space of a given agent.Define the factory functions to create your class:
parallel_envreturns a parallel version of the env,envreturns an AEC version, andraw_envthat is the pure class constructor (it is not used in practice).
(!) Use the conversions that are defined inside our repository, e.g.
mo_parallel_to_aecinstead ofparallel_to_aecfrom PZ.
Add a versioned constructor of your env in the directory which exports the factory functions (see
mobeach_v0.pyfor an example).Add your environment to the tests in
utils/all_modules.pyRun
pytestto check that everything works