def PHC_View(Uid, poly_id, report, formt): file_id = get_file_id(Uid, poly_id) if not os.path.isfile(file_id + ".maple") or not os.path.isfile(file_id + ".python"): data = PHC_Server(Uid, '6', file_id) if report == '0': Print_Text_File(file_id + ".poly") elif report == '1': PHC_View_Bar(poly_id, formt) if formt == '0': Print_Text_File(file_id + ".sol") elif formt == '1': if not os.path.isfile(file_id + ".python"): print "Not Ready, Please Refresh." else: Print_Text_File(file_id + ".python") elif formt == '2': if not os.path.isfile(file_id + ".maple"): print "Not Ready, Please Refresh." else: Print_Text_File(file_id + ".maple") elif report == '2': Print_Text_File(file_id + ".phc") else: print report + ": not such option"
def PHC_Update(Uid, Pid, poly_id, phcdb, sol_page=0): from os import path if poly_id == '': Print_Poly_Empty(Uid) else: file_id = get_file_id(Uid, poly_id) if check_file_exist(file_id + ".poly"): Print_Notice_Top() status = PHC_Status(Uid, poly_id, file_id, phcdb) Print_Area_Eq(file_id + ".poly") if path.isfile(file_id + ".err"): phcdb.userstatus(Uid, "NULL") Print_Button_Status(status, Uid, Pid, poly_id) Print_Notice_Mid(status, Uid, poly_id) elif status == 1: # being computed Print_Button_Status(status, Uid, Pid, poly_id) Print_Notice_Mid(status, Uid, poly_id) elif status == 0: # killed Print_Button_Status(status, Uid, Pid, poly_id) Print_Notice_Mid(status, Uid, poly_id) Print_Report(status, file_id, Uid, poly_id) else: # Just Solved phcdb.userstatus(Uid, "NULL") phcdb.slvpoly2(Uid, poly_id) Print_Button_Status(status, Uid, Pid, poly_id) Print_Notice_Mid(status, Uid, poly_id) Print_Report(status, file_id, Uid, poly_id, sol_page) else: Print_Poly_Empty(Uid) if poly_id == "current": phcdb.userstatus(Uid, "NULL")
def PHC_Update(Uid,Pid,poly_id,phcdb, sol_page=0): from os import path if poly_id == '': Print_Poly_Empty(Uid) else: file_id = get_file_id(Uid, poly_id) if check_file_exist(file_id+".poly"): Print_Notice_Top() status = PHC_Status(Uid, poly_id, file_id, phcdb) Print_Area_Eq(file_id+".poly") if path.isfile(file_id+".err"): phcdb.userstatus(Uid, "NULL") Print_Button_Status(status, Uid, Pid, poly_id) Print_Notice_Mid(status, Uid, poly_id) elif status == 1: # being computed Print_Button_Status(status, Uid, Pid, poly_id) Print_Notice_Mid(status, Uid, poly_id) elif status == 0: # killed Print_Button_Status(status, Uid, Pid, poly_id) Print_Notice_Mid(status, Uid, poly_id) Print_Report(status, file_id, Uid, poly_id) else: # Just Solved phcdb.userstatus(Uid, "NULL") phcdb.slvpoly2(Uid, poly_id) Print_Button_Status(status, Uid, Pid, poly_id) Print_Notice_Mid(status, Uid, poly_id) Print_Report(status, file_id, Uid, poly_id, sol_page) else: Print_Poly_Empty(Uid) if poly_id == "current": phcdb.userstatus(Uid, "NULL")
def slvpoly2(self, Uid, poly_id): from phc_file import Deg_Sols, solve_time, get_file_id file_id = get_file_id(Uid, poly_id) sols, deg = Deg_Sols(file_id) slvtime = solve_time(file_id) commd = "Update polys SET Status = 2, Sols = %d, Time ='%s' WHERE Uid = '%s' and Name = '%s';" %(sols, slvtime, Uid, poly_id) self.run_commd(commd) return 0
def slvpoly2(self, Uid, poly_id): from phc_file import Deg_Sols, solve_time, get_file_id file_id = get_file_id(Uid, poly_id) sols, deg = Deg_Sols(file_id) slvtime = solve_time(file_id) commd = "Update polys SET Status = 2, Sols = %d, Time ='%s' WHERE Uid = '%s' and Name = '%s';" % ( sols, slvtime, Uid, poly_id) self.run_commd(commd) return 0
def phc_kill(self, Uid, msg, poly_id=''): if poly_id == '': poly_id = 'current' print 'Before kill:\n' print processes() file_id = get_file_id(Uid, poly_id) pid = self.get_pid(Uid, poly_id, file_id) if pid != '': PHC_Kill(pid, file_id) print 'After kill:\n' print processes() else: print "No process to kill. The process has not started."
def phc_kill(self, Uid, msg, poly_id = ''): if poly_id == '': poly_id = 'current' print 'Before kill:\n' print processes() file_id = get_file_id(Uid, poly_id) pid = self.get_pid(Uid, poly_id, file_id) if pid !='': PHC_Kill(pid, file_id) print 'After kill:\n' print processes() else: print "No process to kill. The process has not started."
def PHC_Edit_Hom(Uid,form): poly_id = form['poly_id'].value file_id = get_file_id(Uid, poly_id) if not path.isfile(file_id+".start"): data = PHC_Server(Uid, '7', poly_id) if data != 0 and path.isfile(file_id+".start"): Print_Poly_File_New(Uid, poly_id, 1) else: Print_Poly_File_New(Uid, poly_id, 0) print """<p><font color='red'><b>Error:</b> the original system doesn't have a start system. Please just solve it directly.</font></p>""" else: Print_Poly_File_New(Uid, poly_id, 1)
def PHC_Edit_Hom(Uid, form): poly_id = form['poly_id'].value file_id = get_file_id(Uid, poly_id) if not path.isfile(file_id + ".start"): data = PHC_Server(Uid, '7', poly_id) if data != 0 and path.isfile(file_id + ".start"): Print_Poly_File_New(Uid, poly_id, 1) else: Print_Poly_File_New(Uid, poly_id, 0) print """<p><font color='red'><b>Error:</b> the original system doesn't have a start system. Please just solve it directly.</font></p>""" else: Print_Poly_File_New(Uid, poly_id, 1)
def Print_Poly_File_New(Uid, poly_id, homotopy=0): from phc_file import get_file_id file_id = get_file_id(Uid, poly_id) Print_Notice_Top() print """<form name="textform" method="post" action="phcweb.py">""" Print_Area_File("%s.poly" % file_id, "poly") if homotopy == 0: Print_Solve_Button(Uid) else: Print_Solve_Button(Uid, hom=poly_id) Print_Start_Eq(file_id) print "</form>"
def Print_Poly_Preview(Uid, poly, homotopy=0, poly_id=''): Print_Notice_Top() print """<form name="textform" method="post" action="phcweb.py">""" Print_Area_Preview(poly, "poly_preview") if homotopy == 0: Print_Solve_Button(Uid, poly) else: from phc_file import get_file_id file_id = get_file_id(Uid, poly_id) Print_Solve_Button(Uid, poly=poly, hom=poly_id) Print_Start_Eq(file_id) print "</form>"
def Print_Status(status, Uid, name): from os import path from phc_file import get_file_id file_id = get_file_id(Uid, name) print """<table><tr><td>Status:</td>""" if status == 0: print """<td><b>Killed</b></td></tr><td></td> <td>Check the following phc report before killed.""" file_name = "../users/%s/%s" % (Uid, name + ".phc") if path.isfile(file_name): print """Download PHC detailed report <a href="%s" target="_blank"> %s </a>.""" % (file_name, name + ".phc") print "</td></tr>" elif status == 1: print """<td><b>Computing</b></td></tr><tr><td></td><td> <p>Your polynomial has been submitted and is being solved.</p> Notice: You can only solve one polynomial each time. If you want to solve a new one, you have to kill current computation first.""" elif status == 2: if name == "current": print """<td><b>Solved</b>""" else: print """<td><b>Saved as %s</b>""" % name print """</td></tr><tr><td></td> <td><div>Download solutions <a href="../users/%s/%s" target="_blank"> %s </a>. </div> <div>Download PHC detailed report <a href="../users/%s/%s" target="_blank"> %s </a>.</div> </td></tr>""" % ( Uid, name + ".sol", name + ".sol", Uid, name + ".phc", name + ".phc", ) elif status == 9: print "<td><b>Error:</b></td></tr> <tr><td></td><td>The input polynomial has something wrong. Please check the following report:</td></tr><tr><td></td><td>" if path.isfile(file_id + ".err"): f = open(file_id + ".err", "r") for line in f: if line == "\n": print "</br>" else: print line print "</td></tr>" else: print """<td>Status report does not exist.</td>""" print "</table>"
def Print_Poly_Preview(Uid, poly, homotopy=0, poly_id=""): Print_Notice_Top() print """<form name="textform" method="post" action="phcweb.py">""" Print_Area_Preview(poly, "poly_preview") if homotopy == 0: Print_Solve_Button(Uid, poly) else: from phc_file import get_file_id file_id = get_file_id(Uid, poly_id) Print_Solve_Button(Uid, poly=poly, hom=poly_id) Print_Start_Eq(file_id) print "</form>"
def read_poly_client_msg(self): # Use 2st digit to identify client self.client_opt self.client_opt = self.rfile.read(1) # identify client id self.client_id = self.rfile.read(client_id_len) # buffer size to be changed # Save the message messg = self.rfile.read(buffer - client_id_len - 2).strip() if "||" in messg: [self.poly_id, self.client_msg] = messg.split("||") else: self.poly_id = "current" self.client_msg = messg self.job_key = self.client_id + "/" + self.poly_id self.file_id = get_file_id(self.client_id, self.poly_id) # print client information and message self.print_poly_client_msg()
def read_poly_client_msg(self): # Use 2st digit to identify client self.client_opt self.client_opt = self.rfile.read(1) # identify client id self.client_id = self.rfile.read( client_id_len) # buffer size to be changed # Save the message messg = self.rfile.read(buffer - client_id_len - 2).strip() if '||' in messg: [self.poly_id, self.client_msg] = messg.split('||') else: self.poly_id = 'current' self.client_msg = messg self.job_key = self.client_id + '/' + self.poly_id self.file_id = get_file_id(self.client_id, self.poly_id) # print client information and message self.print_poly_client_msg()
def Print_Status(status, Uid, name): from os import path from phc_file import get_file_id file_id = get_file_id(Uid, name) print """<table><tr><td>Status:</td>""" if status == 0: print """<td><b>Killed</b></td></tr><td></td> <td>Check the following phc report before killed.""" file_name = "../users/%s/%s" % (Uid, name + ".phc") if path.isfile(file_name): print """Download PHC detailed report <a href="%s" target="_blank"> %s </a>.""" % ( file_name, name + ".phc") print "</td></tr>" elif status == 1: print """<td><b>Computing</b></td></tr><tr><td></td><td> <p>Your polynomial has been submitted and is being solved.</p> Notice: You can only solve one polynomial each time. If you want to solve a new one, you have to kill current computation first.""" elif status == 2: if name == "current": print """<td><b>Solved</b>""" else: print """<td><b>Saved as %s</b>""" % name print """</td></tr><tr><td></td> <td><div>Download solutions <a href="../users/%s/%s" target="_blank"> %s </a>. </div> <div>Download PHC detailed report <a href="../users/%s/%s" target="_blank"> %s </a>.</div> </td></tr>""" % (Uid, name + ".sol", name + ".sol", Uid, name + ".phc", name + ".phc") elif status == 9: print "<td><b>Error:</b></td></tr> <tr><td></td><td>The input polynomial has something wrong. Please check the following report:</td></tr><tr><td></td><td>" if path.isfile(file_id + ".err"): f = open(file_id + ".err", 'r') for line in f: if line == '\n': print "</br>" else: print line print "</td></tr>" else: print """<td>Status report does not exist.</td>""" print "</table>"
def polyclient_newhom(self): # check whether polynomial system is efficient rm_all_exts(self.file_id) newpoly = [self.client_opt, self.client_id, self.client_msg] self.client_msg = self.client_msg.split('|') if len(self.client_msg) == 1: file_id_start = get_file_id(self.client_id, self.client_msg[0]) if not path.isfile(file_id_start + ".start"): phc_start(file_id_start) self.msg = 'homotopy start system generated' else: with open('%s.poly' % self.file_id, 'w') as f: f.write(self.client_msg[2]) f.close() # distribute job to small or large queue worker_ind, deg = self.job_distributor() if worker_ind == 0: phcdb.delpoly(self.client_id, self.poly_id) with open('%s.err' % self.file_id, 'r') as f: self.msg = f.read() + "received" else: print "**********%s" % deg rm_exts(self.file_id, 'err') with open('%s.sta' % self.file_id, 'w') as f: f.write('submitted') f.close() queue_local.put(newpoly) self.msg = 'homotopy received' # update userstatus to computing phcdb.delpoly(self.client_id, self.poly_id) phcdb.newpoly(self.client_id, self.poly_id, deg, path.getctime('%s.poly' % self.file_id))
def polyclient_newhom(self): # check whether polynomial system is efficient rm_all_exts(self.file_id) newpoly = [self.client_opt, self.client_id, self.client_msg] self.client_msg = self.client_msg.split("|") if len(self.client_msg) == 1: file_id_start = get_file_id(self.client_id, self.client_msg[0]) if not path.isfile(file_id_start + ".start"): phc_start(file_id_start) self.msg = "homotopy start system generated" else: with open("%s.poly" % self.file_id, "w") as f: f.write(self.client_msg[2]) f.close() # distribute job to small or large queue worker_ind, deg = self.job_distributor() if worker_ind == 0: phcdb.delpoly(self.client_id, self.poly_id) with open("%s.err" % self.file_id, "r") as f: self.msg = f.read() + "received" else: print "**********%s" % deg rm_exts(self.file_id, "err") with open("%s.sta" % self.file_id, "w") as f: f.write("submitted") f.close() queue_local.put(newpoly) self.msg = "homotopy received" # update userstatus to computing phcdb.delpoly(self.client_id, self.poly_id) phcdb.newpoly(self.client_id, self.poly_id, deg, path.getctime("%s.poly" % self.file_id))
def PHC_View(Uid, poly_id, report, formt): file_id = get_file_id(Uid, poly_id) if not os.path.isfile(file_id+".maple") or not os.path.isfile(file_id+".python") : data = PHC_Server(Uid,'6',file_id) if report == '0': Print_Text_File(file_id+".poly") elif report == '1': PHC_View_Bar(poly_id, formt) if formt == '0': Print_Text_File(file_id+".sol") elif formt == '1': if not os.path.isfile(file_id+".python"): print "Not Ready, Please Refresh." else: Print_Text_File(file_id+".python") elif formt == '2': if not os.path.isfile(file_id+".maple"): print "Not Ready, Please Refresh." else: Print_Text_File(file_id+".maple") elif report == '2': Print_Text_File(file_id+".phc") else: print report + ": not such option"