Representing nested args by their full "nesting path" even with no conflicts
See original GitHub issuesimple-parsing
is simply awesome (thanks!). I’d like to suggest a feature that is crucial for parsing nested args, in my opinion, and the support of other researchers in my group. Here is a minimal example to make things clear:
from dataclasses import dataclass
from simple_parsing import ArgumentParser, ConflictResolution
@dataclass
class WandbArgs:
dir: str = '' # Wandb run cache dir, relative to project_path; leave empty for default
use: bool # Whether to use wandb for experiment control, logging, saving...
@dataclass
class Data:
dir: str = '' # Data dir, relative to project_path; leave empty for default
@dataclass
class ProjectArgs:
data: Data = Data()
wandb: WandbArgs = WandbArgs()
parser = ArgumentParser(conflict_resolution=ConflictResolution.EXPLICIT)
parser.add_arguments(ProjectArgs, dest='args')
args = parser.parse_args().args
A command line to set all values can be: --use=True --wandb.dir='wandb' --data.dir='data'
.
Since I passed ConflictResolution.EXPLICIT:
- Nested args with conflicts - args that appear under different dataclasses,
dir
in this example, are allowed and accessed in command line by their full “nesting path”,wandb.dir
anddata.dir
. This is organized and makes sense. - HOWEVER, unique args (no conflicts) appear without their “nesting path”, in this example
use
.
I claim that having wandb.use
in the command line is much more clear, unambiguous, simple and intuitive than use
(current behavior), especially for those who have many args and invested time in organizing them with nesting, to make it organized, clear and simple!.
I found a hack to get this functionality: I force duplication for all args by adding parser.add_arguments(ProjectArgs, dest='duplicated')
to my example above (and ignoring the duplicated args) - forcing all args to apepar in command line with their full path. However, since I have many args in my current project, I need to also download and modify simple-parsing
source code - set max_attempts=200
in simple_parsing -> conflicts.py
- otherwise it raises an error, assuming so many conflicts are not possible and must be an error.
Therefore I suggest to add a force_explicit
argument to ArgumentParser, such that ArgumentParser(force_explicit=True)
makes all nested args appear in command line with their full “nesting path”, no hack, no ConflictResolution.EXPLICIT
, no max number of conflicts - simple, organized and clear!
Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Thank you @Ozziko for your proposal. Indeed, I think it is a very useful feature. @lebrice I’ve tried to implement it, as you suggested, in this PR https://github.com/lebrice/SimpleParsing/pull/117. Hope I got it right.
This issue looks to be resolved… the PR is merged, so it can likely be closed.