@@ -30,12 +30,12 @@ def parse_cli_arguments(input_arguments: list[str] = None,
3030
3131 parser = argparse .ArgumentParser (description = "This script is for merging the outputs from a test that uses Vernier callipers into one file. For full documentation please see the post-processing section of the user guide." )
3232
33- parser .add_argument ("-p" , "--path" , type = Path , default = (os .getcwd ()), help = "Path to Vernier output files" )
34- parser .add_argument ("-o" , "--output_name" , type = str , default = str ("vernier-merged-output" ), help = "Name of file to write to" )
35- parser .add_argument ("-i" , "--input_name" , type = str , default = str ("vernier-output-" ), help = "Vernier files to read from" )
36- parser .add_argument ("-d " , "--decimals " , type = int , default = 3 , help = "Number of decimal places calculated results will be reported to " )
37- parser .add_argument ("-b " , "--basic_output " , action = "store_true" , default = False , help = "Outputs only mean values across MPI ranks " )
38-
33+ parser .add_argument ("-p" , "--path" , type = Path , default = (os .getcwd ()), help = "Path to Vernier output files" )
34+ parser .add_argument ("-o" , "--output_name" , type = str , default = str ("vernier-merged-output" ), help = "Name of file to write to" )
35+ parser .add_argument ("-i" , "--input_name" , type = str , default = str ("vernier-output-" ), help = "Vernier files to read from" )
36+ parser .add_argument ("-m " , "--max_only " , action = "store_true" , default = False , help = "Only calculates the maximum value across all ranks " )
37+ parser .add_argument ("-f " , "--full_info " , action = "store_true" , default = False , help = "Enables merging and displaying of all information Vernier records " )
38+ parser . add_argument ( "-d" , "--decimals" , type = int , default = 3 , help = "Number of decimal places calculated results will be reported to" )
3939
4040 return parser .parse_args (args = input_arguments )
4141
@@ -61,17 +61,19 @@ def read_mpi_ranks(directory_path: Path,
6161def read_and_pre_process (file_path : Path ,
6262 rank : int ,
6363 input_name : str ,
64+ full_info_bool : bool ,
6465 ) -> pd .DataFrame :
6566 """ Reads a vernier-output and processes it
6667
6768 Reads in the current vernier-output file for a given rank before removing
6869 whitespace and formatting into a pandas dataframe.
6970
7071 Args:
71- file_path: The path where the vernier outputs are located.
72- rank: The current output file to open, as different output files
73- are ordered according to MPI rank.
74- input_name: The name of the vernier output files without the rank.
72+ file_path: The path where the vernier outputs are located.
73+ rank: The current output file to open, as different output files
74+ are ordered according to MPI rank.
75+ input_name: The name of the vernier output files without the rank.
76+ full_info_bool: A boolean which if set to True will give merge all vernier recordings for final output.
7577
7678 Returns:
7779 A Pandas dataframe containing the processed vernier output data.
@@ -94,14 +96,25 @@ def read_and_pre_process(file_path: Path,
9496 """ Organises the new dataframe """
9597 dataframe = dataframe .sort_values (by = "Routine" )
9698 dataframe = dataframe .reset_index (drop = True )
97- temp_dataframe = dataframe [["Total" , "Self" , "Routine" ]]
99+ dataframe = dataframe .drop (columns = ["index" ])
100+
101+ """ If the user wants the full information then it will be returned,
102+ otherwise the pruned information will be pruned """
103+ if full_info_bool :
104+
105+ return dataframe
106+
107+ else :
98108
99- return temp_dataframe
109+ temp_dataframe = dataframe [["Total" , "Self" , "Routine" ]]
110+
111+ return temp_dataframe
100112
101113def merge_and_analyse (file_path : Path ,
102114 mpiranks : int ,
103115 input_name : str ,
104- basic_output_bool : bool
116+ max_only_bool : bool ,
117+ full_info_bool : bool ,
105118 ) -> pd .DataFrame :
106119 """ Reads in the files and merges them
107120
@@ -110,10 +123,14 @@ def merge_and_analyse(file_path: Path,
110123 before averaging them.
111124
112125 Args:
113- file_path: The path where the vernier outputs are located.
114- mpiranks: The number of mpi ranks (equivalent to the number of files) to iterate through.
115- input_name: The name of the vernier output files without the rank.
116- basic_output_bool: A boolean which if set to True will not calculate minimum/ maximum values.
126+ file_path: The path where the vernier outputs are located.
127+ mpiranks: The number of mpi ranks (equivalent to the number of files) to iterate through.
128+ input_name: The name of the vernier output files without the rank.
129+ max_only_bool: A boolean which if set to True will not calculate minimum/ maximum values.
130+ file_path: The path where the vernier outputs are located.
131+ mpiranks: The number of mpi ranks (equivalent to the number of files) to iterate through.
132+ input_name: The name of the vernier output files without the rank.
133+ full_info_bool: A boolean which if set to True will give merge all vernier recordings for final output.
117134
118135 Returns:
119136 The merged dataframe, containing the routine names and the mean 'Self' and 'Total' values across all outputs.
@@ -125,14 +142,15 @@ def merge_and_analyse(file_path: Path,
125142 for rank in range (0 ,mpiranks ):
126143
127144 """ Open the file, read it, workout where it actually starts """
128- dataframe = read_and_pre_process (file_path , rank , input_name )
145+ dataframe = read_and_pre_process (file_path , rank , input_name , full_info_bool )
129146
130147 if rank == 0 :
131148
149+ """ Creates the initial dataframe for future calculations """
132150 prev_df = dataframe .copy ()
133- if not (basic_output_bool ):
151+ if not (max_only_bool ):
134152 min_df = dataframe .copy ()
135- max_df = dataframe .copy ()
153+ max_df = dataframe .copy ()
136154
137155 else :
138156
@@ -141,10 +159,10 @@ def merge_and_analyse(file_path: Path,
141159 new_df ["Routine" ] = prev_df ["Routine" ]
142160
143161 """ Calculates new min/ max values """
144- if not ( basic_output_bool ) :
145- for column in dataframe . columns :
162+ for column in dataframe . columns :
163+ if not ( max_only_bool ) :
146164 min_df [column ] = min_df [column ].where (min_df [column ] < dataframe [column ], dataframe [column ])
147- max_df [column ] = max_df [column ].where (max_df [column ] > dataframe [column ], dataframe [column ])
165+ max_df [column ] = max_df [column ].where (max_df [column ] > dataframe [column ], dataframe [column ])
148166
149167 prev_df = new_df .copy ()
150168
@@ -154,14 +172,19 @@ def merge_and_analyse(file_path: Path,
154172
155173 """ Adds the min/ max values to the mean dataframe and renames columns """
156174
157- for column in mean_df .drop (columns = ["Routine" ]):
158- mean_df [f"Mean_{ column } " ] = mean_df [column ]
159- if not (basic_output_bool ):
160- mean_df [f"Min_{ column } " ] = min_df [column ]
161- mean_df [f"Max_{ column } " ] = max_df [column ]
162- mean_df = mean_df .drop (columns = [f"{ column } " ])
163-
164- return mean_df
175+ if full_info_bool :
176+ output_df = mean_df .drop (columns = ["Calls" ])
177+ else :
178+ output_df = mean_df .copy ()
179+ for column in output_df .drop (columns = ["Routine" ]):
180+ if not (max_only_bool ):
181+ output_df [f"Min_{ column } " ] = min_df [column ]
182+ output_df [f"Mean_{ column } " ] = mean_df [column ]
183+ output_df [f"Max_{ column } " ] = max_df [column ]
184+ output_df = output_df .drop (columns = [f"{ column } " ])
185+ if full_info_bool :
186+ output_df ["Calls" ] = max_df ["Calls" ]
187+ return output_df
165188
166189def main ():
167190
@@ -170,8 +193,10 @@ def main():
170193 file_path = args .path
171194 merged_file_name = args .output_name
172195 input_name = args .input_name
173- basic_output_bool = args .basic_output
196+ max_only_bool = args .max_only
197+ full_info_bool = args .full_info
174198 decimals = args .decimals
199+
175200 mpiranks = read_mpi_ranks (file_path , input_name )
176201
177202 if decimals >= 4 :
@@ -188,7 +213,7 @@ def main():
188213 print ("\n Reading and Merging..." )
189214
190215
191- merged_frame = merge_and_analyse (file_path , int (mpiranks ), input_name , basic_output_bool )
216+ merged_frame = merge_and_analyse (file_path , int (mpiranks ), input_name , max_only_bool , full_info_bool )
192217
193218 thread_string = "@0"
194219 merged_frame ["Routine" ] = merged_frame ["Routine" ].str .replace (thread_string , '' )
0 commit comments