mirror of
https://github.com/microsoft/autogen.git
synced 2026-01-22 18:28:13 -05:00
bug fix
This commit is contained in:
@@ -19,6 +19,7 @@ import copy
|
||||
import glob
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
from typing import Dict, Optional, Union, List, Tuple
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -43,6 +44,36 @@ UNDEFINED_METRIC_MODE = str(
|
||||
"or pass them to `tune.run()`.")
|
||||
|
||||
|
||||
_logged = set()
|
||||
_disabled = False
|
||||
_periodic_log = False
|
||||
_last_logged = 0.0
|
||||
|
||||
|
||||
def log_once(key):
|
||||
"""Returns True if this is the "first" call for a given key.
|
||||
Various logging settings can adjust the definition of "first".
|
||||
Example:
|
||||
>>> if log_once("some_key"):
|
||||
... logger.info("Some verbose logging statement")
|
||||
"""
|
||||
|
||||
global _last_logged
|
||||
|
||||
if _disabled:
|
||||
return False
|
||||
elif key not in _logged:
|
||||
_logged.add(key)
|
||||
_last_logged = time.time()
|
||||
return True
|
||||
elif _periodic_log and time.time() - _last_logged > 60.0:
|
||||
_logged.clear()
|
||||
_last_logged = time.time()
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
class Searcher:
|
||||
"""Abstract class for wrapping suggesting algorithms.
|
||||
Custom algorithms can extend this class easily by overriding the
|
||||
|
||||
Reference in New Issue
Block a user