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 5 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
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

Check warning on line 27 in src/ansys/aedt/core/visualization/post/spisim.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/spisim.py#L27

Added line #L27 was not covered by tests
from pathlib import Path
import re
import shutil

Check warning on line 30 in src/ansys/aedt/core/visualization/post/spisim.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/spisim.py#L30

Added line #L30 was not covered by tests
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, val):
self._working_directory = val

def _copy_to_relative_path(self, file_name):

Check warning on line 77 in src/ansys/aedt/core/visualization/post/spisim.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/spisim.py#L77

Added line #L77 was not covered by tests
"""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)

Check warning on line 83 in src/ansys/aedt/core/visualization/post/spisim.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/spisim.py#L79-L83

Added lines #L79 - L83 were not covered by tests

@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]

Check warning on line 91 in src/ansys/aedt/core/visualization/post/spisim.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/spisim.py#L90-L91

Added lines #L90 - L91 were not covered by tests
if config_file != "":
command += ["-v", f"CFGFILE={config_file}"]
command += ["-v", f"CFGFILE={cfg_file_only}"]

Check warning on line 93 in src/ansys/aedt/core/visualization/post/spisim.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/spisim.py#L93

Added line #L93 was not covered by tests
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")

Check warning on line 98 in src/ansys/aedt/core/visualization/post/spisim.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/spisim.py#L98

Added line #L98 was not covered by tests

my_env = os.environ.copy()
my_env.update(settings.aedt_environment_variables)
Expand All @@ -96,7 +106,7 @@
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

Check warning on line 109 in src/ansys/aedt/core/visualization/post/spisim.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/spisim.py#L109

Added line #L109 was not covered by tests
return out_processing

@pyaedt_function_handler()
Expand Down Expand Up @@ -227,7 +237,9 @@
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]

Check warning on line 242 in src/ansys/aedt/core/visualization/post/spisim.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/spisim.py#L241-L242

Added lines #L241 - L242 were not covered by tests
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 @@
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)

Check warning on line 281 in src/ansys/aedt/core/visualization/post/spisim.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/spisim.py#L281

Added line #L281 was not covered by tests
results = self.__get_output_parameter_from_result(out_processing, "ERL")
if results:
return results
Expand Down Expand Up @@ -327,8 +339,9 @@
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)

Check warning on line 344 in src/ansys/aedt/core/visualization/post/spisim.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/spisim.py#L342-L344

Added lines #L342 - L344 were not covered by tests
return self.__compute_com(com_param)

@pyaedt_function_handler
Expand All @@ -347,17 +360,26 @@
-------
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"])

Check warning on line 365 in src/ansys/aedt/core/visualization/post/spisim.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/spisim.py#L363-L365

Added lines #L363 - L365 were not covered by tests

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", "./")

Check warning on line 370 in src/ansys/aedt/core/visualization/post/spisim.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/spisim.py#L370

Added line #L370 was not covered by tests
# 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")

Check warning on line 382 in src/ansys/aedt/core/visualization/post/spisim.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/visualization/post/spisim.py#L382

Added line #L382 was not covered by tests
com_parameter.export_spisim_cfg(cfg_file)

out_processing = self.__compute_spisim("COM", cfg_file)
Expand Down
Loading