Skip to content

Commit ad95d41

Browse files
committed
Fix connectors_benchmark.py [RFC/WIP]
PyNN: * use file mode `wb` in save_positions as we write binary data * zipfile now only accepts `w` (no `wb`) connectors_benchmark.py * `3` AllToAllConnector should not need delays? * `7` is somehow broken? Wrong save/load format? * `8` SmallWorldConnector doesn't seem to be supported by nest/mock
1 parent e54fde7 commit ad95d41

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

pyNN/common/populations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ def save_positions(self, file):
579579
Save positions to file. The output format is ``index x y z``
580580
"""
581581
if isinstance(file, basestring):
582-
file = recording.files.StandardTextFile(file, mode='w')
582+
file = recording.files.StandardTextFile(file, mode='wb')
583583
cells = self.all_cells
584584
result = numpy.empty((len(cells), 4))
585585
result[:, 0] = numpy.array([self.id_to_index(id) for id in cells])
@@ -1310,7 +1310,7 @@ def save_positions(self, file):
13101310
Save positions to file. The output format is id x y z
13111311
"""
13121312
if isinstance(file, basestring):
1313-
file = files.StandardTextFile(file, mode='w')
1313+
file = files.StandardTextFile(file, mode='wb')
13141314
cells = self.all_cells
13151315
result = numpy.empty((len(cells), 4))
13161316
result[:, 0] = numpy.array([self.id_to_index(id) for id in cells])

pyNN/recording/files.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
have_hdf5 = False
3030
from pyNN.core import iteritems
3131

32+
try:
33+
basestring
34+
except NameError:
35+
basestring = str
3236

3337
DEFAULT_BUFFER_SIZE = 10000
3438

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

64-
zip = zipfile.ZipFile(file, mode="wb")
68+
zip = zipfile.ZipFile(file, mode="w")
6569

6670
# Place to write temporary .npy files
6771
# before storing them in the zip. We need to path this to have a working

test/benchmarks/connectors_benchmark.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test(cases=[1]):
8080
conn = FixedProbabilityConnector(0.02, safe=safe, callback=callback, allow_self_connections=autapse, rng=rng)
8181
fig_name = "FixedProbability_%s_np_%d.png" % (simulator_name, np)
8282
elif case == 3:
83-
conn = AllToAllConnector(delays=delay, safe=safe, callback=callback, allow_self_connections=autapse)
83+
conn = AllToAllConnector(safe=safe, callback=callback, allow_self_connections=autapse)
8484
fig_name = "AllToAll_%s_np_%d.png" % (simulator_name, np)
8585
elif case == 4:
8686
conn = FixedNumberPostConnector(50, safe=safe, callback=callback, allow_self_connections=autapse, rng=rng)
@@ -92,7 +92,7 @@ def test(cases=[1]):
9292
conn = OneToOneConnector(safe=safe, callback=callback)
9393
fig_name = "OneToOne_%s_np_%d.png" % (simulator_name, np)
9494
elif case == 7:
95-
conn = FromFileConnector(files.NumpyBinaryFile('Results/connections.dat', mode='r'), safe=safe, callback=callback, distributed=True)
95+
conn = FromFileConnector(files.NumpyBinaryFile('Results/connections.dat', mode='rb'), safe=safe, callback=callback, distributed=False)
9696
fig_name = "FromFile_%s_np_%d.png" % (simulator_name, np)
9797
elif case == 8:
9898
conn = SmallWorldConnector(degree=0.1, rewiring=0., safe=safe, callback=callback, allow_self_connections=autapse)

0 commit comments

Comments
 (0)