0

I am new to the click CLI library, so this might be something trivial.

I have a script which has one group and one subcommand, something like this. It is a ML application which has a training phase and evaluation phase.

import click

@click.group()
@click.option('--learning_rate', type=click.FLOAT, default=1.e-4)
@click.pass_context
def train(ctx: click.Context, learning_rate: float):
    ...
    ctx.ensure_object(dict)
    ctx.obj['model'] = 'Trained Model'
    click.echo('Trained complete')

@train.command
@click.option('--eval_param', type=click.INT)
@click.pass_context
def eval(ctx: click.Context, eval_param: int):
    ...
    trained_model = ctx.obj['model']
    click.echo(f'Using {trained_model} for evaluation using eval parameter {eval_param}')

if __name__ == '__main__':
    train()

I can use it like this

>> python ml.py --learning_rate 0.001 eval --eval_param 0
Trained complete
Using Trained Model for evaluation using eval parameter 0

However, I would like to run the evaluation process arbitrarily many times with different --eval_param. Only the parameters change -- the eval() function should remain same. But, dependning on the eval_param, the result changes. BTW, the different evals are independent of each other, given the trained model.

So, I want something like the following

python ml.py --learning_rate 0.001 eval --eval_param 0 eval --eval_param 1 eval --eval_param 2
Trained complete
Using Trained Model for evaluation using eval parameter 0
Using Trained Model for evaluation using eval parameter 1
Using Trained Model for evaluation using eval parameter 2

I can't really figure out what the right approach is. Any help is appreciated.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.