Quanlse/QWaveform.py
def searchWaveTool(container: Dict[str, List[QWaveform]], subSysNum: int, sysLevel: Union[int, List[int]],
                       operators: Union[QOperator, Callable, List[QOperator], List[Callable]] = None,
                       onSubSys: Union[int, List[int]] = None, names: Union[str, List[str]] = None,
                       tag: str = None) -> Dict[str, List[QWaveform]]:
        """
        Search waves by different methods.

        :param container: input dictionary
        :param subSysNum: subsystem number
        :param sysLevel: the system levels
        :param operators: search by operator
        :param onSubSys: search by subsystem
        :param names: search by name
        :param tag: search by tag
        """

        returnDict = {}
        if names is not None:
            def _searchWaveByNames(_returnDict, _name):
                """ Search Waves by name and tag """
                if _name in container.keys():
                    if tag is None:
                        _returnDict[_name] = container[_name]
                    else:
                        _returnDict[_name] = []
                        for _wave in container[_name]:
                            if _wave.tag == tag:
                                _returnDict[_name].append(_wave)

            # When names (of the operators) is not None, then find the waves by the name string
            if isinstance(names, str):
                # If user input a name
                _searchWaveByNames(returnDict, names)
                return returnDict
            elif isinstance(names, list):
                # If user input a list of names
                for name in names:
                    _searchWaveByNames(returnDict, name)
                return returnDict
            else:
                raise Error.ArgumentError("Variable names should be a list or int.")
        elif operators is not None and onSubSys is not None:
            # When names (of the operators) is None, then find the waves by the operators with onSubSys.
            formattedOperators = formatOperatorInput(operators, onSubSys, sysLevel)
            if isinstance(operators, list) and isinstance(onSubSys, list):
                _operators = formattedOperators
                _onSubSys = onSubSys
            else:
                _operators = [formattedOperators]
                _onSubSys = [onSubSys]

            if len(_operators) != len(_onSubSys):
                raise Error.ArgumentError("Length of operators and onSubSys must be the same.")

            for idx in range(len(_operators)):
                operatorForSearch = combineOperatorAndOnSubSys(subSysNum, _operators, _onSubSys)
                opKey = generateOperatorKey(subSysNum, operatorForSearch)
                if opKey in container.keys():
                    if tag is None:
                        returnDict[opKey] = container[opKey]
                    else:
                        returnDict[opKey] = []
                        for wave in container[opKey]:
                            if tag == wave.tag:
                                returnDict[opKey].append(wave)
            return returnDict
        elif tag is not None:
            for opKey in container.keys():
                returnDict[opKey] = []
                for waveform in container[opKey]:
                    if waveform.tag == tag:
                        returnDict[opKey].append(waveform)
            return returnDict
        else:
            raise Error.ArgumentError("You must indicate the operators with onSubSys / names / tag.")

        Search waves by different methods.

        :param container: input dictionary
        :param subSysNum: subsystem number
        :param sysLevel: the system levels
        :param operators: search by operator
        :param onSubSys: search by subsystem
        :param names: search by name
        :param tag: search by tag
        
Search waves by different methods.
Search waves by different methods .
def searchWaveTool(container: Dict[str, List[QWaveform]], subSysNum: int, sysLevel: Union[int, List[int]],
                       operators: Union[QOperator, Callable, List[QOperator], List[Callable]] = None,
                       onSubSys: Union[int, List[int]] = None, names: Union[str, List[str]] = None,
                       tag: str = None) -> Dict[str, List[QWaveform]]:
        returnDict = {}
        if names is not None:
            def _searchWaveByNames(_returnDict, _name):
                if _name in container.keys():
                    if tag is None:
                        _returnDict[_name] = container[_name]
                    else:
                        _returnDict[_name] = []
                        for _wave in container[_name]:
                            if _wave.tag == tag:
                                _returnDict[_name].append(_wave)
            if isinstance(names, str):
                _searchWaveByNames(returnDict, names)
                return returnDict
            elif isinstance(names, list):
                for name in names:
                    _searchWaveByNames(returnDict, name)
                return returnDict
            else:
                raise Error.ArgumentError("Variable names should be a list or int.")
        elif operators is not None and onSubSys is not None:
            formattedOperators = formatOperatorInput(operators, onSubSys, sysLevel)
            if isinstance(operators, list) and isinstance(onSubSys, list):
                _operators = formattedOperators
                _onSubSys = onSubSys
            else:
                _operators = [formattedOperators]
                _onSubSys = [onSubSys]
            if len(_operators) != len(_onSubSys):
                raise Error.ArgumentError("Length of operators and onSubSys must be the same.")
            for idx in range(len(_operators)):
                operatorForSearch = combineOperatorAndOnSubSys(subSysNum, _operators, _onSubSys)
                opKey = generateOperatorKey(subSysNum, operatorForSearch)
                if opKey in container.keys():
                    if tag is None:
                        returnDict[opKey] = container[opKey]
                    else:
                        returnDict[opKey] = []
                        for wave in container[opKey]:
                            if tag == wave.tag:
                                returnDict[opKey].append(wave)
            return returnDict
        elif tag is not None:
            for opKey in container.keys():
                returnDict[opKey] = []
                for waveform in container[opKey]:
                    if waveform.tag == tag:
                        returnDict[opKey].append(waveform)
            return returnDict
        else:
            raise Error.ArgumentError("You must indicate the operators with onSubSys / names / tag.")
