Module neuralops.config.loader

Configuration loader: YAML + CLI overrides → Config dataclass.

Functions

def load_config(yaml_path: str | None = None, cli_args: argparse.Namespace | None = None) ‑> Config
Expand source code
def load_config(
    yaml_path: str | None = None,
    cli_args: argparse.Namespace | None = None,
) -> Config:
    """
    Load configuration from optional YAML file + CLI overrides.
    Always returns a fully populated Config dataclass with defaults.
    """
    cfg_dict: dict[str, Any] = {}
    if yaml_path:
        cfg_dict = load_yaml(yaml_path)
    if cli_args:
        cfg_dict = merge_cli_args(cfg_dict, cli_args)

    # Convert the flat dict to nested Config using the top‑level Config dataclass
    return _dict_to_dataclass(Config, cfg_dict)

Load configuration from optional YAML file + CLI overrides. Always returns a fully populated Config dataclass with defaults.

def load_yaml(path: str) ‑> dict
Expand source code
def load_yaml(path: str) -> dict:
    """Load yaml from disk or config."""
    with open(path) as f:
        return yaml.safe_load(f)

Load yaml from disk or config.

def merge_cli_args(cfg_dict: dict, args: argparse.Namespace) ‑> dict
Expand source code
def merge_cli_args(cfg_dict: dict, args: argparse.Namespace) -> dict:
    """Override YAML values with CLI arguments where not None."""
    cli = vars(args)
    for key, val in cli.items():
        if val is not None and key in cfg_dict:
            cfg_dict[key] = val
    return cfg_dict

Override YAML values with CLI arguments where not None.