Commit d39ea879 authored by Mario's avatar Mario
Browse files

typing and bug fixes

parent b687e040
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ Author: Mario Krattenmacher | Mario.Krattenmacher@semimod.de
# along with this program.  If not, see <http://www.gnu.org/licenses/>
import copy
from collections import OrderedDict
from typing import List, Dict, Type
from typing import List, Dict, Type, Union
from DMT.core import (
    create_md5_hash,
    DutView,
@@ -235,7 +235,7 @@ class DutCircuit(DutView):
        else:
            raise OSError("The modelcard has to be a instance of MCard or its children!")

    def get_hash(self):
    def get_hash(self) -> Union[bool, str]:
        """Returns a md5 hash generated from self.inp_header, if it is not set, this will return False!

        Is overwritten here, to include the imported and appended files!
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ import os
from typing import Union


def create_md5_hash(*contents: Union[str, os.PathLike]):
def create_md5_hash(*contents: Union[str, os.PathLike]) -> str:
    """Construct the hash MD5 string with all parameters

    Parameters
+23 −4
Original line number Diff line number Diff line
@@ -48,11 +48,15 @@ from pathlib import Path

import _pickle as cpickle  # type: ignore
import numpy as np
from typing import Dict, OrderedDict, Type, Union, List, Optional
from typing import Dict, OrderedDict, Type, Union, List, Optional, TYPE_CHECKING
from pint.formatting import siunitx_format_unit
from pint.errors import UndefinedUnitError

from DMT.core import unit_registry

if TYPE_CHECKING:
    from DMT.core.circuit import Circuit

from DMT.exceptions import (
    ValueExcludedError,
    ValueTooLargeError,
@@ -822,7 +826,8 @@ class McParameterCollection(object):
        return collection

    def get(
        self, parameters: Union[str, McParameter, list[str], tuple[str], McParameterCollection]
        self,
        parameters: Union[str, McParameter, list[str], tuple[str], McParameterCollection],
    ) -> Union[McParameter, McParameterCollection]:
        """Returns a McParameterCollection with copies of all given parameter names.

@@ -1243,7 +1248,8 @@ class McParameterCollection(object):
                data_table.end_table_header()
                data_table.add_hline()
                data_table.add_row(
                    (MultiColumn(2, align="r", data="continued on next Page"),), strict=False
                    (MultiColumn(2, align="r", data="continued on next Page"),),
                    strict=False,
                )
                data_table.add_hline()
                data_table.end_table_footer()
@@ -1267,7 +1273,8 @@ class McParameterCollection(object):
                            # )
                            group_desc = self.possible_groups[group]
                            data_table.add_row(
                                (MultiColumn(2, align="l", data=group_desc),), strict=False
                                (MultiColumn(2, align="l", data=group_desc),),
                                strict=False,
                            )
                        except KeyError:
                            pass
@@ -1388,3 +1395,15 @@ class McParameterCollection(object):
            return self.eq_paras(other)

        return NotImplemented

    def get_circuit(self, use_build_in=False, topology=None, **kwargs) -> Circuit:
        """Here the modelcard defines it's default simulation circuit.

        Parameters
        ----------
        use_build_in : {False, True}, optional
            Creates a circtui the modelcard using the build-in model
        topology : optional
            If a model has multiple standard circuits, use the topology to differentiate between them..
        """
        raise NotImplementedError("The superclass McParameterCollection has no circuit :(.")
+22 −6
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ import ast
import operator
import warnings
from pathlib import Path
from typing import Union, Optional
from typing import Union, Optional, TYPE_CHECKING
from types import ModuleType

try:
@@ -44,6 +44,9 @@ except ImportError:
import verilogae

from DMT.core import unit_registry, VAFileMap

if TYPE_CHECKING:
    from DMT.core.circuit import Circuit
from DMT.core.mc_parameter import McParameterCollection, McParameter


@@ -265,7 +268,9 @@ class MCard(McParameterCollection):
        return self._va_codes

    def set_va_codes(
        self, path_to_main_code: Union[os.PathLike, str], version: Union[str, float] = None
        self,
        path_to_main_code: Union[os.PathLike, str],
        version: Union[str, float] = None,
    ):
        """Sets self._va_codes by extracting all included files from the main file down the include tree.

@@ -444,7 +449,7 @@ class MCard(McParameterCollection):

        return super().load_json(file_path, directory_va_file=directory_va_file, ignore_checksum=ignore_checksum)  # type: ignore

    def get_circuit(self, use_build_in=False, topology=None, **kwargs):
    def get_circuit(self, use_build_in=False, topology=None, **kwargs) -> Circuit:
        """Here the modelcard defines it's default simulation circuit.

        Parameters
@@ -462,7 +467,12 @@ class MCard(McParameterCollection):
        raise NotImplementedError("The submodels have to implement the build-in parameters")

    def print_to_file(
        self, path_to_file, file_mode="w", subckt_name=None, module_name=None, line_break="\n"
        self,
        path_to_file,
        file_mode="w",
        subckt_name=None,
        module_name=None,
        line_break="\n",
    ):
        """Generates a spectre .lib file which can be included into an netlist.

@@ -543,7 +553,10 @@ class MCard(McParameterCollection):
        # Loading protocol depends on file ending
        file_ending = path_to_file.suffix
        if file_ending == ".mcp" or file_ending == ".mcard":
            logging.info("Loading model parameters from pickled model card: %s", str(path_to_file))
            logging.info(
                "Loading model parameters from pickled model card: %s",
                str(path_to_file),
            )

            with path_to_file.open("rb") as myfile:
                modcard = pickle.load(myfile)
@@ -570,7 +583,10 @@ class MCard(McParameterCollection):
                param_value = param_value.split("=")
                modcard.append((param_value[0].strip(), float(param_value[1].strip())))
        elif file_ending == ".lib" or file_ending == "":
            logging.info("Loading model parameters from a TRADICA lib-File: %s", str(path_to_file))
            logging.info(
                "Loading model parameters from a TRADICA lib-File: %s",
                str(path_to_file),
            )

            modcard = []
            str_lib = path_to_file.read_text()
+8 −3
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ class SpecifierStr(str):
        sub_specifiers: Union[
            FrozenSet[Union[str, SpecifierStr]],
            Set[Union[str, SpecifierStr]],
            List[Union[str, SpecifierStr]],
            str,
            SpecifierStr,
            None,
@@ -324,7 +325,8 @@ class SpecifierStr(str):
            return string

    def __add__(
        self: SpecifierStr, other: Union[SpecifierStr, str, list[Union[str, SpecifierStr]]]
        self: SpecifierStr,
        other: Union[SpecifierStr, str, list[Union[str, SpecifierStr]]],
    ) -> SpecifierStr:
        """Method stub"""
        raise NotImplementedError
@@ -648,7 +650,9 @@ def add(self: SpecifierStr, other: Union[SpecifierStr, str, List[Union[str, Spec

        if other in SUB_SPECIFIERS_STR:
            return SpecifierStr(
                self.specifier, *self.nodes, sub_specifiers=self.sub_specifiers | {other}
                self.specifier,
                *self.nodes,
                sub_specifiers=self.sub_specifiers | {other},
            )
        else:
            return SpecifierStr(
@@ -1043,7 +1047,8 @@ natural_scales = {
    specifiers.MAXIMUM_OSCILLATION_FREQUENCY: 1e-9,
    specifiers.TRANSCONDUCTANCE: 1,
    specifiers.OUTPUT_CONDUCTANCE: 1,
    specifiers.TRANSIT_FREQUENCY: 1e-9,
    specifiers.TRANSIT_FREQUENCY: 1e-9,  # GHz
    specifiers.TRANSIT_TIME: 1e12,  # ps
    specifiers.CAPACITANCE: 1e15,
    specifiers.CHARGE: 1e15,
    specifiers.CHARGE_DENSITY: 1e15 / (1e6 * 1e6),  # fF/um^2