1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-15 00:36:55 +08:00

Update repr for DatasetH and ExpManager

This commit is contained in:
D-X-Y
2021-03-03 06:47:52 +00:00
parent d1d70616a3
commit a9a70dfddf
4 changed files with 24 additions and 8 deletions

2
.gitignore vendored
View File

@@ -34,3 +34,5 @@ tags
.pytest_cache/ .pytest_cache/
.vscode/ .vscode/
*.swp

View File

@@ -1,5 +1,5 @@
from ...utils.serial import Serializable from ...utils.serial import Serializable
from typing import Union, List, Tuple from typing import Union, List, Tuple, Dict, Text, Optional
from ...utils import init_instance_by_config, np_ffill from ...utils import init_instance_by_config, np_ffill
from ...log import get_module_logger from ...log import get_module_logger
from .handler import DataHandler, DataHandlerLP from .handler import DataHandler, DataHandlerLP
@@ -76,7 +76,7 @@ class DatasetH(Dataset):
- The processing is related to data split. - The processing is related to data split.
""" """
def __init__(self, handler: Union[dict, DataHandler], segments: dict): def __init__(self, handler: Union[Dict, DataHandler], segments: Dict):
""" """
Parameters Parameters
---------- ----------
@@ -87,7 +87,7 @@ class DatasetH(Dataset):
""" """
super().__init__(handler, segments) super().__init__(handler, segments)
def init(self, handler_kwargs: dict = None, segment_kwargs: dict = None): def init(self, handler_kwargs: Optional[Dict] = None, segment_kwargs: Optional[Dict] = None):
""" """
Initialize the DatasetH Initialize the DatasetH
@@ -124,7 +124,7 @@ class DatasetH(Dataset):
raise TypeError(f"param handler_kwargs must be type dict, not {type(segment_kwargs)}") raise TypeError(f"param handler_kwargs must be type dict, not {type(segment_kwargs)}")
self.segments = segment_kwargs.copy() self.segments = segment_kwargs.copy()
def setup_data(self, handler: Union[dict, DataHandler], segments: dict): def setup_data(self, handler: Union[Dict, DataHandler], segments: Dict[Text, Tuple]):
""" """
Setup the underlying data. Setup the underlying data.
@@ -156,6 +156,11 @@ class DatasetH(Dataset):
self.handler = init_instance_by_config(handler, accept_types=DataHandler) self.handler = init_instance_by_config(handler, accept_types=DataHandler)
self.segments = segments.copy() self.segments = segments.copy()
def __repr__(self):
return "{name}(handler={handler}, segments={segments})".format(
name=self.__class__.__name__, handler=self.handler, segments=self.segments
)
def _prepare_seg(self, slc: slice, **kwargs): def _prepare_seg(self, slc: slice, **kwargs):
""" """
Give a slice, retrieve the according data Give a slice, retrieve the according data
@@ -168,7 +173,7 @@ class DatasetH(Dataset):
def prepare( def prepare(
self, self,
segments: Union[List[str], Tuple[str], str, slice], segments: Union[List[Text], Tuple[Text], Text, slice],
col_set=DataHandler.CS_ALL, col_set=DataHandler.CS_ALL,
data_key=DataHandlerLP.DK_I, data_key=DataHandlerLP.DK_I,
**kwargs, **kwargs,
@@ -178,7 +183,7 @@ class DatasetH(Dataset):
Parameters Parameters
---------- ----------
segments : Union[List[str], Tuple[str], str, slice] segments : Union[List[Text], Tuple[Text], Text, slice]
Describe the scope of the data to be prepared Describe the scope of the data to be prepared
Here are some examples: Here are some examples:

View File

@@ -16,8 +16,11 @@ class QlibRecorder:
def __init__(self, exp_manager): def __init__(self, exp_manager):
self.exp_manager = exp_manager self.exp_manager = exp_manager
def __repr__(self):
return "{name}(manager={manager})".format(name=self.__class__.__name__, manager=self.exp_manager)
@contextmanager @contextmanager
def start(self, experiment_name=None, recorder_name=None): def start(self, experiment_name=None, recorder_name=None, uri=None):
""" """
Method to start an experiment. This method can only be called within a Python's `with` statement. Here is the example code: Method to start an experiment. This method can only be called within a Python's `with` statement. Here is the example code:
@@ -34,8 +37,11 @@ class QlibRecorder:
name of the experiment one wants to start. name of the experiment one wants to start.
recorder_name : str recorder_name : str
name of the recorder under the experiment one wants to start. name of the recorder under the experiment one wants to start.
uri : str
the tracking uri of the experiment, where all the artifacts/metrics etc. will be stored.
The default uri are set in the qlib.config.
""" """
run = self.start_exp(experiment_name, recorder_name) run = self.start_exp(experiment_name, recorder_name, uri)
try: try:
yield run yield run
except Exception as e: except Exception as e:

View File

@@ -25,6 +25,9 @@ class ExpManager:
self.default_exp_name = default_exp_name self.default_exp_name = default_exp_name
self.active_experiment = None # only one experiment can active each time self.active_experiment = None # only one experiment can active each time
def __repr__(self):
return "{name}(uri={uri})".format(name=self.__class__.__name__, uri=self.uri)
def start_exp(self, experiment_name=None, recorder_name=None, uri=None, **kwargs): def start_exp(self, experiment_name=None, recorder_name=None, uri=None, **kwargs):
""" """
Start an experiment. This method includes first get_or_create an experiment, and then Start an experiment. This method includes first get_or_create an experiment, and then