예제 #1
0
 def download(self, url, cookie=None):
   suffix = os.path.splitext(urlparse.urlsplit(url)[2])[1]
   fd, filename = tempfile.mkstemp(suffix=suffix, dir=self.dir)
   os.close(fd)
   with timer.print_time('Downloading', url, 'to', filename):
     opener = urllib2.build_opener()
     if cookie:
       opener.addheaders.append(('Cookie', cookie))
     num_tries = 2
     for i in range(num_tries):
       try:
         f = opener.open(url)
       except urllib2.URLError, e:
         print('Failed to open url', url)
         continue
       length = f.headers.get('content-length')
       if not length:
         print('Failed to get content-length')
         continue
       length = int(length)
       with open(filename, 'wb') as out:
         count = 0
         while count < length:
           data = f.read(1024 * 1024)
           count += len(data)
           out.write(data)
예제 #2
0
파일: test_timer.py 프로젝트: anhtuan98/mp
 def test_print_time(self):
   stdout = util.CaptureStdout()
   with stdout:
     with print_time('doing', 'something'):
       do_something()
   self.assertEqual(
     'doing something\ndoing something finished in 0.01 second(s)\n',
     stdout.str())
예제 #3
0
def package(basename, archive_format, package_dir):
  with timer.print_time('Creating', basename, 'package'):
    if archive_format == 'gztar':
      # Use command-line tar instead of shutil.make_archive because the
      # latter is too slow.
      archive = os.path.join(os.getcwd(), basename + '.tar.gz')
      command = ['tar', 'czf', archive] + os.listdir(package_dir)
      subprocess.check_call(command, cwd=package_dir)
    else:
      shutil.make_archive(basename, archive_format, package_dir, '.')
예제 #4
0
def install_mingw(arch):
  bits = '64' if arch.endswith('64') else '32'
  if os.path.exists(r'\mingw' + bits):
    return
  with download(
      'http://sourceforge.net/projects/mingw-w64/files/' +
      'Toolchains%20targetting%20Win' + bits + '/Personal%20Builds/' +
      'mingw-builds/4.8.2/threads-win32/sjlj/' + arch +
      '-4.8.2-release-win32-sjlj-rt_v3-rev4.7z/download') as f:
    with timer.print_time("Installing MinGW" + bits):
      output = check_output([sevenzip, 'x', '-oC:\\', f])
      for line in output.split('\n'):
        if not line.startswith('Extracting '):
          print(line)
예제 #5
0
        total_loss += loss
        #total_success += info
        
    
    if cur_mode != 'test':
        agent.update_target()
        #if (i%100)==0:
        #    agent.saver.save(agent.sess, "./net/"+cur_policy+"/iter_{}.ckpt".format(i))

    avg_return_list.append(total_reward)
    avg_loss_list.append(total_loss)
    avg_success_list.append(total_success)

    #print("vvvvvvvvvvvv")
    #print(vv)
    #timer.print_time()
    
    if (np.mean(avg_return_list) > 490):
        print('{} loss : {:.3f}, return : {:.3f}, success : {:.3f}, eps : {:.3f}'.format(i, np.mean(avg_loss_list), np.mean(avg_return_list), np.mean(avg_success_list), agent.epsilon))
        print('The problem is solved with {} episodes'.format(i))
        #if cur_mode != 'test':
        #    agent.saver.save(agent.sess, "./net/"+cur_policy+"/iter_{}.ckpt".format(i))
        break
    
    if (i%10)==0:
        result_saver.append({'i':i,'visit':vv,'loss':np.mean(avg_loss_list),'return':np.mean(avg_return_list),'success':np.mean(avg_success_list),'eps':agent.epsilon})
        np.save(cur_policy + '_result.npy',result_saver)
        timer.print_time()
        print('{} loss : {:.3f}, return : {:.3f}, success : {:.3f}, eps : {:.3f}'.format(i, np.mean(avg_loss_list), np.mean(avg_return_list), np.mean(avg_success_list), agent.epsilon))