Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connectors_benchmark.py [WIP/RFC] #688

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyNN/common/populations.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def save_positions(self, file):
Save positions to file. The output format is ``index x y z``
"""
if isinstance(file, basestring):
file = recording.files.StandardTextFile(file, mode='w')
file = recording.files.StandardTextFile(file, mode='wb')
cells = self.all_cells
result = numpy.empty((len(cells), 4))
result[:, 0] = numpy.array([self.id_to_index(id) for id in cells])
Expand Down Expand Up @@ -1310,7 +1310,7 @@ def save_positions(self, file):
Save positions to file. The output format is id x y z
"""
if isinstance(file, basestring):
file = files.StandardTextFile(file, mode='w')
file = files.StandardTextFile(file, mode='wb')
cells = self.all_cells
result = numpy.empty((len(cells), 4))
result[:, 0] = numpy.array([self.id_to_index(id) for id in cells])
Expand Down
6 changes: 5 additions & 1 deletion pyNN/recording/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
have_hdf5 = False
from pyNN.core import iteritems

try:
basestring
except NameError:
basestring = str

DEFAULT_BUFFER_SIZE = 10000

Expand Down Expand Up @@ -61,7 +65,7 @@ def savez(file, *args, **kwds):
raise ValueError("Cannot use un-named variables and keyword %s" % key)
namedict[key] = val

zip = zipfile.ZipFile(file, mode="wb")
zip = zipfile.ZipFile(file, mode="w")

# Place to write temporary .npy files
# before storing them in the zip. We need to path this to have a working
Expand Down
28 changes: 14 additions & 14 deletions test/benchmarks/connectors_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def draw_rf(cell, positions, connections, color='k'):
idx = numpy.where(connections[:, 1] == cell)[0]
sources = connections[idx, 0]
for src in sources:
plot([positions[cell, 1], positions[src, 1]], [positions[cell, 2], positions[src, 2]], c=color)
plot([positions[cell, 1], positions[int(src), 1]], [positions[cell, 2], positions[int(src), 2]], c=color)


def distances(pos_1, pos_2, N):
Expand Down Expand Up @@ -73,28 +73,28 @@ def test(cases=[1]):
synapse = StaticSynapse(weight=w, delay=delay)
rng = NumpyRNG(23434, parallel_safe=parallel_safe)

if case is 1:
if case == 1:
conn = DistanceDependentProbabilityConnector(d_expression, safe=safe, callback=callback, allow_self_connections=autapse, rng=rng)
fig_name = "DistanceDependent_%s_np_%d.png" % (simulator_name, np)
elif case is 2:
elif case == 2:
conn = FixedProbabilityConnector(0.02, safe=safe, callback=callback, allow_self_connections=autapse, rng=rng)
fig_name = "FixedProbability_%s_np_%d.png" % (simulator_name, np)
elif case is 3:
conn = AllToAllConnector(delays=delay, safe=safe, callback=callback, allow_self_connections=autapse)
elif case == 3:
conn = AllToAllConnector(safe=safe, callback=callback, allow_self_connections=autapse)
fig_name = "AllToAll_%s_np_%d.png" % (simulator_name, np)
elif case is 4:
elif case == 4:
conn = FixedNumberPostConnector(50, safe=safe, callback=callback, allow_self_connections=autapse, rng=rng)
fig_name = "FixedNumberPost_%s_np_%d.png" % (simulator_name, np)
elif case is 5:
elif case == 5:
conn = FixedNumberPreConnector(50, safe=safe, callback=callback, allow_self_connections=autapse, rng=rng)
fig_name = "FixedNumberPre_%s_np_%d.png" % (simulator_name, np)
elif case is 6:
elif case == 6:
conn = OneToOneConnector(safe=safe, callback=callback)
fig_name = "OneToOne_%s_np_%d.png" % (simulator_name, np)
elif case is 7:
conn = FromFileConnector(files.NumpyBinaryFile('Results/connections.dat', mode='r'), safe=safe, callback=callback, distributed=True)
elif case == 7:
conn = FromFileConnector(files.NumpyBinaryFile('Results/connections.dat', mode='rb'), safe=safe, callback=callback, distributed=False)
fig_name = "FromFile_%s_np_%d.png" % (simulator_name, np)
elif case is 8:
elif case == 8:
conn = SmallWorldConnector(degree=0.1, rewiring=0., safe=safe, callback=callback, allow_self_connections=autapse)
fig_name = "SmallWorld_%s_np_%d.png" % (simulator_name, np)

Expand All @@ -110,7 +110,7 @@ def test(cases=[1]):
if not(os.path.isdir('Results')):
os.mkdir('Results')
print("Saving Connections....")
prj.save('all', files.NumpyBinaryFile('Results/connections.dat', mode='w'), gather=True)
prj.save('all', files.NumpyBinaryFile('Results/connections.dat', mode='wb'), gather=True)

mytime = timer.diff()
print("Time to save the projection:", mytime, 's')
Expand All @@ -126,7 +126,7 @@ def test(cases=[1]):
positions = numpy.loadtxt('Results/positions.dat')

positions[:, 0] -= positions[:, 0].min()
connections = files.NumpyBinaryFile('Results/connections.dat', mode='r').read()
connections = files.NumpyBinaryFile('Results/connections.dat', mode='rb').read()
print(positions.shape, connections.shape)
connections[:, 0] -= connections[:, 0].min()
connections[:, 1] -= connections[:, 1].min()
Expand All @@ -147,7 +147,7 @@ def test(cases=[1]):
ids = numpy.random.permutation(positions[:, 0])[0:6]
colors = ['k', 'r', 'b', 'g', 'c', 'y']
for count, cell in enumerate(ids):
draw_rf(cell, positions, connections, colors[count])
draw_rf(int(cell), positions, connections, colors[int(count)])
subplot(235)
plot(d, connections[:, 2], '.')

Expand Down