camall3n / onager

Lightweight python library for launching experiments and tuning hyperparameters, either locally or on a cluster
MIT License
20 stars 4 forks source link

Avoid command switching between '+' and '--' syntax #33

Open camall3n opened 4 years ago

camall3n commented 4 years ago

Currently the prelaunch command args use '+' prefixes, whereas the rest of the library uses '--' prefixes. This is confusing.

Cam: "+arg has a nice intuitive meaning for me, whereas +jobname does not." Neev: "Yeah. But I'd rather have consistency."

Neev: "I catch myself using + by accident in launch too."

neevparikh commented 4 years ago

I would prefer to switch the whole interface to '+'

camall3n commented 4 years ago

I have two main issues with using '+' globally:

  1. It's not what most people expect from a command-line tool, so it might be confusing
  2. It's harder to type than '-' or even '--'

I remember that we settled on '+' for prelaunch because we wanted a way to avoid conflicts between user-script arguments and prelaunch arguments. I still wonder if there's a way to achieve that while retaining the normal '--arg' syntax...?

neevparikh commented 4 years ago

I dunno, I feel like one can get used to it real quick. What's confusing is having two different versions simultaneously.

As for another way to accomplish the not-conflating thing, I'm open to any method that's not significantly more complicated.

camall3n commented 3 years ago

Here's a sketch of a solution. We make multiple passes through the arguments. We continue to use both + and -- prefixes for prelaunch only, and leave the other subcommands unchanged with -- only. However, most of the prelaunch options switch to --; only the +arg, +pos-arg and +flag prelaunch options would continue to use +.

Input:

onager prelaunch --jobname myjob --command mycommand +arg --some-arg 1 2 +arg --other-arg foo bar +flag

We initially modify the prelaunch subcommand to prelaunch+, so it gets parsed by the + parser.

if sys.argv[1] == 'prelaunch':
    sys.argv[1] = 'prelaunch+'

First pass; look for + commands:

> args, other_args = parse_args()
> args
Namespace(
  arg=[['--some-arg', '1', '2'], ['--other-arg', 'foo', 'bar']],
  flag=['--some-flag']
)
> other_args
['--jobname', 'myjob', '--command', 'mycommand']

Second pass; look for -- commands and add to existing namespace:

> parse_args(['prelaunch-'] + other_args, namespace=args)
> args
Namespace(
  arg=[['--some-arg', '1', '2'], ['--other-arg', 'foo', 'bar']],
  flag=['--some-flag'],
  command='mycommand',
  jobname='myjobname'
)
camall3n commented 3 years ago

This would require modifying the help subcommand to properly show both types of input args (+ and --), but I suspect that's possible. And even if it needs to be done by hand, it's worth it to have a unified interface.