Quanlse/ErrorMitigation/Utils/Visualization.py
def plotRescaleHamiltonianPulse(rescaleCoes: List[float], hamList: List[QHamiltonian], numChannel: int,
                                figsize: tuple = (12, 6), title=None):
    """
    Plot each pulse channel of a series of time-rescaling Hamiltonians. Suppose len(rescaleCoes)=r and numChannel=n,
    this function will show a figure including r*c subfigures which are
    arranged in "r" rows and "c" columns.

    :param rescaleCoes: rescaling coefficients
    :param hamList: Hamiltonian list whose length is equal to `rescaleCoes`
    :param numChannel: number of pulse channels
    :param figsize: size of the entire figure
    :param title: super title of the entire figure
    :return: fig, axes
    """
    fig = plt.figure(figsize=figsize)
    axes = []
    colorList = plt.rcParams['axes.prop_cycle'].by_key()['color']

    if len(rescaleCoes) != len(hamList):
        raise ArgumentError("Length of 'rescaleCoes' and length of 'hamList' are not equal!")
    grids = gridspec.GridSpec(len(rescaleCoes), numChannel)
    # dtList: e.g. [1, 1.25, ...]
    dtList = [ham.dt for ham in hamList]
    # tList: e.g. [1*16, 1.25*16, ...]
    tList = [ham.dt * ham.job.endTimeDt for ham in hamList]

    tMax = max(tList)
    driveNames = ['Drive X Pulse', 'Drive Y Pulse']
    if numChannel == 3:
        driveNames.append('Drive Z Pulse')

    for c, dr in enumerate(driveNames):
        for r, coe in enumerate(rescaleCoes):
            dt = dtList[r]
            ham = hamList[r]

            # ax lies in (row, col): (r, c)
            ax = plt.subplot(grids[r, c])

            # key: the name of pulse channel
            key = list(ham.ctrlCache.keys())[c]
            endDt = ham.job.endTimeDt
            As = [ham.job.waveCache[key][i] for i in range(endDt)]
            tBar = []
            Abar = []
            # construct tBar (list type) and Abar (list type) to plot a bar figure
            for i in range(endDt + 1):
                tBar.extend([i * dt, i * dt])
                if i == 0:
                    Abar.extend([0, As[i]])
                elif i == endDt:
                    Abar.extend([As[i - 1], 0])
                else:
                    Abar.extend([As[i - 1], As[i]])

            plt.fill(tBar, Abar, color=colorList[r], alpha=0.6)
            plt.plot(tBar, Abar, color=colorList[r], label='coe: {:.2f}'.format(coe))
            plt.legend(loc='upper right')

            plt.xlim(0, tMax)

            if r == 0:
                plt.title(key)
            if r == len(rescaleCoes) - 1:
                plt.xlabel('Times')

            axes.append(ax)

    fig.tight_layout()
    plt.suptitle(title)
    return fig, axes

    Plot each pulse channel of a series of time-rescaling Hamiltonians. Suppose len(rescaleCoes)=r and numChannel=n,
    this function will show a figure including r*c subfigures which are
    arranged in "r" rows and "c" columns.

    :param rescaleCoes: rescaling coefficients
    :param hamList: Hamiltonian list whose length is equal to `rescaleCoes`
    :param numChannel: number of pulse channels
    :param figsize: size of the entire figure
    :param title: super title of the entire figure
    :return: fig, axes
    
Plot each pulse channel of a series of time-rescaling Hamiltonians. Suppose len(rescaleCoes)=r and numChannel=n,
this function will show a figure including r*c subfigures which are
arranged in "r" rows and "c" columns.
Plot each pulse channel of a series of time - rescaling Hamiltonians . Suppose len ( rescaleCoes ) = r and numChannel = n this function will show a figure including r * c subfigures which are arranged in " r " rows and " c " columns .
def plotRescaleHamiltonianPulse(rescaleCoes: List[float], hamList: List[QHamiltonian], numChannel: int,
                                figsize: tuple = (12, 6), title=None):
    fig = plt.figure(figsize=figsize)
    axes = []
    colorList = plt.rcParams['axes.prop_cycle'].by_key()['color']
    if len(rescaleCoes) != len(hamList):
        raise ArgumentError("Length of 'rescaleCoes' and length of 'hamList' are not equal!")
    grids = gridspec.GridSpec(len(rescaleCoes), numChannel)
    dtList = [ham.dt for ham in hamList]
    tList = [ham.dt * ham.job.endTimeDt for ham in hamList]
    tMax = max(tList)
    driveNames = ['Drive X Pulse', 'Drive Y Pulse']
    if numChannel == 3:
        driveNames.append('Drive Z Pulse')
    for c, dr in enumerate(driveNames):
        for r, coe in enumerate(rescaleCoes):
            dt = dtList[r]
            ham = hamList[r]
            ax = plt.subplot(grids[r, c])
            key = list(ham.ctrlCache.keys())[c]
            endDt = ham.job.endTimeDt
            As = [ham.job.waveCache[key][i] for i in range(endDt)]
            tBar = []
            Abar = []
            for i in range(endDt + 1):
                tBar.extend([i * dt, i * dt])
                if i == 0:
                    Abar.extend([0, As[i]])
                elif i == endDt:
                    Abar.extend([As[i - 1], 0])
                else:
                    Abar.extend([As[i - 1], As[i]])
            plt.fill(tBar, Abar, color=colorList[r], alpha=0.6)
            plt.plot(tBar, Abar, color=colorList[r], label='coe: {:.2f}'.format(coe))
            plt.legend(loc='upper right')
            plt.xlim(0, tMax)
            if r == 0:
                plt.title(key)
            if r == len(rescaleCoes) - 1:
                plt.xlabel('Times')
            axes.append(ax)
    fig.tight_layout()
    plt.suptitle(title)
    return fig, axes
