Ejemplo n.º 1
0
def main() -> None:
    args = parse_args()
    print(
        f"Converting {args.trainer_config_path} and saving to {args.output_config_path}."
    )

    old_config = load_config(args.trainer_config_path)
    behavior_config_dict = convert_behaviors(old_config)
    full_config = {"behaviors": behavior_config_dict}

    # Convert curriculum and sampler. note that we don't validate these; if it was correct
    # before it should be correct now.
    if args.curriculum is not None:
        curriculum_config_dict = load_config(args.curriculum)
        full_config["curriculum"] = curriculum_config_dict

    if args.sampler is not None:
        old_sampler_config_dict = load_config(args.sampler)
        sampler_config_dict = convert_samplers(old_sampler_config_dict)
        full_config["parameter_randomization"] = sampler_config_dict

    # Convert config to dict
    unstructed_config = cattr.unstructure(full_config)
    unstructed_config = remove_nones(unstructed_config)
    write_to_yaml_file(unstructed_config, args.output_config_path)
Ejemplo n.º 2
0
def main() -> None:
    args = parse_args()
    print(
        f"Converting {args.trainer_config_path} and saving to {args.output_config_path}."
    )

    old_config = load_config(args.trainer_config_path)
    curriculum_config_dict = None
    old_sampler_config_dict = None
    if args.curriculum is not None:
        curriculum_config_dict = load_config(args.curriculum)
    if args.sampler is not None:
        old_sampler_config_dict = load_config(args.sampler)
    new_config = convert(old_config, curriculum_config_dict, old_sampler_config_dict)
    unstructed_config = remove_nones(new_config)
    write_to_yaml_file(unstructed_config, args.output_config_path)
Ejemplo n.º 3
0
    def from_argparse(args: argparse.Namespace) -> "RunOptions":
        """
        Takes an argparse.Namespace as specified in `parse_command_line`, loads input configuration files
        from file paths, and converts to a RunOptions instance.
        :param args: collection of command-line parameters passed to mlagents-learn
        :return: RunOptions representing the passed in arguments, with trainer config, curriculum and sampler
          configs loaded from files.
        """
        argparse_args = vars(args)
        config_path = StoreConfigFile.trainer_config_path

        # Load YAML
        configured_dict: Dict[str, Any] = {
            "checkpoint_settings": {},
            "env_settings": {},
            "engine_settings": {},
            "torch_settings": {},
        }
        _require_all_behaviors = True
        if config_path is not None:
            configured_dict.update(load_config(config_path))
        else:
            # If we're not loading from a file, we don't require all behavior names to be specified.
            _require_all_behaviors = False

        # Use the YAML file values for all values not specified in the CLI.
        for key in configured_dict.keys():
            # Detect bad config options
            if key not in attr.fields_dict(RunOptions):
                raise TrainerConfigError(
                    "The option {} was specified in your YAML file, but is invalid.".format(
                        key
                    )
                )
        # Override with CLI args
        # Keep deprecated --load working, TODO: remove
        argparse_args["resume"] = argparse_args["resume"] or argparse_args["load_model"]
        for key, val in argparse_args.items():
            if key in DetectDefault.non_default_args:
                if key in attr.fields_dict(CheckpointSettings):
                    configured_dict["checkpoint_settings"][key] = val
                elif key in attr.fields_dict(EnvironmentSettings):
                    configured_dict["env_settings"][key] = val
                elif key in attr.fields_dict(EngineSettings):
                    configured_dict["engine_settings"][key] = val
                elif key in attr.fields_dict(TorchSettings):
                    configured_dict["torch_settings"][key] = val
                else:  # Base options
                    configured_dict[key] = val

        final_runoptions = RunOptions.from_dict(configured_dict)
        final_runoptions.checkpoint_settings.prioritize_resume_init()
        # Need check to bypass type checking but keep structure on dict working
        if isinstance(final_runoptions.behaviors, TrainerSettings.DefaultTrainerDict):
            # configure whether or not we should require all behavior names to be found in the config YAML
            final_runoptions.behaviors.set_config_specified(_require_all_behaviors)
        return final_runoptions
Ejemplo n.º 4
0
def main():
    """
    Provides an alternative CLI interface to mlagents-learn, 'mlagents-run-experiment'.
    Accepts a JSON/YAML formatted mlagents.trainers.learn.RunOptions object, and executes
    the run loop as defined in mlagents.trainers.learn.run_cli.
    """
    args = parse_command_line()
    expt_config = load_config(args.experiment_config_path)
    run_cli(RunOptions.from_dict(expt_config))
Ejemplo n.º 5
0
    def from_argparse(args: argparse.Namespace) -> "RunOptions":
        """
        Takes an argparse.Namespace as specified in `parse_command_line`, loads input configuration files
        from file paths, and converts to a RunOptions instance.
        :param args: collection of command-line parameters passed to mlagents-learn
        :return: RunOptions representing the passed in arguments, with trainer config, curriculum and sampler
          configs loaded from files.
        """
        argparse_args = vars(args)
        config_path = StoreConfigFile.trainer_config_path

        # Load YAML
        configured_dict: Dict[str, Any] = {
            "checkpoint_settings": {},
            "env_settings": {},
            "engine_settings": {},
            "torch_settings": {},
        }
        if config_path is not None:
            configured_dict.update(load_config(config_path))

        # Use the YAML file values for all values not specified in the CLI.
        for key in configured_dict.keys():
            # Detect bad config options
            if key not in attr.fields_dict(RunOptions):
                raise TrainerConfigError(
                    "The option {} was specified in your YAML file, but is invalid.".format(
                        key
                    )
                )
        # Override with CLI args
        # Keep deprecated --load working, TODO: remove
        argparse_args["resume"] = argparse_args["resume"] or argparse_args["load_model"]
        for key, val in argparse_args.items():
            if key in DetectDefault.non_default_args:
                if key in attr.fields_dict(CheckpointSettings):
                    configured_dict["checkpoint_settings"][key] = val
                elif key in attr.fields_dict(EnvironmentSettings):
                    configured_dict["env_settings"][key] = val
                elif key in attr.fields_dict(EngineSettings):
                    configured_dict["engine_settings"][key] = val
                elif key in attr.fields_dict(TorchSettings):
                    configured_dict["torch_settings"][key] = val
                else:  # Base options
                    configured_dict[key] = val

        final_runoptions = RunOptions.from_dict(configured_dict)
        return final_runoptions
Ejemplo n.º 6
0
def test_load_config_missing_file():
    with pytest.raises(TrainerConfigError):
        load_config("thisFileDefinitelyDoesNotExist.yaml")
Ejemplo n.º 7
0
        default=None,
    )
    argparser.add_argument(
        "--sampler",
        help=
        "Path to old format (<=0.16.X) parameter randomization configuration YAML.",
        default=None,
    )
    argparser.add_argument("output_config_path",
                           help="Path to write converted YAML file.")
    args = argparser.parse_args()
    print(
        f"Converting {args.trainer_config_path} and saving to {args.output_config_path}."
    )

    old_config = load_config(args.trainer_config_path)
    behavior_config_dict = convert_behaviors(old_config)
    full_config = {"behaviors": behavior_config_dict}

    # Convert curriculum and sampler. note that we don't validate these; if it was correct
    # before it should be correct now.
    if args.curriculum is not None:
        curriculum_config_dict = load_config(args.curriculum)
        full_config["curriculum"] = curriculum_config_dict

    if args.sampler is not None:
        sampler_config_dict = load_config(args.curriculum)
        full_config["parameter_randomization"] = sampler_config_dict

    write_to_yaml_file(full_config, args.output_config_path)