File: test_openmp_3.py

package info (click to toggle)
brian 2.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,872 kB
  • sloc: python: 51,820; cpp: 2,033; makefile: 108; sh: 72
file content (89 lines) | stat: -rw-r--r-- 2,948 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import sys, os, numpy, time, pylab

filename = 'example_standalone.py'
datapath = 'data_example'
threads  = [0, 1, 2, 4, 6]
results  = {}
results['duration'] = []

for t in threads:
    start = time.time()
    os.system('python %s 1 %d' %(filename, t))
    with open('%s_%d/speed.txt' %(datapath, t), 'r') as f:
        results['duration'] += [float(f.read())]
    results[t] = {}

for t in threads:
    results[t]  = {}
    path        = datapath + '_%d/' %t
    ids         = numpy.fromfile(path+'results/_dynamic_array_spikemonitor_i', dtype=numpy.int32)
    times       = numpy.fromfile(path+'results/_dynamic_array_spikemonitor_t', dtype=numpy.float64)
    w           = numpy.fromfile(path+'results/_dynamic_array_synapses_w', dtype=numpy.float64)
    times_w     = numpy.fromfile(path+'results/_dynamic_array_statemonitor_t', dtype=numpy.float64)
    w_over_time = numpy.fromfile(path+'results/_dynamic_array_statemonitor__recorded_w', dtype=numpy.float64)
    v_over_time = numpy.fromfile(path+'results/_dynamic_array_statemonitor_1__recorded_v', dtype=numpy.float64)
    times_v     = numpy.fromfile(path+'results/_dynamic_array_statemonitor_1_t', dtype=numpy.float64)
    results[t]['spikes']  = (times, ids)
    results[t]['w']       = w
    results[t]['trace_w'] = w_over_time.reshape(len(times_w), len(w_over_time)/len(times_w))
    results[t]['trace_v'] = v_over_time.reshape(len(times_v), len(v_over_time)/len(times_v))

results['colors'] = ['b', 'g', 'r', 'c', 'k']

pylab.figure()
pylab.subplot(321)
pylab.title('Raster plots')
pylab.xlabel('Time [s]')
pylab.ylabel('# cell')
for t in threads:
    pylab.plot(results[t]['spikes'][0], results[t]['spikes'][1], '.')
pylab.legend([str(t) for t in threads])
#pylab.xlim(0.5, 0.6)

pylab.subplot(322)
pylab.title('Final Distribution')
pylab.xlabel('Weight [ns]')
pylab.ylabel('Number of synapses')
for t in threads:
    x, y = numpy.histogram(results[t]['w'], 100)
    pylab.plot(y[1:], x)
pylab.legend([str(t) for t in threads])

pylab.subplot(323)
pylab.title('Weight Evolution')
pylab.xlabel('Time [s]')
pylab.ylabel('Weight [ns]')
for t in threads:
    pylab.plot(results[t]['trace_w'].T[0])
pylab.legend([str(t) for t in threads])

pylab.subplot(324)
pylab.title('Weight Evolution')
pylab.xlabel('Time [s]')
pylab.ylabel('Weight [ns]')
for count, t in enumerate(threads):
    for i in range(3):
        pylab.plot(results[t]['trace_w'].T[i], c=results['colors'][count])
#pylab.legend(map(str, threads))

pylab.subplot(325)
pylab.title('Voltage Evolution')
pylab.xlabel('Time [s]')
pylab.ylabel('Voltage [mv]')
for count, t in enumerate(threads):
    for i in range(3):
        pylab.plot(results[t]['trace_v'].T[i], c=results['colors'][count])
#pylab.legend(map(str, threads))

pylab.subplot(326)
pylab.title('Speed')
pylab.plot(threads, results['duration'])
pylab.xlabel('# threads')
pylab.ylabel('Time [s]')

pylab.tight_layout()


pylab.savefig('net1_openmp.png')

pylab.show()