Exemplo n.º 1
0
    def __init__(self, f, ports, argsList):
        """Constructor

        makes a device from a set of arguments

        The device is assigned to self.m_spf if frequencyDependent and assumed
        to be an instance of class SParameters.
        Otherwise, it is assigned to self.m_sp and is assumed to be a list of
        list matrix.

        The intent of this class is that "Parser" classes use this DeviceParser
        to parse netlist lines that have 'device'
        as the first token.  It keeps these s-parameters and assigns them as
        it loops over the frequencies generating numeric
        solutions.

        @param f list of frequencies
        @param ports integer number of ports
        @param argsList list of arguments.  The name of the device is the
        first argument.
        If the device has no keyword for the argument, then that argument is next. 
        Otherwise, besides the name and the argument with no keyword, the
        remaining arguments come in keyword/value pairs where the
        keyword is a string and the value is the value of the keyword.
        @return None
        @throw SignalIntegrityExceptionDeviceParser if the device cannot be created.
        @see SignalIntegrity.Parsers.SystemDescriptionParser
        """
        # pragma: silent exclude
        from SignalIntegrity.Lib.Exception import SignalIntegrityExceptionDeviceParser
        from SignalIntegrity.Lib.SubCircuits.SubCircuit import SubCircuit
        # pragma: include
        self.m_f = f
        self.m_sp = None
        self.m_spf = None
        if argsList is None:
            return
        if len(argsList) == 0:
            return
        if argsList[0] == 'subcircuit':
            self.m_spf = SubCircuit(
                self.m_f, argsList[1], ' '.join([
                    x if len(x.split()) == 1 else "\'" + x + "\'"
                    for x in argsList[2:]
                ]))
            return
        if self.deviceFactory.MakeDevice(ports, argsList, f):
            if self.deviceFactory.frequencyDependent:
                self.m_spf = self.deviceFactory.dev
            else:
                self.m_sp = self.deviceFactory.dev
        else:
            #print 'device not found: '+' '.join(argsList)
            raise SignalIntegrityExceptionDeviceParser('device not found: ' +
                                                       ' '.join(argsList))
        return
