Quanlse/ErrorMitigation/Utils/Visualization.py
def plotZNESequences(expectationsRescaled: List[List], expectationsExtrapolated: List[List], expectationsIdeal: List,
                     fileName: str = None):
    """
    Plot a figure that shows the extrapolated results and noise-rescaling results, with the X-axis
    representing the size of quantum gate sequences and the Y-axis representing the expectation
    values of the given mechanical quantity.

    :param expectationsRescaled: a series of noise-rescaling expectation values with shape [n, d + 1]
    :param expectationsExtrapolated: a series of extrapolated expectation values with shape [n, d]
    :param expectationsIdeal: a series of ideal expectation values with shape [n,]
    :param fileName: file name
    :return: None
    """
    # shape: [numSeq, d + 1] --> [d + 1, numSeq]
    expectationsRescaled = np.array(expectationsRescaled).transpose()
    # shape: [numSeq, d] --> [d, numSeq]
    expectationsExtrapolated = np.array(expectationsExtrapolated).transpose()
    numSeq = expectationsRescaled.shape[1]
    lengthEachSequence = list(range(1, numSeq + 1))

    # plot results
    plt.figure(figsize=(10, 6))
    for d, Es in enumerate(expectationsRescaled):
        plt.plot(lengthEachSequence, Es, 'o-', label='{}-order rescaled'.format(d + 1))
    for d, Es in enumerate(expectationsExtrapolated):
        plt.plot(lengthEachSequence, Es, 'o--', label='{}-order extrapolated'.format(d + 1))
    plt.plot(lengthEachSequence, expectationsIdeal, 'k+--', label='Ideal')
    plt.xlabel('Size of Clifford sequence')
    plt.ylabel('Expectation value')
    plt.title('Richardson Extrapolation Result of Different Order')
    plt.legend()
    plt.xticks(lengthEachSequence)
    if fileName is not None:
        localFile = os.path.join(outputPath, fileName)
        plt.savefig(localFile)
    plt.show()

    Plot a figure that shows the extrapolated results and noise-rescaling results, with the X-axis
    representing the size of quantum gate sequences and the Y-axis representing the expectation
    values of the given mechanical quantity.

    :param expectationsRescaled: a series of noise-rescaling expectation values with shape [n, d + 1]
    :param expectationsExtrapolated: a series of extrapolated expectation values with shape [n, d]
    :param expectationsIdeal: a series of ideal expectation values with shape [n,]
    :param fileName: file name
    :return: None
    
Plot a figure that shows the extrapolated results and noise-rescaling results, with the X-axis
representing the size of quantum gate sequences and the Y-axis representing the expectation
values of the given mechanical quantity.
Plot a figure that shows the extrapolated results and noise - rescaling results with the X - axis representing the size of quantum gate sequences and the Y - axis representing the expectation values of the given mechanical quantity .
def plotZNESequences(expectationsRescaled: List[List], expectationsExtrapolated: List[List], expectationsIdeal: List,
                     fileName: str = None):
    expectationsRescaled = np.array(expectationsRescaled).transpose()
    expectationsExtrapolated = np.array(expectationsExtrapolated).transpose()
    numSeq = expectationsRescaled.shape[1]
    lengthEachSequence = list(range(1, numSeq + 1))
    plt.figure(figsize=(10, 6))
    for d, Es in enumerate(expectationsRescaled):
        plt.plot(lengthEachSequence, Es, 'o-', label='{}-order rescaled'.format(d + 1))
    for d, Es in enumerate(expectationsExtrapolated):
        plt.plot(lengthEachSequence, Es, 'o--', label='{}-order extrapolated'.format(d + 1))
    plt.plot(lengthEachSequence, expectationsIdeal, 'k+--', label='Ideal')
    plt.xlabel('Size of Clifford sequence')
    plt.ylabel('Expectation value')
    plt.title('Richardson Extrapolation Result of Different Order')
    plt.legend()
    plt.xticks(lengthEachSequence)
    if fileName is not None:
        localFile = os.path.join(outputPath, fileName)
        plt.savefig(localFile)
    plt.show()
def plotZNESequences ( expectationsRescaled : List [ List ] , expectationsExtrapolated : List [ List ] , expectationsIdeal : List , fileName : str = None ) : expectationsRescaled = np . array ( expectationsRescaled ) . transpose ( ) expectationsExtrapolated = np . array ( expectationsExtrapolated ) . transpose ( ) numSeq = expectationsRescaled . shape [ 1 ] lengthEachSequence = list ( range ( 1 , numSeq + 1 ) ) plt . figure ( figsize = ( 10 , 6 ) ) for d , Es in enumerate ( expectationsRescaled ) : plt . plot ( lengthEachSequence , Es , 'o-' , label = '{}-order rescaled' . format ( d + 1 ) ) for d , Es in enumerate ( expectationsExtrapolated ) : plt . plot ( lengthEachSequence , Es , 'o--' , label = '{}-order extrapolated' . format ( d + 1 ) ) plt . plot ( lengthEachSequence , expectationsIdeal , 'k+--' , label = 'Ideal' ) plt . xlabel ( 'Size of Clifford sequence' ) plt . ylabel ( 'Expectation value' ) plt . title ( 'Richardson Extrapolation Result of Different Order' ) plt . legend ( ) plt . xticks ( lengthEachSequence ) if fileName is not None : localFile = os . path . join ( outputPath , fileName ) plt . savefig ( localFile ) plt . show ( )
Plot a figure that shows the extrapolated results and noise-rescaling results, with the X-axis
representing the size of quantum gate sequences and the Y-axis representing the expectation
values of the given mechanical quantity.
Plot a figure that shows the extrapolated results and noise - rescaling results with the X - axis representing the size of quantum gate sequences and the Y - axis representing the expectation values of the given mechanical quantity .
"""
    Plot a figure that shows the extrapolated results and noise-rescaling results, with the X-axis
    representing the size of quantum gate sequences and the Y-axis representing the expectation
    values of the given mechanical quantity.

    :param expectationsRescaled: a series of noise-rescaling expectation values with shape [n, d + 1]
    :param expectationsExtrapolated: a series of extrapolated expectation values with shape [n, d]
    :param expectationsIdeal: a series of ideal expectation values with shape [n,]
    :param fileName: file name
    :return: None
    """ # shape: [numSeq, d + 1] --> [d + 1, numSeq] # shape: [numSeq, d] --> [d, numSeq] # plot results
None
expectationsRescaled
List[List]
a series of noise-rescaling expectation values with shape [n, d + 1]
a series of noise - rescaling expectation values with shape [ n d + 1 ]
expectationsExtrapolated
List[List]
a series of extrapolated expectation values with shape [n, d]
a series of extrapolated expectation values with shape [ n d ]
expectationsIdeal
List
a series of ideal expectation values with shape [n,]
a series of ideal expectation values with shape [ n ]
fileName
str
None