A convenient string representation of how long after the run started we started.

    :API: public
186661
def start_delta_string(self):
    
    delta = int(self.start_time) - int(self.root().start_time)
    return '{:02}:{:02}'.format(int(delta / 60), delta % 60)
241439
def progress_string(self):
        """"""

        if not self.last_result:
            return self._status_string()

        def location_string(hostname, pid):
            if hostname == os.uname()[1]:
                return "pid={}".format(pid)
            else:
                return "{} pid={}".format(hostname, pid)

        pieces = [
            "{}".format(self._status_string()), "[{}]".format(
                self.resources.summary_string()), "[{}]".format(
                    location_string(
                        self.last_result.get(HOSTNAME),
                        self.last_result.get(PID))), "{} s".format(
                            int(self.last_result.get(TIME_TOTAL_S)))
        ]

        if self.last_result.get(TRAINING_ITERATION) is not None:
            pieces.append("{} iter".format(
                self.last_result[TRAINING_ITERATION]))

        if self.last_result.get(TIMESTEPS_TOTAL) is not None:
            pieces.append("{} ts".format(self.last_result[TIMESTEPS_TOTAL]))

        if self.last_result.get(EPISODE_REWARD_MEAN) is not None:
            pieces.append("{} rew".format(
                format(self.last_result[EPISODE_REWARD_MEAN], ".3g")))

        if self.last_result.get(MEAN_LOSS) is not None:
            pieces.append("{} loss".format(
                format(self.last_result[MEAN_LOSS], ".3g")))

        if self.last_result.get(MEAN_ACCURACY) is not None:
            pieces.append("{} acc".format(
                format(self.last_result[MEAN_ACCURACY], ".3g")))

        return ", ".join(pieces)
607384
def after_run(self, run_context, run_values):  # pylint: disable=unused-argument
    
    global_step = run_values.results

    if self._timer.should_trigger_for_step(
        global_step) and global_step > self._warm_steps:
      elapsed_time, elapsed_steps = self._timer.update_last_triggered_step(
          global_step)
      if elapsed_time is not None:
        self._step_train_time += elapsed_time
        self._total_steps += elapsed_steps

        # average examples per second is based on the total (accumulative)
        # training steps and training time so far
        average_examples_per_sec = self._batch_size * (
            self._total_steps / self._step_train_time)
        # current examples per second is based on the elapsed training steps
        # and training time per batch
        current_examples_per_sec = self._batch_size * (
            elapsed_steps / elapsed_time)
        # Current examples/sec followed by average examples/sec
        tf.logging.info('Batch [%g]:  current exp/sec = %g, average exp/sec = '
                        '%g', self._total_steps, current_examples_per_sec,
                        average_examples_per_sec)
1202395
def readiterinit(d):
    

    # set requested time range based on given parameters
    starttime_mjd = d['starttime_mjd']
    timeskip = d['inttime']*d['nskip']
    starttime = qa.getvalue(qa.convert(qa.time(qa.quantity(starttime_mjd+timeskip/(24.*60*60),'d'),form=['ymd'], prec=9)[0], 's'))[0]
    stoptime = qa.getvalue(qa.convert(qa.time(qa.quantity(starttime_mjd+(timeskip+(d['nints']+1)*d['inttime'])/(24.*60*60), 'd'), form=['ymd'], prec=9)[0], 's'))[0]  # nints+1 to be avoid buffer running out and stalling iteration
    logger.debug('Time of first integration:', qa.time(qa.quantity(starttime_mjd,'d'),form=['ymd'],prec=9)[0])
    logger.info('Reading times %s to %s in %d iterations' % (qa.time(qa.quantity(starttime_mjd+timeskip/(24.*60*60),'d'),form=['hms'], prec=9)[0], qa.time(qa.quantity(starttime_mjd+(timeskip+(d['nints']+1)*d['inttime'])/(24.*60*60), 'd'), form=['hms'], prec=9)[0], d['nthread']))

    # read data into data structure
    ms.open(d['filename'])
    if len(d['spwlist']) == 1:
        ms.selectinit(datadescid=d['spwlist'][0])
    else:
        ms.selectinit(datadescid=0, reset=True)    # reset includes spw in iteration over time
    selection = {'time': [starttime, stoptime], 'uvdist': [1., 1e10], 'antenna1': d['ants'], 'antenna2': d['ants']}    # exclude auto-corrs
    ms.select(items = selection)
    ms.selectpolarization(d['pols'])
    ms.iterinit(['TIME'], 0, d['iterint']*d['nbl']*d['nspw']*d['npol'], adddefaultsortcolumns=False)
    iterstatus = ms.iterorigin()
