|
|
|
|
|
|
"""Contains the MetaCurriculum class.""" |
|
|
|
|
|
|
|
import os |
|
|
|
from typing import Any, Dict, Set |
|
|
|
from mlagents.trainers.curriculum import Curriculum |
|
|
|
from mlagents.trainers.exception import MetaCurriculumError |
|
|
|
|
|
|
|
|
|
|
particular brain in the environment. |
|
|
|
""" |
|
|
|
|
|
|
|
def __init__(self, curriculum_folder, default_reset_parameters): |
|
|
|
def __init__( |
|
|
|
self, curriculum_folder: str, default_reset_parameters: Dict[str, Any] |
|
|
|
): |
|
|
|
"""Initializes a MetaCurriculum object. |
|
|
|
|
|
|
|
Args: |
|
|
|
|
|
|
default_reset_parameters (dict): The default reset parameters |
|
|
|
of the environment. |
|
|
|
""" |
|
|
|
used_reset_parameters = set() |
|
|
|
self._brains_to_curriculums = {} |
|
|
|
used_reset_parameters: Set[str] = set() |
|
|
|
self._brains_to_curriculums: Dict[str, Curriculum] = {} |
|
|
|
|
|
|
|
try: |
|
|
|
for curriculum_filename in os.listdir(curriculum_folder): |
|
|
|
|
|
|
curriculum_folder, curriculum_filename |
|
|
|
) |
|
|
|
curriculum = Curriculum(curriculum_filepath, default_reset_parameters) |
|
|
|
config_keys: Set[str] = set(curriculum.get_config().keys()) |
|
|
|
if any( |
|
|
|
[ |
|
|
|
(parameter in curriculum.get_config().keys()) |
|
|
|
for parameter in used_reset_parameters |
|
|
|
] |
|
|
|
): |
|
|
|
if config_keys & used_reset_parameters: |
|
|
|
logger.warning( |
|
|
|
"Two or more curriculums will " |
|
|
|
"attempt to change the same reset " |
|
|
|
|
|
|
|
|
|
|
used_reset_parameters.update(curriculum.get_config().keys()) |
|
|
|
used_reset_parameters.update(config_keys) |
|
|
|
self._brains_to_curriculums[brain_name] = curriculum |
|
|
|
except NotADirectoryError: |
|
|
|
raise MetaCurriculumError( |
|
|
|