diff --git a/.gitignore b/.gitignore index 5b3745a02..0ddd5d21f 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,5 @@ tags .pytest_cache/ .vscode/ + +*.swp diff --git a/qlib/data/dataset/__init__.py b/qlib/data/dataset/__init__.py index 8ff8c1210..ecbeebc95 100644 --- a/qlib/data/dataset/__init__.py +++ b/qlib/data/dataset/__init__.py @@ -1,5 +1,5 @@ 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 ...log import get_module_logger from .handler import DataHandler, DataHandlerLP @@ -76,7 +76,7 @@ class DatasetH(Dataset): - 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 ---------- @@ -87,7 +87,7 @@ class DatasetH(Dataset): """ 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 @@ -124,7 +124,7 @@ class DatasetH(Dataset): raise TypeError(f"param handler_kwargs must be type dict, not {type(segment_kwargs)}") 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. @@ -156,6 +156,11 @@ class DatasetH(Dataset): self.handler = init_instance_by_config(handler, accept_types=DataHandler) 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): """ Give a slice, retrieve the according data @@ -168,7 +173,7 @@ class DatasetH(Dataset): def prepare( self, - segments: Union[List[str], Tuple[str], str, slice], + segments: Union[List[Text], Tuple[Text], Text, slice], col_set=DataHandler.CS_ALL, data_key=DataHandlerLP.DK_I, **kwargs, @@ -178,7 +183,7 @@ class DatasetH(Dataset): 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 Here are some examples: diff --git a/qlib/workflow/__init__.py b/qlib/workflow/__init__.py index aedf73a9c..9602963d8 100644 --- a/qlib/workflow/__init__.py +++ b/qlib/workflow/__init__.py @@ -16,8 +16,11 @@ class QlibRecorder: def __init__(self, exp_manager): self.exp_manager = exp_manager + def __repr__(self): + return "{name}(manager={manager})".format(name=self.__class__.__name__, manager=self.exp_manager) + @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: @@ -34,8 +37,11 @@ class QlibRecorder: name of the experiment one wants to start. recorder_name : str 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: yield run except Exception as e: diff --git a/qlib/workflow/expm.py b/qlib/workflow/expm.py index a50dce7c9..e905434cb 100644 --- a/qlib/workflow/expm.py +++ b/qlib/workflow/expm.py @@ -25,6 +25,9 @@ class ExpManager: self.default_exp_name = default_exp_name 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): """ Start an experiment. This method includes first get_or_create an experiment, and then