コード例 #1
0
def test_assemble_curriculum_config():
    file_contents = """
behavior1:
    curriculum:
        foo: 5
behavior2:
    curriculum:
        foo: 6
    """
    trainer_config = _load_config(file_contents)
    curriculum_config = assemble_curriculum_config(trainer_config)
    assert curriculum_config == {
        "behavior1": {
            "foo": 5
        },
        "behavior2": {
            "foo": 6
        }
    }

    # Check that nothing is returned if no curriculum.
    file_contents = """
behavior1:
    foo: 3
behavior2:
    foo: 4
    """
    trainer_config = _load_config(file_contents)
    curriculum_config = assemble_curriculum_config(trainer_config)
    assert curriculum_config == {}

    # Check that method doesn't break if 1st level entity isn't a dict.
    # Note: this is a malformed configuration.
    file_contents = """
behavior1: 3
behavior2: 4
    """
    trainer_config = _load_config(file_contents)
    curriculum_config = assemble_curriculum_config(trainer_config)
    assert curriculum_config == {}
コード例 #2
0
def run_training(run_seed: int, options: RunOptions) -> None:
    """
    Launches training session.
    :param options: parsed command line arguments
    :param run_seed: Random seed used for training.
    :param run_options: Command line arguments for training.
    """
    with hierarchical_timer("run_training.setup"):
        base_path = "results"
        write_path = os.path.join(base_path, options.run_id)
        maybe_init_path = (
            os.path.join(base_path, options.run_id) if options.initialize_from else None
        )
        run_logs_dir = os.path.join(write_path, "run_logs")
        port = options.base_port
        # Check if directory exists
        handle_existing_directories(
            write_path, options.resume, options.force, maybe_init_path
        )
        # Make run logs directory
        os.makedirs(run_logs_dir, exist_ok=True)
        # Configure CSV, Tensorboard Writers and StatsReporter
        # We assume reward and episode length are needed in the CSV.
        csv_writer = CSVWriter(
            write_path,
            required_fields=[
                "Environment/Cumulative Reward",
                "Environment/Episode Length",
            ],
        )
        tb_writer = TensorboardWriter(write_path, clear_past_data=not options.resume)
        gauge_write = GaugeWriter()
        console_writer = ConsoleWriter()
        StatsReporter.add_writer(tb_writer)
        StatsReporter.add_writer(csv_writer)
        StatsReporter.add_writer(gauge_write)
        StatsReporter.add_writer(console_writer)

        if options.env_path is None:
            port = UnityEnvironment.DEFAULT_EDITOR_PORT
        env_factory = create_environment_factory(
            options.env_path,
            options.no_graphics,
            run_seed,
            port,
            options.env_args,
            os.path.abspath(run_logs_dir),  # Unity environment requires absolute path
        )
        engine_config = EngineConfig(
            width=options.width,
            height=options.height,
            quality_level=options.quality_level,
            time_scale=options.time_scale,
            target_frame_rate=options.target_frame_rate,
            capture_frame_rate=options.capture_frame_rate,
        )
        env_manager = SubprocessEnvManager(env_factory, engine_config, options.num_envs)
        curriculum_config = assemble_curriculum_config(options.behaviors)
        maybe_meta_curriculum = try_create_meta_curriculum(
            curriculum_config, env_manager, options.lesson
        )
        sampler_manager, resampling_interval = create_sampler_manager(
            options.parameter_randomization, run_seed
        )
        trainer_factory = TrainerFactory(
            options.behaviors,
            options.run_id,
            write_path,
            options.keep_checkpoints,
            not options.inference,
            options.resume,
            run_seed,
            maybe_init_path,
            maybe_meta_curriculum,
            options.multi_gpu,
        )
        # Create controller and begin training.
        tc = TrainerController(
            trainer_factory,
            write_path,
            options.run_id,
            options.save_freq,
            maybe_meta_curriculum,
            not options.inference,
            run_seed,
            sampler_manager,
            resampling_interval,
        )

    # Begin training
    try:
        tc.start_learning(env_manager)
    finally:
        env_manager.close()
        write_run_options(write_path, options)
        write_timing_tree(run_logs_dir)