Skip to content

Commit

Permalink
Rel. v6.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
capn-freako committed Sep 9, 2024
1 parent ed58876 commit 185aa84
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .proj_ver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export PROJ_VER=6.1.1
export PROJ_VER=6.2.0
54 changes: 24 additions & 30 deletions src/pyibisami/ami/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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
"""
Expand Down Expand Up @@ -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
Expand All @@ -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]:
"""
Expand Down Expand Up @@ -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 = {}
Expand All @@ -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)
Expand All @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions src/pyibisami/ami/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -211,8 +211,8 @@ def input_ami_param(self, params, pname):
try: # Querry for a mapped trait, first, by trying to get '<trait_name>_'. (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 = {}
Expand Down Expand Up @@ -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)})
Expand Down
2 changes: 1 addition & 1 deletion src/pyibisami/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pyibisami/ibis/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions type_stubs/pyibisami/__init__.pyi

This file was deleted.

0 comments on commit 185aa84

Please sign in to comment.