Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update repr for dataset/workflow classes and add uri kwarg for QlibRecorder #302

Merged
merged 8 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ tags

.pytest_cache/
.vscode/

*.swp
17 changes: 11 additions & 6 deletions qlib/data/dataset/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
----------
Expand All @@ -87,7 +87,7 @@ def __init__(self, handler: Union[dict, DataHandler], segments: dict):
"""
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

Expand Down Expand Up @@ -124,7 +124,7 @@ def init(self, handler_kwargs: dict = None, segment_kwargs: dict = None):
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.

Expand Down Expand Up @@ -156,6 +156,11 @@ def setup_data(self, handler: Union[dict, DataHandler], segments: dict):
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
Expand All @@ -168,7 +173,7 @@ def _prepare_seg(self, slc: slice, **kwargs):

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,
Expand All @@ -178,7 +183,7 @@ def prepare(

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:

Expand Down
6 changes: 3 additions & 3 deletions qlib/data/dataset/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DataHandler(Serializable):
The data handler try to maintain a handler with 2 level.
`datetime` & `instruments`.

Any order of the index level can be suported(The order will implied in the data).
Any order of the index level can be suported (The order will be implied in the data).
The order <`datetime`, `instruments`> will be used when the dataframe index name is missed.

Example of the data:
Expand All @@ -47,8 +47,8 @@ class DataHandler(Serializable):
$close $volume Ref($close, 1) Mean($close, 3) $high-$low LABEL0
datetime instrument
2010-01-04 SH600000 81.807068 17145150.0 83.737389 83.016739 2.741058 0.0032
SH600004 13.313329 11800983.0 13.313329 13.317701 0.183632 0.0042
SH600005 37.796539 12231662.0 38.258602 37.919757 0.970325 0.0289
SH600004 13.313329 11800983.0 13.313329 13.317701 0.183632 0.0042
SH600005 37.796539 12231662.0 38.258602 37.919757 0.970325 0.0289

"""

Expand Down
10 changes: 8 additions & 2 deletions qlib/workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Derek-Wds marked this conversation as resolved.
Show resolved Hide resolved
"""
Method to start an experiment. This method can only be called within a Python's `with` statement. Here is the example code:

Expand All @@ -34,8 +37,11 @@ def start(self, experiment_name=None, recorder_name=None):
name of the experiment one wants to start.
recorder_name : str
name of the recorder under the experiment one wants to start.
uri : str
D-X-Y marked this conversation as resolved.
Show resolved Hide resolved
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:
Expand Down
3 changes: 3 additions & 0 deletions qlib/workflow/expm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def __init__(self, uri, default_exp_name):
self.default_exp_name = default_exp_name
self.active_experiment = None # only one experiment can active each time

def __repr__(self):
Derek-Wds marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down