Quanlse/Utils/ODESolver.py
def solverNormal(ham: 'QHamiltonian', state0=None, shot=None, recordEvolution=False, accelerate=False):
    """
    Calculate the unitary evolution operator with a given Hamiltonian. This function supports
    both single-job and batch-job processing.

    :param ham: QHamiltonian object
    :param state0: the initial state vector. If None is given, this function will return the time-ordered
                   evolution operator, otherwise returns the final state vector.
    :param recordEvolution: the detailed procedure will be recorded if True
    :param accelerate: use numba expm if true
    :param shot: return the population of the eigenstates when ``shot`` is provided
    :return: result dictionary (or a list of result dictionaries when ``jobList`` is provided)
    """

    # Import expm
    if accelerate:
        from Quanlse.Utils.NumbaSupport import expm
    else:
        from scipy.linalg import expm

    sysLevelLen = 1 if isinstance(ham.sysLevel, int) else len(ham.sysLevel)
    sysLevel = [ham.sysLevel] if isinstance(ham.sysLevel, int) else ham.sysLevel
    subSysNum = ham.subSysNum

    ctrlList, waveList = _cacheDictToList(ham.ctrlCache, ham.waveCache)

    if state0 is not None:
        # Initialize stateOrUnitary
        stateOrUnitary = copy.deepcopy(state0)
    else:
        # If the sysLevel is an integer to indicate the same energy level for each subsystem
        if sysLevelLen == 1:
            stateOrUnitary = identity(sysLevel[0] ** subSysNum, dtype=complex)
        else:
            # If the sysLevel is a list of energy levels for different subsystem
            dim = 1
            for subSysLvl in sysLevel:
                dim = dim * subSysLvl
            stateOrUnitary = identity(dim, dtype=complex)

    # Start time
    startTime = time.time()
    # Create evolution history list
    history = []

    for nowDt in range(0, ham.job.endTimeDt):
        totalHam = ham.driftCache.copy()
        # Traverse all the control Hamiltonian
        for key in range(len(ctrlList)):
            totalHam += ctrlList[key] * waveList[key][nowDt]
        tUnitary = expm(- 1j * totalHam * ham.dt)
        stateOrUnitary = dot(tUnitary, stateOrUnitary)
        if recordEvolution:
            history.append(stateOrUnitary)

    if state0 is not None:
        _state = stateOrUnitary
        _unitary = None
        if shot is not None:
            _population = list(map(int, round(square(abs(_state)) * shot)))
        else:
            _population = None
    else:
        _unitary = stateOrUnitary
        _state = None
        _population = None

    ret = {
        "unitary": _unitary,
        "state": _state,
        "population": _population,
        "dt": ham.dt,
        "dts": ham.job.endTimeDt,
        "ns": ham.job.endTimeDt * ham.dt,
        "time_consuming": time.time() - startTime,
        "evolution_history": history,
        "numba-simulator": "local-built-in-normal"
    }
    return ret

    Calculate the unitary evolution operator with a given Hamiltonian. This function supports
    both single-job and batch-job processing.

    :param ham: QHamiltonian object
    :param state0: the initial state vector. If None is given, this function will return the time-ordered
                   evolution operator, otherwise returns the final state vector.
    :param recordEvolution: the detailed procedure will be recorded if True
    :param accelerate: use numba expm if true
    :param shot: return the population of the eigenstates when ``shot`` is provided
    :return: result dictionary (or a list of result dictionaries when ``jobList`` is provided)
    
Calculate the unitary evolution operator with a given Hamiltonian. This function supports
both single-job and batch-job processing.
Calculate the unitary evolution operator with a given Hamiltonian . This function supports both single - job and batch - job processing .
def solverNormal(ham: 'QHamiltonian', state0=None, shot=None, recordEvolution=False, accelerate=False):
    if accelerate:
        from Quanlse.Utils.NumbaSupport import expm
    else:
        from scipy.linalg import expm
    sysLevelLen = 1 if isinstance(ham.sysLevel, int) else len(ham.sysLevel)
    sysLevel = [ham.sysLevel] if isinstance(ham.sysLevel, int) else ham.sysLevel
    subSysNum = ham.subSysNum
    ctrlList, waveList = _cacheDictToList(ham.ctrlCache, ham.waveCache)
    if state0 is not None:
        stateOrUnitary = copy.deepcopy(state0)
    else:
        if sysLevelLen == 1:
            stateOrUnitary = identity(sysLevel[0] ** subSysNum, dtype=complex)
        else:
            dim = 1
            for subSysLvl in sysLevel:
                dim = dim * subSysLvl
            stateOrUnitary = identity(dim, dtype=complex)
    startTime = time.time()
    history = []
    for nowDt in range(0, ham.job.endTimeDt):
        totalHam = ham.driftCache.copy()
        for key in range(len(ctrlList)):
            totalHam += ctrlList[key] * waveList[key][nowDt]
        tUnitary = expm(- 1j * totalHam * ham.dt)
        stateOrUnitary = dot(tUnitary, stateOrUnitary)
        if recordEvolution:
            history.append(stateOrUnitary)
    if state0 is not None:
        _state = stateOrUnitary
        _unitary = None
        if shot is not None:
            _population = list(map(int, round(square(abs(_state)) * shot)))
        else:
            _population = None
    else:
        _unitary = stateOrUnitary
        _state = None
        _population = None
    ret = {
        "unitary": _unitary,
        "state": _state,
        "population": _population,
        "dt": ham.dt,
        "dts": ham.job.endTimeDt,
        "ns": ham.job.endTimeDt * ham.dt,
        "time_consuming": time.time() - startTime,
        "evolution_history": history,
        "numba-simulator": "local-built-in-normal"
    }
    return ret