def plotRescaleHamiltonianPulse ( rescaleCoes : List [ float ] , hamList : List [ QHamiltonian ] , numChannel : int , figsize : tuple = ( 12 , 6 ) , title = None ) : fig = plt . figure ( figsize = figsize ) axes = [ ] colorList = plt . rcParams [ 'axes.prop_cycle' ] . by_key ( ) [ 'color' ] if len ( rescaleCoes ) != len ( hamList ) : raise ArgumentError ( "Length of 'rescaleCoes' and length of 'hamList' are not equal!" ) grids = gridspec . GridSpec ( len ( rescaleCoes ) , numChannel ) dtList = [ ham . dt for ham in hamList ] tList = [ ham . dt * ham . job . endTimeDt for ham in hamList ] tMax = max ( tList ) driveNames = [ 'Drive X Pulse' , 'Drive Y Pulse' ] if numChannel == 3 : driveNames . append ( 'Drive Z Pulse' ) for c , dr in enumerate ( driveNames ) : for r , coe in enumerate ( rescaleCoes ) : dt = dtList [ r ] ham = hamList [ r ] ax = plt . subplot ( grids [ r , c ] ) key = list ( ham . ctrlCache . keys ( ) ) [ c ] endDt = ham . job . endTimeDt As = [ ham . job . waveCache [ key ] [ i ] for i in range ( endDt ) ] tBar = [ ] Abar = [ ] for i in range ( endDt + 1 ) : tBar . extend ( [ i * dt , i * dt ] ) if i == 0 : Abar . extend ( [ 0 , As [ i ] ] ) elif i == endDt : Abar . extend ( [ As [ i - 1 ] , 0 ] ) else : Abar . extend ( [ As [ i - 1 ] , As [ i ] ] ) plt . fill ( tBar , Abar , color = colorList [ r ] , alpha = 0.6 ) plt . plot ( tBar , Abar , color = colorList [ r ] , label = 'coe: {:.2f}' . format ( coe ) ) plt . legend ( loc = 'upper right' ) plt . xlim ( 0 , tMax ) if r == 0 : plt . title ( key ) if r == len ( rescaleCoes ) - 1 : plt . xlabel ( 'Times' ) axes . append ( ax ) fig . tight_layout ( ) plt . suptitle ( title ) return fig , axes
Plot each pulse channel of a series of time-rescaling Hamiltonians.
Plot each pulse channel of a series of time - rescaling Hamiltonians .
"""
    Plot each pulse channel of a series of time-rescaling Hamiltonians. Suppose len(rescaleCoes)=r and numChannel=n,
    this function will show a figure including r*c subfigures which are
    arranged in "r" rows and "c" columns.

    :param rescaleCoes: rescaling coefficients
    :param hamList: Hamiltonian list whose length is equal to `rescaleCoes`
    :param numChannel: number of pulse channels
    :param figsize: size of the entire figure
    :param title: super title of the entire figure
    :return: fig, axes
    """ # dtList: e.g. [1, 1.25, ...] # tList: e.g. [1*16, 1.25*16, ...] # ax lies in (row, col): (r, c) # key: the name of pulse channel # construct tBar (list type) and Abar (list type) to plot a bar figure
None
rescaleCoes
List[float]
None
hamList
List[QHamiltonian]
Hamiltonian list whose length is equal to `rescaleCoes`
Hamiltonian list whose length is equal to ` rescaleCoes `
numChannel
int
number of pulse channels
number of pulse channels
figsize
tuple
size of the entire figure
size of the entire figure
title
super title of the entire figure
super title of the entire figure