From fa201679dd877dce39f879bc2adab9b9107da9f2 Mon Sep 17 00:00:00 2001 From: mcapodif Date: Thu, 10 Apr 2025 16:50:27 +0200 Subject: [PATCH 1/6] Update Spisim to relative path during command execution to workaround an issue in the tool --- .../aedt/core/visualization/post/spisim.py | 58 +++++++++++++------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/src/ansys/aedt/core/visualization/post/spisim.py b/src/ansys/aedt/core/visualization/post/spisim.py index 6515bfc7721..2b961e733c5 100644 --- a/src/ansys/aedt/core/visualization/post/spisim.py +++ b/src/ansys/aedt/core/visualization/post/spisim.py @@ -24,12 +24,13 @@ # coding=utf-8 import os +import pathlib from pathlib import Path import re +import shutil from struct import unpack import subprocess # nosec -from ansys.aedt.core.generic.file_utils import generate_unique_folder_name from ansys.aedt.core.generic.file_utils import generate_unique_name from ansys.aedt.core.generic.file_utils import open_file from ansys.aedt.core.generic.general_methods import env_value @@ -78,14 +79,15 @@ def __compute_spisim(self, parameter, config_file, out_file=""): exec_name = "SPISimJNI_LX64.exe" if is_linux else "SPISimJNI_WIN64.exe" spisim_exe = os.path.join(self.desktop_install_dir, "spisim", "SPISim", "modules", "ext", exec_name) command = [spisim_exe, parameter] - + config_folder = os.path.dirname(config_file) + cfg_file_only = os.path.split(config_file)[-1] if config_file != "": - command += ["-v", f"CFGFILE={config_file}"] + command += ["-v", f"CFGFILE={cfg_file_only}"] if out_file: - command += [",", "-o", f"{out_file}"] + # command += [",", "-o", f"{out_file}"] out_processing = os.path.join(out_file, generate_unique_name("spsim_out") + ".txt") else: - out_processing = os.path.join(generate_unique_folder_name(), generate_unique_name("spsim_out") + ".txt") + out_processing = os.path.join(self.working_directory, generate_unique_name("spsim_out") + ".txt") my_env = os.environ.copy() my_env.update(settings.aedt_environment_variables) @@ -96,7 +98,7 @@ def __compute_spisim(self, parameter, config_file, out_file=""): my_env["SPISIM_OUTPUT_LOG"] = os.path.join(out_file, generate_unique_name("spsim_out") + ".log") with open_file(out_processing, "w") as outfile: - subprocess.run(command, env=my_env, stdout=outfile, stderr=outfile, check=True) # nosec + subprocess.run(command, env=my_env, cwd=config_folder, stdout=outfile, stderr=outfile, check=True) # nosec return out_processing @pyaedt_function_handler() @@ -227,7 +229,10 @@ def compute_erl( cfg_dict[split_line[0]] = split_line[1] self.touchstone_file = self.touchstone_file.replace("\\", "/") - cfg_dict["INPARRY"] = self.touchstone_file + if pathlib.Path(self.touchstone_file).parent != pathlib.Path(self.working_directory): + shutil.copy(self.touchstone_file, pathlib.Path(self.working_directory)) + self.touchstone_file = os.path.join(self.working_directory, os.path.split(self.touchstone_file)[-1]) + cfg_dict["INPARRY"] = os.path.split(self.touchstone_file)[-1] cfg_dict["MIXMODE"] = "" if "MIXMODE" not in cfg_dict else cfg_dict["MIXMODE"] if port_order is not None and self.touchstone_file.lower().endswith(".s4p"): cfg_dict["MIXMODE"] = port_order @@ -266,7 +271,7 @@ def compute_erl( retries = 10 nb_retry = 0 while nb_retry < retries: - out_processing = self.__compute_spisim("CalcERL", config_file, out_file=self.working_directory) + out_processing = self.__compute_spisim("CalcERL", config_file) results = self.__get_output_parameter_from_result(out_processing, "ERL") if results: return results @@ -327,8 +332,9 @@ def compute_com( com_param.set_parameter("NEXTARY", next_s4p if not isinstance(next_s4p, list) else ";".join(next_s4p)) com_param.set_parameter("Port Order", "[1 3 2 4]" if port_order == "EvenOdd" else "[1 2 3 4]") - - com_param.set_parameter("RESULT_DIR", out_folder if out_folder else self.working_directory) + if out_folder: + self.working_directory = out_folder + com_param.set_parameter("RESULT_DIR", self.working_directory) return self.__compute_com(com_param) @pyaedt_function_handler @@ -347,17 +353,35 @@ def __compute_com( ------- float or list """ - thru_snp = com_parameter.parameters["THRUSNP"].replace("\\", "/") - fext_snp = com_parameter.parameters["FEXTARY"].replace("\\", "/") - next_snp = com_parameter.parameters["NEXTARY"].replace("\\", "/") - result_dir = com_parameter.parameters["RESULT_DIR"].replace("\\", "/") + if pathlib.Path(com_parameter.parameters["THRUSNP"]).is_file(): + if pathlib.Path(com_parameter.parameters["THRUSNP"]).parent != pathlib.Path(self.working_directory): + shutil.copy(com_parameter.parameters["THRUSNP"], self.working_directory) + thru_snp = pathlib.Path(com_parameter.parameters["THRUSNP"]).name + if pathlib.Path(com_parameter.parameters["FEXTARY"]).is_file(): + if pathlib.Path(com_parameter.parameters["FEXTARY"]).parent != pathlib.Path(self.working_directory): + shutil.copy(com_parameter.parameters["FEXTARY"], self.working_directory) + fext_snp = pathlib.Path(com_parameter.parameters["FEXTARY"]).name + if pathlib.Path(com_parameter.parameters["NEXTARY"]).is_file(): + if pathlib.Path(com_parameter.parameters["NEXTARY"]).parent != pathlib.Path(self.working_directory): + shutil.copy(com_parameter.parameters["NEXTARY"], self.working_directory) + next_snp = pathlib.Path(com_parameter.parameters["NEXTARY"]).name com_parameter.set_parameter("THRUSNP", thru_snp) com_parameter.set_parameter("FEXTARY", fext_snp) com_parameter.set_parameter("NEXTARY", next_snp) - com_parameter.set_parameter("RESULT_DIR", result_dir) - - cfg_file = os.path.join(com_parameter.parameters["RESULT_DIR"], "com_parameters.cfg") + com_parameter.set_parameter("RESULT_DIR", "./") + # thru_snp = com_parameter.parameters["THRUSNP"].replace("\\", "/") + # fext_snp = com_parameter.parameters["FEXTARY"].replace("\\", "/") + # next_snp = com_parameter.parameters["NEXTARY"].replace("\\", "/") + # result_dir = com_parameter.parameters["RESULT_DIR"].replace("\\", "/") + # + # com_parameter.set_parameter("THRUSNP", thru_snp) + # com_parameter.set_parameter("FEXTARY", fext_snp) + # com_parameter.set_parameter("NEXTARY", next_snp) + # com_parameter.set_parameter("RESULT_DIR", result_dir) + + # cfg_file = os.path.join(com_parameter.parameters["RESULT_DIR"], "com_parameters.cfg") + cfg_file = os.path.join(self.working_directory, "com_parameters.cfg") com_parameter.export_spisim_cfg(cfg_file) out_processing = self.__compute_spisim("COM", cfg_file) From af1be053b2aec954d6a072cf716c815852a8c811 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Thu, 10 Apr 2025 14:53:16 +0000 Subject: [PATCH 2/6] chore: adding changelog file 6033.fixed.md [dependabot-skip] --- doc/changelog.d/6033.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/6033.fixed.md diff --git a/doc/changelog.d/6033.fixed.md b/doc/changelog.d/6033.fixed.md new file mode 100644 index 00000000000..1e6841d2e91 --- /dev/null +++ b/doc/changelog.d/6033.fixed.md @@ -0,0 +1 @@ +Update Spisim to relative path \ No newline at end of file From 44677f1c0afba7180f9a5b136235b8fb1831926a Mon Sep 17 00:00:00 2001 From: mcapodif Date: Thu, 10 Apr 2025 17:01:00 +0200 Subject: [PATCH 3/6] Update Spisim to relative path during command execution to workaround an issue in the tool --- .../aedt/core/visualization/post/spisim.py | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/ansys/aedt/core/visualization/post/spisim.py b/src/ansys/aedt/core/visualization/post/spisim.py index 2b961e733c5..0221f24f1c3 100644 --- a/src/ansys/aedt/core/visualization/post/spisim.py +++ b/src/ansys/aedt/core/visualization/post/spisim.py @@ -74,6 +74,14 @@ def working_directory(self): def working_directory(self, val): self._working_directory = val + def _copy_to_relative_path(self, file_name): + """Convert a path to a relative path.""" + if not pathlib.Path(file_name).is_file(): + return file_name + if pathlib.Path(file_name).parent != pathlib.Path(self.working_directory): + shutil.copy(file_name, pathlib.Path(self.working_directory)) + return str(pathlib.Path(file_name).name) + @pyaedt_function_handler() def __compute_spisim(self, parameter, config_file, out_file=""): exec_name = "SPISimJNI_LX64.exe" if is_linux else "SPISimJNI_WIN64.exe" @@ -229,9 +237,8 @@ def compute_erl( cfg_dict[split_line[0]] = split_line[1] self.touchstone_file = self.touchstone_file.replace("\\", "/") - if pathlib.Path(self.touchstone_file).parent != pathlib.Path(self.working_directory): - shutil.copy(self.touchstone_file, pathlib.Path(self.working_directory)) - self.touchstone_file = os.path.join(self.working_directory, os.path.split(self.touchstone_file)[-1]) + + self.touchstone_file = self._copy_to_relative_path(self.touchstone_file) cfg_dict["INPARRY"] = os.path.split(self.touchstone_file)[-1] cfg_dict["MIXMODE"] = "" if "MIXMODE" not in cfg_dict else cfg_dict["MIXMODE"] if port_order is not None and self.touchstone_file.lower().endswith(".s4p"): @@ -353,18 +360,9 @@ def __compute_com( ------- float or list """ - if pathlib.Path(com_parameter.parameters["THRUSNP"]).is_file(): - if pathlib.Path(com_parameter.parameters["THRUSNP"]).parent != pathlib.Path(self.working_directory): - shutil.copy(com_parameter.parameters["THRUSNP"], self.working_directory) - thru_snp = pathlib.Path(com_parameter.parameters["THRUSNP"]).name - if pathlib.Path(com_parameter.parameters["FEXTARY"]).is_file(): - if pathlib.Path(com_parameter.parameters["FEXTARY"]).parent != pathlib.Path(self.working_directory): - shutil.copy(com_parameter.parameters["FEXTARY"], self.working_directory) - fext_snp = pathlib.Path(com_parameter.parameters["FEXTARY"]).name - if pathlib.Path(com_parameter.parameters["NEXTARY"]).is_file(): - if pathlib.Path(com_parameter.parameters["NEXTARY"]).parent != pathlib.Path(self.working_directory): - shutil.copy(com_parameter.parameters["NEXTARY"], self.working_directory) - next_snp = pathlib.Path(com_parameter.parameters["NEXTARY"]).name + thru_snp = self._copy_to_relative_path(com_parameter.parameters["THRUSNP"]) + fext_snp = self._copy_to_relative_path(com_parameter.parameters["FEXTARY"]) + next_snp = self._copy_to_relative_path(com_parameter.parameters["NEXTARY"]) com_parameter.set_parameter("THRUSNP", thru_snp) com_parameter.set_parameter("FEXTARY", fext_snp) From 7c79de8df877b3147bfdb40ac59aa4c42cb4593c Mon Sep 17 00:00:00 2001 From: mcapodif Date: Thu, 10 Apr 2025 17:26:22 +0200 Subject: [PATCH 4/6] fixed pass fail ERL table --- .../core/visualization/post/compliance.py | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/ansys/aedt/core/visualization/post/compliance.py b/src/ansys/aedt/core/visualization/post/compliance.py index e1639306f5c..c5f429b00a5 100644 --- a/src/ansys/aedt/core/visualization/post/compliance.py +++ b/src/ansys/aedt/core/visualization/post/compliance.py @@ -925,7 +925,9 @@ def _create_parameters(self, pdf_report): spisim = SpiSim(None) if name == "erl": pdf_report.add_sub_chapter("Effective Return Loss") - table_out = [["ERL", "Value", "Pass/Fail"]] + table_out = [["ERL", "Value", "Criteria", "Pass/Fail"]] + font_table = [["", None]] + traces = template_report.traces trace_pins = template_report.trace_pins for trace_name, trace_pin in zip(traces, trace_pins): @@ -944,23 +946,31 @@ def _create_parameters(self, pdf_report): failed = True if float(erl_value) > float(pass_fail_criteria) else False except ValueError: failed = True - table_out.append([trace_name, erl_value, "PASS" if not failed else "FAIL"]) + table_out.append( + [trace_name, erl_value, pass_fail_criteria, "PASS" if not failed else "FAIL"] + ) self._summary.append( ["Effective Return Loss", "COMPLIANCE PASSED" if not failed else "COMPLIANCE FAILED"] ) self._summary_font.append([None, [255, 0, 0]] if failed else ["", None]) + font_table.append([None, [255, 0, 0]] if failed else ["", None]) + else: + table_out.append([trace_name, erl_value, "NA", "PASS"]) self._summary.append(["Effective Return Loss", "COMPLIANCE PASSED"]) self._summary_font.append(["", None]) + font_table.append(["", None]) + else: + table_out.append( + [trace_name, "Failed to Compute", pass_fail_criteria, "PASS" if not failed else "FAIL"] + ) self._summary.append(["Effective Return Loss", "Failed to compute ERL."]) self._summary_font.append([None, [255, 0, 0]]) + font_table.append([None, [255, 0, 0]]) - pdf_report.add_table( - "Effective Return Losses", - table_out, - ) + pdf_report.add_table("Effective Return Losses", table_out, font_table) settings.logger.info(f"Parameters {template_report.name} added to the report.") @pyaedt_function_handler() From 2049eab3b9e2429e6eab828d4444c55c78bf86d6 Mon Sep 17 00:00:00 2001 From: mcapodif Date: Thu, 10 Apr 2025 17:28:20 +0200 Subject: [PATCH 5/6] fixed pass fail ERL table --- src/ansys/aedt/core/visualization/post/compliance.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ansys/aedt/core/visualization/post/compliance.py b/src/ansys/aedt/core/visualization/post/compliance.py index c5f429b00a5..c958e4a387e 100644 --- a/src/ansys/aedt/core/visualization/post/compliance.py +++ b/src/ansys/aedt/core/visualization/post/compliance.py @@ -964,8 +964,14 @@ def _create_parameters(self, pdf_report): else: table_out.append( - [trace_name, "Failed to Compute", pass_fail_criteria, "PASS" if not failed else "FAIL"] + [ + trace_name, + "Failed to Compute", + pass_fail_criteria if pass_fail else "NA", + "PASS" if not failed else "FAIL", + ] ) + self._summary.append(["Effective Return Loss", "Failed to compute ERL."]) self._summary_font.append([None, [255, 0, 0]]) font_table.append([None, [255, 0, 0]]) From 7b9728b104acb2ca2d3faf9e715a4076a8a1c41c Mon Sep 17 00:00:00 2001 From: mcapodif Date: Fri, 11 Apr 2025 11:29:03 +0200 Subject: [PATCH 6/6] added try except to the copy of the file to relative path --- src/ansys/aedt/core/visualization/post/spisim.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ansys/aedt/core/visualization/post/spisim.py b/src/ansys/aedt/core/visualization/post/spisim.py index 0221f24f1c3..8446c077f7b 100644 --- a/src/ansys/aedt/core/visualization/post/spisim.py +++ b/src/ansys/aedt/core/visualization/post/spisim.py @@ -79,7 +79,10 @@ def _copy_to_relative_path(self, file_name): if not pathlib.Path(file_name).is_file(): return file_name if pathlib.Path(file_name).parent != pathlib.Path(self.working_directory): - shutil.copy(file_name, pathlib.Path(self.working_directory)) + try: + shutil.copy(file_name, pathlib.Path(self.working_directory)) + except Exception: + self.logger.warning(f"Failed to copy {file_name}") return str(pathlib.Path(file_name).name) @pyaedt_function_handler()