Coverage for lasso/diffcrash/run.py: 0%

39 statements  

« prev     ^ index     » next       coverage.py v7.2.4, created at 2023-04-28 18:42 +0100

1from concurrent import futures 

2 

3from lasso.diffcrash.diffcrash_run import ( 

4 DC_STAGE_EIGEN, 

5 DC_STAGE_EXPORT, 

6 DC_STAGE_IMPORT, 

7 DC_STAGE_MATH, 

8 DC_STAGE_MATRIX, 

9 DC_STAGE_MERGE, 

10 DC_STAGE_SETUP, 

11 DC_STAGES, 

12 DiffcrashRun, 

13 parse_diffcrash_args, 

14) 

15 

16from ..logging import str_error 

17 

18 

19def _parse_stages(start_stage: str, end_stage: str): 

20 

21 # check validity 

22 if start_stage not in DC_STAGES or end_stage not in DC_STAGES: 

23 raise ValueError( 

24 str_error(f"{start_stage} is not a valid stage. Try: {', '.join(DC_STAGES)}.") 

25 ) 

26 

27 # get indexes 

28 start_stage_index = DC_STAGES.index(start_stage) 

29 end_stage_index = DC_STAGES.index(end_stage) 

30 

31 # check if start and end are in correct order 

32 if start_stage_index > end_stage_index: 

33 raise ValueError( 

34 str_error( 

35 f"The specified end stage '{end_stage}' comes before " 

36 f"the start stage ({start_stage}). " 

37 f"Try the order: {', '.join(DC_STAGES)}" 

38 ) 

39 ) 

40 

41 return start_stage_index, end_stage_index 

42 

43 

44def main(): 

45 """Main function for running diffcrash""" 

46 

47 # parse command line stuff 

48 parser = parse_diffcrash_args() 

49 

50 # parse settings from command line 

51 diffcrash_run = DiffcrashRun( 

52 project_dir=parser.project_dir, 

53 crash_code=parser.crash_code, 

54 reference_run=parser.reference_run, 

55 exclude_runs=parser.exclude_runs, 

56 simulation_runs=parser.simulation_runs, 

57 diffcrash_home=parser.diffcrash_home, 

58 use_id_mapping=parser.use_id_mapping, 

59 config_file=parser.config_file, 

60 parameter_file=parser.parameter_file, 

61 n_processes=parser.n_processes, 

62 ) 

63 

64 # determine start and end stages 

65 start_stage_index, end_stage_index = _parse_stages(parser.start_stage, parser.end_stage) 

66 

67 # remove old stuff 

68 if start_stage_index == 0: 

69 diffcrash_run.clear_project_dir() 

70 diffcrash_run.create_project_dirs() 

71 

72 # do the thing 

73 print() 

74 print(" ---- Running Routines ---- ") 

75 print() 

76 

77 # initiate threading pool for handling jobs 

78 with futures.ThreadPoolExecutor(max_workers=diffcrash_run.n_processes) as pool: 

79 

80 # setup 

81 if start_stage_index <= DC_STAGES.index(DC_STAGE_SETUP) <= end_stage_index: 

82 diffcrash_run.run_setup(pool) 

83 

84 # import 

85 if start_stage_index <= DC_STAGES.index(DC_STAGE_IMPORT) <= end_stage_index: 

86 diffcrash_run.run_import(pool) 

87 

88 # math 

89 if start_stage_index <= DC_STAGES.index(DC_STAGE_MATH) <= end_stage_index: 

90 diffcrash_run.run_math(pool) 

91 

92 # export 

93 if start_stage_index <= DC_STAGES.index(DC_STAGE_EXPORT) <= end_stage_index: 

94 diffcrash_run.run_export(pool) 

95 

96 # matrix 

97 if start_stage_index <= DC_STAGES.index(DC_STAGE_MATRIX) <= end_stage_index: 

98 diffcrash_run.run_matrix(pool) 

99 

100 # eigen 

101 if start_stage_index <= DC_STAGES.index(DC_STAGE_EIGEN) <= end_stage_index: 

102 diffcrash_run.run_eigen(pool) 

103 

104 # merge 

105 if start_stage_index <= DC_STAGES.index(DC_STAGE_MERGE) <= end_stage_index: 

106 diffcrash_run.run_merge(pool) 

107 

108 # final spacing 

109 print() 

110 

111 

112if __name__ == "__main__": 

113 main()