def updata_jobtable(tocken,un,pa): #同步云脑数据库job信息 job = models.User_Job.objects.all().order_by("id") job = job.exclude(state="STOPPED").exclude(state="FAIL").exclude(state="SUCCEEDED") for jd in job: print(jd) jd_detail = API_tools.get_jobinfo(jd.jobid,tocken,un,pa) if jd_detail["code"] == "S000": jd.state = jd_detail["payload"]["jobStatus"]["state"] timeStamp2 = int(jd_detail['payload']['jobStatus']["completedTime"]) if timeStamp2 != 0: timeArray2 = time.localtime(timeStamp2 / 1000) otherStyleTime2 = time.strftime("%Y-%m-%d %H:%M:%S", timeArray2) jd.completedTime = otherStyleTime2 jd.save() print("$$$$$$$$ Update Dataset Success")
def insert_train_job(user,job_id,algo=None): res_info=API_tools.get_jobinfo(job_id,"",user.username,user.first_name) job=res_info["payload"] print("RESPONSE JOB INFO: ",res_info) jid=job['id'] if jid != job_id: return ["Job id Error"] createdTime = datetime.datetime.fromtimestamp(job['jobStatus']["completedTime"]/1000) # compeletedTime = createdTime models.customize_job.objects.create( job_id=jid, name=job['name'], state=job['jobStatus']['state'], created_at=createdTime, # completed_at=compeletedTime, uid=user, algo_id=algo, ) return []
def refresh_train_job(user): ''' Args: user: 用户实例 ''' # 以本地数据库的信息为主 un=user.username pa=user.first_name token=API_tools.get_tocken(un,pa) job_list=models.customize_job.objects.all() for rec in job_list: # print("JOB: ", rec.jobid) info=API_tools.get_jobinfo(rec.job_id,token,un,pa) if info['code'] == 'S000': # 存在该任务 job=info['payload'] rec.state = job["jobStatus"]["state"] timeStamp2 = int(job['jobStatus']["completedTime"]) if timeStamp2 == 0: continue rec.completed_at = datetime.datetime.fromtimestamp( timeStamp2/1000 ) rec.save() else: rec=models.customize_job.objects.get(id=rec.id) rec.delete()
def AutoSearch(method:str,hyper:dict,package:dict,api_config:dict,interval:int=60): print("子进程(%s) 开始执行,父进程为(%s)" % (os.getpid(), os.getppid())) time.sleep(5) print("========MISSION REPORT========") print("pid: %s METHOD is: "%(os.getpid()),method) time.sleep(5) print("-"*24) time.sleep(5) print("pid: %s Hypers: "%(os.getpid())) a=[print(k,v) for k,v in enumerate(hyper.items())] print("-"*24) time.sleep(5) print("pid: %s Job config is: "%(os.getpid())) a=[print(k,v) for k,v in package.items()] print("-"*24) time.sleep(5) print("pid: %s Search config is: "%(os.getpid())) a=[print(k,v) for k,v in api_config.items()] print("="*24) return optimizer=None # 【需要字典形式列出的黑盒方法集合】 for ii in range(hyper['epoch']): points=optimizer.suggest(hyper['suggest']) success=[] jobid=[] for jj,point in enumerate(points): # 创建每个建议参数的任务 print(point) param=get_param(package['param'],point) # 【需要知道point的形式】 info=API_tools.mission_submit( job_name="as_"+package['job_name'], project_dir=package['project_dir'], main_file = package['main_file'], param=param, resource=package['resource'], username=package['username'], password=package['password'],) if type(info) != dict or info.__contains__("code") and info["code"]!="S000": print("ERROR: mission creation failed.\n* Epoch:{}, P:{}, {}".format(ii,jj,point)) success.append(False) else: jobid.append(info['payload']['jobId']) success.append(True) if not all(success): print("Some mission failed, exit this search procedure.") break finish=[False]*hyper['suggest'] retry=[10]*hyper['suggest'] stop=False while(all(finish) or stop): for i,jid in enumerate(jobid): info=API_tools.get_jobinfo(jid,username=package['username'],password=package['password']) if info['code'] == 'S000': status=info['payload']['jobStatus']['state'].lower() if status == 'succeeded': finish[i] = True if status == 'waiting': pass if status == 'running': pass if status == 'failed': stop=True if status == 'stopped': stop=True else: retry[i]-=1 if stop : break stop=any([x<0 for x in retry]) time.sleep(interval) if all(finish) and not stop: ylist=get_result(package['username'],hyper['result']) optimizer.observe(points,ylist)