def cmd_gen(args): if args.version: yield 'version' elif args.execute: yield args.execute else: res = parse_addr(args.addr, default_port=8077) hosts = ['{}:{}'.format(res['host'], res['port'])] config = { 'hosts': hosts, } loud = Loud(**config) if not loud.ping(): logging.error("%s: connect: connection refused", args.addr) logging.error( "Please check your connection settings and ensure 'loudmld' is running." ) # noqa sys.exit(2) print('Connected to {} version {}'.format(args.addr, loud.version())) print('Loud ML shell {}'.format( pkg_resources.require("loudml-python")[0].version)) while True: r = input('> ').strip() if len(r): yield r
async def exec(self, args): loud = Loud(**self.config) if args.data: fd = open(args.data) else: fd = sys.stdin points = json.load(fd) fd.close() for job in tqdm(loud.buckets.write( bucket_name=args.bucket_name, points=points, batch_size=args.batch_size, ), total=math.ceil(len(points) / args.batch_size)): def cancel_job_handler(*args): job.cancel() print('Signal received. Canceled job: ', job.id) sys.exit() saved_sigint_handler = signal.getsignal(signal.SIGINT) signal.signal(signal.SIGINT, cancel_job_handler) while not job.done(): time.sleep(1) job.fetch() signal.signal(signal.SIGINT, saved_sigint_handler)
async def exec(self, args): if not args.from_date: raise LoudMLException("'from' argument is required") if not args.to_date: raise LoudMLException("'to' argument is required") loud = Loud(**self.config) job_name = loud.models.eval_model( model_name=args.model_name, input_bucket=args.input, output_bucket=args.output if args.save else None, _from=args.from_date, _to=args.to_date, save_output_data=args.save, flag_abnormal_data=args.anomalies, ) if args.bg: print(job_name) else: job = loud.jobs.id(job_name) poll_job(job) if job.success() and not self.quiet: out = job.fetch_result() for line in format_buckets(out): print(line)
async def exec(self, args): if not args.from_date: raise LoudMLException("'from' argument is required") if not args.to_date: raise LoudMLException("'to' argument is required") constraint = parse_constraint(args.constraint) if args.constraint \ else None loud = Loud(**self.config) job_name = loud.models.forecast( model_name=args.model_name, input_bucket=args.input, output_bucket=args.output if args.save else None, save_output_data=args.save, _from=args.from_date, _to=args.to_date, constraint=constraint, p_val=args.p_val, ) if args.bg: print(job_name) else: job = loud.jobs.id(job_name) poll_job(job) if job.success() and not self.quiet: out = job.fetch_result() for line in format_buckets(out): print(line)
async def exec(self, args): loud = Loud(**self.config) templates = loud.templates.get() if args.show_all: print(yaml.dump(templates, indent=2)) else: print('\n'.join([tmpl['name'] for tmpl in templates]))
async def exec(self, args): loud = Loud(**self.config) _ = loud.models.get_latent_data( model_name=args.model_name, _from=args.from_date, _to=args.to_date, )
async def exec_all(self, args): loud = Loud(**self.config) for model in loud.models.generator( fields=['settings'], include_fields=True, ): args.model_name = model['settings']['name'] self.exec(args)
async def exec(self, args): loud = Loud(**self.config) settings = self.load_scheduled_job_file(args.scheduled_job_file) if args.force and loud.scheduled_jobs.exists(settings.get('name')): loud.scheduled_jobs.delete(settings.get('name')) loud.scheduled_jobs.create(settings=settings)
async def exec(self, args): loud = Loud(**self.config) settings = self._load_model_json(args.model_file) if args.force and loud.templates.exists(args.template_name): loud.templates.delete(args.template_name) loud.templates.create(settings, args.template_name)
async def exec(self, args): loud = Loud(**self.config) buckets = loud.buckets.get(bucket_names=[args.bucket_name], ) if not len(buckets): print('Not found:', args.bucket_name) exit(1) print(yaml.dump(buckets, indent=2))
async def exec(self, args): loud = Loud(**self.config) settings = self.load_bucket_file(args.bucket_file) if args.force and loud.buckets.exists(settings.get('name')): loud.buckets.delete(settings.get('name')) loud.buckets.create(settings)
async def exec(self, args): loud = Loud(**self.config) jobs = list( loud.jobs.generator( fields=['result'], include_fields=False, )) for line in format_jobs(jobs): print(line)
async def exec(self, args): loud = Loud(**self.config) if args.template_name is not None: settings = self._load_model_json(args.model_file) else: settings = self.load_model_file(args.model_file) if args.force and loud.models.exists(settings.get('name')): loud.models.delete(settings.get('name')) loud.models.create(settings=settings, from_template=args.template_name)
async def exec(self, args): loud = Loud(**self.config) if args.show_all: scheduled_jobs = list( loud.scheduled_jobs.generator( fields=None, include_fields=None, )) print(yaml.dump(scheduled_jobs, indent=2)) else: for scheduled_job in loud.scheduled_jobs.generator( fields=['name'], include_fields=True, ): print(scheduled_job['name'])
async def exec(self, args): loud = Loud(**self.config) if args.show_all: models = list( loud.models.generator( fields=None, include_fields=None, )) print(yaml.dump(models, indent=2)) else: for model in loud.models.generator( fields=['state'], include_fields=False, ): print(model['settings']['name'])
async def exec(self, args): loud = Loud(**self.config) if args.show_all: buckets = list( loud.buckets.generator( fields=None, include_fields=None, )) print(yaml.dump(buckets, indent=2)) else: for bucket in loud.buckets.generator( fields=['name'], include_fields=True, ): print(bucket['name'])
async def exec(self, args): loud = Loud(**self.config) if args.show_all: include_fields = None fields = None else: include_fields = False fields = ['state'] models = loud.models.get( model_names=[args.model_name], fields=fields, include_fields=include_fields, ) if not len(models): print('Not found:', args.model_name) exit(1) print(yaml.dump(models, indent=2))
async def exec(self, args): loud = Loud(**self.config) if args.show_all: include_fields = None fields = None else: include_fields = True fields = ['state', 'version'] models = loud.models.versions.get( model_name=args.model_name, fields=fields, include_fields=include_fields, ) if not len(models): print('Not found:', args.model_name) exit(1) if args.show_all: print(yaml.dump(models, indent=2)) else: for line in format_model_versions(models): print(line)
async def exec(self, args): if not args.from_date: raise LoudMLException("'from' argument is required") if not args.to_date: raise LoudMLException("'to' argument is required") loud = Loud(**self.config) job_name = loud.buckets.read( bucket_name=args.bucket_name, _from=args.from_date, _to=args.to_date, bucket_interval=args.bucket_interval, features=args.features, ) if args.bg: print(job_name) else: job = loud.jobs.id(job_name) poll_job(job) if job.success() and not self.quiet: out = job.fetch_result() for line in format_buckets(out): print(line)
async def exec(self, args): if args.model_name == '*': return self.exec_all(args) if not args.from_date: raise LoudMLException("'from' argument is required", ) if not args.to_date: raise LoudMLException("'to' argument is required", ) loud = Loud(**self.config) job_name = loud.models.train( model_name=args.model_name, _from=args.from_date, _to=args.to_date, max_evals=args.max_evals, epochs=args.epochs, _continue=args.resume_training, ) if not job_name: print("Failed to start job") exit(1) if args.bg: print(job_name) else: job = loud.jobs.id(job_name) poll_job(job)
async def exec(self, args): loud = Loud(**self.config) loud.scheduled_jobs.delete(args.scheduled_job_name)
async def exec(self, args): loud = Loud(**self.config) loud.templates.delete(args.template_name)
async def exec(self, args): loud = Loud(**self.config) loud.models.stop_inference(model_names=[args.model_name])
async def exec(self, args): loud = Loud(**self.config) loud.models.start_inference(model_names=[args.model_name], save_output_data=True, flag_abnormal_data=True)
async def exec(self, args): loud = Loud(**self.config) loud.models.delete(args.model_name)
async def exec(self, args): loud = Loud(**self.config) loud.models.versions.load(model_name=args.model_name, version=args.version_name)
async def exec(self, args): loud = Loud(**self.config) loud.buckets.clear(bucket_name=args.bucket_name, )
async def exec(self, args): loud = Loud(**self.config) print(loud.version())
async def exec(self, args): loud = Loud(**self.config) loud.jobs.cancel_jobs(job_names=[args.job_id])
async def exec(self, args): loud = Loud(**self.config) loud.buckets.delete(args.bucket_name)