Esempio n. 1
0
   def polyfile_homotopy(self, Uid, msg):
      from phc_file import rm_exts, phc_start
      from os import path
      
      [poly_id, poly_id_start, poly_data] = msg.split('|')
      
      # Generate poly file
      file_id = "../users/%s/%s" %(Uid, poly_id)

      exts = ['cmd', 'sol','phc']
      rm_exts(file_id,exts)

      print "msg = %s"% msg
   
      # Generate start system file from phc file         
      file_id_start= "../users/%s/%s" %(Uid, poly_id_start)
      
      rm_exts(file_id_start, ['cmd'])
      
      if not path.isfile(file_id_start+".start"):
         phc_start(file_id_start)
      
      with open('%s.cmd'%file_id_start, 'w') as f:
         f.write("y\n%s.sol\n%s.start\n0\n0\n0\n0\n"%(file_id, file_id_start))
      f.close()
      
      return file_id, file_id_start
Esempio n. 2
0
    def polyfile_homotopy(self, Uid, msg):
        from phc_file import rm_exts, phc_start
        from os import path

        [poly_id, poly_id_start, poly_data] = msg.split('|')

        # Generate poly file
        file_id = "../users/%s/%s" % (Uid, poly_id)

        exts = ['cmd', 'sol', 'phc']
        rm_exts(file_id, exts)

        print "msg = %s" % msg

        # Generate start system file from phc file
        file_id_start = "../users/%s/%s" % (Uid, poly_id_start)

        rm_exts(file_id_start, ['cmd'])

        if not path.isfile(file_id_start + ".start"):
            phc_start(file_id_start)

        with open('%s.cmd' % file_id_start, 'w') as f:
            f.write("y\n%s.sol\n%s.start\n0\n0\n0\n0\n" %
                    (file_id, file_id_start))
        f.close()

        return file_id, file_id_start
Esempio n. 3
0
 def polyfile(self, Uid, msg, poly_id):
    from phc_file import rm_exts
    file_id = "../users/%s/%s" %(Uid, poly_id)
    
    exts = ['cmd','sol','phc','err']
    rm_exts(file_id,exts)
    
    with open( file_id+'.sol', 'w') as f:
       f.write(msg)
       f.close()
    
    return file_id
Esempio n. 4
0
    def polyfile(self, Uid, msg, poly_id):
        from phc_file import rm_exts
        file_id = "../users/%s/%s" % (Uid, poly_id)

        exts = ['cmd', 'sol', 'phc', 'err']
        rm_exts(file_id, exts)

        with open(file_id + '.sol', 'w') as f:
            f.write(msg)
            f.close()

        return file_id
Esempio n. 5
0
    def polyclient_newpoly(self):
        """
      polyclient to submit new poly
      """
        if self.client_id in Usersolver:
            self.msg = "one polynomial is being solved"
        else:
            # check whether polynomial system is efficient
            rm_all_exts(self.file_id)
            phcdb.delpoly(self.client_id, self.poly_id)

            with open('%s.poly' % self.file_id, 'w') as f:
                f.write(self.client_msg)
                f.close()

            start_time = time()
            # distribute job to small or large queue
            worker_ind, deg = self.job_distributor()
            end_time = time()
            time_cost = end_time - start_time
            print "check_time = %f" % time_cost
            poly_status = '1'
            if worker_ind == 0:
                with open('%s.err' % self.file_id, 'r') as f:
                    self.msg = f.read() + "received"
                poly_status = '9'
            else:
                rm_exts(self.file_id, 'err')
                with open('%s.sta' % self.file_id, 'w') as f:
                    f.write('submitted')
                    f.close()

                newpoly = [self.client_opt, self.client_id, self.client_msg]
                if worker_ind == 1:
                    queue_local.put(newpoly)
                    self.msg = 'small polynomial received'
                else:
                    queue.append(newpoly)
                    self.msg = 'large polynomial received'

            # update userstatus to computing
            phcdb.newpoly(self.client_id, self.poly_id, deg,
                          path.getctime('%s.poly' % self.file_id), poly_status)
Esempio n. 6
0
    def polyclient_newpoly(self):
        """
      polyclient to submit new poly
      """
        if self.client_id in Usersolver:
            self.msg = "one polynomial is being solved"
        else:
            # check whether polynomial system is efficient
            rm_all_exts(self.file_id)
            phcdb.delpoly(self.client_id, self.poly_id)

            with open("%s.poly" % self.file_id, "w") as f:
                f.write(self.client_msg)
                f.close()

            start_time = time()
            # distribute job to small or large queue
            worker_ind, deg = self.job_distributor()
            end_time = time()
            time_cost = end_time - start_time
            print "check_time = %f" % time_cost
            poly_status = "1"
            if worker_ind == 0:
                with open("%s.err" % self.file_id, "r") as f:
                    self.msg = f.read() + "received"
                poly_status = "9"
            else:
                rm_exts(self.file_id, "err")
                with open("%s.sta" % self.file_id, "w") as f:
                    f.write("submitted")
                    f.close()

                newpoly = [self.client_opt, self.client_id, self.client_msg]
                if worker_ind == 1:
                    queue_local.put(newpoly)
                    self.msg = "small polynomial received"
                else:
                    queue.append(newpoly)
                    self.msg = "large polynomial received"

            # update userstatus to computing
            phcdb.newpoly(self.client_id, self.poly_id, deg, path.getctime("%s.poly" % self.file_id), poly_status)
Esempio n. 7
0
    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))
Esempio n. 8
0
    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))