Beispiel #1
0
def manage_cmd(args):
    '''
    Calls diverse model maintenance commands
    '''

    import flame.manage as manage

    version = utils.intver(args.version)

    if args.action == 'new':
        # check if config model repo path is correct
        utils.check_repository_path()
        success, results = manage.action_new(args.endpoint)
    elif args.action == 'kill':
        success, results = manage.action_kill(args.endpoint)
    elif args.action == 'remove':
        success, results = manage.action_remove(args.endpoint, version)
    elif args.action == 'publish':
        success, results = manage.action_publish(args.endpoint)
    elif args.action == 'list':
        success, results = manage.action_list(args.endpoint)
    elif args.action == 'import':
        success, results = manage.action_import(args.infile)
    elif args.action == 'export':
        success, results = manage.action_export(args.endpoint)
    elif args.action == 'refactoring':
        success, results = manage.action_refactoring(args.file)
    elif args.action == 'info':
        success, results = manage.action_info(args.endpoint, version)
    elif args.action == 'results':
        success, results = manage.action_results(args.endpoint, version)
    elif args.action == 'parameters':
        success, results = manage.action_parameters(args.endpoint, version)
    elif args.action == 'dir':
        success, results = manage.action_dir()
    elif args.action == 'report':
        success, results = manage.action_report()
    else:
        success = False
        results = "Specified manage action is not defined"

    return success, results
Beispiel #2
0
def manage_cmd(args):
    '''
    Instantiates a Build object to build a model using the given input
    file (training series) and model (name of endpoint, eg. 'CACO2')
    '''

    version = utils.intver(args.version)

    if args.action == 'new':
        # check if config model repo path is correct
        utils.check_repository_path()
        success, results = manage.action_new(args.endpoint)
    elif args.action == 'kill':
        success, results = manage.action_kill(args.endpoint)
    elif args.action == 'remove':
        success, results = manage.action_remove(args.endpoint, version)
    elif args.action == 'publish':
        success, results = manage.action_publish(args.endpoint)
    elif args.action == 'list':
        success, results = manage.action_list(args.endpoint)
    elif args.action == 'import':
        success, results = manage.action_import(args.infile)
    elif args.action == 'export':
        success, results = manage.action_export(args.endpoint)
    elif args.action == 'refactoring':
        success, results = manage.action_refactoring(args.file)
    elif args.action == 'dir':
        success, results = manage.action_dir()
    elif args.action == 'info':
        success, results = manage.action_info(args.endpoint, version)
    elif args.action == 'results':
        success, results = manage.action_results(args.endpoint, version)
    else:
        raise ValueError("Specified action does not exist.")

    print('flame : ', results)
Beispiel #3
0
def manage_cmd(args):
    '''
    Calls diverse model or space maintenance commands
    '''

    version = utils.intver(args.version)

    if args.space is not None or 'searches' in args.action :
    
        import flame.smanage as smanage
    
        if args.action == 'new':
            success, results = smanage.action_new(args.space)
        elif args.action == 'kill':
            success, results = smanage.action_kill(args.space)
        elif args.action == 'remove':
            success, results = smanage.action_remove(args.space, version)
        elif args.action == 'publish':
            success, results = smanage.action_publish(args.space)
        elif args.action == 'list':
            success, results = smanage.action_list(args.space)
        elif args.action == 'parameters':
            success, results = smanage.action_parameters(args.space, version)
        elif args.action == 'info':
            success, results = smanage.action_info(args.space, version)
        elif args.action == 'dir':
            success, results = smanage.action_dir()
        elif args.action == 'searches_result':
            success, results = smanage.action_searches_result(args.label)
        else: 
            success = False
            results = "Specified manage action is not defined"
    else: 

        import flame.manage as manage

        if args.action == 'new':
            success, results = manage.action_new(args.endpoint)
        elif args.action == 'kill':
            success, results = manage.action_kill(args.endpoint)
        elif args.action == 'remove':
            success, results = manage.action_remove(args.endpoint, version)
        elif args.action == 'publish':
            success, results = manage.action_publish(args.endpoint)
        elif args.action == 'list':
            success, results = manage.action_list(args.endpoint)
        elif args.action == 'export':
            success, results = manage.action_export(args.endpoint)
        elif args.action == 'info':
            success, results = manage.action_info(args.endpoint, version)
        elif args.action == 'refresh':
            if args.version == None:
                version = None
            success, results = manage.action_refresh(args.endpoint, version)
        elif args.action == 'series':
            success, results = manage.action_series(args.endpoint, version)         
        elif args.action == 'results':
            success, results = manage.action_results(args.endpoint, version)
        elif args.action == 'parameters':
            success, results = manage.action_parameters(args.endpoint, version)
        elif args.action == 'documentation':
            success, results = manage.action_documentation(args.endpoint,
            version, args.documentation_file)
        elif args.action == 'model_template':
            success, results = manage.action_model_template(args.endpoint, 
            version,  args.documentation_file)
        elif args.action == 'prediction_template':
            success, results = manage.action_prediction_template(args.endpoint, version)
        elif args.action == 'import':
            success, results = manage.action_import(args.infile)
        elif args.action == 'dir':
            success, results = manage.action_dir()
        elif args.action == 'report':
            success, results = manage.action_report()
        elif args.action == 'list':
            success, results = manage.action_list(args.endpoint)
        elif args.action == 'predictions':
            success, results = manage.action_predictions_list()
        elif args.action == 'predictions_result':
            success, results = manage.action_predictions_result(args.label)
        elif args.action == 'predictions_remove':
            success, results = manage.action_predictions_remove(args.label)
        elif args.action == 'label':
            success, results = manage.action_label(args.endpoint, version, args.label)
        else: 
            success = False
            results = "Specified manage action is not defined"

    return success, results
