Skip to content
Open
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
4 changes: 2 additions & 2 deletions qlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def init(default_conf="client", **kwargs):

Parameters
----------
default_conf: str
the default value is client. Accepted values: client/server.
default_conf: str or ModeType
the default value is client. Accepted values: ModeType.CLIENT/ModeType.SERVER (or "client"/"server").
**kwargs :
clear_mem_cache: str
the default value is True;
Expand Down
14 changes: 7 additions & 7 deletions qlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from typing import Callable, Optional, Union
from typing import TYPE_CHECKING

from qlib.constant import REG_CN, REG_US, REG_TW
from qlib.constant import REG_CN, REG_US, REG_TW, ModeType

if TYPE_CHECKING:
from qlib.utils.time import Freq
Expand Down Expand Up @@ -247,7 +247,7 @@ def register_from_C(config, skip_register=True):
}

MODE_CONF = {
"server": {
ModeType.SERVER: {
# config it in qlib.init()
"provider_uri": "",
# redis
Expand All @@ -260,7 +260,7 @@ def register_from_C(config, skip_register=True):
"local_cache_path": Path("~/.cache/qlib_simple_cache").expanduser().resolve(),
"mount_path": None,
},
"client": {
ModeType.CLIENT: {
# config it in user's own code
"provider_uri": QSETTINGS.provider_uri,
# cache
Expand Down Expand Up @@ -385,7 +385,7 @@ def get_data_uri(self, freq: Optional[Union[str, Freq]] = None) -> Path:

def set_mode(self, mode):
# raise KeyError
self.update(MODE_CONF[mode])
self.update(MODE_CONF[ModeType(mode)])
# TODO: update region based on kwargs

def set_region(self, region):
Expand Down Expand Up @@ -420,7 +420,7 @@ def resolve_path(self):
self["provider_uri"] = _provider_uri
self["mount_path"] = _mount_path

def set(self, default_conf: str = "client", **kwargs):
def set(self, default_conf: Union[str, ModeType] = ModeType.CLIENT, **kwargs):
"""
configure qlib based on the input parameters

Expand All @@ -435,8 +435,8 @@ def set(self, default_conf: str = "client", **kwargs):

Parameters
----------
default_conf : str
the default config template chosen by user: "server", "client"
default_conf : str or ModeType
the default config template chosen by user: ModeType.SERVER, ModeType.CLIENT (or "server", "client")
"""
from .utils import set_log_with_config, get_module_logger, can_use_cache # pylint: disable=C0415

Expand Down
8 changes: 8 additions & 0 deletions qlib/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Licensed under the MIT License.

# REGION CONST
from enum import Enum
from typing import TypeVar

import numpy as np
Expand All @@ -20,3 +21,10 @@
ONE_MIN = pd.Timedelta("1min")
EPS_T = pd.Timedelta("1s") # use 1 second to exclude the right interval point
float_or_ndarray = TypeVar("float_or_ndarray", float, np.ndarray)


class ModeType(str, Enum):
"""Mode type for qlib initialization: client or server."""

CLIENT = "client"
SERVER = "server"