Closed hadipash closed 8 months ago
save
/dump
are supposed to be used with the same ArgumentParser
as the one used to parse. This is necessary so that it can be known how to serialize each key. That is why you get that error, since the empty parser ArgumentParser()
doesn't know about the config
key. Why is it that you want to do this?
This is because args
may change due to environmental setup or system requirements, so I would like to save the updated version.
Sorry, I am not sure I understand. The details of a parser could depend on environment or other factors. But why aren't you able to use the proper parser to save instead of an empty one? If it is in different places of the codebase, you could have a function that creates the parser, and create one right before saving. But preferably use the same parser instance that was used to parse.
It is useful, for example, when the directory in which to save the config file is not known until a later stage in the program's execution. I feel that carrying the original parser throughout the script for the sole purpose of saving is a bit of an overkill.
Indeed carrying around a parser is not nice. But you can have a function that creates the parser. Then have a save function that creates a new parser same as the original one and then do the save.
It is by design that the same parser should be used to save. It is a bit unfortunate that I added the skip_check
parameter since it can be misleading. Anyway, if you really want to save a namespace without what the save method is intended to do, you can simple do:
data = strip_meta(args).as_dict()
and then just dump it as yaml. There is a risk that some things might not work, but not necessarily in your case.
Thanks for detailed reply!
🐛 Bug report
To reproduce
Output:
Expected behavior
It works if
args.config[0]
is explicitly converted into a string orconfig
key is popped fromargs
.Or, is there a better way to handle these kinds of situations?
Environment
pip install jsonargparse[all]
): pip install jsonargparse[signatures,omegaconf,urls]>=4.25.0