Skip to content
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

Possibility to support python-fire? #33

Open
TheShadow29 opened this issue Sep 27, 2018 · 5 comments
Open

Possibility to support python-fire? #33

TheShadow29 opened this issue Sep 27, 2018 · 5 comments

Comments

@TheShadow29
Copy link

I usually use python fire (https://github.com/google/python-fire), it creates the parser arguments by default looking at the function to be called. Is there any possibility of integrating this into the existing framework?

@williamFalcon
Copy link
Owner

what do you mean usually? looks cool, can you share an example?

@TheShadow29
Copy link
Author

TheShadow29 commented Sep 27, 2018

Here is an example

"""
main.py
"""
import fire
from utils import get_data

def main(exp_name, batch_size, num_workers):
    print(f'Starting Experiment {exp_name}')
    data = get_data(batch_size, num_workers)

if __name__ == '__main__':
    fire.Fire(main)

Now, in my terminal, I can directly do this

python main.py "exp1" 32 8

This would directly pass the arguments to the main function without explicitly importing argparse and is more succint. To be specific, it is like a wrapper around the argparse and calls it internally.

In general, fire supports many other stuff like here: https://github.com/google/python-fire/blob/master/docs/guide.md. Though not all of it would be relevant to test-tube.

@williamFalcon
Copy link
Owner

Interesting.... could you propose an example using test tube (ie: a dream use case)? I see this as an addition and not necessarily a replacement of argparse because most academic researchers use argparse right now so it's easy to integrate with their code (ie... not many changes)

@TheShadow29
Copy link
Author

Yeah, I meant this to be an addition. Here is a small example I am cooking up from your example. https://github.com/williamFalcon/test-tube/blob/master/examples/pytorch_hpc_example.py

The given code:

# set up our argparser and make the y_val tunable
parser = HyperOptArgumentParser(strategy='random_search')
parser.add_argument('--test_tube_exp_name', default='my_test')
parser.add_argument('--log_path', default='/some/path/to/log')
parser.opt_list('--y_val', default=12, options=[1, 2, 3, 4, 5, 6], tunable=True)
parser.opt_list('--x_val', default=12, options=[20, 12, 30, 45], tunable=True)
hyperparams = parser.parse_args()

can be rewritten as:

"""eg.py"""
def main(*args, **kwargs):
     # cfg.json has a dictionary like {"strategy": "random_search"} and other default values
    cfg = json.load(open('./cfg.json'))
    cfg.update(kwargs)
    # Use cfg to update hyperopt
    pass
if __name__ = '__main__':
      fire.Fire(main)

Now from my terminal I can simply call, python eg.py --y_val=5 and done. Makes the code way simpler I think.

@dreamgonfly
Copy link

dreamgonfly commented Sep 24, 2019

There are other cool arguments parser libraries like http://docopt.org/ as well. We could generalize this issue by supporting json format parsed arguments, instead of relying on a specific format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants