def from_directory(folder_path: str) -> "MetaCurriculum": """ Creates a MetaCurriculum given a folder full of curriculum config files. :param folder_path: The path to the folder which holds the curriculum configs for this environment. The folder should contain JSON files whose names are the brains that the curricula belong to. """ try: curricula = {} for curriculum_filename in os.listdir(folder_path): # This process requires JSON files brain_name, extension = os.path.splitext(curriculum_filename) if extension.lower() != ".json": continue curriculum_filepath = os.path.join(folder_path, curriculum_filename) curriculum_config = Curriculum.load_curriculum_file( curriculum_filepath) curricula[brain_name] = Curriculum(brain_name, curriculum_config) return MetaCurriculum(curricula) except NotADirectoryError: raise MetaCurriculumError( f"{folder_path} is not a directory. Refer to the ML-Agents " "curriculum learning docs.")
def test_simple_metacurriculum(curriculum_brain_name): env = Simple1DEnvironment(use_discrete=False) with patch( "builtins.open", new_callable=mock_open, read_data=dummy_curriculum_json_str ): curriculum_config = Curriculum.load_curriculum_file("TestBrain.json") curriculum = Curriculum("TestBrain", curriculum_config) mc = MetaCurriculum({curriculum_brain_name: curriculum}) _check_environment_trains(env, META_CURRICULUM_CONFIG, mc, -100.0)
def test_curriculum_load_missing_file(): with pytest.raises(CurriculumLoadingError): Curriculum.load_curriculum_file("notAValidFile.json")
def test_load_bad_curriculum_file_raises_error(mock_file): with pytest.raises(CurriculumConfigError): Curriculum( "TestBrain", Curriculum.load_curriculum_file(dummy_curriculum_config_path))