Quanlse/Simulator/PulseSimQCQ.py
def pauliCoefficient(obj: Union[PulseModel, QHamiltonian], drivingAmp: Optional[float] = None) -> Dict:
    r"""
    Return Pauli coefficients of the Hamiltonian with CR drive

    :param obj: input PulseModel object or QHamiltonian object
    :param drivingAmp: amplitude of CR pulse

    :return: Pauli coefficients dictionary
    """

    def _diagnoalize(mat: ndarray):
        """
        Diagonalize the given matrix

        :param mat: input square matrix

        :return: diagonal matrix and the corresponding transformation unitary
        """
        matCache = copy.deepcopy(mat)
        eigenVals, eigenVecs = eigenSystem(matCache)
        indexVecList = createBasis(mat.shape[0], mat.shape[0])
        indexList = findIndex(eigenVecs, indexVecList)
        diagMat = diag(eigenVals[indexList])
        unitary = eigenVecs[:, indexList]
        return diagMat, unitary

    # Define pauli operator
    pauliOpZZ = tensor(sigmaZ().matrix, sigmaZ().matrix)
    pauliOpZX = tensor(sigmaZ().matrix, sigmaX().matrix)
    pauliOpZY = tensor(sigmaZ().matrix, sigmaY().matrix)
    pauliOpZI = tensor(sigmaZ().matrix, identity(2))
    pauliOpIZ = tensor(identity(2), sigmaZ().matrix)
    pauliOpIX = tensor(identity(2), sigmaX().matrix)
    pauliOpIY = tensor(identity(2), sigmaY().matrix)

    # Define the cross-resonance driving operator
    driveCRop = tensor((create(4).matrix + destroy(4).matrix),
                       identity(4))

    # Initial Hamiltonian
    if isinstance(obj, PulseModel):
        ham = obj.createQHamiltonian(frameMode='lab')
    elif isinstance(obj, QHamiltonian):
        ham = obj
    else:
        raise Error.ArgumentError("Pleases input a PulseModel object or a QHamiltonian object.")

    if ham.sysLevel == [3, 4, 4]:

        ham.buildCache()
        matQCQ = copy.deepcopy(ham.driftCache)

        # Decoupling coupler
        matQC1Q, unitaryC1 = fastBlockDiagonalization(mat=matQCQ, blockDim=2 * (4 ** 2))
        matQC0Q, unitaryC0 = fastBlockDiagonalization(mat=matQC1Q, blockDim=(4 ** 2))

        # Rearrange
        matQQ = rearrange(copy.deepcopy(matQC0Q[:(4 ** 2), :(4 ** 2)]))
        driveRearrange = rearrange(driveCRop)

        # Diagonalize the Q-Q subspace matrix
        matDiagQQ, unitaryDiagQQ = _diagnoalize(matQQ)

        if drivingAmp is not None:
            # Transform driving term
            driveMat = dagger(unitaryDiagQQ) @ driveRearrange @ unitaryDiagQQ

            # Initialize rotating term
            dressFreq = (matDiagQQ[1, 1] - matDiagQQ[0, 0] + matDiagQQ[3, 3] - matDiagQQ[2, 2]) / 2
            numberOperator = diag(array([0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6]))

            rotMat = matDiagQQ + drivingAmp * 0.5 * driveMat - dressFreq * numberOperator
            computeBlockMat, computeSubT = computeBlockDiagonalize(rotMat, 4)
            computeMat = computeBlockMat[:4, :4]

            if obj.qubitFreq[1] >= obj.qubitFreq[2]:
                finalMat, T = blockDiag(computeMat, [0, 1])
            else:
                finalMat, T = blockDiag(computeMat, [2, 3])

            pauliDict = {
                'ZI': trace(pauliOpZI @ finalMat).real / 2,
                'IZ': trace(pauliOpIZ @ finalMat).real / 2,
                'ZZ': trace(pauliOpZZ @ finalMat).real / 2,
                'ZX': trace(pauliOpZX @ finalMat).real / 2,
                'IX': trace(pauliOpIX @ finalMat).real / 2,
                'ZY': trace(pauliOpZY @ finalMat).real / 2,
                'IY': trace(pauliOpIY @ finalMat).real / 2
            }
        else:
            finalMat = matDiagQQ[:4, :4]

            pauliDict = {
                'ZI': trace(pauliOpZI @ finalMat).real / 2,
                'IZ': trace(pauliOpIZ @ finalMat).real / 2,
                'ZZ': trace(pauliOpZZ @ finalMat).real / 2,
                'ZX': trace(pauliOpZX @ finalMat).real / 2,
                'IX': trace(pauliOpIX @ finalMat).real / 2,
                'ZY': trace(pauliOpZY @ finalMat).real / 2,
                'IY': trace(pauliOpIY @ finalMat).real / 2
            }
    else:
        raise Error.ArgumentError("Coupler (index: 0) level should be 3 and Qubit (index: 1, 2) level should be 4.")

    return pauliDict
