def capture_output(self, output_size=50): """capture standard output""" import sys do_stderr = sys.stderr is not sys.stdout self.stdout = RingOutputDecorator(file=sys.stdout, n_entries=options('log.stdout_capture', output_size)) sys.stdout = self.stdout if do_stderr: self.stderr = RingOutputDecorator(file=sys.stderr, n_entries=options('log.stderr_capture', output_size)) sys.stderr = self.stderr return self
def show_eta(self, step: int, timer: StatStream, msg: str = '', throttle=options('log.print.throttle', None), every=options('log.print.every', None), no_print=options('log.print.disable', False)): self.eta.timer = timer if self.batch_printer is None: self.batch_printer = throttled(self.eta.show_eta, throttle, every) if not no_print: self.batch_printer(step, msg) return self
def __init__(self, backend=options('log.backend.name', default='none')): self.project = None self.group = None self.trial = None self.protocol = get_protocol(backend) self.logger: TrialLogger = None self.set_version() self.version = None self.set_version() # Orion integration # ----------------- orion_name = os.environ.get('ORION_PROJECT') if orion_name is not None: self.set_project(name=orion_name, get_only=True) orion_exp = os.environ.get('ORION_EXPERIMENT') if orion_exp is not None: self.set_group(name=orion_exp, get_only=True) orion_trial = os.environ.get('ORION_TRIAL_ID') if orion_trial is not None: self.set_trial(uid=orion_trial)
def test_config_env_override(): """ return the value stored in the environment """ with workind_dir(wd): pop(os.environ, 'TRACK_CONFIG_SOMETHING2') os.environ['TRACK_CONFIG_SOMETHING2'] = '127' assert int(options('config.something2')) == 127
def test_config_env(): """ return the value stored in the environment """ with workind_dir(wd): pop(os.environ, 'TRACK_CONFIG_TEST') os.environ['TRACK_CONFIG_TEST'] = '123' assert int(options('config.test')) == 123
def make_lock(name, eager): if eager: return FileLock(name, timeout=options('log.backend.lock_timeout', 30)) return _NoLockLock()
def test_config_file(): """ load configuration file and return the value there """ with workind_dir(wd): assert options('config.something', 124) == 125
def test_config_nothing(): """ load configuration file but does not find the value, no default is found""" with workind_dir(wd): assert options('config.nothing') is none
def test_config_default(): """ load configuration file but does not find the value so use the provided default""" with workind_dir(wd): assert options('config.none', 124) == 124