[docs]defload_config(path:str|Path,config_cls:Type[T])->T:""" Load a YAML config file and convert to a Pydantic config object. Args: path: Path to YAML config file config_cls: Pydantic config class to instantiate (e.g., EvalConfig) Returns: Instantiated and validated config object Example: >>> from myriad.configs.default import EvalConfig >>> config = load_config("config.yaml", EvalConfig) """path=Path(path)ifnotpath.exists():raiseFileNotFoundError(f"Config file not found: {path}")withopen(path,"r")asf:config_dict=yaml.safe_load(f)returnconfig_cls(**config_dict)
defsave_config(config:BaseModel,path:str|Path)->Path:""" Save a Pydantic config to a YAML file. Args: path: Path to write the YAML config file config: Pydantic config object (e.g., Config, EvalConfig) Returns: The path written to (for chaining) Example: >>> from myriad import save_config >>> save_config(config, "my_run/config.yaml") """path=Path(path)path.parent.mkdir(parents=True,exist_ok=True)withopen(path,"w")asf:yaml.dump(config.model_dump(mode="json"),f,default_flow_style=False,sort_keys=False)returnpath