1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-13 07:46:53 +08:00

Fix some warnings in log.py. (#805)

* Fix some warnings in log.py.

* Fix typo and using black format.

* Fix black.

* Rename dict_ to attrs
This commit is contained in:
Chia-hung Tai
2022-01-06 15:36:00 +08:00
committed by GitHub
parent 93088485c3
commit 6c1332f604
3 changed files with 35 additions and 15 deletions

View File

@@ -4,7 +4,7 @@
About the configs About the configs
================= =================
The config will based on _default_config. The config will be based on _default_config.
Two modes are supported Two modes are supported
- client - client
- server - server
@@ -28,7 +28,7 @@ if TYPE_CHECKING:
class Config: class Config:
def __init__(self, default_conf): def __init__(self, default_conf):
self.__dict__["_default_config"] = copy.deepcopy(default_conf) # avoiding conflictions with __getattr__ self.__dict__["_default_config"] = copy.deepcopy(default_conf) # avoiding conflicts with __getattr__
self.reset() self.reset()
def __getitem__(self, key): def __getitem__(self, key):
@@ -271,7 +271,11 @@ class QlibConfig(Config):
self._registered = False self._registered = False
class DataPathManager: class DataPathManager:
def __init__(self, provider_uri: Union[str, Path, dict], mount_path: Union[str, Path, dict]): def __init__(
self,
provider_uri: Union[str, Path, dict],
mount_path: Union[str, Path, dict],
):
self.provider_uri = provider_uri self.provider_uri = provider_uri
self.mount_path = mount_path self.mount_path = mount_path
@@ -360,10 +364,10 @@ class QlibConfig(Config):
""" """
configure qlib based on the input parameters configure qlib based on the input parameters
The configure will act like a dictionary. The configuration will act like a dictionary.
Normally, it literally replace the value according to the keys. Normally, it literally is replaced the value according to the keys.
However, sometimes it is hard for users to set the config when the configure is nested and complicated However, sometimes it is hard for users to set the config when the configuration is nested and complicated
So this API provides some special parameters for users to set the keys in a more convenient way. So this API provides some special parameters for users to set the keys in a more convenient way.
- region: REG_CN, REG_US - region: REG_CN, REG_US

View File

@@ -13,12 +13,12 @@ from .config import C
class MetaLogger(type): class MetaLogger(type):
def __new__(cls, name, bases, dict): def __new__(mcs, name, bases, attrs):
wrapper_dict = logging.Logger.__dict__.copy() wrapper_dict = logging.Logger.__dict__.copy()
for key in wrapper_dict: for key in wrapper_dict:
if key not in dict and key != "__reduce__": if key not in attrs and key != "__reduce__":
dict[key] = wrapper_dict[key] attrs[key] = wrapper_dict[key]
return type.__new__(cls, name, bases, dict) return type.__new__(mcs, name, bases, attrs)
class QlibLogger(metaclass=MetaLogger): class QlibLogger(metaclass=MetaLogger):
@@ -48,7 +48,7 @@ class QlibLogger(metaclass=MetaLogger):
return self.logger.__getattribute__(name) return self.logger.__getattribute__(name)
def get_module_logger(module_name, level: Optional[int] = None) -> logging.Logger: def get_module_logger(module_name, level: Optional[int] = None) -> QlibLogger:
""" """
Get a logger for a specific module. Get a logger for a specific module.
@@ -107,7 +107,7 @@ class TimeInspector:
""" """
Get last time mark from stack, calculate time diff with current time, and log time diff and info. Get last time mark from stack, calculate time diff with current time, and log time diff and info.
:param info: str :param info: str
Info that will be log into stdout. Info that will be logged into stdout.
""" """
cost_time = time() - cls.time_marks.pop() cost_time = time() - cls.time_marks.pop()
cls.timer_logger.info("Time cost: {0:.3f}s | {1}".format(cost_time, info)) cls.timer_logger.info("Time cost: {0:.3f}s | {1}".format(cost_time, info))
@@ -146,6 +146,7 @@ def set_log_with_config(log_config: Dict[Text, Any]):
class LogFilter(logging.Filter): class LogFilter(logging.Filter):
def __init__(self, param=None): def __init__(self, param=None):
super().__init__()
self.param = param self.param = param
@staticmethod @staticmethod

View File

@@ -81,7 +81,14 @@ class QlibRecorder:
self.end_exp(Recorder.STATUS_FI) self.end_exp(Recorder.STATUS_FI)
def start_exp( def start_exp(
self, *, experiment_id=None, experiment_name=None, recorder_id=None, recorder_name=None, uri=None, resume=False self,
*,
experiment_id=None,
experiment_name=None,
recorder_id=None,
recorder_name=None,
uri=None,
resume=False,
): ):
""" """
Lower level method for starting an experiment. When use this method, one should end the experiment manually Lower level method for starting an experiment. When use this method, one should end the experiment manually
@@ -289,7 +296,10 @@ class QlibRecorder:
An experiment instance with given id or name. An experiment instance with given id or name.
""" """
return self.exp_manager.get_exp( return self.exp_manager.get_exp(
experiment_id=experiment_id, experiment_name=experiment_name, create=create, start=False experiment_id=experiment_id,
experiment_name=experiment_name,
create=create,
start=False,
) )
def delete_exp(self, experiment_id=None, experiment_name=None): def delete_exp(self, experiment_id=None, experiment_name=None):
@@ -355,7 +365,12 @@ class QlibRecorder:
self.exp_manager.set_uri(prev_uri) self.exp_manager.set_uri(prev_uri)
def get_recorder( def get_recorder(
self, *, recorder_id=None, recorder_name=None, experiment_id=None, experiment_name=None self,
*,
recorder_id=None,
recorder_name=None,
experiment_id=None,
experiment_name=None,
) -> Recorder: ) -> Recorder:
""" """
Method for retrieving a recorder. Method for retrieving a recorder.