Skip to content

Commit

Permalink
spisim_com_enhancement (#4312)
Browse files Browse the repository at this point in the history
Co-authored-by: ring630 <@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sébastien Morais <[email protected]>
  • Loading branch information
3 people authored Mar 20, 2024
1 parent 75fab9f commit a632843
Show file tree
Hide file tree
Showing 11 changed files with 1,280 additions and 806 deletions.
61 changes: 40 additions & 21 deletions _unittest_solvers/test_00_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from _unittest_solvers.conftest import desktop_version
from _unittest_solvers.conftest import local_path

from pathlib import Path

from pyaedt import is_linux
from pyaedt import Icepak
from pyaedt import Hfss3dLayout
Expand Down Expand Up @@ -436,7 +438,6 @@ def test_06_m3d_harmonic_forces(self, m3dtransient):
)
assert m3dtransient.export_element_based_harmonic_force(number_of_frequency=5)


def test_07_export_maxwell_fields(self, m3dtransient):
m3dtransient.analyze(m3dtransient.active_setup, num_cores=2)
fld_file_3 = os.path.join(self.local_scratch.path, "test_fld_3.fld")
Expand Down Expand Up @@ -493,26 +494,14 @@ def test_08_compute_erl(self, circuit_erl):
def test_09a_compute_com(self, local_scratch, circuit_com):
touchstone_file = circuit_com.export_touchstone()
spisim = SpiSim(touchstone_file)
assert spisim.com_standards
assert spisim.com_parameters()

report_dir = os.path.join(spisim.working_directory, "50GAUI-1_C2C")
os.mkdir(report_dir)
com_0, com_1 = spisim.compute_com(
standard="50GAUI-1_C2C",
out_folder=report_dir,
)
assert com_0 and com_1

