question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Representing nested args by their full "nesting path" even with no conflicts

See original GitHub issue

simple-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 and data.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:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ivanpradocommented, Apr 8, 2022

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.

1reaction
nacitarcommented, Jun 17, 2022

This issue looks to be resolved… the PR is merged, so it can likely be closed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript: deep keyof of a nested object - Stack Overflow
UPDATE for TS4.1 It is now possible to concatenate string literals at the type level, using template literal types as implemented in ...
Read more >
Customizing the behavior of cached fields - Apollo GraphQL
You can customize how a particular field in your Apollo Client cache is read and written. To do so, you define a field...
Read more >
[css-nesting] Conflicts in proposal with Sass/Less · Issue #2937
This doesn't address placing the inherited / parent selector after the nested selector, but is that very CSS-y anyway? That's certainly not how ......
Read more >
Best practices for REST API design - Stack Overflow Blog
In this article, we'll look at how to design REST APIs to be easy to understand for anyone consuming them, future-proof, and secure...
Read more >
The Limited Role of Number of Nested Syntactic ... - NCBI
This argues against De Vries et al.'s (2011) claim that the human parser can process no more than two nested dependencies. The results...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found