Skip to content

Commit

Permalink
Tweak LPU.graph_to_dicts() to not choke on non-string node IDs.
Browse files Browse the repository at this point in the history
  • Loading branch information
lebedov committed Dec 23, 2015
1 parent 6edf0c5 commit 6f91bdf
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions neurokernel/LPU/LPU.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ def graph_to_dicts(graph):

# parse neuron data
n_dict = {}
neurons = [x for x in graph.node.items() if 'synapse' not in x[0]]

# Cast node IDs to str in case they are ints so that the conditional
# below doesn't fail:
neurons = [x for x in graph.node.items() if 'synapse' not in str(x[0])]

# sort based on id (id is first converted to an integer)
# this is done so that consecutive neurons of the same type
# in the constructed LPU is the same in neurokernel
Expand Down Expand Up @@ -1048,8 +1052,10 @@ def synapse_cmp(x, y):
"""
post-synaptic cite might be another synapse, with convention 'synapse-id'.
"""
pre_x = 'synapse' in x[1]
pre_y = 'synapse' in y[1]

# Cast x[1] and y[1] to str in case they are ints:
pre_x = 'synapse' in str(x[1])
pre_y = 'synapse' in str(y[1])
int_x = int(x[1]) if not pre_x else int(x[1][8:])
int_y = int(y[1]) if not pre_y else int(y[1][8:])
if pre_x and not pre_y:
Expand Down

0 comments on commit 6f91bdf

Please sign in to comment.