-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing a List of dataclasses #271
Comments
Hello again @JonasFrey96 ! There is limited support for something similar, but not exactly the same: https://github.com/lebrice/SimpleParsing/blob/master/examples/merging/multiple_example.py In particular, this example here might be of interest to you: https://github.com/lebrice/SimpleParsing/blob/master/examples/merging/multiple_lists_example.py Let me know what you think! |
In my specific use case, it would be great to allow for parsing a list of data classes. |
Hey @JonasFrey96 , did you look at this example? https://github.com/lebrice/SimpleParsing/blob/master/examples/merging/multiple_lists_example.py |
Hi, I think this feature would be very useful for things like lists of data augmentations in deep learning code. Is it planned to be implemented? |
Hi, I'm also interested in this feature. From my understanding the idea of the feature, would be to enable this type of hierarchical dataclass definition with List. @dataclass
class CNNStack:
name: str = "stack"
num_layers: int = 3
kernel_sizes: Tuple[int, int, int] = (7, 5, 5)
num_filters: List[int] = field(default_factory=[32, 64, 64].copy)
@dataclass
class Config:
stack_list: List[CNNStack] = field(default_factory=[CNNStack(), CNNStack(), CNNStack()].copy)
parser = ArgumentParser(conflict_resolution=ConflictResolution.ALWAYS_MERGE)
parser.add_arguments(Config, dest="config", default=Config())
args = parser.parse_args()
print(args) However this is not supported yet, this only works if we manually construct the parser which in my use cases is not very convenient. |
I think the challenging part and the main difference with the multiple_lists_example.py is that in the proposed feature the number of CNNStack would not be fixed but could vary depending on the number of arguments provided by user. |
Hey there @hugobb , @MiguelMonteiro , thanks for commenting. I agree with you, this feature would be great to have. @hugobb you're right: this would be challenging to implement, especially if we don't know how many dataclasses to parse in advance! I guess a first step could be to make this work when we know the number of classes in advance, for instance something like Then, as a next step, we could probably figure out the number of values by inspecting the parsed values during postprocessing, or by adding an argument that can be used explicitly, like This feature will probably require a substantial refactoring of the current "reuse" feature, which is quite messy:
I could potentially invest some time in order to try to get this to work, but I'd like to get a bit more info if possible before that. Here are some design-y questions to start us off:
Thanks again @hugobb @MiguelMonteiro @JonasFrey96 for posting. Lets keep this ball rolling. |
Hi @lebrice, thanks for your answer.
I am not sure how this feature works, sorry
Perhaps the most intuitive way is for the parser to automatically append ".1", ".2", etc... to the end of the name.
Ideally, it would be infered from the arguemnts passed from the command line. What I am still unsure is if it would ever be possible to handle lists with different dataclasses in them. This would be very useful to configure data-augmentations for example. |
Hello,
it would be great if we could add support to pass a List of dataclasses:
Is there any way to elegantly parse such a configuration file:
This relates to:
If someone can point me toward what to change, I am happy to contribute.
The text was updated successfully, but these errors were encountered: