Repository navigation
Expand file tree
/
Copy pathcli.py
More file actions
65 lines (47 loc) · 1.52 KB
/
Copy pathcli.py
File metadata and controls
65 lines (47 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
72F2
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import sys, os
from pathlib import Path
import qlib
import fire
import pandas as pd
import ruamel.yaml as yaml
from qlib.config import C
from qlib.model.trainer import task_train
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
path of the configuration
"""
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", uri_folder="mlruns"):
with open(config_path) as fp:
config = yaml.load(fp, Loader=yaml.Loader)
# config the `sys` section
sys_config(config, config_path)
exp_manager = C["exp_manager"]
exp_manager["kwargs"]["uri"] = "file:" + str(Path(os.getcwd()).resolve() / uri_folder)
qlib.init(**config.get("qlib_init"), exp_manager=exp_manager)
task_train(config.get("task"), experiment_name=experiment_name)
# function to run worklflow by config
def run():
fire.Fire(workflow)
if __name__ == "__main__":
run()