| 1 |
''' |
| 2 |
How long does synapse creation take? Brian1 for comparison |
| 3 |
''' |
| 4 |
import time |
| 5 |
import pickle |
| 6 |
|
| 7 |
import numpy as np |
| 8 |
import joblib |
| 9 |
|
| 10 |
from brian import * |
| 11 |
|
| 12 |
repetitions = 5 |
| 13 |
|
| 14 |
memory = joblib.Memory(cachedir='.', verbose=0) |
| 15 |
|
| 16 |
@memory.cache |
| 17 |
def test_connectivity(N, i, j, n, p): |
| 18 |
G = NeuronGroup(N, '') |
| 19 |
# Do it once without measuring the time to ignore the compilation time for |
| 20 |
# C code -- not really necessary for Brian1 but leave it in for perfect |
| 21 |
# comparability |
| 22 |
S = Synapses(G, G, '') |
| 23 |
S[:, :] = i |
| 24 |
connections = len(S) |
| 25 |
del S |
| 26 |
times = [] |
| 27 |
for _ in range(repetitions): |
| 28 |
S = Synapses(G, G, '') |
| 29 |
start = time.time() |
| 30 |
S[:, :] = i |
| 31 |
times.append(time.time() - start) |
| 32 |
del S |
| 33 |
|
| 34 |
return np.median(times), connections |
| 35 |
|
| 36 |
conditions = [('Full', True), |
| 37 |
('Full (no-self)', 'i != j'), |
| 38 |
('One-to-one', 'i == j'), |
| 39 |
('Simple neighbourhood', 'abs(i-j) < 5'), |
| 40 |
('Gauss neighbourhood', 'exp(-(i - j)**2/5) > 0.005'), |
| 41 |
('Random (50%)', 0.5), |
| 42 |
('Random (10%)', 0.1), |
| 43 |
('Random (1%)', 0.01), |
| 44 |
('Random no-self (50%)', '(i != j) * 0.5'), |
| 45 |
('Random no-self (10%)', '(i != j) * 0.1'), |
| 46 |
('Random no-self (1%)', '(i != j) * 0.01')] |
| 47 |
results = {} |
| 48 |
lang_name = 'Brian 1' |
| 49 |
max_connections = 10000000 |
| 50 |
for pattern, condition in conditions: |
| 51 |
N = 1 |
| 52 |
connections = took = 0 |
| 53 |
while connections < max_connections and took < 60.: |
| 54 |
print(lang_name, pattern) |
| 55 |
took, connections = test_connectivity(N, condition, None, 1, 1.) |
| 56 |
print(N, '%.4fs (for %d connections)' % (took, connections)) |
| 57 |
results[(lang_name, connections, pattern)] = took |
| 58 |
N *= 2 |
| 59 |
|
| 60 |
with open('synapse_creation_times_brian1.pickle', 'w') as f: |
| 61 |
pickle.dump(results, f) |