In the following we will see how to:
- Create new tasks from a new environment
- Create new tasks from an existing environment
Here are the steps to create a new task and a new environment.
- Create your
CustomEnvTaskandCustomEnvClassfollowing the example inenvironments/customenv/common.py. This is an enum with task entries and a class with abstract functions you need to implement. The entries of the enum will be the uppercase names of your tasks. - Create a
conf/task/customenvfolder with a yaml configuration file for each of your tasks. This folder will have a yaml configuration for each task. You can seeconf/task/customenvfor an example. (NOTE: only include thedefaultssection at the top of the file if you are doing step 6) - Place your task script in
benchmarl/environments/customenv/common.pyand your config inbenchmarl/conf/task/customenv(or any other place you want to override from). - Add
CustomEnvTasktobenchmarl.environments.taskslist. - Load it with
python benchmarl/run.py task=customenv/task_1 algorithm=...- (Optional) You can create python dataclasses to use as schemas for your tasks
to validate their config. This will allow to check the configuration entries and types for each task.
This step is optional and, if you skip it, everything will work (just without the task config being checked against python dataclasses).
To do it, just create
environments/customenv/taskname.pyfor each task, with aTaskConfigobject following the structure shown inenvironments/customenv/task_1.py. In our example,task_1has such dataclass, whiletask_2doesn't. The name of the python file has to be the name of the task in lower case. Then you need to tell hydra to use this as a schema by addingcustomenv_taskname_configto the defaults at the top of the task yaml file. Seeconf/task/customenv/task_1.yamlfor an example.
Imagine we now have already in the library customenv with task_1 and task_2.
To create a new task (e.g., task_3) in an existing environment , follow these steps:
-
Add
TASK_3 = NonetoCustomEnvTaskinenvironments/customenv/common.py. -
Add
task_3.yamltoconf/task/customenv -
(Optional) Add
task_3.pytoenvironments/customenvand the defaultcustomenv_task_3_configat the top oftask_3.yaml.
PR #84 contains an example on how to add a your own PettingZoo task.