def searchWaveTool ( container : Dict [ str , List [ QWaveform ] ] , subSysNum : int , sysLevel : Union [ int , List [ int ] ] , operators : Union [ QOperator , Callable , List [ QOperator ] , List [ Callable ] ] = None , onSubSys : Union [ int , List [ int ] ] = None , names : Union [ str , List [ str ] ] = None , tag : str = None ) -> Dict [ str , List [ QWaveform ] ] : returnDict = { } if names is not None : def _searchWaveByNames ( _returnDict , _name ) : """ Search Waves by name and tag """ if _name in container . keys ( ) : if tag is None : _returnDict [ _name ] = container [ _name ] else : _returnDict [ _name ] = [ ] for _wave in container [ _name ] : if _wave . tag == tag : _returnDict [ _name ] . append ( _wave ) if isinstance ( names , str ) : _searchWaveByNames ( returnDict , names ) return returnDict elif isinstance ( names , list ) : for name in names : _searchWaveByNames ( returnDict , name ) return returnDict else : raise Error . ArgumentError ( "Variable names should be a list or int." ) elif operators is not None and onSubSys is not None : formattedOperators = formatOperatorInput ( operators , onSubSys , sysLevel ) if isinstance ( operators , list ) and isinstance ( onSubSys , list ) : _operators = formattedOperators _onSubSys = onSubSys else : _operators = [ formattedOperators ] _onSubSys = [ onSubSys ] if len ( _operators ) != len ( _onSubSys ) : raise Error . ArgumentError ( "Length of operators and onSubSys must be the same." ) for idx in range ( len ( _operators ) ) : operatorForSearch = combineOperatorAndOnSubSys ( subSysNum , _operators , _onSubSys ) opKey = generateOperatorKey ( subSysNum , operatorForSearch ) if opKey in container . keys ( ) : if tag is None : returnDict [ opKey ] = container [ opKey ] else : returnDict [ opKey ] = [ ] for wave in container [ opKey ] : if tag == wave . tag : returnDict [ opKey ] . append ( wave ) return returnDict elif tag is not None : for opKey in container . keys ( ) : returnDict [ opKey ] = [ ] for waveform in container [ opKey ] : if waveform . tag == tag : returnDict [ opKey ] . append ( waveform ) return returnDict else : raise Error . ArgumentError ( "You must indicate the operators with onSubSys / names / tag." )
Search waves by different methods.
Search waves by different methods .
"""
        Search waves by different methods.

        :param container: input dictionary
        :param subSysNum: subsystem number
        :param sysLevel: the system levels
        :param operators: search by operator
        :param onSubSys: search by subsystem
        :param names: search by name
        :param tag: search by tag
        """ """ Search Waves by name and tag """ # When names (of the operators) is not None, then find the waves by the name string # If user input a name # If user input a list of names # When names (of the operators) is None, then find the waves by the operators with onSubSys.
container
Dict[str, List[QWaveform]]
None
subSysNum
int
None
sysLevel
Union[int, List[int]]
the system levels
the system levels
operators
Union[QOperator, Callable, List[QOperator], List[Callable]]
search by operator
search by operator
onSubSys
Union[int, List[int]]
search by subsystem
search by subsystem
names
Union[str, List[str]]
search by name
search by name
tag
str
search by tag
search by tag