Beispiel #4
0
def main():

    LOG.debug('-------------NEW RUN-------------\n')
    parser = argparse.ArgumentParser(
        description=
        'Use Flame to either build a model from or apply a model to the input file.'
    )

    parser.add_argument('-f', '--infile', help='Input file.', required=False)

    parser.add_argument('-e',
                        '--endpoint',
                        help='Endpoint model name.',
                        required=False)

    parser.add_argument('-v',
                        '--version',
                        help='Endpoint model version.',
                        required=False)

    parser.add_argument('-a',
                        '--action',
                        help='Manage action.',
                        required=False)

    parser.add_argument(
        '-c',
        '--command',
        action='store',
        choices=['predict', 'build', 'manage', 'config'],
        help='Action type: \'predict\' or \'build\' or \'manage\'',
        required=True)

    # parser.add_argument('-log', '--loglevel',
    #                     help='Logger level of verbosity',)

    parser.add_argument('-p',
                        '--path',
                        help='Defines de new path for models repository.',
                        required=False)

    args = parser.parse_args()

    # init logger Level and set general config
    # another way around would be create a handler with the level
    # and append it to the global instance of logger

    # if args.loglevel:
    #     numeric_level = getattr(logging, args.loglevel.upper(), None)
    #     if not isinstance(numeric_level, int):
    #         raise ValueError('Invalid log level: {}'.format(args.loglevel))
    #     logging.basicConfig(level=numeric_level)

    # make sure flame has been configured before running any command, unless this command if used to
    # configure flame
    if args.command != 'config':
        configuration_warning()

    if args.command == 'predict':

        if (args.endpoint is None) or (args.infile is None):
            print(
                'flame predict : endpoint and input file arguments are compulsory'
            )
            return

        version = utils.intver(args.version)

        command_predict = {
            'endpoint': args.endpoint,
            'version': version,
            'infile': args.infile
        }

        LOG.info(f'Starting prediction with model {args.endpoint}'
                 f' version {version} for file {args.infile}')

        success, results = context.predict_cmd(command_predict)
        # print('flame predict : ', success, results)

    elif args.command == 'build':

        if (args.endpoint is None) or (args.infile is None):
            print(
                'flame build : endpoint and input file arguments are compulsory'
            )
            return

        command_build = {'endpoint': args.endpoint, 'infile': args.infile}

        LOG.info(f'Starting building model {args.endpoint}'
                 f' with file {args.infile}')

        success, results = context.build_cmd(command_build)
        # print('flame build : ', success, results)

    elif args.command == 'manage':
        manage_cmd(args)

    elif args.command == 'config':
        config(args.path)
        change_config_status()
