Quanlse/Utils/Benchmark.py
def evolution(ham: QHamiltonian, stateInitial: ndarray = None, matrix: ndarray = None) -> Dict[str, Any]:
    """
    Return the expectation value of the given matrix for given initial states. The input can be a list
    containing all the matrices and states that the users want to calculate.

    :param ham: Hamiltonian Dictionary
    :param stateInitial: the list of numpy.ndarray that represents an initial state in the Hilbert space
    :param matrix: the list of matrix whose expectation values to be evaluated
    :return: the dictionary that contains all the expectation values for all initial states
    """

    # If the input data is not list, we transform it into a list
    if type(matrix) is ndarray:
        matrixList = [matrix]
    else:
        matrixList = matrix
    if type(stateInitial) is ndarray:
        stateInitial = [stateInitial]

    result = ham.simulate(recordEvolution=True)
    unitaryList = result[0]['evolution_history']
    # x = numpy.linspace(0, ham['circuit']['max_time_ns'], ham['circuit']['max_time_dt'])

    stateList = {}
    # We first calculate all the intermediate states in the process
    for stateIndex, stateItem in enumerate(stateInitial):
        stateListTemp = evolutionList(stateItem, unitaryList)
        stateList[str(stateIndex)] = {}
        stateList[str(stateIndex)]['state_form'] = stateItem
        stateList[str(stateIndex)]['state_evolution_history'] = stateListTemp
        matrixTempDict = {}
        for matrixIndex, matrixItem in enumerate(matrixList):
            matrixTempDict['matrix-' + str(matrixIndex) + '-form'] = matrixItem
            valueList = []
            for stateItemTemp in stateListTemp:
                valueList.append(expect(matrixItem, stateItemTemp))
            matrixTempDict['matrix-' + str(matrixIndex) + '-value'] = valueList
        stateList[str(stateIndex)]['result'] = matrixTempDict
    return stateList

    Return the expectation value of the given matrix for given initial states. The input can be a list
    containing all the matrices and states that the users want to calculate.

    :param ham: Hamiltonian Dictionary
    :param stateInitial: the list of numpy.ndarray that represents an initial state in the Hilbert space
    :param matrix: the list of matrix whose expectation values to be evaluated
    :return: the dictionary that contains all the expectation values for all initial states
    
Return the expectation value of the given matrix for given initial states. The input can be a list
containing all the matrices and states that the users want to calculate.
Return the expectation value of the given matrix for given initial states . The input can be a list containing all the matrices and states that the users want to calculate .
def evolution(ham: QHamiltonian, stateInitial: ndarray = None, matrix: ndarray = None) -> Dict[str, Any]:
    if type(matrix) is ndarray:
        matrixList = [matrix]
    else:
        matrixList = matrix
    if type(stateInitial) is ndarray:
        stateInitial = [stateInitial]
    result = ham.simulate(recordEvolution=True)
    unitaryList = result[0]['evolution_history']
    stateList = {}
    for stateIndex, stateItem in enumerate(stateInitial):
        stateListTemp = evolutionList(stateItem, unitaryList)
        stateList[str(stateIndex)] = {}
        stateList[str(stateIndex)]['state_form'] = stateItem
        stateList[str(stateIndex)]['state_evolution_history'] = stateListTemp
        matrixTempDict = {}
        for matrixIndex, matrixItem in enumerate(matrixList):
            matrixTempDict['matrix-' + str(matrixIndex) + '-form'] = matrixItem
            valueList = []
            for stateItemTemp in stateListTemp:
                valueList.append(expect(matrixItem, stateItemTemp))
            matrixTempDict['matrix-' + str(matrixIndex) + '-value'] = valueList
        stateList[str(stateIndex)]['result'] = matrixTempDict
    return stateList
def evolution ( ham : QHamiltonian , stateInitial : ndarray = None , matrix : ndarray = None ) -> Dict [ str , Any ] : if type ( matrix ) is ndarray : matrixList = [ matrix ] else : matrixList = matrix if type ( stateInitial ) is ndarray : stateInitial = [ stateInitial ] result = ham . simulate ( recordEvolution = True ) unitaryList = result [ 0 ] [ 'evolution_history' ] stateList = { } for stateIndex , stateItem in enumerate ( stateInitial ) : stateListTemp = evolutionList ( stateItem , unitaryList ) stateList [ str ( stateIndex ) ] = { } stateList [ str ( stateIndex ) ] [ 'state_form' ] = stateItem stateList [ str ( stateIndex ) ] [ 'state_evolution_history' ] = stateListTemp matrixTempDict = { } for matrixIndex , matrixItem in enumerate ( matrixList ) : matrixTempDict [ 'matrix-' + str ( matrixIndex ) + '-form' ] = matrixItem valueList = [ ] for stateItemTemp in stateListTemp : valueList . append ( expect ( matrixItem , stateItemTemp ) ) matrixTempDict [ 'matrix-' + str ( matrixIndex ) + '-value' ] = valueList stateList [ str ( stateIndex ) ] [ 'result' ] = matrixTempDict return stateList
Return the expectation value of the given matrix for given initial states.
Return the expectation value of the given matrix for given initial states .
"""
    Return the expectation value of the given matrix for given initial states. The input can be a list
    containing all the matrices and states that the users want to calculate.

    :param ham: Hamiltonian Dictionary
    :param stateInitial: the list of numpy.ndarray that represents an initial state in the Hilbert space
    :param matrix: the list of matrix whose expectation values to be evaluated
    :return: the dictionary that contains all the expectation values for all initial states
    """ # If the input data is not list, we transform it into a list # x = numpy.linspace(0, ham['circuit']['max_time_ns'], ham['circuit']['max_time_dt']) # We first calculate all the intermediate states in the process
the dictionary that contains all the expectation values for all initial states
the dictionary that contains all the expectation values for all initial states
ham
QHamiltonian
None
stateInitial
ndarray
the list of numpy.ndarray that represents an initial state in the Hilbert space
the list of numpy . ndarray that represents an initial state in the Hilbert space
matrix
ndarray
the list of matrix whose expectation values to be evaluated
the list of matrix whose expectation values to be evaluated