151175
def time_restarts(data_path):
    
    path = os.path.join(data_path, 'last_restarted')
    if not os.path.isfile(path):
        with open(path, 'a'):
            os.utime(path, None)

    last_modified = os.stat(path).st_mtime

    with open(path, 'a'):
        os.utime(path, None)

    now = os.stat(path).st_mtime
    dif = round(now - last_modified, 2)
    last_restart = datetime.fromtimestamp(now).strftime('%H:%M:%S')
    result = 'LAST RESTART WAS {} SECONDS AGO at {}'.format(dif, last_restart)
    print(style(fg='green', bg='red', text=result))
599642
def end_timing(self):
        

        if self._callback != None:
            elapsed = time.perf_counter() * 1000 - self._start
            self._callback.end_timing(self._counter, elapsed)
316874
def str_uptime(self):
        """"""
        mins, secs = divmod(self.uptime, 60)
        hours, mins = divmod(mins, 60)
        return '%02d:%02d:%02d' % (hours, mins, secs)
1232012
def elapsed_time(self):
        """"""

        # Timer is running
        if self._t0 is not None:
            return self._time + self._get_time()
        else:
            return self._time
575714
def execution_time(object):
    

    @functools.wraps(object)
    def execution_time_wrapper(*args, **kwargs):
        """
        Implements execution timing.

        :param \*args: Arguments.
        :type \*args: \*
        :param \*\*kwargs: Keywords arguments.
        :type \*\*kwargs: \*\*
        :return: Object.
        :rtype: object
        """

        start_time = time.time()

        value = object(*args, **kwargs)

        end_time = time.time()

        sys.stdout.write("{0} | '{1}' object processed during '{2:f}' ms!\n".format(__name__,
                                                                                    object.__name__,
                                                                                    (end_time - start_time) * 1000.0))

        return value

    return execution_time_wrapper
1056534
def _elapsed(self):
        
        self.last_time = time.time()
        return self.last_time - self.start
1203005
def _prerun(self):
        
        self.check_required_params()
        self._set_status("RUNNING")
        logger.debug(
            "{}.PreRun: {}[{}]: running...".format(
                self.__class__.__name__, self.__class__.path, self.uuid
            ),
            extra=dict(
                kmsg=Message(
                    self.uuid, entrypoint=self.__class__.path,
                    params=self.params
                ).dump()
            )
        )
        return self.prerun()
1035730
def str(self,local):
        
        s = self.start_time.str(local) \
            + u" to " \
            + self.end_time.str(local)
        return s
482442
def runtime(self):
        
        t = time.time() - self.start
        self.start = time.time()
        return t
1038257
def get_elapsed(self, restart=True):
        '''
        
        '''
        end = time.time()
        span = end - self.__start
        if restart:
            self.__start = end
        return span
1080438
def get_remaining_time(program):
    '''
    
    '''
    now = datetime.datetime.now()
    program_start = program.get('start_time')
    program_end = program.get('end_time')
    if not program_start or not program_end:
        _LOGGER.error('Could not determine program start and/or end times.')
        _LOGGER.debug('Program data: %s', program)
        return
    if now > program_end:
        _LOGGER.error('The provided program has already ended.')
        _LOGGER.debug('Program data: %s', program)
        return 0
    progress = now - program_start
    return progress.seconds
432995
def parse_duration(self):
        
        for edit in self.track_edits:
            if edit.edit_type == 'loopPlugin':
                self.duration += (
                    (edit.options['end'] -
                     edit.options['start']) *
                    float(edit.options['loop'])
                )
1069922
def duration(self):
        
        d = self.for_attempt(self.cur_attempt)
        self.cur_attempt += 1
        return d