Quanlse/Utils/Functions.py
def fitCR(xData: array, yData: array):
    """
    Fit the rabi oscillation of cross-resonance effect.

    :param xData: The data of x values.
    :param yData: The data of y values.

    :return: The callable fitting function and the fitting parameters.
    """

    def fit(x, p):
        return 0.5 * cos(2 * pi * p[1] * x) + 0.5

    def error(p, x, y, fitFunc):
        return ((y - fitFunc(x, p)) ** 2).sum() / len(y)

    step = xData[1] - xData[0]
    pows = abs(fft.fft(yData))
    freqs = fft.fftfreq(xData.size, step)
    index = argmax(pows[freqs > 0])

    a1Init = abs(yData).max()
    a2Init = freqs[index + 1]

    paraFit = fmin(error, [a1Init, a2Init], (xData, yData, fit))
    return fit, paraFit

    Fit the rabi oscillation of cross-resonance effect.

    :param xData: The data of x values.
    :param yData: The data of y values.

    :return: The callable fitting function and the fitting parameters.
    
Fit the rabi oscillation of cross-resonance effect.
Fit the rabi oscillation of cross - resonance effect .
def fitCR(xData: array, yData: array):
    def fit(x, p):
        return 0.5 * cos(2 * pi * p[1] * x) + 0.5
    def error(p, x, y, fitFunc):
        return ((y - fitFunc(x, p)) ** 2).sum() / len(y)
    step = xData[1] - xData[0]
    pows = abs(fft.fft(yData))
    freqs = fft.fftfreq(xData.size, step)
    index = argmax(pows[freqs > 0])
    a1Init = abs(yData).max()
    a2Init = freqs[index + 1]
    paraFit = fmin(error, [a1Init, a2Init], (xData, yData, fit))
    return fit, paraFit
def fitCR ( xData : array , yData : array ) : def fit ( x , p ) : return 0.5 * cos ( 2 * pi * p [ 1 ] * x ) + 0.5 def error ( p , x , y , fitFunc ) : return ( ( y - fitFunc ( x , p ) ) ** 2 ) . sum ( ) / len ( y ) step = xData [ 1 ] - xData [ 0 ] pows = abs ( fft . fft ( yData ) ) freqs = fft . fftfreq ( xData . size , step ) index = argmax ( pows [ freqs > 0 ] ) a1Init = abs ( yData ) . max ( ) a2Init = freqs [ index + 1 ] paraFit = fmin ( error , [ a1Init , a2Init ] , ( xData , yData , fit ) ) return fit , paraFit
Fit the rabi oscillation of cross-resonance effect.
Fit the rabi oscillation of cross - resonance effect .
"""
    Fit the rabi oscillation of cross-resonance effect.

    :param xData: The data of x values.
    :param yData: The data of y values.

    :return: The callable fitting function and the fitting parameters.
    """
The callable fitting function and the fitting parameters.
The callable fitting function and the fitting parameters .
xData
array
The data of x values.
The data of x values .
yData
array
The data of y values.
The data of y values .