Package: ml-confs
A small, highly opinionatedpythontool to handle configurations for machine learning pipelines.
The library is designed to load configurations from bothjsonandyamlfiles, as well as from standard python dictionaries.Design rulesThe configurations, once loaded are frozen. Each configuration file can contain onlyint,float,str,boolandNonefields, as well ashomogeneouslists of one of the same types. That's all. No nested structures are allowed.InstallationML configurations can be installed directly fromgitby runningpip install ml-confsBasic usageA validml_confsconfiguration fileconfigs.ymlin YAML is:int_field:1float_field:1.0str_field:'string'bool_field:truenone_field:nulllist_field:[1,2,3]To load it we just use:importml_confs#Loading configsconfigs=ml_confs.from_file('configs.yml')#Accessing configs with dot notationprint(configs.int_field)# >>> 1#Additionally, one can use the ** notation to unpack the configurationsdeffoo(**kwargs):# Do stuff...foo(**configs)#Saving configs to json formatconfigs.to_file('json_configs_copy.json')#Will create a .json fileOne can also pretty print a loaded configuration withconfigs.tabulate(), which in the previous example would output:┏━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Key         ┃ Value     ┃ Type      ┃
┡━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━┩
│ int_field   │ 1         │ int       │
│ float_field │ 1.0       │ float     │
│ str_field   │ string    │ str       │
│ bool_field  │ True      │ bool      │
│ none_field  │ None      │ NoneType  │
│ list_field  │ [1, 2, 3] │ list[int] │
└─────────────┴───────────┴───────────┘JAX Pytree registrationBy default,ml_confswill try to register the configuration object as a JAX pytree, so thatconfigscan be safely used with JAX transformations.importml_confsimportjaxconfigs=mlc.from_dict({'exp':1.5})@jax.jitdefpower_fn(x,cfg):returnx**cfg.expassertf(2.0,configs)==2.0**exp# This works!assertjax.grad(power_fn)(3.0,configs)==3.0**(exp-1.0)*exp# This works too!If JAX is not installed the following warning will be displayed:Unable to import JAX. The argument register_jax_pytree will be ignored. To suppress this warning, load the configurations with register_jax_pytree=False.If one is not interested in this feature, the warning can be silenced by explicitly settingregister_jax_pytreetoFalseupon configuration loading.API Referencefunctionml_confs.from_jsonfrom_json(path:os.PathLike,register_jax_pytree:bool=True)Load configurations from a JSON file.Args:path(os.PathLike):  Configuration file path.register_jax_pytree(bool, optional):  Register the configuration as aJAXpytree. This allows the configurations to be safely used inJAX's transformations.. Defaults to False.Returns:Configs:  Instance of the loaded configurations.functionml_confs.from_yamlfrom_yaml(path:os.PathLike,register_jax_pytree:bool=True)Load configurations from a YAML file.Args:path(os.PathLike):  Configuration file path.register_jax_pytree(bool, optional):  Register the configuration as aJAXpytree. This allows the configurations to be safely used inJAX's transformations.. Defaults to False.Returns:Configs:  Instance of the loaded configurations.functionml_confs.from_dictfrom_dict(storage:dict,register_jax_pytree:bool=True)Load configurations from a python dictionary.Args:storage(dict):  Configuration dictionary.register_jax_pytree(bool, optional):  Register the configuration as aJAXpytree. This allows the configurations to be safely used inJAX's transformations.. Defaults to False.Returns:Configs:  Instance of the loaded configurations.functionml_confs.from_filefrom_file(path:os.PathLike,register_jax_pytree:bool=True)Load configurations from a YAML/JSON file.Args:path(os.PathLike):  Configuration file path.register_jax_pytree(bool, optional):  Register the configuration as aJAXpytree. This allows the configurations to be safely used inJAX's transformations.. Defaults to False.Returns:Configs:  Instance of the loaded configurations.classConfigsmethodConfigs.tabulatetabulate()Print the configurations in a tabular format.methodConfigs.to_dictto_dict()→dictExport configurations to a python dictionary.Returns:dict:  A standard python dictionary containing the configurations.methodConfigs.to_fileto_file(path:os.PathLike)Save configurations to a YAML/JSON file.Args:path(os.PathLike):  File path to save the configurations.methodConfigs.to_jsonto_json(path:os.PathLike)Save configurations to a JSON file.Args:path(os.PathLike):  File path to save the configurations.methodConfigs.to_yamlto_yaml(path:os.PathLike)Save configurations to a YAML file.Args:path(os.PathLike):  File path to save the configurations.The API reference was automatically generated vialazydocs.