From 3d698f96a4d6b464abf56b7112c1373db6185bcc Mon Sep 17 00:00:00 2001 From: Ayush Ojha Date: Fri, 30 Jan 2026 06:38:29 -0800 Subject: [PATCH] refactor: separate constants from config.py into constant.py Moves PROTOCOL_VERSION, NUM_USABLE_CPU, DISK_DATASET_CACHE, SIMPLE_DATASET_CACHE, DISK_EXPRESSION_CACHE, and DEPENDENCY_REDIS_CACHE from qlib/config.py to qlib/constant.py where other project constants already reside. The constants are re-imported in config.py to maintain backward compatibility. Closes #807 --- qlib/config.py | 24 +++++++++++------------- qlib/constant.py | 12 ++++++++++++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/qlib/config.py b/qlib/config.py index 4e5d62564f7..837efe2fb9e 100644 --- a/qlib/config.py +++ b/qlib/config.py @@ -17,12 +17,21 @@ import copy import logging import platform -import multiprocessing from pathlib import Path 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, + PROTOCOL_VERSION, + NUM_USABLE_CPU, + DISK_DATASET_CACHE, + SIMPLE_DATASET_CACHE, + DISK_EXPRESSION_CACHE, + DEPENDENCY_REDIS_CACHE, +) if TYPE_CHECKING: from qlib.utils.time import Freq @@ -120,17 +129,6 @@ def register_from_C(config, skip_register=True): C.register() -# pickle.dump protocol version: https://docs.python.org/3/library/pickle.html#data-stream-format -PROTOCOL_VERSION = 4 - -NUM_USABLE_CPU = max(multiprocessing.cpu_count() - 2, 1) - -DISK_DATASET_CACHE = "DiskDatasetCache" -SIMPLE_DATASET_CACHE = "SimpleDatasetCache" -DISK_EXPRESSION_CACHE = "DiskExpressionCache" - -DEPENDENCY_REDIS_CACHE = (DISK_DATASET_CACHE, DISK_EXPRESSION_CACHE) - _default_config = { # data provider config "calendar_provider": "LocalCalendarProvider", diff --git a/qlib/constant.py b/qlib/constant.py index ac6c76ae22c..d11ea0ec6c5 100644 --- a/qlib/constant.py +++ b/qlib/constant.py @@ -2,6 +2,7 @@ # Licensed under the MIT License. # REGION CONST +import multiprocessing from typing import TypeVar import numpy as np @@ -20,3 +21,14 @@ 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) + +# pickle.dump protocol version: https://docs.python.org/3/library/pickle.html#data-stream-format +PROTOCOL_VERSION = 4 + +NUM_USABLE_CPU = max(multiprocessing.cpu_count() - 2, 1) + +DISK_DATASET_CACHE = "DiskDatasetCache" +SIMPLE_DATASET_CACHE = "SimpleDatasetCache" +DISK_EXPRESSION_CACHE = "DiskExpressionCache" + +DEPENDENCY_REDIS_CACHE = (DISK_DATASET_CACHE, DISK_EXPRESSION_CACHE)