From 185aa84d5a1edd4588bb87ed2bf9ca7bcec95ae1 Mon Sep 17 00:00:00 2001 From: David Banas Date: Mon, 9 Sep 2024 06:30:09 -0400 Subject: [PATCH] Rel. v6.2.0 --- .proj_ver | 2 +- src/pyibisami/ami/model.py | 54 ++++++++++++++----------------- src/pyibisami/ami/parser.py | 20 ++++++------ src/pyibisami/common.py | 2 +- src/pyibisami/ibis/parser.py | 2 +- tox.ini | 1 + type_stubs/pyibisami/__init__.pyi | 3 -- 7 files changed, 38 insertions(+), 46 deletions(-) delete mode 100644 type_stubs/pyibisami/__init__.pyi diff --git a/.proj_ver b/.proj_ver index e136d44..a3aa6c3 100644 --- a/.proj_ver +++ b/.proj_ver @@ -1 +1 @@ -export PROJ_VER=6.1.1 +export PROJ_VER=6.2.0 diff --git a/src/pyibisami/ami/model.py b/src/pyibisami/ami/model.py index 0ec7981..7a6fde5 100644 --- a/src/pyibisami/ami/model.py +++ b/src/pyibisami/ami/model.py @@ -10,10 +10,10 @@ import copy as cp from ctypes import CDLL, byref, c_char_p, c_double # pylint: disable=no-name-in-module from pathlib import Path -from typing import Any, Iterator, Optional +from typing import Any, Optional import numpy as np -from numpy.random import randint +# from numpy.random import randint from pyibisami.common import * # pylint: disable=wildcard-import,unused-wildcard-import # noqa: F403 @@ -272,22 +272,22 @@ def initialize(self, init_object: AMIModelInitializer): self._amiClose(self._ami_mem_handle) # Set up the AMI_Init() arguments. - self._channel_response = init_object._init_data[ + self._channel_response = init_object._init_data[ # pylint: disable=protected-access,attribute-defined-outside-init "channel_response" - ] # pylint: disable=protected-access,attribute-defined-outside-init + ] self._initOut = cp.copy(self._channel_response) # type: ignore # pylint: disable=attribute-defined-outside-init - self._row_size = init_object._init_data[ + self._row_size = init_object._init_data[ # pylint: disable=protected-access,attribute-defined-outside-init "row_size" - ] # pylint: disable=protected-access,attribute-defined-outside-init - self._num_aggressors = init_object._init_data[ + ] + self._num_aggressors = init_object._init_data[ # pylint: disable=protected-access,attribute-defined-outside-init "num_aggressors" - ] # pylint: disable=protected-access,attribute-defined-outside-init - self._sample_interval = init_object._init_data[ + ] + self._sample_interval = init_object._init_data[ # pylint: disable=protected-access,attribute-defined-outside-init "sample_interval" - ] # pylint: disable=protected-access,attribute-defined-outside-init - self._bit_time = init_object._init_data[ + ] + self._bit_time = init_object._init_data[ # pylint: disable=protected-access,attribute-defined-outside-init "bit_time" - ] # pylint: disable=protected-access,attribute-defined-outside-init + ] self._info_params = init_object.info_params # pylint: disable=attribute-defined-outside-init assert self._info_params, RuntimeError( f"`info_params` is None!\n`init_object: {init_object}" @@ -358,12 +358,12 @@ def sexpr(pname, pval): # And there may be an advantage to having it not be! if (bit_time % sample_interval) > (sample_interval / 100): raise ValueError( - f"Bit time ({bit_time * 1e9 : 6.3G} ns) must be an integral multiple of sample interval ({sample_interval * 1e9 : 6.3G} ns)." + f"Bit time ({bit_time * 1e9: 6.3G} ns) must be an integral multiple of sample interval ({sample_interval * 1e9: 6.3G} ns)." ) self._samps_per_bit = int(bit_time / sample_interval) # pylint: disable=attribute-defined-outside-init - self._bits_per_call = ( + self._bits_per_call = ( # pylint: disable=attribute-defined-outside-init init_object.row_size / self._samps_per_bit - ) # pylint: disable=attribute-defined-outside-init + ) def getWave(self, wave: Rvec, bits_per_call: int = 0) -> tuple[Rvec, Rvec, list[str]]: # noqa: F405 """ @@ -409,7 +409,7 @@ def getWave(self, wave: Rvec, bits_per_call: int = 0) -> tuple[Rvec, Rvec, list[ Signal = c_double * remaining_samps tmp_wave = wave[idx:] else: - tmp_wave = wave[idx : idx + samps_per_call] + tmp_wave = wave[idx: idx + samps_per_call] _wave = Signal(*tmp_wave) self._amiGetWave( byref(_wave), len(_wave), byref(_clock_times), byref(self._ami_params_out), self._ami_mem_handle @@ -421,10 +421,10 @@ def getWave(self, wave: Rvec, bits_per_call: int = 0) -> tuple[Rvec, Rvec, list[ return np.array(wave_out), np.array(clock_times[: len(wave_out) // self._samps_per_bit]), params_out - def get_responses( + def get_responses( # pylint: disable=too-many-locals self, bits_per_call: int = 0, - bit_gen: Optional[Iterator[int]] = None, # pylint: disable=too-many-locals + # bit_gen: Optional[Iterator[int]] = None, pad_bits: int = 10, ) -> dict[str, Any]: """ @@ -455,6 +455,10 @@ def get_responses( 2. An empty dictionary implies that neither the `Init_Returns_Impulse` nor the `GetWave_Exists` AMI reserved parameter was True. 3. Note that impulse responses are returned with units: (V/sample), not (V/s). + + ToDo: + 1. Implement `bit_gen`. + 2. Implement `ignore_bits`. """ rslt = {} @@ -463,7 +467,8 @@ def get_responses( impulse_length = self.row_size ui = self.bit_time ts = self.sample_interval - ignore_bits = self.info_params["Ignore_Bits"] + # info_params = self.info_params + # ignore_bits = info_params["Ignore_Bits"] if "Ignore_Bits" in info_params else 0 # Capture/convert instance variables. chnl_imp = np.array(self.channel_response) * ts # input (a.k.a. - "channel") impulse response (V/sample) @@ -490,23 +495,12 @@ def get_responses( # Then, run a perfect step, to extract model's step response. wave_out, _, _ = self.getWave( - # np.array([0] * impulse_length + [1] * impulse_length) - 0.5, bits_per_call=bits_per_call np.array([0] * pad_samps + [1] * impulse_length) - 0.5, bits_per_call=bits_per_call, ) - # Remove any artifactual vertical offset from beginning of result: - # rslt["step_resp_getw"] = wave_out[impulse_length - nspui: -nspui] - wave_out[impulse_length - 1] - # rslt["step_resp_getw"] = wave_out[10 * nspui:] - # rslt["step_resp_getw"] -= rslt["step_resp_getw"][0] # Calculate other responses from step response. - # rslt["imp_resp_getw"] = np.pad(np.diff(rslt["step_resp_getw"]), (1, 0), mode="constant", constant_values=0) - # rslt["imp_resp_getw"] = np.diff(rslt["step_resp_getw"]) rslt["imp_resp_getw"] = np.diff(wave_out[pad_samps:]) - # rslt["pulse_resp_getw"] = rslt["step_resp_getw"] - np.pad( - # rslt["step_resp_getw"][:-nspui], (nspui, 0), mode="constant", constant_values=0 - # ) - # rslt["freq_resp_getw"] = np.fft.rfft(rslt["imp_resp_getw"]) # Calculate effective cumulative impulse response (i.e. - channel + Tx). # - Form the step response equivalent to the given channel impulse response. diff --git a/src/pyibisami/ami/parser.py b/src/pyibisami/ami/parser.py index 2892acc..77db739 100644 --- a/src/pyibisami/ami/parser.py +++ b/src/pyibisami/ami/parser.py @@ -9,7 +9,7 @@ import re -from parsec import ParseError, generate, many, many1, regex, string +from parsec import ParseError, generate, many, regex, string from traits.api import Bool, Enum, HasTraits, Range, Trait from traitsui.api import Group, Item, View from traitsui.menu import ModalButtons @@ -211,8 +211,8 @@ def input_ami_param(self, params, pname): try: # Querry for a mapped trait, first, by trying to get '_'. (Note the underscore.) res[pname] = self.get(pname + "_")[pname + "_"] except ( - Exception - ): # If we get an exception, we have an ordinary (i.e. - not mapped) trait. # pylint: disable=broad-exception-caught + Exception # pylint: disable=broad-exception-caught + ): # If we get an exception, we have an ordinary (i.e. - not mapped) trait. res[pname] = self.get(pname)[pname] elif isinstance(param, dict): # We received a dictionary of subparameters, in 'param'. subs = {} @@ -323,13 +323,13 @@ def proc_branch(branch): try: if ( - (len(param_tags) > 1) # noqa: W503 - and ( - param_tags[0][0] in AMIParameter._param_def_tag_procs - ) # pylint: disable=protected-access # noqa: W503 - and ( - param_tags[1][0] in AMIParameter._param_def_tag_procs - ) # pylint: disable=protected-access # noqa: W503 + (len(param_tags) > 1) + and ( # noqa: W503 + param_tags[0][0] in AMIParameter._param_def_tag_procs # pylint: disable=protected-access # noqa: W503 + ) + and ( # noqa: W503 + param_tags[1][0] in AMIParameter._param_def_tag_procs # pylint: disable=protected-access # noqa: W503 + ) ): try: results = ("", {param_name: AMIParameter(param_name, param_tags)}) diff --git a/src/pyibisami/common.py b/src/pyibisami/common.py index 95c0d1b..4bc68ae 100644 --- a/src/pyibisami/common.py +++ b/src/pyibisami/common.py @@ -8,7 +8,7 @@ Copyright (c) 2024 David Banas; all rights reserved World wide. """ -from typing import TypeAlias, TypeVar +from typing_extensions import TypeAlias, TypeVar import numpy.typing as npt # type: ignore from scipy.linalg import convolution_matrix, lstsq diff --git a/src/pyibisami/ibis/parser.py b/src/pyibisami/ibis/parser.py index fffcb1d..05eb23e 100644 --- a/src/pyibisami/ibis/parser.py +++ b/src/pyibisami/ibis/parser.py @@ -59,7 +59,7 @@ def fn(txt, ix): res = p(txt, ix) if not res.status: print( - f"{preStr}: Expected {res.expected} in '{txt[res.index : res.index+5]}' at {ParseError.loc_info(txt, res.index)}." + f"{preStr}: Expected {res.expected} in '{txt[res.index: res.index + 5]}' at {ParseError.loc_info(txt, res.index)}." ) return res diff --git a/tox.ini b/tox.ini index 2d9b464..b53ff72 100644 --- a/tox.ini +++ b/tox.ini @@ -26,6 +26,7 @@ deps = pytest pytest-xdist pytest-cov + typing_extensions py39-mac: enable @ https://github.com/capn-freako/PyBERT/raw/master/deps/enable-6.1.0.dev0-cp39-cp39-macosx_12_0_arm64.whl py310-mac: enable @ https://github.com/capn-freako/PyBERT/raw/master/deps/enable-6.1.0.dev0-cp310-cp310-macosx_12_0_arm64.whl py311-mac: enable @ https://github.com/capn-freako/PyBERT/raw/master/deps/enable-6.2.0.dev0-cp311-cp311-macosx_10_9_universal2.whl diff --git a/type_stubs/pyibisami/__init__.pyi b/type_stubs/pyibisami/__init__.pyi deleted file mode 100644 index d0ac9aa..0000000 --- a/type_stubs/pyibisami/__init__.pyi +++ /dev/null @@ -1,3 +0,0 @@ -__date__: str -__authors__: str -__copy__: str