Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions qlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
About the configs
=================

The config will based on _default_config.
The config will be based on _default_config.
Two modes are supported
- client
- server
Expand All @@ -28,7 +28,7 @@

class Config:
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()

def __getitem__(self, key):
Expand Down Expand Up @@ -271,7 +271,11 @@ def __init__(self, default_conf):
self._registered = False

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.mount_path = mount_path

Expand Down Expand Up @@ -360,10 +364,10 @@ def set(self, default_conf: str = "client", **kwargs):
"""
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.
However, sometimes it is hard for users to set the config when the configure is nested and complicated
Normally, it literally is replaced the value according to the keys.
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.
- region: REG_CN, REG_US
Expand Down
13 changes: 7 additions & 6 deletions qlib/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@


class MetaLogger(type):
def __new__(cls, name, bases, dict):
def __new__(mcs, name, bases, attrs):
wrapper_dict = logging.Logger.__dict__.copy()
for key in wrapper_dict:
if key not in dict and key != "__reduce__":
dict[key] = wrapper_dict[key]
return type.__new__(cls, name, bases, dict)
if key not in attrs and key != "__reduce__":
attrs[key] = wrapper_dict[key]
return type.__new__(mcs, name, bases, attrs)


class QlibLogger(metaclass=MetaLogger):
Expand Down Expand Up @@ -48,7 +48,7 @@ def __getattr__(self, 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.

Expand Down Expand Up @@ -107,7 +107,7 @@ def log_cost_time(cls, info="Done"):
"""
Get last time mark from stack, calculate time diff with current time, and log time diff and info.
:param info: str
Info that will be log into stdout.
Info that will be logged into stdout.
"""
cost_time = time() - cls.time_marks.pop()
cls.timer_logger.info("Time cost: {0:.3f}s | {1}".format(cost_time, info))
Expand Down Expand Up @@ -146,6 +146,7 @@ def set_log_with_config(log_config: Dict[Text, Any]):

class LogFilter(logging.Filter):
def __init__(self, param=None):
super().__init__()
self.param = param

@staticmethod
Expand Down
21 changes: 18 additions & 3 deletions qlib/workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@ def start(
self.end_exp(Recorder.STATUS_FI)

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
Expand Down Expand Up @@ -289,7 +296,10 @@ def get_exp(self, *, experiment_id=None, experiment_name=None, create: bool = Tr
An experiment instance with given id or name.
"""
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):
Expand Down Expand Up @@ -355,7 +365,12 @@ def uri_context(self, uri: Text):
self.exp_manager.set_uri(prev_uri)

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:
"""
Method for retrieving a recorder.
Expand Down