omni-us / jsonargparse

Implement minimal boilerplate CLIs derived from type hints and parse from command line, config files and environment variables
https://jsonargparse.readthedocs.io
MIT License
314 stars 42 forks source link

Support for a list of nested objects #385

Open memray opened 11 months ago

memray commented 11 months ago

Hi there,

Great tool! I wonder if it is possible to load/dump configs as a list of nested objects/dataclasses, like the data shown below? It's quite common for ML projects. Thanks! https://github.com/OpenNMT/OpenNMT-py/blob/master/data/features_data.yaml

image

mauvilsa commented 11 months ago

Types like list[<subtype>] are supported. The subtype could be simple, like an int, or complex like a dataclass or a base class to accept subclasses. See for example pytorch lightning's callbacks (LightningCLI is jsonargparse under the hood). The config above doesn't look like a list. Looks more like nested dataclasses, which are also supported.

Note that jsonargparse was developed based on machine learning needs and most of its users are from this community. Depending on what you want, I could advice how to best proceed. Feel free to ask.