Quanlse/Utils/Functions.py
def combineOperatorAndOnSubSys(subSysNum: int, operators: Union[QOperator, List[QOperator]] = None,
                               onSubSys: Union[int, List[int]] = None) -> Union[QOperator, List[QOperator]]:
    """
    Set onSubSys information into the operator.

    :param subSysNum: subsystem's number
    :param operators: the corresponding operator object(s)
    :param onSubSys: subsystem's index(es)
    :return: returned QOperator object(s)

    """
    # Verify if operator and onSubSys have the same size
    if isinstance(operators, list) and not isinstance(onSubSys, list):
        raise ArgumentError("operator is a list, however onSubSys is not a list.")
    if not isinstance(operators, list) and isinstance(onSubSys, list):
        raise ArgumentError("onSubSys is a list, however operator is not a list.")

    if isinstance(operators, list) and isinstance(onSubSys, list):
        if len(operators) != len(onSubSys):
            raise ArgumentError(f"The size of operator ({len(operators)}) != that "
                                      f"of onSubSys ({len(onSubSys)})!")

    # Verify the range and set the onSubSys
    if isinstance(onSubSys, int):
        if onSubSys >= subSysNum:
            raise ArgumentError(f"onSubSys ({onSubSys}) is larger than the "
                                      f"subSysNum {subSysNum}.")
        operators.onSubSys = onSubSys
        operatorForSave = operators
    elif isinstance(onSubSys, list):
        if max(onSubSys) >= subSysNum:
            raise ArgumentError(f"onSubSys ({onSubSys}) is larger than the "
                                      f"subSysNum {subSysNum}.")
        # Sort the operators according to on onSubSys
        sortedIndex = list(array(onSubSys).argsort())
        sortedOperators = [operators[i] for i in sortedIndex]
        sortedOnSubSys = [onSubSys[i] for i in sortedIndex]

        # Set the onSubSys
        for i in range(len(sortedIndex)):
            sortedOperators[i].onSubSys = sortedOnSubSys[i]
        operatorForSave = sortedOperators
    else:
        raise ArgumentError("onSubSys should be an integer or a list!")

    return operatorForSave

    Set onSubSys information into the operator.

    :param subSysNum: subsystem's number
    :param operators: the corresponding operator object(s)
    :param onSubSys: subsystem's index(es)
    :return: returned QOperator object(s)

    
Set onSubSys information into the operator.
Set onSubSys information into the operator .
def combineOperatorAndOnSubSys(subSysNum: int, operators: Union[QOperator, List[QOperator]] = None,
                               onSubSys: Union[int, List[int]] = None) -> Union[QOperator, List[QOperator]]:
    if isinstance(operators, list) and not isinstance(onSubSys, list):
        raise ArgumentError("operator is a list, however onSubSys is not a list.")
    if not isinstance(operators, list) and isinstance(onSubSys, list):
        raise ArgumentError("onSubSys is a list, however operator is not a list.")
    if isinstance(operators, list) and isinstance(onSubSys, list):
        if len(operators) != len(onSubSys):
            raise ArgumentError(f"The size of operator ({len(operators)}) != that "
                                      f"of onSubSys ({len(onSubSys)})!")
    if isinstance(onSubSys, int):
        if onSubSys >= subSysNum:
            raise ArgumentError(f"onSubSys ({onSubSys}) is larger than the "
                                      f"subSysNum {subSysNum}.")
        operators.onSubSys = onSubSys
        operatorForSave = operators
    elif isinstance(onSubSys, list):
        if max(onSubSys) >= subSysNum:
            raise ArgumentError(f"onSubSys ({onSubSys}) is larger than the "
                                      f"subSysNum {subSysNum}.")
        sortedIndex = list(array(onSubSys).argsort())
        sortedOperators = [operators[i] for i in sortedIndex]
        sortedOnSubSys = [onSubSys[i] for i in sortedIndex]
        for i in range(len(sortedIndex)):
            sortedOperators[i].onSubSys = sortedOnSubSys[i]
        operatorForSave = sortedOperators
    else:
        raise ArgumentError("onSubSys should be an integer or a list!")
    return operatorForSave
def combineOperatorAndOnSubSys ( subSysNum : int , operators : Union [ QOperator , List [ QOperator ] ] = None , onSubSys : Union [ int , List [ int ] ] = None ) -> Union [ QOperator , List [ QOperator ] ] : if isinstance ( operators , list ) and not isinstance ( onSubSys , list ) : raise ArgumentError ( "operator is a list, however onSubSys is not a list." ) if not isinstance ( operators , list ) and isinstance ( onSubSys , list ) : raise ArgumentError ( "onSubSys is a list, however operator is not a list." ) if isinstance ( operators , list ) and isinstance ( onSubSys , list ) : if len ( operators ) != len ( onSubSys ) : raise ArgumentError ( f"The size of operator ({len(operators)}) != that " f"of onSubSys ({len(onSubSys)})!" ) if isinstance ( onSubSys , int ) : if onSubSys >= subSysNum : raise ArgumentError ( f"onSubSys ({onSubSys}) is larger than the " f"subSysNum {subSysNum}." ) operators . onSubSys = onSubSys operatorForSave = operators elif isinstance ( onSubSys , list ) : if max ( onSubSys ) >= subSysNum : raise ArgumentError ( f"onSubSys ({onSubSys}) is larger than the " f"subSysNum {subSysNum}." ) sortedIndex = list ( array ( onSubSys ) . argsort ( ) ) sortedOperators = [ operators [ i ] for i in sortedIndex ] sortedOnSubSys = [ onSubSys [ i ] for i in sortedIndex ] for i in range ( len ( sortedIndex ) ) : sortedOperators [ i ] . onSubSys = sortedOnSubSys [ i ] operatorForSave = sortedOperators else : raise ArgumentError ( "onSubSys should be an integer or a list!" ) return operatorForSave
Set onSubSys information into the operator.
Set onSubSys information into the operator .
"""
    Set onSubSys information into the operator.

    :param subSysNum: subsystem's number
    :param operators: the corresponding operator object(s)
    :param onSubSys: subsystem's index(es)
    :return: returned QOperator object(s)

    """ # Verify if operator and onSubSys have the same size # Verify the range and set the onSubSys # Sort the operators according to on onSubSys # Set the onSubSys
returned QOperator object(s)
returned QOperator object ( s )
subSysNum
int
None
operators
Union[QOperator, List[QOperator]]
the corresponding operator object(s)
the corresponding operator object ( s )
onSubSys
Union[int, List[int]]
None