def solverNormal ( ham : 'QHamiltonian' , state0 = None , shot = None , recordEvolution = False , accelerate = False ) : if accelerate : from Quanlse . Utils . NumbaSupport import expm else : from scipy . linalg import expm sysLevelLen = 1 if isinstance ( ham . sysLevel , int ) else len ( ham . sysLevel ) sysLevel = [ ham . sysLevel ] if isinstance ( ham . sysLevel , int ) else ham . sysLevel subSysNum = ham . subSysNum ctrlList , waveList = _cacheDictToList ( ham . ctrlCache , ham . waveCache ) if state0 is not None : stateOrUnitary = copy . deepcopy ( state0 ) else : if sysLevelLen == 1 : stateOrUnitary = identity ( sysLevel [ 0 ] ** subSysNum , dtype = complex ) else : dim = 1 for subSysLvl in sysLevel : dim = dim * subSysLvl stateOrUnitary = identity ( dim , dtype = complex ) startTime = time . time ( ) history = [ ] for nowDt in range ( 0 , ham . job . endTimeDt ) : totalHam = ham . driftCache . copy ( ) for key in range ( len ( ctrlList ) ) : totalHam += ctrlList [ key ] * waveList [ key ] [ nowDt ] tUnitary = expm ( - 1j * totalHam * ham . dt ) stateOrUnitary = dot ( tUnitary , stateOrUnitary ) if recordEvolution : history . append ( stateOrUnitary ) if state0 is not None : _state = stateOrUnitary _unitary = None if shot is not None : _population = list ( map ( int , round ( square ( abs ( _state ) ) * shot ) ) ) else : _population = None else : _unitary = stateOrUnitary _state = None _population = None ret = { "unitary" : _unitary , "state" : _state , "population" : _population , "dt" : ham . dt , "dts" : ham . job . endTimeDt , "ns" : ham . job . endTimeDt * ham . dt , "time_consuming" : time . time ( ) - startTime , "evolution_history" : history , "numba-simulator" : "local-built-in-normal" } return ret
Calculate the unitary evolution operator with a given Hamiltonian.
Calculate the unitary evolution operator with a given Hamiltonian .
"""
    Calculate the unitary evolution operator with a given Hamiltonian. This function supports
    both single-job and batch-job processing.

    :param ham: QHamiltonian object
    :param state0: the initial state vector. If None is given, this function will return the time-ordered
                   evolution operator, otherwise returns the final state vector.
    :param recordEvolution: the detailed procedure will be recorded if True
    :param accelerate: use numba expm if true
    :param shot: return the population of the eigenstates when ``shot`` is provided
    :return: result dictionary (or a list of result dictionaries when ``jobList`` is provided)
    """ # Import expm # Initialize stateOrUnitary # If the sysLevel is an integer to indicate the same energy level for each subsystem # If the sysLevel is a list of energy levels for different subsystem # Start time # Create evolution history list # Traverse all the control Hamiltonian
result dictionary (or a list of result dictionaries when ``jobList`` is provided)
result dictionary ( or a list of result dictionaries when ` ` jobList ` ` is provided )
ham
'QHamiltonian'
None
state0
the initial state vector. If None is given, this function will return the time-ordered
evolution operator, otherwise returns the final state vector.
the initial state vector . If None is given this function will return the time - ordered evolution operator otherwise returns the final state vector .
shot
return the population of the eigenstates when ``shot`` is provided
return the population of the eigenstates when ` ` shot ` ` is provided
recordEvolution
the detailed procedure will be recorded if True
the detailed procedure will be recorded if True
accelerate
use numba expm if true
use numba expm if true