r"""
    Return Pauli coefficients of the Hamiltonian with CR drive

    :param obj: input PulseModel object or QHamiltonian object
    :param drivingAmp: amplitude of CR pulse

    :return: Pauli coefficients dictionary
    
r"""
Return Pauli coefficients of the Hamiltonian with CR drive
r " " " Return Pauli coefficients of the Hamiltonian with CR drive
def pauliCoefficient(obj: Union[PulseModel, QHamiltonian], drivingAmp: Optional[float] = None) -> Dict:
    def _diagnoalize(mat: ndarray):
        matCache = copy.deepcopy(mat)
        eigenVals, eigenVecs = eigenSystem(matCache)
        indexVecList = createBasis(mat.shape[0], mat.shape[0])
        indexList = findIndex(eigenVecs, indexVecList)
        diagMat = diag(eigenVals[indexList])
        unitary = eigenVecs[:, indexList]
        return diagMat, unitary
    pauliOpZZ = tensor(sigmaZ().matrix, sigmaZ().matrix)
    pauliOpZX = tensor(sigmaZ().matrix, sigmaX().matrix)
    pauliOpZY = tensor(sigmaZ().matrix, sigmaY().matrix)
    pauliOpZI = tensor(sigmaZ().matrix, identity(2))
    pauliOpIZ = tensor(identity(2), sigmaZ().matrix)
    pauliOpIX = tensor(identity(2), sigmaX().matrix)
    pauliOpIY = tensor(identity(2), sigmaY().matrix)
    driveCRop = tensor((create(4).matrix + destroy(4).matrix),
                       identity(4))
    if isinstance(obj, PulseModel):
        ham = obj.createQHamiltonian(frameMode='lab')
    elif isinstance(obj, QHamiltonian):
        ham = obj
    else:
        raise Error.ArgumentError("Pleases input a PulseModel object or a QHamiltonian object.")
    if ham.sysLevel == [3, 4, 4]:
        ham.buildCache()
        matQCQ = copy.deepcopy(ham.driftCache)
        matQC1Q, unitaryC1 = fastBlockDiagonalization(mat=matQCQ, blockDim=2 * (4 ** 2))
        matQC0Q, unitaryC0 = fastBlockDiagonalization(mat=matQC1Q, blockDim=(4 ** 2))
        matQQ = rearrange(copy.deepcopy(matQC0Q[:(4 ** 2), :(4 ** 2)]))
        driveRearrange = rearrange(driveCRop)
        matDiagQQ, unitaryDiagQQ = _diagnoalize(matQQ)
        if drivingAmp is not None:
            driveMat = dagger(unitaryDiagQQ) @ driveRearrange @ unitaryDiagQQ
            dressFreq = (matDiagQQ[1, 1] - matDiagQQ[0, 0] + matDiagQQ[3, 3] - matDiagQQ[2, 2]) / 2
            numberOperator = diag(array([0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6]))
            rotMat = matDiagQQ + drivingAmp * 0.5 * driveMat - dressFreq * numberOperator
            computeBlockMat, computeSubT = computeBlockDiagonalize(rotMat, 4)
            computeMat = computeBlockMat[:4, :4]
            if obj.qubitFreq[1] >= obj.qubitFreq[2]:
                finalMat, T = blockDiag(computeMat, [0, 1])
            else:
                finalMat, T = blockDiag(computeMat, [2, 3])
            pauliDict = {
                'ZI': trace(pauliOpZI @ finalMat).real / 2,
                'IZ': trace(pauliOpIZ @ finalMat).real / 2,
                'ZZ': trace(pauliOpZZ @ finalMat).real / 2,
                'ZX': trace(pauliOpZX @ finalMat).real / 2,
                'IX': trace(pauliOpIX @ finalMat).real / 2,
                'ZY': trace(pauliOpZY @ finalMat).real / 2,
                'IY': trace(pauliOpIY @ finalMat).real / 2
            }
        else:
            finalMat = matDiagQQ[:4, :4]
            pauliDict = {
                'ZI': trace(pauliOpZI @ finalMat).real / 2,
                'IZ': trace(pauliOpIZ @ finalMat).real / 2,
                'ZZ': trace(pauliOpZZ @ finalMat).real / 2,
                'ZX': trace(pauliOpZX @ finalMat).real / 2,
                'IX': trace(pauliOpIX @ finalMat).real / 2,
                'ZY': trace(pauliOpZY @ finalMat).real / 2,
                'IY': trace(pauliOpIY @ finalMat).real / 2
            }
    else:
        raise Error.ArgumentError("Coupler (index: 0) level should be 3 and Qubit (index: 1, 2) level should be 4.")
    return pauliDict
