Пример #1
0
    def dump_tabular(self):
        """
        Write all of the diagnostics from the current iteration
        """
        if (MPIUtil.is_root_proc()):
            if (self.first_row):
                self._dump_str_template = self._build_str_template()

            vals = []
            for key in self.log_headers:
                val = self.log_current_row.get(key, "")
                vals.append(val)

            if self.output_file is not None:
                if self.first_row:
                    header_str = self._dump_str_template.format(
                        *self.log_headers)
                    self.output_file.write(header_str + "\n")

                val_str = self._dump_str_template.format(*map(str, vals))
                self.output_file.write(val_str + "\n")
                self.output_file.flush()

        self.log_current_row.clear()
        self.first_row = False
        return
Пример #2
0
  def dump_tabular(self):
    """
        Write all of the diagnostics from the current iteration
        """
    if (MPIUtil.is_root_proc()):
      if (self.first_row):
        self._dump_str_template = self._build_str_template()

      vals = []
      for key in self.log_headers:
        val = self.log_current_row.get(key, "")
        vals.append(val)

      if self.output_file is not None:
        if self.first_row:
          header_str = self._dump_str_template.format(*self.log_headers)
          self.output_file.write(header_str + "\n")

        val_str = self._dump_str_template.format(*map(str, vals))
        self.output_file.write(val_str + "\n")
        self.output_file.flush()

    self.log_current_row.clear()
    self.first_row = False
    return
Пример #3
0
 def check_synced(self):
   synced = True
   if MPIUtil.is_root_proc():
     vars = np.concatenate([self.mean, self.mean_sq])
     MPIUtil.bcast(vars)
   else:
     vars_local = np.concatenate([self.mean, self.mean_sq])
     vars_root = np.empty_like(vars_local)
     MPIUtil.bcast(vars_root)
     synced = (vars_local == vars_root).all()
   return synced
Пример #4
0
 def check_synced(self):
     synced = True
     if MPIUtil.is_root_proc():
         vars = np.concatenate([self.mean, self.mean_sq])
         MPIUtil.bcast(vars)
     else:
         vars_local = np.concatenate([self.mean, self.mean_sq])
         vars_root = np.empty_like(vars_local)
         MPIUtil.bcast(vars_root)
         synced = (vars_local == vars_root).all()
     return synced
Пример #5
0
    def configure_output_file(self, filename=None):
        """
        Set output directory to d, or to /tmp/somerandomnumber if d is None
        """
        self.first_row = True
        self.log_headers = []
        self.log_current_row = {}

        output_path = filename or "output/log_%i.txt" % int(time.time())

        out_dir = os.path.dirname(output_path)
        if not os.path.exists(out_dir) and MPIUtil.is_root_proc():
            os.makedirs(out_dir)

        if (MPIUtil.is_root_proc()):
            self.output_file = open(output_path, 'w')
            assert osp.exists(output_path)
            atexit.register(self.output_file.close)

            Logger.print2("Logging data to " + self.output_file.name)
        return
Пример #6
0
  def configure_output_file(self, filename=None):
    """
        Set output directory to d, or to /tmp/somerandomnumber if d is None
        """
    self.first_row = True
    self.log_headers = []
    self.log_current_row = {}

    output_path = filename or "output/log_%i.txt" % int(time.time())

    out_dir = os.path.dirname(output_path)
    if not os.path.exists(out_dir) and MPIUtil.is_root_proc():
      os.makedirs(out_dir)

    if (MPIUtil.is_root_proc()):
      self.output_file = open(output_path, 'w')
      assert osp.exists(output_path)
      atexit.register(self.output_file.close)

      Logger.print2("Logging data to " + self.output_file.name)
    return
Пример #7
0
 def print_tabular(self):
     """
     Print all of the diagnostics from the current iteration
     """
     if (MPIUtil.is_root_proc()):
         vals = []
         Logger.print2("-" * 37)
         for key in self.log_headers:
             val = self.log_current_row.get(key, "")
             if isinstance(val, float):
                 valstr = "%8.3g" % val
             elif isinstance(val, int):
                 valstr = str(val)
             else:
                 valstr = val
             Logger.print2("| %15s | %15s |" % (key, valstr))
             vals.append(val)
         Logger.print2("-" * 37)
     return
Пример #8
0
 def print_tabular(self):
   """
       Print all of the diagnostics from the current iteration
       """
   if (MPIUtil.is_root_proc()):
     vals = []
     Logger.print2("-" * 37)
     for key in self.log_headers:
       val = self.log_current_row.get(key, "")
       if isinstance(val, float):
         valstr = "%8.3g" % val
       elif isinstance(val, int):
         valstr = str(val)
       else:
         valstr = val
       Logger.print2("| %15s | %15s |" % (key, valstr))
       vals.append(val)
     Logger.print2("-" * 37)
   return
Пример #9
0
 def _enable_int_output(self):
     return MPIUtil.is_root_proc() and self.int_output_dir != ""
Пример #10
0
 def print2(str):
     if (MPIUtil.is_root_proc()):
         print(str)
     return
Пример #11
0
 def _is_root(self):
   return MPIUtil.is_root_proc()
Пример #12
0
 def print2(str):
   if (MPIUtil.is_root_proc()):
     print(str)
   return
Пример #13
0
 def _enable_int_output(self):
     return MPIUtil.is_root_proc() and self.int_output_dir != ""
Пример #14
0
 def _is_root(self):
     return MPIUtil.is_root_proc()