コード例 #1
0
ファイル: __init__.py プロジェクト: pabloriera/gpuODE
def run_ode( FORMULA, FUNCTIONS, INPUTS,  inits, params, T , fs, inputs = None, decimate=1 ,variable_length = False, stochastic = False, Tterm = 0, gpu = False, nthreads = 4 , dtype = np.float32, debug = False,seed =None,threads_per_block=32 ):
    from gpuODE import ode, param_grid, funcs2code

           
    PARAMETERS = params.keys()
       
    odeRK4 = ode("ode")
    odeRK4.setup(FORMULA, PARAMETERS, INPUTS)
    
    Tt = T + Tterm
    dt = 1.0/np.array(fs)
    N = np.int32(Tt*fs)
    
    Nterm = np.int32(Tterm*fs)
    
    extra_funcs = funcs2code(FUNCTIONS, gpu = gpu)
    odeRK4.extra_func = extra_funcs
    odeRK4.generate_code(debug=debug, gpu = gpu,variable_length = variable_length, stochastic=stochastic, dtype = dtype)
    odeRK4.compile()

    if gpu==True:

        time, out = odeRK4.run(inits, param_grid(**params) , dt, decimate = decimate, inputs=inputs, N = N, Nterm = Nterm,seed = seed,threads_per_block=threads_per_block)
        return time, out
        
    else:

        import distributed_exploration as de
        import timeit
        from random import randint
        seed_off = 0

        #Modifications are needed to change the seed on differnet threads
        def func(**args):
            seedr = seed + randint(0,10000)
            time,out = odeRK4.run(inits, args, dt ,decimate=decimate, inputs=inputs, N = N , Nterm = Nterm,seed = seedr)
            return time, out
        
        tic = timeit.default_timer()
        out0 = de.explore_thread(func, param_grid(**params) ,nthreads=nthreads)
        toc = timeit.default_timer()

        Nm = int(T*fs)/decimate
        M = len(out0)

        out = {}

        for j,k in enumerate(FORMULA.keys()):   

            out[k] = np.zeros((Nm,M))
            
        for i,o in enumerate(out0):
            for j,k in enumerate(FORMULA.keys()):
                out[k][:,i] = o['out'][1][k].T[0,:N]
    
            
        return toc-tic, out
コード例 #2
0
Tterm = 0
decimate = 1
inputs = None
debug = True
nthreads = 1

T = T + Tterm
dt = 1.0/float(fs)
N = np.int32(T*fs)

Nterm = np.int32(Tterm*fs).min()
dtype = np.float32
variable_length = False

extra_funcs = funcs2code(FUNCTION, gpu = gpu)
odeRK4.extra_func = extra_funcs
odeRK4.generate_code(debug=debug, gpu = gpu,variable_length = variable_length, stochastic=stochastic, dtype = dtype )
odeRK4.compile()

if gpu==True:

    time, out = odeRK4.run(x0, param_grid(**params) , dt, decimate = decimate, inputs=inputs, N = N, Nterm = Nterm)

    w = out['w']
    
else:



    time,out = odeRK4.run(x0, param_grid(**params) , dt,decimate=decimate, inputs=inputs, N = N , Nterm = Nterm,seed = 1234) 
コード例 #3
0
ファイル: aplysia_gpu.py プロジェクト: pabloriera/gpuODE
if stochastic:
    cond = "+ noise_amp*noise"
else:
    cond = ""
    
FORMULA = {"c"  : "rho*(K_c*x_t*(V_ca - V) - c) /tau",
           "x_t": "( ( s_t(V) - x_t)/tau_xt {}) / tau ".format(cond),
           "x_k": "( s_k(Vs(V,a,b)) - x_k)/tau_xk(Vs(V,a,b))/tau  ",
           "y_i": "( z_i(Vs(V,a,b)) - y_i)/tau_yi(Vs(V,a,b))/tau",
           "V": "( (g_i*powf(s_i(Vs(V,a,b)),3.0)*y_i+g_t*x_t)*(V_i-V) + (g_k*powf(x_k,4.0) + g_p*c/(K_p+c) )*(V_k-V)  + g_l*(V_l-V) + I  )/tau "}
           
PARAMETERS = params.keys()

aplysia.setup(FORMULA, PARAMETERS, INPUTS)
aplysia.extra_func = funcs2code(fnspecs,gpu=True)
aplysia.generate_code(debug=False, stochastic = stochastic, gpu = True, dtype = np.float32)
aplysia.compile()

M = 32

params['tau_xt'] = np.linspace(70,400,M)

Tterm = 1000
T = 1000.0 + Tterm
fs = 400.0
dt = 1/fs
N = int(T*fs)
Nterm = int(Tterm*fs)

decimate = 4