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
CustomEnvTask
following the example inenvironments/customenv/common.py
. This is an enum with task entries and some abstract functions you need to implement. The entries of this enum will be the uppercase names of your tasks. - Create a
conf/task/customenv
folder with a yaml configuration file for each of your tasks. This folder will have a yaml configuration for each task. You can seeconf/task/customenv
for an example. - Place your task script in
benchmarl/environments/customenv/common.py
and your config inbenchmarl/conf/task/customenv
(or any other place you want to override from). - Add
CustomEnvTask
tobenchmarl.environments.tasks
list. - 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.py
for each task, with aTaskConfig
object following the structure shown inenvironments/customenv/task_1.py
. In our example,task_1
has such dataclass, whiletask_2
doesn'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_config
to the defaults at the top of the task yaml file. Seeconf/task/customenv/task_1.yaml
for 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 = None
toCustomEnvTask
inenvironments/customenv/common.py
. -
Add
task_3.yaml
toconf/task/customenv
-
(Optional) Add
task_3.py
toenvironments/customenv
and the defaultcustomenv_task_3_config
at the top oftask_3.yaml
.