コード例 #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
ファイル: vdp_gpu_float64.py プロジェクト: pabloriera/gpuODE
# -*- coding: utf-8 -*-

from __future__ import division
from gpuODE import ode, param_grid
import pylab as pl
import numpy as np
            
vdp = ode("vdp")

PARAMETERS = ["mu"]
INPUTS = ["I"]
FORMULA = {"x": "mu*(x-x*x*x/3 -y)",
           "y": "x/mu"}

vdp.setup(FORMULA, PARAMETERS, INPUTS)
vdp.generate_code(debug=False, stochastic = False, gpu = True, dtype = np.float32)
vdp.compile()

x0 = {'x':1,'y':0}

M = 32

mu = np.linspace(-1,10,M)

params = {'mu': mu}

Tterm = 0
T = 100 + Tterm
fs = 100
dt = 1/fs
N = int(T*fs)
コード例 #3
0
# -*- coding: utf-8 -*-

from __future__ import division

from gpuODE import ode, param_grid
import pylab as pl
import numpy as np

#from utils import *   

hr = ode("hr")

extra_func="""
__device__ float phi( float x,float a, float b)
    {
        return -a*x*x*x+b*x*x;
    }
__device__ float psi( float x,float c, float d)
    {
        return  c-d*x*x;
    }
"""

PARAMETERS = ["a","b","c","d","r","s","xr","i"]
INPUTS = ["I"]
FORMULA = {'x':'y + phi( x ,a,b)  - z + i + I + noise', 
            'y':'psi( x , c ,d )- y',
            'z':'r*(s*(x - xr) - z )'}
                         

hr.setup(FORMULA, PARAMETERS, INPUTS)
コード例 #4
0
ファイル: hopf_gpu.py プロジェクト: pabloriera/gpuODE
# -*- coding: utf-8 -*-

from __future__ import division
from gpuODE import ode, param_grid
import pylab as pl
import numpy as np
            
hopf = ode("hopf")

PARAMETERS = ["e","w"]
INPUTS = ["I1","I2"]
FORMULA = {"x": "w*y + w*e*x - (x*x+y*y)*x + I1",
           "y": "-w*x + w*e*y - (x*x+y*y)*y + I2"}

hopf.setup(FORMULA, PARAMETERS, INPUTS)
hopf.generate_code(debug=False, stochastic = False, gpu = True, dtype = np.float32)
hopf.compile()

x0 = {'x':0,'y':0}

M1 = 128


ff = np.logspace(np.log10(100.0),np.log10(5000.0),M1)
w = 2*np.pi*ff

es = np.logspace(0,-2,5)
e = np.r_[-es,0,0.0005]

M2 = len(e)
コード例 #5
0
INPUTS = []
FORMULA = {"w": "noise"}
           
x0 = {'w':0}
M = 2
params = {'d':np.ones(M)}

T = 0.001
fs = 1000

stochastic = True
gpu = False
           
PARAMETERS = params.keys()
   
odeRK4 = ode("ode")
odeRK4.setup(FORMULA, PARAMETERS, INPUTS)

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
コード例 #6
0
ファイル: aplysia_gpu.py プロジェクト: pabloriera/gpuODE
# -*- coding: utf-8 -*-

from __future__ import division

from gpuODE import ode, param_grid, funcs2code
import pylab as pl
import numpy as np

aplysia = ode("aplysia")

Vhna = 115.0
Vhk = -12.0
V_i = 30.0
V_k = -75.0

a = (Vhna-Vhk)/(V_i-V_k)
b = -(Vhna*V_k-V_i*Vhk )/(V_i-V_k)

params = {'a'  :a,
        'b'  :b,
        'g_i':4.0,
        'g_t':0.01,
        'g_k':0.3,
        'g_p':0.03,
        'g_l':0.003,
        'K_p':0.5,
        'K_c':0.008,
        'rho':0.0001,
        'V_i':V_i,
        'V_k':V_k,
        'V_l':-40.0,
コード例 #7
0
ファイル: osc_gpu_vlength.py プロジェクト: pabloriera/gpuODE
# -*- coding: utf-8 -*-

from __future__ import division

from gpuODE import ode, param_grid
import pylab as pl
import numpy as np

#from utils import *   

osc = ode("osc")

INPUTS = ["I"]
PARAMETERS = ["e","w"]
FORMULA = {"x": "w*y + w*e*x",
           "y": "-w*x + w*e*y"}
                         

osc.setup(FORMULA, PARAMETERS, INPUTS)
osc.generate_code(debug=False, stochastic = False, gpu = True, variable_length = True, dtype = np.float32)
osc.compile()

x0 = {'x':1,'y':0}

M = 32
                    
freq_list = np.linspace(10,1000,M)
w_list = 2*np.pi*freq_list 

params = {'w':w_list,
          'e':-0.1}