mirror of
https://github.com/microsoft/qlib.git
synced 2026-06-06 05:51:17 +08:00
add sys section parser to the workflow config
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
|
||||
sys:
|
||||
rel_path: .
|
||||
provider_uri: "~/.qlib/qlib_data/cn_data"
|
||||
region: cn
|
||||
market: &market csi300
|
||||
@@ -28,7 +29,7 @@ port_analysis_config: &port_analysis_config
|
||||
task:
|
||||
model:
|
||||
class: TFTModel
|
||||
module_path: qlib.examples.benchmarks.TFT
|
||||
module_path: tft
|
||||
dataset:
|
||||
class: DatasetH
|
||||
module_path: qlib.data.dataset
|
||||
|
||||
@@ -13,11 +13,43 @@ from qlib.workflow import R
|
||||
from qlib.workflow.record_temp import SignalRecord
|
||||
|
||||
|
||||
def get_path_list(path):
|
||||
if isinstance(path, str):
|
||||
return [path]
|
||||
else:
|
||||
return [p for p in path]
|
||||
|
||||
|
||||
def sys_config(config, config_path):
|
||||
"""
|
||||
Configure the `sys` section
|
||||
|
||||
Parameters
|
||||
----------
|
||||
config : dict
|
||||
configuration of the workflow
|
||||
config_path : str
|
||||
configuration of the path
|
||||
"""
|
||||
sys_config = config.get("sys", {})
|
||||
|
||||
# abspath
|
||||
for p in get_path_list(sys_config.get("path", [])):
|
||||
sys.path.append(p)
|
||||
|
||||
# relative path to config path
|
||||
for p in get_path_list(sys_config.get("rel_path", [])):
|
||||
sys.path.append(str(Path(config_path).parent.resolve().absolute() / p))
|
||||
|
||||
|
||||
# worflow handler function
|
||||
def workflow(config_path, experiment_name="workflow"):
|
||||
with open(config_path) as fp:
|
||||
config = yaml.load(fp, Loader=yaml.Loader)
|
||||
|
||||
# config the `sys` section
|
||||
sys_config(config, config_path)
|
||||
|
||||
provider_uri = config.get("provider_uri")
|
||||
region = config.get("region")
|
||||
qlib.init(provider_uri=provider_uri, region=region)
|
||||
|
||||
Reference in New Issue
Block a user