Exemplo n.º 1
0
 def __init__(self, conf: Any):
     super().__init__(conf)
     self._host = conf.get_or_throw("fugue.rpc.flask_server.host", str)
     self._port = conf.get_or_throw("fugue.rpc.flask_server.port", int)
     timeout = conf.get_or_none("fugue.rpc.flask_server.timeout", object)
     self._timeout_sec = (-1.0 if timeout is None else
                          to_timedelta(timeout).total_seconds())
     self._server: Optional[FlaskRPCServer._Thread] = None
Exemplo n.º 2
0
def no_update_period(period: Any) -> SimpleNonIterativeStopper:
    _interval = to_timedelta(period)

    def func(current: TrialReport, updated: bool, reports: List[TrialReport]):
        if updated or len(reports) == 0:
            return False
        return datetime.now() - reports[-1].log_time > _interval

    return SimpleNonIterativeStopper(func, log_best_only=True)
Exemplo n.º 3
0
 def __init__(
     self,
     interval: Any = "1sec",
     best_only: bool = True,
     always_update: bool = False,
 ):
     super().__init__()
     self._lock = RLock()
     self._last: Any = None
     self._bins: Dict[str, "_ReportBin"] = {}
     self._interval = to_timedelta(interval)
     self._best_only = best_only
     self._always_update = always_update
Exemplo n.º 4
0
 def __init__(
     self,
     name: str,
     data_type: Any,
     nullable: bool,
     required: bool = True,
     default_value: Any = None,
     timeout: Any = 0,
     default_on_timeout: bool = False,
     metadata: Any = None,
 ):
     super().__init__(name, data_type, nullable, required, default_value,
                      metadata)
     self.timeout = to_timedelta(timeout).total_seconds()
     self.default_on_timeout = default_on_timeout
     aot(self.timeout >= 0, "timeout can't be negative")
     if required:
         aot(not default_on_timeout,
             "default is not allowed for required input")
Exemplo n.º 5
0
def run_monitored_process(
    target: Callable[..., T],
    args: List[Any],
    kwargs: Dict[str, Any],
    stop_checker: Callable[[], bool],
    interval: Any = TUNE_STOPPER_DEFAULT_CHECK_INTERVAL,
) -> T:
    interval_sec = to_timedelta(interval).total_seconds()
    blob = cloudpickle.dumps((target, args, kwargs))
    pool = Pool(1)
    result = pool.map_async(_run_target, [blob])
    while True:
        result.wait(interval_sec)
        if result.ready():
            pool.close()
            pool.join()
            res = result.get(timeout=1)[0]
            return cloudpickle.loads(res)
        if stop_checker():
            pool.terminate()
            pool.join()
            raise TuneInterrupted()
Exemplo n.º 6
0
def test_to_timedelta():
    raises(TypeError, lambda: to_timedelta(None))
    dt = timedelta(days=2)
    assert dt == to_timedelta(dt)
    assert dt == to_timedelta("2d")
    assert dt == to_timedelta("48h")
    dt = timedelta(days=2, minutes=1)
    assert dt == to_timedelta("2 day 1 min")
    assert dt == to_timedelta("2d1m")
    dt = pd.Timedelta("2d")
    assert timedelta(days=2) == to_timedelta(dt)
    raises(TypeError, lambda: to_timedelta("x"))
    assert timedelta() == to_timedelta(0)
    assert timedelta(seconds=2.5) == to_timedelta(2.5)
    assert timedelta(seconds=2.1) == to_timedelta(np.float64(2.1))
    assert timedelta(seconds=2) == to_timedelta(np.int32(2))
    assert timedelta.max == to_timedelta("Max")
    assert timedelta.max == to_timedelta("InF")
    assert timedelta.min == to_timedelta("mIn")
    assert timedelta.min == to_timedelta("-InF")
Exemplo n.º 7
0
def t1(a, wait=None):
    if wait is not None:
        sleep(to_timedelta(wait).total_seconds())
    return a * 10