report_dir = os.path.join(spisim.working_directory, "100GBASE-KR4")
os.mkdir(report_dir)
com_0, com_1 = spisim.compute_com(
standard="100GBASE-KR4",
fext_s4p=[touchstone_file, touchstone_file],
next_s4p=touchstone_file,
com = spisim.compute_com(
standard="50GAUI-1-C2C",
out_folder=report_dir,
)
assert com_0 and com_1
assert com

def test_09b_compute_com(self, local_scratch):
com_example_file_folder = os.path.join(local_path, "example_models", test_subfolder, "com_unit_test_sparam")
Expand All @@ -523,18 +512,48 @@ def test_09b_compute_com(self, local_scratch):
next_s4p = local_scratch.copyfile(
os.path.join(com_example_file_folder, "FCI_CC_Long_Link_Pair_11_to_Pair_9_NEXT.s4p")
)

report_dir = os.path.join(local_scratch.path, "custom")
os.mkdir(report_dir)

spisim = SpiSim(thru_s4p)
spisim.export_com_configure_file(os.path.join(spisim.working_directory, "custom.cfg"))
spisim.working_directory = local_scratch.path

com_0, com_1 = spisim.compute_com(
standard="custom",
config_file=os.path.join(spisim.working_directory, "custom.cfg"),
standard="50GAUI-1-C2C",
port_order="EvenOdd",
fext_s4p=fext_s4p,
next_s4p=next_s4p,
out_folder=report_dir,
)
assert com_0 and com_1
com_0, com_1 = spisim.compute_com(
standard="100GBASE-KR4",
port_order="EvenOdd",
fext_s4p=fext_s4p,
next_s4p=next_s4p,
out_folder=report_dir,
)
assert com_0 and com_1
com_0, com_1 = spisim.compute_com(
standard="100GBASE-KP4",
port_order="EvenOdd",
fext_s4p=fext_s4p,
next_s4p=next_s4p,
out_folder=report_dir,
)
assert com_0 and com_1

def test_09c_compute_com(self, local_scratch):
com_example_file_folder = Path(local_path) / "example_models" / test_subfolder / "com_unit_test_sparam"
thru_s4p = local_scratch.copyfile(com_example_file_folder / "SerDes_Demo_02_Thru.s4p")
spisim = SpiSim(thru_s4p)
spisim.export_com_configure_file(Path(local_scratch.path) / "test.cfg")
com_0, com_1 = spisim.compute_com("custom", Path(local_scratch.path) / "test.cfg")
assert com_0 and com_1

spisim.export_com_configure_file(os.path.join(spisim.working_directory, "custom.json"))
com_0, com_1 = spisim.compute_com(
standard="custom",
config_file=os.path.join(spisim.working_directory, "custom.json"),
port_order="EvenOdd",
)
assert com_0 and com_1
83 changes: 0 additions & 83 deletions pyaedt/generic/com_parameters.py

This file was deleted.

90 changes: 54 additions & 36 deletions pyaedt/generic/spisim.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
from numpy import float64
from numpy import zeros

from pyaedt import generate_unique_folder_name
from pyaedt import generate_unique_name
from pyaedt import is_linux
from pyaedt import pyaedt_function_handler
from pyaedt import settings
from pyaedt.generic.com_parameters import COMParameters
from pyaedt.generic.general_methods import env_value
from pyaedt.misc import current_version
from pyaedt.misc.spisim_com_configuration_files.com_parameters import COMParametersVer3p4


class SpiSim:
Expand Down Expand Up @@ -63,7 +64,11 @@ def _compute_spisim(self, parameter, out_file="", touchstone_file="", config_fil
command = [spisimExe, parameter, cfgCmmd]
# Debug('%s %s' % (cmdList[0], ' '.join(arguments)))
# try up to three times to be sure
out_processing = os.path.join(out_file, generate_unique_name("spsim_out") + ".txt")
if 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")

my_env = os.environ.copy()
my_env.update(settings.aedt_environment_variables)
if is_linux: # pragma: no cover
Expand Down Expand Up @@ -97,9 +102,19 @@ def _get_output_parameter_from_result(self, out_file, parameter_name):
try:
with open(out_file, "r") as infile:
txt = infile.read()
com_case_0 = re.search(r"Case 0: Calculated COM = (.*?),", txt).groups()[0]
com_case_1 = re.search(r"Case 1: Calculated COM = (.*?),", txt).groups()[0]
return float(com_case_0), float(com_case_1)
i = 0
com_results = []
while True:
m = re.search(r"Case {}: Calculated COM = (.*?),".format(i), txt)
if m:
com_results.append(float(m.groups()[0]))
i = i + 1
else:
if i == 0:
self.logger.error("Failed to find results from SPISim log file. \n{txt}")
break

return com_results
except IndexError: # pragma: no cover
self.logger.error("Failed to compute {}. Check input parameters and retry".format(parameter_name))

Expand Down Expand Up @@ -255,13 +270,14 @@ def compute_com(
next_s4p="",
out_folder="",
):
"""Compute Channel Operating Margin.
"""Compute Channel Operating Margin. Only COM ver3.4 is supported.
Parameters
----------
standard : str
Name of the standard to apply.
config_file : str, optional
Name of the standard to apply. Options are ``"Custom"`, ``"50GAUI-1-C2C"`, ``"100GBASE-KR4"`` and
``"100GBASE-KP4"``.
config_file : str, Path, optional
Config file to use.
port_order : str, optional
Whether to use "``EvenOdd``" or "``Incremental``" numbering for S4P files. The default is ``EvenOdd``.
Expand All @@ -277,19 +293,24 @@ def compute_com(
-------
"""
if standard == "custom":
com_param = COMParameters()
com_param.load(config_file)

com_param = COMParametersVer3p4()
if standard.lower() == "custom":

if os.path.splitext(config_file)[-1] == ".cfg":
com_param.load_spisim_cfg(config_file)
else:
com_param.load(config_file)
else:
com_param = COMParameters(standard)
com_param.standard = standard

com_param.THRUSNP = self.touchstone_file
com_param.FEXTARY = fext_s4p if not isinstance(fext_s4p, list) else ";".join(fext_s4p)
com_param.NEXTARY = next_s4p if not isinstance(next_s4p, list) else ";".join(next_s4p)
com_param.set_parameter("THRUSNP", self.touchstone_file)
com_param.set_parameter("FEXTARY", fext_s4p if not isinstance(fext_s4p, list) else ";".join(fext_s4p))
com_param.set_parameter("NEXTARY", next_s4p if not isinstance(next_s4p, list) else ";".join(next_s4p))

com_param.PORT_ORDER = "[1 3 2 4]" if port_order == "EvenOdd" else "[1 2 3 4]"
com_param.set_parameter("Port Order", "[1 3 2 4]" if port_order == "EvenOdd" else "[1 2 3 4]")

com_param.RESULT_DIR = out_folder if out_folder else self.working_directory
com_param.set_parameter("RESULT_DIR", out_folder if out_folder else self.working_directory)
return self._compute_com(com_param)

@pyaedt_function_handler
Expand All @@ -308,42 +329,39 @@ def _compute_com(
-------
"""
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.THRUSNP = com_parameter.THRUSNP.replace("\\", "/")
com_parameter.FEXTARY = com_parameter.FEXTARY.replace("\\", "/")
com_parameter.NEXTARY = com_parameter.NEXTARY.replace("\\", "/")
com_parameter.RESULT_DIR = com_parameter.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.RESULT_DIR, "com_parameters.cfg")
com_parameter.export(cfg_file)
cfg_file = os.path.join(com_parameter.parameters["RESULT_DIR"], "com_parameters.cfg")
com_parameter.export_spisim_cfg(cfg_file)

out_processing = self._compute_spisim(parameter="COM", config_file=cfg_file)
return self._get_output_parameter_from_result(out_processing, "COM")

@property
def com_standards(self):
"""List of supported COM standards."""
return list(COMParameters._STD_TABLE_MAPPING.keys())

@staticmethod
@pyaedt_function_handler
def com_parameters(standard="50GAUI-1_C2C"):
return COMParameters(standard).parameters

@pyaedt_function_handler
def export_com_configure_file(self, file_path, standard="50GAUI-1_C2C"):
def export_com_configure_file(self, file_path, standard="50GAUI-1-C2C"):
"""Generate a configuration file for SpiSim.
Parameters
----------
file_path : str
file_path : str, Path
Full path to configuration file to create.
Returns
-------
bool
"""
return COMParameters(standard).export(file_path)
if os.path.splitext(file_path)[-1] == ".cfg":
COMParametersVer3p4(standard).export_spisim_cfg(file_path)
else:
return COMParametersVer3p4(standard).export(file_path)


def detect_encoding(file_path, expected_pattern="", re_flags=0):
Expand Down
3 changes: 3 additions & 0 deletions pyaedt/misc/spisim_com_configuration_files/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from pathlib import Path

workdir = Path(__file__).parent
Loading

0 comments on commit a632843

Please sign in to comment.