From 0e45735e8b72a7e2cf12e9b30b0161b2e63db305 Mon Sep 17 00:00:00 2001 From: Neïl Zaim <49716072+NeilZaim@users.noreply.github.com> Date: Tue, 13 Jun 2023 19:52:57 +0200 Subject: Add python script to update benchmarks from Azure output (#2355) * Add python script to update benchmarks from Azure output * Update Regression/Checksum/update_benchmarks_from_azure_output.py Co-authored-by: Edoardo Zoni <59625522+EZoni@users.noreply.github.com> * Cleaner python script * Remove empirical numbers and read and write the json files once * Also read dashes in test names * Move script to Tools/DevUtils folder * Add documentation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Directly parse the new file * Apply suggestions from code review Co-authored-by: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com> --------- Co-authored-by: Edoardo Zoni <59625522+EZoni@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Roelof Groenewald <40245517+roelof-groenewald@users.noreply.github.com> --- .../update_benchmarks_from_azure_output.py | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Tools/DevUtils/update_benchmarks_from_azure_output.py (limited to 'Tools/DevUtils/update_benchmarks_from_azure_output.py') diff --git a/Tools/DevUtils/update_benchmarks_from_azure_output.py b/Tools/DevUtils/update_benchmarks_from_azure_output.py new file mode 100644 index 000000000..28c3dc6b5 --- /dev/null +++ b/Tools/DevUtils/update_benchmarks_from_azure_output.py @@ -0,0 +1,65 @@ +# Copyright 2023 Neil Zaim +# +# This file is part of WarpX. +# +# License: BSD-3-Clause-LBNL + +import json +import re +import sys + +''' +This Python script updates the Azure benchmarks automatically using a raw Azure output textfile +that is given as the first and only argument of the script. + +In the Azure output, we read the lines contained between +"New file for Test_Name:" +and the next occurrence of +"'----------------'" +And use these lines to update the benchmarks +''' + +azure_output_filename = sys.argv[1] + +pattern_test_name = 'New file for (?P[\w\-]*)' +closing_string = '----------------' +benchmark_path = "../../Regression/Checksum/benchmarks_json/" +benchmark_suffix = ".json" + +first_line_read = False +current_test = "" + +with open(azure_output_filename, "r") as f: + for line in f: + + if current_test == "": + # Here we search lines that read, for example, + # "New file for LaserAcceleration_BTD" + # and we set current_test = "LaserAcceleration_BTD" + match_test_name = re.search(pattern_test_name, line) + if match_test_name: + current_test = match_test_name.group('testname') + new_file_string = "" + + else: + # We add each line to the new file string until we find the line containing + # "----------------" + # which indicates that we have read the new file entirely + + if not closing_string in line: + if not first_line_read: + # Raw Azure output comes with a prefix at the beginning of each line that we do + # not need here. The first line that we will read is the prefix followed by the + # "{" character, so we determine how long the prefix is by finding the last + # occurence of the "{" character in this line. + azure_indent = line.rfind('{') + first_line_read = True + new_file_string += line[azure_indent:] + + else: + # We have read the new file entirely. Dump it in the json file. + new_file_json = json.loads(new_file_string) + json_filepath = benchmark_path+current_test+benchmark_suffix + with open(json_filepath, "w") as f_json: + json.dump(new_file_json, f_json, indent=2) + current_test = "" -- cgit v1.2.3