mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-12 23:36:54 +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"
|
provider_uri: "~/.qlib/qlib_data/cn_data"
|
||||||
region: cn
|
region: cn
|
||||||
market: &market csi300
|
market: &market csi300
|
||||||
@@ -28,7 +29,7 @@ port_analysis_config: &port_analysis_config
|
|||||||
task:
|
task:
|
||||||
model:
|
model:
|
||||||
class: TFTModel
|
class: TFTModel
|
||||||
module_path: qlib.examples.benchmarks.TFT
|
module_path: tft
|
||||||
dataset:
|
dataset:
|
||||||
class: DatasetH
|
class: DatasetH
|
||||||
module_path: qlib.data.dataset
|
module_path: qlib.data.dataset
|
||||||
|
|||||||
@@ -13,11 +13,43 @@ from qlib.workflow import R
|
|||||||
from qlib.workflow.record_temp import SignalRecord
|
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
|
# worflow handler function
|
||||||
def workflow(config_path, experiment_name="workflow"):
|
def workflow(config_path, experiment_name="workflow"):
|
||||||
with open(config_path) as fp:
|
with open(config_path) as fp:
|
||||||
config = yaml.load(fp, Loader=yaml.Loader)
|
config = yaml.load(fp, Loader=yaml.Loader)
|
||||||
|
|
||||||
|
# config the `sys` section
|
||||||
|
sys_config(config, config_path)
|
||||||
|
|
||||||
provider_uri = config.get("provider_uri")
|
provider_uri = config.get("provider_uri")
|
||||||
region = config.get("region")
|
region = config.get("region")
|
||||||
qlib.init(provider_uri=provider_uri, region=region)
|
qlib.init(provider_uri=provider_uri, region=region)
|
||||||
|
|||||||
Reference in New Issue
Block a user