Ejemplo n.º 1
0
def test_get_config(mock_file):
    curriculum = Curriculum("TestBrain.json")
    assert curriculum.get_config() == {"param1": 0.7, "param2": 100, "param3": 0.2}

    curriculum.lesson_num = 2
    assert curriculum.get_config() == {"param1": 0.3, "param2": 20, "param3": 0.7}
    assert curriculum.get_config(0) == {"param1": 0.7, "param2": 100, "param3": 0.2}
Ejemplo n.º 2
0
def test_get_parameters():
    curriculum = Curriculum("TestBrain", dummy_curriculum_config)
    assert curriculum.get_config() == {
        "param1": 0.7,
        "param2": 100,
        "param3": 0.2
    }

    curriculum.lesson_num = 2
    assert curriculum.get_config() == {
        "param1": 0.3,
        "param2": 20,
        "param3": 0.7
    }
    assert curriculum.get_config(0) == {
        "param1": 0.7,
        "param2": 100,
        "param3": 0.2
    }
Ejemplo n.º 3
0
    def __init__(self, curriculum_folder, default_reset_parameters):
        """Initializes a MetaCurriculum object.

        Args:
            curriculum_folder (str): The relative or absolute path of the
                folder which holds the curriculums for this environment.
                The folder should contain JSON files whose names are the
                brains that the curriculums belong to.
            default_reset_parameters (dict): The default reset parameters
                of the environment.
        """
        used_reset_parameters = set()
        self._brains_to_curriculums = {}

        try:
            for curriculum_filename in os.listdir(curriculum_folder):
                brain_name = curriculum_filename.split('.')[0]
                curriculum_filepath = \
                    os.path.join(curriculum_folder, curriculum_filename)
                curriculum = Curriculum(curriculum_filepath,
                                        default_reset_parameters)

                # Check if any two curriculums use the same reset params.
                if any([(parameter in curriculum.get_config().keys())
                        for parameter in used_reset_parameters]):
                    logger.warning('Two or more curriculums will '
                                   'attempt to change the same reset '
                                   'parameter. The result will be '
                                   'non-deterministic.')

                used_reset_parameters.update(curriculum.get_config().keys())
                self._brains_to_curriculums[brain_name] = curriculum
        except NotADirectoryError:
            raise MetaCurriculumError(curriculum_folder + ' is not a '
                                      'directory. Refer to the ML-Agents '
                                      'curriculum learning docs.')
Ejemplo n.º 4
0
    def __init__(self, curriculum_folder: str):
        """Initializes a MetaCurriculum object.

        Args:
            curriculum_folder (str): The relative or absolute path of the
                folder which holds the curriculums for this environment.
                The folder should contain JSON files whose names are the
                brains that the curriculums belong to.
            default_reset_parameters (dict): The default reset parameters
                of the environment.
        """
        used_reset_parameters: Set[str] = set()
        self._brains_to_curriculums: Dict[str, Curriculum] = {}

        try:
            for curriculum_filename in os.listdir(curriculum_folder):
                # This process requires JSON files
                brain_name, extension = os.path.splitext(curriculum_filename)
                if extension.lower() != ".json":
                    continue
                curriculum_filepath = os.path.join(
                    curriculum_folder, curriculum_filename
                )
                curriculum = Curriculum(curriculum_filepath)
                config_keys: Set[str] = set(curriculum.get_config().keys())

                # Check if any two curriculums use the same reset params.
                if config_keys & used_reset_parameters:
                    logger.warning(
                        "Two or more curriculums will "
                        "attempt to change the same reset "
                        "parameter. The result will be "
                        "non-deterministic."
                    )

                used_reset_parameters.update(config_keys)
                self._brains_to_curriculums[brain_name] = curriculum
        except NotADirectoryError:
            raise MetaCurriculumError(
                curriculum_folder + " is not a "
                "directory. Refer to the ML-Agents "
                "curriculum learning docs."
            )