Quanlse/Utils/Functions.py
def generateBasisIndexList(basisStrList: List[str], sysLevel: int) -> List[int]:
    """
    Return a list of integers which indicates the basis indices according to the input basis string list.
    For example, ``generateBasisIndexList(['00', '01', '10', '11'], 3)`` will return:
    ``[0, 1, 3, 4]``

    :param basisStrList: basis string list
    :param sysLevel: the energy level of qubits in the system.
    :return: basis indixes list
    """
    if not isinstance(sysLevel, int):
        raise ArgumentError('The system level can only be an integer.')
        
    strLen = [len(item) for item in basisStrList]
    if max(strLen) != min(strLen):
        raise ArgumentError('All input digital strings should have same length.')
    digLen = max(strLen)

    def translateStrToInt(strN: str) -> int:
        """
        Translate a string to int.
        :param strN: input string
        :return: an int value
        """
        intNum = 0
        for digIndex, charN in enumerate(strN):
            dig = int(charN)
            if dig >= sysLevel:
                raise ArgumentError(f"Digit '{dig}' is greater than sysLevel '{sysLevel}'.")
            intNum += (sysLevel ** (digLen - digIndex - 1)) * dig
        return intNum

    basisIntList = []
    for strNum in basisStrList:
        basisIntList.append(translateStrToInt(strNum))

    return basisIntList

    Return a list of integers which indicates the basis indices according to the input basis string list.
    For example, ``generateBasisIndexList(['00', '01', '10', '11'], 3)`` will return:
    ``[0, 1, 3, 4]``

    :param basisStrList: basis string list
    :param sysLevel: the energy level of qubits in the system.
    :return: basis indixes list
    
Return a list of integers which indicates the basis indices according to the input basis string list.
Return a list of integers which indicates the basis indices according to the input basis string list .
def generateBasisIndexList(basisStrList: List[str], sysLevel: int) -> List[int]:
    if not isinstance(sysLevel, int):
        raise ArgumentError('The system level can only be an integer.')
    strLen = [len(item) for item in basisStrList]
    if max(strLen) != min(strLen):
        raise ArgumentError('All input digital strings should have same length.')
    digLen = max(strLen)
    def translateStrToInt(strN: str) -> int:
        intNum = 0
        for digIndex, charN in enumerate(strN):
            dig = int(charN)
            if dig >= sysLevel:
                raise ArgumentError(f"Digit '{dig}' is greater than sysLevel '{sysLevel}'.")
            intNum += (sysLevel ** (digLen - digIndex - 1)) * dig
        return intNum
    basisIntList = []
    for strNum in basisStrList:
        basisIntList.append(translateStrToInt(strNum))
    return basisIntList
def generateBasisIndexList ( basisStrList : List [ str ] , sysLevel : int ) -> List [ int ] : if not isinstance ( sysLevel , int ) : raise ArgumentError ( 'The system level can only be an integer.' ) strLen = [ len ( item ) for item in basisStrList ] if max ( strLen ) != min ( strLen ) : raise ArgumentError ( 'All input digital strings should have same length.' ) digLen = max ( strLen ) def translateStrToInt ( strN : str ) -> int : """
        Translate a string to int.
        :param strN: input string
        :return: an int value
        """ intNum = 0 for digIndex , charN in enumerate ( strN ) : dig = int ( charN ) if dig >= sysLevel : raise ArgumentError ( f"Digit '{dig}' is greater than sysLevel '{sysLevel}'." ) intNum += ( sysLevel ** ( digLen - digIndex - 1 ) ) * dig return intNum basisIntList = [ ] for strNum in basisStrList : basisIntList . append ( translateStrToInt ( strNum ) ) return basisIntList
Return a list of integers which indicates the basis indices according to the input basis string list.
Return a list of integers which indicates the basis indices according to the input basis string list .
"""
    Return a list of integers which indicates the basis indices according to the input basis string list.
    For example, ``generateBasisIndexList(['00', '01', '10', '11'], 3)`` will return:
    ``[0, 1, 3, 4]``

    :param basisStrList: basis string list
    :param sysLevel: the energy level of qubits in the system.
    :return: basis indixes list
    """ """
        Translate a string to int.
        :param strN: input string
        :return: an int value
        """
basis indixes list
basis indixes list
basisStrList
List[str]
basis string list
basis string list
sysLevel
int
the energy level of qubits in the system.
the energy level of qubits in the system .