| 1 |
import sys, os, numpy, time, pylab |
| 2 |
|
| 3 |
filename = 'example_standalone.py' |
| 4 |
datapath = 'data_example' |
| 5 |
threads = [0, 1, 2, 4, 6] |
| 6 |
results = {} |
| 7 |
results['duration'] = [] |
| 8 |
|
| 9 |
for t in threads: |
| 10 |
start = time.time() |
| 11 |
os.system('python %s 1 %d' %(filename, t)) |
| 12 |
with open('%s_%d/speed.txt' %(datapath, t), 'r') as f: |
| 13 |
results['duration'] += [float(f.read())] |
| 14 |
results[t] = {} |
| 15 |
|
| 16 |
for t in threads: |
| 17 |
results[t] = {} |
| 18 |
path = datapath + '_%d/' %t |
| 19 |
ids = numpy.fromfile(path+'results/_dynamic_array_spikemonitor_i', dtype=numpy.int32) |
| 20 |
times = numpy.fromfile(path+'results/_dynamic_array_spikemonitor_t', dtype=numpy.float64) |
| 21 |
w = numpy.fromfile(path+'results/_dynamic_array_synapses_w', dtype=numpy.float64) |
| 22 |
times_w = numpy.fromfile(path+'results/_dynamic_array_statemonitor_t', dtype=numpy.float64) |
| 23 |
w_over_time = numpy.fromfile(path+'results/_dynamic_array_statemonitor__recorded_w', dtype=numpy.float64) |
| 24 |
v_over_time = numpy.fromfile(path+'results/_dynamic_array_statemonitor_1__recorded_v', dtype=numpy.float64) |
| 25 |
times_v = numpy.fromfile(path+'results/_dynamic_array_statemonitor_1_t', dtype=numpy.float64) |
| 26 |
results[t]['spikes'] = (times, ids) |
| 27 |
results[t]['w'] = w |
| 28 |
results[t]['trace_w'] = w_over_time.reshape(len(times_w), len(w_over_time)/len(times_w)) |
| 29 |
results[t]['trace_v'] = v_over_time.reshape(len(times_v), len(v_over_time)/len(times_v)) |
| 30 |
|
| 31 |
results['colors'] = ['b', 'g', 'r', 'c', 'k'] |
| 32 |
|
| 33 |
pylab.figure() |
| 34 |
pylab.subplot(321) |
| 35 |
pylab.title('Raster plots') |
| 36 |
pylab.xlabel('Time [s]') |
| 37 |
pylab.ylabel('# cell') |
| 38 |
for t in threads: |
| 39 |
pylab.plot(results[t]['spikes'][0], results[t]['spikes'][1], '.') |
| 40 |
pylab.legend([str(t) for t in threads]) |
| 41 |
#pylab.xlim(0.5, 0.6) |
| 42 |
|
| 43 |
pylab.subplot(322) |
| 44 |
pylab.title('Final Distribution') |
| 45 |
pylab.xlabel('Weight [ns]') |
| 46 |
pylab.ylabel('Number of synapses') |
| 47 |
for t in threads: |
| 48 |
x, y = numpy.histogram(results[t]['w'], 100) |
| 49 |
pylab.plot(y[1:], x) |
| 50 |
pylab.legend([str(t) for t in threads]) |
| 51 |
|
| 52 |
pylab.subplot(323) |
| 53 |
pylab.title('Weight Evolution') |
| 54 |
pylab.xlabel('Time [s]') |
| 55 |
pylab.ylabel('Weight [ns]') |
| 56 |
for t in threads: |
| 57 |
pylab.plot(results[t]['trace_w'].T[0]) |
| 58 |
pylab.legend([str(t) for t in threads]) |
| 59 |
|
| 60 |
pylab.subplot(324) |
| 61 |
pylab.title('Weight Evolution') |
| 62 |
pylab.xlabel('Time [s]') |
| 63 |
pylab.ylabel('Weight [ns]') |
| 64 |
for count, t in enumerate(threads): |
| 65 |
for i in range(3): |
| 66 |
pylab.plot(results[t]['trace_w'].T[i], c=results['colors'][count]) |
| 67 |
#pylab.legend(map(str, threads)) |
| 68 |
|
| 69 |
pylab.subplot(325) |
| 70 |
pylab.title('Voltage Evolution') |
| 71 |
pylab.xlabel('Time [s]') |
| 72 |
pylab.ylabel('Voltage [mv]') |
| 73 |
for count, t in enumerate(threads): |
| 74 |
for i in range(3): |
| 75 |
pylab.plot(results[t]['trace_v'].T[i], c=results['colors'][count]) |
| 76 |
#pylab.legend(map(str, threads)) |
| 77 |
|
| 78 |
pylab.subplot(326) |
| 79 |
pylab.title('Speed') |
| 80 |
pylab.plot(threads, results['duration']) |
| 81 |
pylab.xlabel('# threads') |
| 82 |
pylab.ylabel('Time [s]') |
| 83 |
|
| 84 |
pylab.tight_layout() |
| 85 |
|
| 86 |
|
| 87 |
pylab.savefig('net1_openmp.png') |
| 88 |
|
| 89 |
pylab.show() |