def pauliCoefficient ( obj : Union [ PulseModel , QHamiltonian ] , drivingAmp : Optional [ float ] = None ) -> Dict : def _diagnoalize ( mat : ndarray ) : """
        Diagonalize the given matrix

        :param mat: input square matrix

        :return: diagonal matrix and the corresponding transformation unitary
        """ matCache = copy . deepcopy ( mat ) eigenVals , eigenVecs = eigenSystem ( matCache ) indexVecList = createBasis ( mat . shape [ 0 ] , mat . shape [ 0 ] ) indexList = findIndex ( eigenVecs , indexVecList ) diagMat = diag ( eigenVals [ indexList ] ) unitary = eigenVecs [ : , indexList ] return diagMat , unitary pauliOpZZ = tensor ( sigmaZ ( ) . matrix , sigmaZ ( ) . matrix ) pauliOpZX = tensor ( sigmaZ ( ) . matrix , sigmaX ( ) . matrix ) pauliOpZY = tensor ( sigmaZ ( ) . matrix , sigmaY ( ) . matrix ) pauliOpZI = tensor ( sigmaZ ( ) . matrix , identity ( 2 ) ) pauliOpIZ = tensor ( identity ( 2 ) , sigmaZ ( ) . matrix ) pauliOpIX = tensor ( identity ( 2 ) , sigmaX ( ) . matrix ) pauliOpIY = tensor ( identity ( 2 ) , sigmaY ( ) . matrix ) driveCRop = tensor ( ( create ( 4 ) . matrix + destroy ( 4 ) . matrix ) , identity ( 4 ) ) if isinstance ( obj , PulseModel ) : ham = obj . createQHamiltonian ( frameMode = 'lab' ) elif isinstance ( obj , QHamiltonian ) : ham = obj else : raise Error . ArgumentError ( "Pleases input a PulseModel object or a QHamiltonian object." ) if ham . sysLevel == [ 3 , 4 , 4 ] : ham . buildCache ( ) matQCQ = copy . deepcopy ( ham . driftCache ) matQC1Q , unitaryC1 = fastBlockDiagonalization ( mat = matQCQ , blockDim = 2 * ( 4 ** 2 ) ) matQC0Q , unitaryC0 = fastBlockDiagonalization ( mat = matQC1Q , blockDim = ( 4 ** 2 ) ) matQQ = rearrange ( copy . deepcopy ( matQC0Q [ : ( 4 ** 2 ) , : ( 4 ** 2 ) ] ) ) driveRearrange = rearrange ( driveCRop ) matDiagQQ , unitaryDiagQQ = _diagnoalize ( matQQ ) if drivingAmp is not None : driveMat = dagger ( unitaryDiagQQ ) @ driveRearrange @ unitaryDiagQQ dressFreq = ( matDiagQQ [ 1 , 1 ] - matDiagQQ [ 0 , 0 ] + matDiagQQ [ 3 , 3 ] - matDiagQQ [ 2 , 2 ] ) / 2 numberOperator = diag ( array ( [ 0 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 4 , 4 , 4 , 5 , 5 , 6 ] ) ) rotMat = matDiagQQ + drivingAmp * 0.5 * driveMat - dressFreq * numberOperator computeBlockMat , computeSubT = computeBlockDiagonalize ( rotMat , 4 ) computeMat = computeBlockMat [ : 4 , : 4 ] if obj . qubitFreq [ 1 ] >= obj . qubitFreq [ 2 ] : finalMat , T = blockDiag ( computeMat , [ 0 , 1 ] ) else : finalMat , T = blockDiag ( computeMat , [ 2 , 3 ] ) pauliDict = { 'ZI' : trace ( pauliOpZI @ finalMat ) . real / 2 , 'IZ' : trace ( pauliOpIZ @ finalMat ) . real / 2 , 'ZZ' : trace ( pauliOpZZ @ finalMat ) . real / 2 , 'ZX' : trace ( pauliOpZX @ finalMat ) . real / 2 , 'IX' : trace ( pauliOpIX @ finalMat ) . real / 2 , 'ZY' : trace ( pauliOpZY @ finalMat ) . real / 2 , 'IY' : trace ( pauliOpIY @ finalMat ) . real / 2 } else : finalMat = matDiagQQ [ : 4 , : 4 ] pauliDict = { 'ZI' : trace ( pauliOpZI @ finalMat ) . real / 2 , 'IZ' : trace ( pauliOpIZ @ finalMat ) . real / 2 , 'ZZ' : trace ( pauliOpZZ @ finalMat ) . real / 2 , 'ZX' : trace ( pauliOpZX @ finalMat ) . real / 2 , 'IX' : trace ( pauliOpIX @ finalMat ) . real / 2 , 'ZY' : trace ( pauliOpZY @ finalMat ) . real / 2 , 'IY' : trace ( pauliOpIY @ finalMat ) . real / 2 } else : raise Error . ArgumentError ( "Coupler (index: 0) level should be 3 and Qubit (index: 1, 2) level should be 4." ) return pauliDict
r"""
Return Pauli coefficients of the Hamiltonian with CR drive
r " " " Return Pauli coefficients of the Hamiltonian with CR drive
r"""
    Return Pauli coefficients of the Hamiltonian with CR drive

    :param obj: input PulseModel object or QHamiltonian object
    :param drivingAmp: amplitude of CR pulse

    :return: Pauli coefficients dictionary
    """ """
        Diagonalize the given matrix

        :param mat: input square matrix

        :return: diagonal matrix and the corresponding transformation unitary
        """ # Define pauli operator # Define the cross-resonance driving operator # Initial Hamiltonian # Decoupling coupler # Rearrange # Diagonalize the Q-Q subspace matrix # Transform driving term # Initialize rotating term
Pauli coefficients dictionary
Pauli coefficients dictionary
obj
Union[PulseModel, QHamiltonian]
input PulseModel object or QHamiltonian object
input PulseModel object or QHamiltonian object
drivingAmp
Optional[float]
amplitude of CR pulse
amplitude of CR pulse