def post(self, request): """ Set flame configuration (path to models, predictions and spaces) """ newpath = request.POST.get('newpath') flame_status = config.configure(newpath, silent=True) if flame_status[0]: return Response(flame_status[0], status=status.HTTP_200_OK) else: return JsonResponse({'error': flame_status[1]}, status=status.HTTP_404_NOT_FOUND)
def get(self, request): """ Retrieve flame configuration """ flame_status = config.configure(None, silent=False) if flame_status[0]: model_path = flame_status[1]['model_repository_path'] root_path = os.path.split(model_path)[0] return Response((root_path, flame_status[1]), status=status.HTTP_200_OK) else: return JsonResponse({'error': flame_status[1]}, status=status.HTTP_404_NOT_FOUND)
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')