Beispiel #5
0
def main():

    LOG.debug('-------------NEW RUN-------------\n')
    parser = argparse.ArgumentParser(
        description=
        f'Flame version {__version__}. Use Flame to build and manage predictive models or to predict using them.'
    )

    parser.add_argument('-f', '--infile', help='Input file.', required=False)

    parser.add_argument('-e',
                        '--endpoint',
                        help='Endpoint model name.',
                        required=False)

    parser.add_argument('-s',
                        '--space',
                        help='Chemical space name.',
                        required=False)

    parser.add_argument('-v',
                        '--version',
                        help='Endpoint model version.',
                        required=False)

    parser.add_argument('-a',
                        '--action',
                        help='Manage action.',
                        required=False)

    parser.add_argument('-p',
                        '--parameters',
                        help='File with parameters for the current action.',
                        required=False)

    parser.add_argument(
        '-c',
        '--command',
        action='store',
        choices=['predict', 'search', 'build', 'sbuild', 'manage', 'config'],
        help=
        'Action type: \'predict\' or \'search\' or \'build\' \'sbuild\' or \'manage\' or \'config\'',
        required=True)

    # parser.add_argument('-log', '--loglevel',
    #                     help='Logger level of verbosity',)

    parser.add_argument(
        '-d',
        '--directory',
        help=
        'Defines the root directory for the models and spaces repositories.',
        required=False)
    parser.add_argument('-t',
                        '--documentation_file',
                        help='File with manually filled documentation fields.',
                        required=False)

    parser.add_argument(
        '-l',
        '--label',
        help='Label for facilitating the identification of the prediction.',
        required=False)

    parser.add_argument(
        '-inc',
        '--incremental',
        help=
        'The input file must be added to the existing training series. Only for "build" command.',
        action='store_true',
        required=False)

    parser.add_argument('--smarts',
                        help='SMARTS string used as input for similarity',
                        required=False)

    args = parser.parse_args()

    # init logger Level and set general config
    # another way around would be create a handler with the level
    # and append it to the global instance of logger

    # if args.loglevel:
    #     numeric_level = getattr(logging, args.loglevel.upper(), None)
    #     if not isinstance(numeric_level, int):
    #         raise ValueError('Invalid log level: {}'.format(args.loglevel))
    #     logging.basicConfig(level=numeric_level)

    if args.infile is not None:
        if not os.path.isfile(args.infile):
            LOG.error(f'Input file {args.infile} not found')
            return

    # make sure flame has been configured before running any command, unless this command if used to
    # configure flame
    if args.command != 'config':
        utils.config_test()

    if args.command == 'predict':

        if (args.endpoint is None) or (args.infile is None):
            LOG.error(
                'flame predict : endpoint and input file arguments are compulsory'
            )
            return

        version = utils.intver(args.version)

        if args.label is None:
            label = 'temp'
        else:
            label = args.label

        command_predict = {
            'endpoint': args.endpoint,
            'version': version,
            'label': label,
            'infile': args.infile
        }

        LOG.info(
            f'Starting prediction with model {args.endpoint}'
            f' version {version} for file {args.infile}, labelled as {label}')

        success, results = context.predict_cmd(command_predict)
        if not success:
            LOG.error(results)

    elif args.command == 'search':

        if (args.space is None) or (args.infile is None
                                    and args.smarts is None):
            LOG.error(
                'flame search : space and input file arguments are compulsory')
            return

        version = utils.intver(args.version)
        if args.label is None:
            label = 'temp'
        else:
            label = args.label

        command_search = {
            'space': args.space,
            'version': version,
            'infile': args.infile,
            'smarts': args.smarts,
            'runtime_param': args.parameters,
            'label': label
        }

        LOG.info(
            f'Starting search on space {args.space}'
            f' version {version} for file {args.infile}, labelled as {label}')

        success, results = context.search_cmd(command_search)

        if not success:
            LOG.error(results)

    elif args.command == 'build':

        if (args.endpoint is None):
            LOG.error('flame build : endpoint argument is compulsory')
            return

        command_build = {
            'endpoint': args.endpoint,
            'infile': args.infile,
            'param_file': args.parameters,
            'incremental': args.incremental
        }

        LOG.info(f'Starting building model {args.endpoint}'
                 f' with file {args.infile} and parameters {args.parameters}')

        success, results = context.build_cmd(command_build)

        if not success:
            LOG.error(results)

    elif args.command == 'sbuild':

        if (args.space is None):
            LOG.error('flame sbuild : space argument is compulsory')
            return

        command_build = {
            'space': args.space,
            'infile': args.infile,
            'param_file': args.parameters
        }

        LOG.info(f'Starting building model {args.space}'
                 f' with file {args.infile} and parameters {args.parameters}')

        success, results = context.sbuild_cmd(command_build)

        if not success:
            LOG.error(results)

    elif args.command == 'manage':
        success, results = context.manage_cmd(args)
        if not success:
            LOG.error(results)

    elif args.command == 'config':
        success, results = config.configure(args.directory,
                                            (args.action == 'silent'))
        if not success:
            LOG.error(f'{results}, configuration unchanged')