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 extendMOParallelEnv
orMOAECEnv
. Override the PettingZoo methods (see their documentation). Additionally, you should define a memberself.reward_spaces
that is a dictionary of space specifying the shape of the reward vector of each agent, as well as a methodreward_space(self, agent) -> Space
that returns the reward space of a given agent.Define the factory functions to create your class:
parallel_env
returns a parallel version of the env,env
returns an AEC version, andraw_env
that 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_aec
instead ofparallel_to_aec
from PZ.
Add a versioned constructor of your env in the directory which exports the factory functions (see
mobeach_v0.py
for an example).Add your environment to the tests in
utils/all_modules.py
Run
pytest
to check that everything works