From 24ecac506d76417ffd7fd0b60a16f94b9d5f9d1c Mon Sep 17 00:00:00 2001 From: mlcommons-bot Date: Tue, 12 Nov 2024 23:25:20 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=84=20synced=20local=20'tools/subm?= =?UTF-8?q?ission/power/power=5Fchecker.py'=20with=20remote=20'compliance/?= =?UTF-8?q?check.py'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/submission/power/power_checker.py | 77 ++++++++----------------- 1 file changed, 23 insertions(+), 54 deletions(-) diff --git a/tools/submission/power/power_checker.py b/tools/submission/power/power_checker.py index 834cd59dd..93d9d6fb9 100755 --- a/tools/submission/power/power_checker.py +++ b/tools/submission/power/power_checker.py @@ -81,8 +81,7 @@ class CheckerWarning(Exception): ] COMMON_ERROR_TESTING = ["USB."] WARNING_NEEDS_TO_BE_ERROR_TESTING_RE = [ - re.compile( - r"Uncertainty \d+.\d+%, which is above 1.00% limit for the last sample!") + re.compile(r"Uncertainty \d+.\d+%, which is above 1.00% limit for the last sample!") ] TIME_DELTA_TOLERANCE = 800 # in milliseconds @@ -90,7 +89,7 @@ class CheckerWarning(Exception): def _normalize(path: str) -> str: allparts: List[str] = [] - while True: + while 1: parts = os.path.split(path) if parts[0] == path: # sentinel for absolute paths allparts.insert(0, parts[0]) @@ -127,10 +126,8 @@ def get_time_from_line( ) -> float: log_time_str = re.search(data_regexp, line) if log_time_str and log_time_str.group(0): - log_datetime = datetime.strptime( - log_time_str.group(0), "%m-%d-%Y %H:%M:%S.%f") - return log_datetime.replace( - tzinfo=timezone.utc).timestamp() + timezone_offset + log_datetime = datetime.strptime(log_time_str.group(0), "%m-%d-%Y %H:%M:%S.%f") + return log_datetime.replace(tzinfo=timezone.utc).timestamp() + timezone_offset raise LineWithoutTimeStamp(f"{line.strip()!r} in {file}.") @@ -159,10 +156,8 @@ def required_fields_check(self) -> None: ), f"Required fields {', '.join(absent_keys)!r} does not exist in {self.path!r}" -def compare_dicts_values( - d1: Dict[str, str], d2: Dict[str, str], comment: str) -> None: - files_with_diff_check_sum = {k: d1[k] - for k in d1 if k in d2 and d1[k] != d2[k]} +def compare_dicts_values(d1: Dict[str, str], d2: Dict[str, str], comment: str) -> None: + files_with_diff_check_sum = {k: d1[k] for k in d1 if k in d2 and d1[k] != d2[k]} assert len(files_with_diff_check_sum) == 0, f"{comment}" + "".join( [ f"Expected {d1[i]}, but got {d2[i]} for {i}\n" @@ -171,8 +166,7 @@ def compare_dicts_values( ) -def compare_dicts(s1: Dict[str, str], - s2: Dict[str, str], comment: str) -> None: +def compare_dicts(s1: Dict[str, str], s2: Dict[str, str], comment: str) -> None: assert ( not s1.keys() - s2.keys() ), f"{comment} Missing {', '.join(sorted(s1.keys() - s2.keys()))!r}" @@ -230,8 +224,7 @@ def check_reply(cmd: str, reply: str) -> None: for msg in msgs: if msg["cmd"].startswith(cmd): if msg["cmd"] == "Stop": - # In normal flow the third answer to stop command is - # `Error: no measurement to stop` + # In normal flow the third answer to stop command is `Error: no measurement to stop` if stop_counter == 2: reply = "Error: no measurement to stop" stop_counter += 1 @@ -250,15 +243,13 @@ def check_reply(cmd: str, reply: str) -> None: def get_initial_range(param_num: int, reply: str) -> str: reply_list = reply.split(",") try: - if reply_list[param_num] == "0" and float( - reply_list[param_num + 1]) > 0: + if reply_list[param_num] == "0" and float(reply_list[param_num + 1]) > 0: return reply_list[param_num + 1] except (ValueError, IndexError): assert False, f"Can not get power meters initial values from {reply!r}" return "Auto" - def get_command_by_value_and_number( - cmd: str, number: int) -> Optional[str]: + def get_command_by_value_and_number(cmd: str, number: int) -> Optional[str]: command_counter = 0 for msg in msgs: if msg["cmd"].startswith(cmd): @@ -282,8 +273,7 @@ def get_command_by_value_and_number( ), f"Do not set Volts range as initial. Expected 'SR,V,{initial_volts}', got {initial_volts_command!r}." -def uuid_check(client_sd: SessionDescriptor, - server_sd: SessionDescriptor) -> None: +def uuid_check(client_sd: SessionDescriptor, server_sd: SessionDescriptor) -> None: """Compare UUIDs from client.json and server.json. They should be the same.""" uuid_c = client_sd.json_object["uuid"] uuid_s = server_sd.json_object["uuid"] @@ -372,8 +362,7 @@ def compare_duration(range_duration: float, test_duration: float) -> None: def compare_time_boundaries( begin: float, end: float, phases: List[Any], mode: str ) -> None: - # TODO: temporary workaround, remove when proper DST handling is - # implemented! + # TODO: temporary workaround, remove when proper DST handling is implemented! assert ( phases[1][0] < begin < phases[2][0] or phases[1][0] < begin - 3600 < phases[2][0] @@ -391,16 +380,8 @@ def compare_time_boundaries( os.path.join(path, "run_1"), client_sd ) - compare_time_boundaries( - system_begin_r, - system_end_r, - phases_ranging_c, - "ranging") - compare_time_boundaries( - system_begin_t, - system_end_t, - phases_testing_c, - "testing") + compare_time_boundaries(system_begin_r, system_end_r, phases_ranging_c, "ranging") + compare_time_boundaries(system_begin_t, system_end_t, phases_testing_c, "testing") ranging_duration_d = system_end_r - system_begin_r testing_duration_d = system_end_t - system_begin_t @@ -483,8 +464,7 @@ def session_name_check( ), f"Session name is not equal. Client session name is {session_name_c!r}. Server session name is {session_name_s!r}" -def messages_check(client_sd: SessionDescriptor, - server_sd: SessionDescriptor) -> None: +def messages_check(client_sd: SessionDescriptor, server_sd: SessionDescriptor) -> None: """Compare client and server messages list length. Compare messages values and replies from client.json and server.json. Compare client and server version. @@ -508,19 +488,14 @@ def messages_check(client_sd: SessionDescriptor, ) # Check client and server version from server.json. - # Server.json contains all client.json messages and replies. Checked - # earlier. + # Server.json contains all client.json messages and replies. Checked earlier. def get_version(regexp: str, line: str) -> str: version_o = re.search(regexp, line) assert version_o is not None, f"Server version is not defined in:'{line}'" return version_o.group(1) - client_version = get_version( - r"mlcommons\/power client v(\d+)$", - ms[0]["cmd"]) - server_version = get_version( - r"mlcommons\/power server v(\d+)$", - ms[0]["reply"]) + client_version = get_version(r"mlcommons\/power client v(\d+)$", ms[0]["cmd"]) + server_version = get_version(r"mlcommons\/power server v(\d+)$", ms[0]["reply"]) assert ( client_version == server_version @@ -575,8 +550,7 @@ def remove_optional_path(res: Dict[str, str]) -> None: f"{client_sd.path} and {server_sd.path} results checksum comparison", ) - # Check if the hashes of the files in results directory match the ones - # recorded in server.json/client.json. + # Check if the hashes of the files in results directory match the ones recorded in server.json/client.json. result_c_s = {**results_c, **results_s} compare_dicts( @@ -642,8 +616,7 @@ def find_error_or_warning(reg_exp: str, line: str, error: bool) -> None: # Treat uncommon errors in ranging phase as warnings if all( - not problem_line.group(0).strip().startswith( - common_ranging_error) + not problem_line.group(0).strip().startswith(common_ranging_error) for common_ranging_error in COMMON_ERROR_RANGING ): raise CheckerWarning( @@ -701,8 +674,7 @@ def get_msg_without_time(line: str) -> Optional[str]: is_uncertainty_check_activated = False for line in ptd_log_lines: - msg_o = re.search( - r"Uncertainty checking for Yokogawa\S+ is activated", line) + msg_o = re.search(r"Uncertainty checking for Yokogawa\S+ is activated", line) if msg_o is not None: try: log_time = None @@ -770,8 +742,7 @@ def debug_check(server_sd: SessionDescriptor) -> None: ), "Server was running in debug mode" -def check_with_logging( - check_name: str, check: Callable[[], None]) -> Tuple[bool, bool]: +def check_with_logging(check_name: str, check: Callable[[], None]) -> Tuple[bool, bool]: try: check() except AssertionError as e: @@ -840,9 +811,7 @@ def check(path: str) -> int: parser = argparse.ArgumentParser( description="Check PTD client-server session results" ) - parser.add_argument( - "session_directory", - help="directory with session results data") + parser.add_argument("session_directory", help="directory with session results data") args = parser.parse_args() From 4af5992de253cf11106f2e0261a6e7681d293620 Mon Sep 17 00:00:00 2001 From: mlcommons-bot Date: Tue, 12 Nov 2024 23:25:48 +0000 Subject: [PATCH 2/2] [Automated Commit] Format Codebase --- tools/submission/power/power_checker.py | 75 +++++++++++++++++-------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/tools/submission/power/power_checker.py b/tools/submission/power/power_checker.py index 93d9d6fb9..5a0eb0953 100755 --- a/tools/submission/power/power_checker.py +++ b/tools/submission/power/power_checker.py @@ -81,7 +81,8 @@ class CheckerWarning(Exception): ] COMMON_ERROR_TESTING = ["USB."] WARNING_NEEDS_TO_BE_ERROR_TESTING_RE = [ - re.compile(r"Uncertainty \d+.\d+%, which is above 1.00% limit for the last sample!") + re.compile( + r"Uncertainty \d+.\d+%, which is above 1.00% limit for the last sample!") ] TIME_DELTA_TOLERANCE = 800 # in milliseconds @@ -126,8 +127,10 @@ def get_time_from_line( ) -> float: log_time_str = re.search(data_regexp, line) if log_time_str and log_time_str.group(0): - log_datetime = datetime.strptime(log_time_str.group(0), "%m-%d-%Y %H:%M:%S.%f") - return log_datetime.replace(tzinfo=timezone.utc).timestamp() + timezone_offset + log_datetime = datetime.strptime( + log_time_str.group(0), "%m-%d-%Y %H:%M:%S.%f") + return log_datetime.replace( + tzinfo=timezone.utc).timestamp() + timezone_offset raise LineWithoutTimeStamp(f"{line.strip()!r} in {file}.") @@ -156,8 +159,10 @@ def required_fields_check(self) -> None: ), f"Required fields {', '.join(absent_keys)!r} does not exist in {self.path!r}" -def compare_dicts_values(d1: Dict[str, str], d2: Dict[str, str], comment: str) -> None: - files_with_diff_check_sum = {k: d1[k] for k in d1 if k in d2 and d1[k] != d2[k]} +def compare_dicts_values( + d1: Dict[str, str], d2: Dict[str, str], comment: str) -> None: + files_with_diff_check_sum = {k: d1[k] + for k in d1 if k in d2 and d1[k] != d2[k]} assert len(files_with_diff_check_sum) == 0, f"{comment}" + "".join( [ f"Expected {d1[i]}, but got {d2[i]} for {i}\n" @@ -166,7 +171,8 @@ def compare_dicts_values(d1: Dict[str, str], d2: Dict[str, str], comment: str) - ) -def compare_dicts(s1: Dict[str, str], s2: Dict[str, str], comment: str) -> None: +def compare_dicts(s1: Dict[str, str], + s2: Dict[str, str], comment: str) -> None: assert ( not s1.keys() - s2.keys() ), f"{comment} Missing {', '.join(sorted(s1.keys() - s2.keys()))!r}" @@ -224,7 +230,8 @@ def check_reply(cmd: str, reply: str) -> None: for msg in msgs: if msg["cmd"].startswith(cmd): if msg["cmd"] == "Stop": - # In normal flow the third answer to stop command is `Error: no measurement to stop` + # In normal flow the third answer to stop command is + # `Error: no measurement to stop` if stop_counter == 2: reply = "Error: no measurement to stop" stop_counter += 1 @@ -243,13 +250,15 @@ def check_reply(cmd: str, reply: str) -> None: def get_initial_range(param_num: int, reply: str) -> str: reply_list = reply.split(",") try: - if reply_list[param_num] == "0" and float(reply_list[param_num + 1]) > 0: + if reply_list[param_num] == "0" and float( + reply_list[param_num + 1]) > 0: return reply_list[param_num + 1] except (ValueError, IndexError): assert False, f"Can not get power meters initial values from {reply!r}" return "Auto" - def get_command_by_value_and_number(cmd: str, number: int) -> Optional[str]: + def get_command_by_value_and_number( + cmd: str, number: int) -> Optional[str]: command_counter = 0 for msg in msgs: if msg["cmd"].startswith(cmd): @@ -273,7 +282,8 @@ def get_command_by_value_and_number(cmd: str, number: int) -> Optional[str]: ), f"Do not set Volts range as initial. Expected 'SR,V,{initial_volts}', got {initial_volts_command!r}." -def uuid_check(client_sd: SessionDescriptor, server_sd: SessionDescriptor) -> None: +def uuid_check(client_sd: SessionDescriptor, + server_sd: SessionDescriptor) -> None: """Compare UUIDs from client.json and server.json. They should be the same.""" uuid_c = client_sd.json_object["uuid"] uuid_s = server_sd.json_object["uuid"] @@ -362,7 +372,8 @@ def compare_duration(range_duration: float, test_duration: float) -> None: def compare_time_boundaries( begin: float, end: float, phases: List[Any], mode: str ) -> None: - # TODO: temporary workaround, remove when proper DST handling is implemented! + # TODO: temporary workaround, remove when proper DST handling is + # implemented! assert ( phases[1][0] < begin < phases[2][0] or phases[1][0] < begin - 3600 < phases[2][0] @@ -380,8 +391,16 @@ def compare_time_boundaries( os.path.join(path, "run_1"), client_sd ) - compare_time_boundaries(system_begin_r, system_end_r, phases_ranging_c, "ranging") - compare_time_boundaries(system_begin_t, system_end_t, phases_testing_c, "testing") + compare_time_boundaries( + system_begin_r, + system_end_r, + phases_ranging_c, + "ranging") + compare_time_boundaries( + system_begin_t, + system_end_t, + phases_testing_c, + "testing") ranging_duration_d = system_end_r - system_begin_r testing_duration_d = system_end_t - system_begin_t @@ -464,7 +483,8 @@ def session_name_check( ), f"Session name is not equal. Client session name is {session_name_c!r}. Server session name is {session_name_s!r}" -def messages_check(client_sd: SessionDescriptor, server_sd: SessionDescriptor) -> None: +def messages_check(client_sd: SessionDescriptor, + server_sd: SessionDescriptor) -> None: """Compare client and server messages list length. Compare messages values and replies from client.json and server.json. Compare client and server version. @@ -488,14 +508,19 @@ def messages_check(client_sd: SessionDescriptor, server_sd: SessionDescriptor) - ) # Check client and server version from server.json. - # Server.json contains all client.json messages and replies. Checked earlier. + # Server.json contains all client.json messages and replies. Checked + # earlier. def get_version(regexp: str, line: str) -> str: version_o = re.search(regexp, line) assert version_o is not None, f"Server version is not defined in:'{line}'" return version_o.group(1) - client_version = get_version(r"mlcommons\/power client v(\d+)$", ms[0]["cmd"]) - server_version = get_version(r"mlcommons\/power server v(\d+)$", ms[0]["reply"]) + client_version = get_version( + r"mlcommons\/power client v(\d+)$", + ms[0]["cmd"]) + server_version = get_version( + r"mlcommons\/power server v(\d+)$", + ms[0]["reply"]) assert ( client_version == server_version @@ -550,7 +575,8 @@ def remove_optional_path(res: Dict[str, str]) -> None: f"{client_sd.path} and {server_sd.path} results checksum comparison", ) - # Check if the hashes of the files in results directory match the ones recorded in server.json/client.json. + # Check if the hashes of the files in results directory match the ones + # recorded in server.json/client.json. result_c_s = {**results_c, **results_s} compare_dicts( @@ -616,7 +642,8 @@ def find_error_or_warning(reg_exp: str, line: str, error: bool) -> None: # Treat uncommon errors in ranging phase as warnings if all( - not problem_line.group(0).strip().startswith(common_ranging_error) + not problem_line.group(0).strip().startswith( + common_ranging_error) for common_ranging_error in COMMON_ERROR_RANGING ): raise CheckerWarning( @@ -674,7 +701,8 @@ def get_msg_without_time(line: str) -> Optional[str]: is_uncertainty_check_activated = False for line in ptd_log_lines: - msg_o = re.search(r"Uncertainty checking for Yokogawa\S+ is activated", line) + msg_o = re.search( + r"Uncertainty checking for Yokogawa\S+ is activated", line) if msg_o is not None: try: log_time = None @@ -742,7 +770,8 @@ def debug_check(server_sd: SessionDescriptor) -> None: ), "Server was running in debug mode" -def check_with_logging(check_name: str, check: Callable[[], None]) -> Tuple[bool, bool]: +def check_with_logging( + check_name: str, check: Callable[[], None]) -> Tuple[bool, bool]: try: check() except AssertionError as e: @@ -811,7 +840,9 @@ def check(path: str) -> int: parser = argparse.ArgumentParser( description="Check PTD client-server session results" ) - parser.add_argument("session_directory", help="directory with session results data") + parser.add_argument( + "session_directory", + help="directory with session results data") args = parser.parse_args()