Exemplo n.º 2
0
    def MakeDevice(self,ports,argsList,f):
        """makes a device from a set of arguments
        The device is assigned to self.dev and self.frequencyDependent determines whether the
        device is frequency dependent.  Frequency dependent devices are assumed to be instances
        of the class SParameters.  Otherwise, they are list of list matrices.

        @param ports integer number of ports
        @param argsList list of arguments.  The name of the device is the first argument.
        If the device has no keyword for the argument, then that argument is next.  Otherwise, besides
        the name and the argument with no keyword, the remaining arguments come in keyword/value pairs where the
        keyword is a string and the value is the value of the keyword.
        @param f list of frequencies
        @return boolean whether the device was created.
        @throw SignalIntegrityExceptionDeviceParser if the device cannot be created.
        """
        # pragma: silent exclude
        from SignalIntegrity.Lib.SParameters import SParameterFile
        from SignalIntegrity.Lib.Devices.CurrentAmplifier import CurrentAmplifier
        from SignalIntegrity.Lib.Devices.CurrentControlledCurrentSource import CurrentControlledCurrentSource
        from SignalIntegrity.Lib.Devices.CurrentControlledVoltageSource import CurrentControlledVoltageSource
        from SignalIntegrity.Lib.Devices.DirectionalCoupler import DirectionalCoupler
        from SignalIntegrity.Lib.Devices.Ground import Ground
        from SignalIntegrity.Lib.Devices.IdealTransformer import IdealTransformer
        from SignalIntegrity.Lib.Devices.MixedModeConverter import MixedModeConverter
        from SignalIntegrity.Lib.Devices.Open import Open
        from SignalIntegrity.Lib.Devices.OperationalAmplifier import OperationalAmplifier
        from SignalIntegrity.Lib.Devices.SeriesZ import SeriesZ
        from SignalIntegrity.Lib.Devices.TerminationZ import TerminationZ
        from SignalIntegrity.Lib.Devices.MixedModeConverter import MixedModeConverterVoltage
        from SignalIntegrity.Lib.Devices.Thru import Thru
        from SignalIntegrity.Lib.Devices.VoltageAmplifier import VoltageAmplifier
        from SignalIntegrity.Lib.Devices.ShuntZ import ShuntZ
        from SignalIntegrity.Lib.Devices.Tee import Tee
        from SignalIntegrity.Lib.Devices.TransconductanceAmplifier import TransconductanceAmplifier
        from SignalIntegrity.Lib.Devices.TransresistanceAmplifier import TransresistanceAmplifier
        from SignalIntegrity.Lib.Devices.VoltageControlledVoltageSource import VoltageControlledVoltageSource
        from SignalIntegrity.Lib.Devices.VoltageControlledCurrentSource import VoltageControlledCurrentSource
        from SignalIntegrity.Lib.Devices.IdealRelay import IdealRelay
        from SignalIntegrity.Lib.Fit.RLGCFitFromFile import RLGCFitFromFile
        from SignalIntegrity.Lib.SParameters.Devices.SeriesRse import SeriesRse
        from SignalIntegrity.Lib.SParameters.Devices.Mutual import Mutual
        from SignalIntegrity.Lib.SParameters.Devices.SeriesC import SeriesC
        from SignalIntegrity.Lib.SParameters.Devices.SeriesL import SeriesL
        from SignalIntegrity.Lib.SParameters.Devices.TerminationC import TerminationC
        from SignalIntegrity.Lib.SParameters.Devices.TerminationL import TerminationL
        from SignalIntegrity.Lib.SParameters.Devices.TLineLossless import TLineLossless
        from SignalIntegrity.Lib.SParameters.Devices.TLineTwoPortRLGC import TLineTwoPortRLGC
        from SignalIntegrity.Lib.Exception import SignalIntegrityExceptionDeviceParser
        from SignalIntegrity.Lib.Measurement.CalKit.Standards.ShortStandard import ShortStandard
        from SignalIntegrity.Lib.Measurement.CalKit.Standards.OpenStandard import OpenStandard
        from SignalIntegrity.Lib.Measurement.CalKit.Standards.LoadStandard import LoadStandard
        from SignalIntegrity.Lib.Measurement.CalKit.Standards.ThruStandard import ThruStandard
        from SignalIntegrity.Lib.Measurement.CalKit.Standards.Offset import Offset
        from SignalIntegrity.Lib.SParameters.Devices.TLineDifferentialRLGC import TLineDifferentialRLGC
        from SignalIntegrity.Lib.Measurement.Calibration.NetworkAnalyzer import NetworkAnalyzer
        from SignalIntegrity.Lib.SParameters.Devices.WElement import WElementFile
        from SignalIntegrity.Lib.SParameters.Devices.ClassicalFilter import ButterworthLowPassFilter,BesselLowPassFilter
        from SignalIntegrity.Lib.SParameters.Devices.Laplace import Laplace
        from SignalIntegrity.Lib.SParameters.Devices.Equalizer import FFE,CTLE
        from SignalIntegrity.Lib.SParameters.Devices.ImpulseResponseFilter import ImpulseResponseFilter
        # pragma: include
        self.dev=None
        if len(argsList) == 0:
            return False
        name=argsList[0].lower()
        argsList=argsList[1:]
        for device in self:
            if device.ports is not None:
                if isinstance(device.ports,int):
                    if device.ports != ports:
                        continue
                elif isinstance(device.ports,str):
                    if '-' in device.ports:
                        (minPort,maxPort) = device.ports.split('-')
                        if ports < int(minPort):
                            continue
                        if ports > int(maxPort):
                            continue
                    else:
                        acceptablePorts = device.ports.split(',')
                        if not any(ports == int(acceptablePort)
                                   for acceptablePort in acceptablePorts):
                            continue
            if device.devicename != name: continue
            # this is the device, try to make it
            if device.arginname:
                if len(argsList) > 0:
                    argsList=['']+argsList
            # pragma: silent exclude
            if len(argsList)//2*2 != len(argsList): # must be keyword value pairs
                raise SignalIntegrityExceptionDeviceParser(
                    'arguments must come in keyword pairs: '+name+' '+' '.join(argsList))
            # pragma: include
            argsProvidedDict = {argsList[i].lower():argsList[i+1]
                                for i in range(0,len(argsList),2)}
            # pragma: silent exclude
            if not all(key in device.defaults for key in argsProvidedDict.keys()):
                invalidKeyList=[]
                for key in argsProvidedDict.keys():
                    if key not in device.defaults:
                        invalidKeyList.append(key)
                raise SignalIntegrityExceptionDeviceParser(
                    'argument keyword(s) invalid: '+str(invalidKeyList)+' for '+name)
            # pragma: include
            arg=copy.copy(device.defaults)
            arg.update(argsProvidedDict)
            # pragma: silent exclude
            if not all(arg[key] != None for key in arg.keys()):
                argNotProvidedList=[]
                for key in arg:
                    if arg[key] == None:
                        argNotProvidedList.append(key)
                raise SignalIntegrityExceptionDeviceParser(
                    'mandatory keyword(s) not supplied: '+str(argNotProvidedList)+' for '+name)
            # pragma: include
            # pragma: silent exclude
            try:
            # pragma: include outdent
                self.dev=eval(device.func)
                self.frequencyDependent=device.frequencyDependent
            # pragma: silent exclude indent
            except:
                try:
                    f=[0]
                    eval(device.func)
                except:
                    raise SignalIntegrityExceptionDeviceParser(
                        'device '+name+' could not be instantiated with arguments: '+' '.join(argsList))
                raise SignalIntegrityExceptionDeviceParser(
                    'frequency dependent device '+name+' could not be instantiated because no frequencies provided')
            # pragma: include
            return True
        return False