-
Notifications
You must be signed in to change notification settings - Fork 0
/
params.py
34 lines (27 loc) · 992 Bytes
/
params.py
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
import yaml
import paramgen
from pprint import pprint
class DAGParams:
def __init__(self, params_file_path: str=None) -> None:
if params_file_path:
self.load_params(params_file_path)
else:
self.params = {}
def load_params(self, params_file_path: str):
# print("111" + params_file_path)
with open(params_file_path, "r") as f:
self.params = yaml.safe_load(f)
def save_params(self, params_file_path: str):
with open(params_file_path, "w") as f:
yaml.dump(self.params, f)
def set_params(self, params: dict):
self.params = params
if __name__ == "__main__":
params = DAGParams()
generator = paramgen.DAGParamGenerator()
params.set_params(generator.generate_param())
params.save_params("temp_params.yaml")
loaded_params = DAGParams("temp_params.yaml")
assert params.params == loaded_params.params
pprint(params.params)
pprint(loaded_params.params)