Skip to content

Commit

Permalink
Merge pull request #28 from project-rig/fix-#22
Browse files Browse the repository at this point in the history
Fix connections from pass nodes to Nodes
  • Loading branch information
tcstewar committed Jun 16, 2015
2 parents dfb358a + cf53492 commit be30c67
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
6 changes: 4 additions & 2 deletions nengo_spinnaker/builder/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def get_node_source(self, model, cn):
# reference to the value source we created earlier.
return spec(ObjectPort(self._f_of_t_nodes[cn.pre_obj],
OutputPort.standard))
elif type(cn.post_obj) is nengo.Node:
elif (type(cn.post_obj) is nengo.Node and
cn.post_obj not in self._passthrough_nodes):
# If this connection goes from a Node to another Node (exactly, not
# any subclasses) then we just add both nodes and the connection to
# the host model.
Expand Down Expand Up @@ -190,7 +191,8 @@ def get_node_sink(self, model, cn):
# to the Filter operator we created earlier regardless.
return spec(ObjectPort(self._passthrough_nodes[cn.post_obj],
InputPort.standard))
elif type(cn.pre_obj) is nengo.Node:
elif (type(cn.pre_obj) is nengo.Node and
cn.pre_obj not in self._passthrough_nodes):
# If this connection goes from a Node to another Node (exactly, not
# any subclasses) then we just add both nodes and the connection to
# the host model.
Expand Down
18 changes: 18 additions & 0 deletions regression-tests/test_passnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
def test_probe_passnodes():
"""Test that pass nodes are left on SpiNNaker and that they may be probed.
"""
class ValueReceiver(object):
def __init__(self):
self.ts = list()
self.values = list()

def __call__(self, t, x):
self.ts.append(t)
self.values.append(x[:])

with nengo.Network("Test Network") as net:
# Create an input Node which is a function of time only
input_node = nengo.Node(lambda t: -0.33 if t < 1.0 else 0.10,
Expand All @@ -22,6 +31,12 @@ def test_probe_passnodes():
transform=[[1.0], [0.0], [-1.0]])
p_ens = nengo.Probe(ens.output, synapse=0.05)

# Also add a node connected to the end of the ensemble array to ensure
# that multiple things correctly receive values from the filter.
receiver = ValueReceiver()
n_receiver = nengo.Node(receiver, size_in=3)
nengo.Connection(ens.output, n_receiver, synapse=0.05)

# Mark the input Node as being a function of time
nengo_spinnaker.add_spinnaker_params(net.config)
net.config[input_node].function_of_time = True
Expand Down Expand Up @@ -50,6 +65,9 @@ def test_probe_passnodes():
np.all(-0.05 >= data[index20:, 2]) and
np.all(-0.15 <= data[index20:, 2]))

# Check that values came into the node correctly
assert +0.05 <= receiver.values[-1][0] <= +0.15
assert -0.05 >= receiver.values[-1][2] >= -0.15

if __name__ == "__main__":
test_probe_passnodes()
10 changes: 10 additions & 0 deletions tests/builder/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,22 @@ def test_passthrough_nodes_with_other_nodes(self):
assert spec.target.obj is model.object_operators[b]
assert spec.target.port is OutputPort.standard

# Get the sink and ensure that the appropriate object is returned
with mock.patch.object(nioc, "get_spinnaker_sink_for_node"):
assert nioc.get_node_sink(model, b_c) is not None
assert c in nioc._input_nodes

# Get the sink and ensure that the appropriate object is returned
with mock.patch.object(nioc, "get_spinnaker_sink_for_node") as gssfn:
spec = nioc.get_node_sink(model, a_b)
assert spec.target.obj is model.object_operators[b]
assert spec.target.port is InputPort.standard

# Get the source and ensure that the appropriate object is returned
with mock.patch.object(nioc, "get_spinnaker_source_for_node") as gssfn:
assert nioc.get_node_source(model, a_b) is not None
assert a in nioc._output_nodes

def test_get_node_sink_standard(self):
"""Test that calling a NodeIOController to get the sink for a
connection which terminates at a Node calls the method
Expand Down

0 comments on commit be30c67

Please sign in to comment.