-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain1_read.py
68 lines (52 loc) · 2.66 KB
/
main1_read.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 4 21:38:39 2018
@author: Meg_94
"""
from time import time as time_time
start_time = time_time()
from os import path as os_path, mkdir as os_mkdir, chdir as os_chdir
os_chdir(os_path.dirname(os_path.abspath(__file__)))
from sys import path as sys_path
# insert at 1, 0 is the script path (or '' in REPL)
sys_path.insert(1, './functions_py3/')
from yaml import load as yaml_load, dump as yaml_dump, Loader as yaml_Loader
from argparse import ArgumentParser as argparse_ArgumentParser
from logging import basicConfig as logging_basicConfig, INFO as logging_INFO, DEBUG as logging_DEBUG
from pickle import dump as pickle_dump
from read_pp_graph import read_graphs
def main():
parser = argparse_ArgumentParser("Input parameters")
parser.add_argument("--input_file_name", default="input_toy.yaml", help="Input parameters file name")
parser.add_argument("--graph_files_dir", default="", help="Graph files' folder path")
parser.add_argument("--out_dir_name", default="/results", help="Output directory name")
args = parser.parse_args()
with open(args.input_file_name, 'r') as f:
inputs = yaml_load(f, yaml_Loader)
# Override output directory name if same as gen
if args.out_dir_name or inputs['out_comp_nm'] == "/results/res":
if not os_path.exists(inputs['dir_nm'] + args.out_dir_name):
os_mkdir(inputs['dir_nm'] + args.out_dir_name)
inputs['out_comp_nm'] = args.out_dir_name + "/res"
inputs['graph_files_dir'] = ''
if args.graph_files_dir:
if not os_path.exists(inputs['dir_nm'] + args.graph_files_dir):
os_mkdir(inputs['dir_nm'] + args.graph_files_dir)
inputs['graph_files_dir'] = args.graph_files_dir
with open(inputs['dir_nm'] + inputs['out_comp_nm'] + "_input.yaml", 'w') as outfile:
yaml_dump(inputs, outfile, default_flow_style=False)
logging_basicConfig(filename=inputs['dir_nm'] + inputs['out_comp_nm'] + "_logs.yaml", level=logging_INFO)
start_time_read = time_time()
myGraph = read_graphs(inputs)
read_time = time_time() - start_time_read
myGraphName = inputs['dir_nm']+ inputs['graph_files_dir'] + "/res_myGraph"
with open(myGraphName, 'wb') as f:
pickle_dump(myGraph, f)
tot_time = time_time() - start_time
out_comp_nm = inputs['dir_nm'] + inputs['out_comp_nm']
# Write to yaml file instead
with open(out_comp_nm + '_runtime_performance.out', "a") as fid:
print("Read network time (s) = ", read_time, "[", round(100 * float(read_time) / tot_time, 2), "%]", file=fid)
print("Total time (s) = ", tot_time, file=fid)
if __name__ == '__main__':
main()