def _progress_update(self, numerator_increment, stage=0): """ Updates the progress. Will update progress bars or other progress output. Parameters ---------- numerator : int numerator of partial work done already in current stage stage : int, nonnegative, default=0 Current stage of the algorithm, 0 or greater """ if hasattr(self, 'show_progress') and not self.show_progress: return if stage not in self._prog_rep_progressbars: raise RuntimeError( "call _progress_register(amount_of_work, stage=x) on this instance first!" ) pg = self._prog_rep_progressbars[stage] pg.numerator += numerator_increment _show_progressbar(pg) if hasattr(self, '_prog_rep_callbacks'): for callback in self._prog_rep_callbacks[stage]: callback(stage, pg)
def _progress_force_finish(self, stage=0): """ forcefully finish the progress for given stage """ if hasattr(self, 'show_progress') and not self.show_progress: return if stage not in self._prog_rep_progressbars: raise RuntimeError( "call _progress_register(amount_of_work, stage=x) on this instance first!" ) pg = self._prog_rep_progressbars[stage] pg.numerator = pg.denominator pg._eta.eta_epoch = 0 _show_progressbar(pg) _hide_progressbar(pg)
def _progress_update(self, numerator_increment, stage=0, show_eta=True, **kw): """ Updates the progress. Will update progress bars or other progress output. Parameters ---------- numerator : int numerator of partial work done already in current stage stage : int, nonnegative, default=0 Current stage of the algorithm, 0 or greater """ if not self.show_progress: return if stage not in self._prog_rep_progressbars: raise RuntimeError( "call _progress_register(amount_of_work, stage=x) on this instance first!" ) if hasattr(self._prog_rep_progressbars[stage], '_dummy'): return pg = self._prog_rep_progressbars[stage] pg.numerator += numerator_increment # we are done if pg.numerator == pg.denominator: if stage in self._prog_rep_callbacks: for callback in self._prog_rep_callbacks[stage]: callback(stage, pg, **kw) self._progress_force_finish(stage) return elif pg.numerator > pg.denominator: import warnings warnings.warn( "This should not happen. An caller pretended to have " "achieved more work than registered") return desc = self._prog_rep_descriptions[stage].format(**kw) pg.description = desc _show_progressbar(pg, show_eta=show_eta, description=desc) if stage in self._prog_rep_callbacks: for callback in self._prog_rep_callbacks[stage]: callback(stage, pg, **kw)
def _progress_force_finish(self, stage=0): """ forcefully finish the progress for given stage """ if not self.show_progress: return if stage not in self._prog_rep_progressbars: raise RuntimeError( "call _progress_register(amount_of_work, stage=x) on this instance first!") pg = self._prog_rep_progressbars[stage] if not isinstance(pg, _ProgressBar): return pg.numerator = pg.denominator pg._eta.eta_epoch = 0 _show_progressbar(pg, description=self._prog_rep_descriptions[stage]) _hide_progressbar(pg)