Skip to content

FIX: Update Spisim to relative path #6033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/6033.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update Spisim to relative path
28 changes: 22 additions & 6 deletions src/ansys/aedt/core/visualization/post/compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,9 @@
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):
Expand All @@ -944,23 +946,37 @@
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"])

Check warning on line 960 in src/ansys/aedt/core/visualization/post/compliance.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/compliance.py#L960

Added line #L960 was not covered by tests
self._summary.append(["Effective Return Loss", "COMPLIANCE PASSED"])
self._summary_font.append(["", None])
font_table.append(["", None])

Check warning on line 963 in src/ansys/aedt/core/visualization/post/compliance.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/compliance.py#L963

Added line #L963 was not covered by tests

else:
table_out.append(

Check warning on line 966 in src/ansys/aedt/core/visualization/post/compliance.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/compliance.py#L966

Added line #L966 was not covered by tests
[
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]])

Check warning on line 977 in src/ansys/aedt/core/visualization/post/compliance.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/compliance.py#L977

Added line #L977 was not covered by tests

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()
Expand Down
56 changes: 39 additions & 17 deletions src/ansys/aedt/core/visualization/post/spisim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,19 +74,28 @@ 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"
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)
Expand All @@ -96,7 +106,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()
Expand Down Expand Up @@ -227,7 +237,9 @@ def compute_erl(
cfg_dict[split_line[0]] = split_line[1]

self.touchstone_file = self.touchstone_file.replace("\\", "/")
cfg_dict["INPARRY"] = self.touchstone_file

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"):
cfg_dict["MIXMODE"] = port_order
Expand Down Expand Up @@ -266,7 +278,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
Expand Down Expand Up @@ -327,8 +339,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
Expand All @@ -347,17 +360,26 @@ 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("\\", "/")
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)
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)
Expand Down
Loading