def test_stat_aggregator(): agg = StatAggregator(skip_obs=10) for i in range(0, 100): agg.append(i) assert agg.avg == 54.5 assert agg.min == 9 assert agg.max == 99 assert agg.sd == 25.97915831328387 assert agg.sum == sum(range(10, 100))
def log_trial_chrono_start( self, trial, name: str, aggregator: Callable[[], Aggregator] = StatAggregator.lazy(1), start_callback=None, end_callback=None): """Send the start signal for an event Parameters ---------- trial: Trial trial sending the event name: str name of the event aggregator: Aggregator container used to accumulate elapsed time start_callback: Callable function called at start time end_callback: Callable function called at the end """ raise NotImplementedError()
def log_trial_chrono_start( self, trial, name: str, aggregator: Callable[[], Aggregator] = StatAggregator.lazy(1), start_callback=None, end_callback=None): if start_callback is not None: start_callback() self.chrono[name] = {'start': time.time(), 'cb': end_callback}
def log_trial_chrono_start( self, trial, name: str, aggregator: Callable[[], Aggregator] = StatAggregator.lazy(1), start_callback=None, end_callback=None): return [ p.log_trial_chrono_start(trial, name, aggregator, start_callback, end_callback) for p in self.protos ][-1]
def log_trial_chrono_start( self, trial, name: str, aggregator: Callable[[], Aggregator] = StatAggregator.lazy(1), start_callback=None, end_callback=None): kwargs = dict() kwargs['__rpc__'] = 'log_trial_chrono_start' kwargs['trial'] = trial.uid kwargs['name'] = name send(self.socket, kwargs) return _check(recv(self.socket))
def log_trial_chrono_start( self, trial, name: str, aggregator: Callable[[], Aggregator] = StatAggregator.lazy(1), start_callback=None, end_callback=None): ntrial = self.storage.objects.get(trial.uid) agg = trial.chronos.get(name) if agg is None: agg = aggregator() trial.chronos[name] = agg self.chronos[name] = time.time() ntrial.chronos[name] = agg self._inc_trial(ntrial)
from track.structure import Project, Trial, TrialGroup from track.persistence.protocol import Protocol from track.persistence.storage import load_database, LocalStorage from track.persistence.utils import parse_uri from track.containers.types import float32 from track.aggregators.aggregator import Aggregator from track.aggregators.aggregator import RingAggregator from track.aggregators.aggregator import StatAggregator from track.aggregators.aggregator import ValueAggregator from track.aggregators.aggregator import TimeSeriesAggregator value_aggregator = ValueAggregator.lazy() ring_aggregator = RingAggregator.lazy(10, float32) stat_aggregator = StatAggregator.lazy(1) ts_aggregator = TimeSeriesAggregator.lazy() file_lock_logger().setLevel(logging.ERROR) def _make_container(step, aggregator): if step is None: if aggregator is None: # favor ts aggregator because it has an option to cut the TS for printing purposes return ts_aggregator() return aggregator() else: return dict()
def __init__(self, protocol, trial, acc=StatAggregator(), name=None, **kwargs): self.chrono = ChronoContext(acc=acc) self.protocol = protocol self.trial = trial self.args = kwargs self.name = name
from track.utils.eta import EstimatedTime if __name__ == '__main__': import time from track.chrono import ChronoContext from track.aggregators.aggregator import StatAggregator agg = StatAggregator() eta = EstimatedTime(agg, (5, 1)) print(eta.total) for i in range(0, 5): for j in range(0, 10): with ChronoContext(agg, None, None): time.sleep(1) eta.show_eta((i, j)) agg = StatAggregator() eta = EstimatedTime(agg, 50) print(eta.total) for i in range(50): with ChronoContext(agg, None, None): time.sleep(1)
def from_json(self, obj, short=False): return StatAggregator.from_json(obj)