Esempio n. 1
0
    def test_get_node_source_f_of_t(self):
        """Test that calling the NodeIOController for a f_of_t->xx connection
        doesn't ask for a SpiNNaker sorce and instead returns the value source
        that was associated with the Node.
        """
        with nengo.Network() as net:
            a = nengo.Node(lambda t: t)
            b = nengo.Ensemble(100, 1)
            a_b = nengo.Connection(a, b)

        # Mark the Node as being a function of time
        add_spinnaker_params(net.config)
        net.config[a].function_of_time = True

        # Create a model and build the Node
        model = Model()
        model.config = net.config
        nioc = NodeIOController()
        nioc.build_node(model, a)

        # Get the source and ensure that the appropriate object is returned
        with mock.patch.object(nioc, "get_spinnaker_source_for_node") as gssfn:
            spec = nioc.get_node_source(model, a_b)
            assert spec.target.obj is model.object_operators[a]
            assert spec.target.port is OutputPort.standard

            # Assert this _didn't_ call `get_spinnaker_source_for_node`
            assert not gssfn.called

        # There should be nothing in the host network
        assert nioc.host_network.all_nodes == list()
        assert nioc.host_network.all_connections == list()
Esempio n. 2
0
    def test_build_node_function_of_time(self, period):
        """Test that building a function of time Node creates a new operator.
        """
        with nengo.Network() as net:
            a = nengo.Node(lambda t: [t, t**2], size_in=0)

        # Mark the Node as a function of time
        add_spinnaker_params(net.config)
        net.config[a].function_of_time = True
        if period is not None:
            net.config[a].function_of_time_period = period

        # Create the model
        model = Model()
        model.config = net.config

        # Build the Node
        nioc = NodeIOController()
        nioc.build_node(model, a)

        # Assert that this added a new operator to the model
        assert model.object_operators[a].function is a.output
        if period is not None:
            assert model.object_operators[a].period == period
        else:
            assert model.object_operators[a].period is None

        assert model.extra_operators == list()
Esempio n. 3
0
    def test_get_node_source_f_of_t(self):
        """Test that calling the NodeIOController for a f_of_t->xx connection
        doesn't ask for a SpiNNaker sorce and instead returns the value source
        that was associated with the Node.
        """
        with nengo.Network() as net:
            a = nengo.Node(lambda t: t)
            b = nengo.Ensemble(100, 1)
            a_b = nengo.Connection(a, b)

        # Mark the Node as being a function of time
        add_spinnaker_params(net.config)
        net.config[a].function_of_time = True

        # Create a model and build the Node
        model = Model()
        model.config = net.config
        nioc = NodeIOController()
        nioc.build_node(model, a)

        # Get the source and ensure that the appropriate object is returned
        with mock.patch.object(nioc, "get_spinnaker_source_for_node") as gssfn:
            spec = nioc.get_node_source(model, a_b)
            assert spec.target.obj is model.object_operators[a]
            assert spec.target.port is OutputPort.standard

            # Assert this _didn't_ call `get_spinnaker_source_for_node`
            assert not gssfn.called

        # There should be nothing in the host network
        assert nioc.host_network.all_nodes == list()
        assert nioc.host_network.all_connections == list()
Esempio n. 4
0
    def test_build_node_function_of_time(self, period):
        """Test that building a function of time Node creates a new operator.
        """
        with nengo.Network() as net:
            a = nengo.Node(lambda t: [t, t**2], size_in=0)

        # Mark the Node as a function of time
        add_spinnaker_params(net.config)
        net.config[a].function_of_time = True
        if period is not None:
            net.config[a].function_of_time_period = period

        # Create the model
        model = Model()
        model.config = net.config

        # Build the Node
        nioc = NodeIOController()
        nioc.build_node(model, a)

        # Assert that this added a new operator to the model
        assert model.object_operators[a].function is a.output
        if period is not None:
            assert model.object_operators[a].period == period
        else:
            assert model.object_operators[a].period is None

        assert model.extra_operators == list()
Esempio n. 5
0
    def test_build_node_function_of_time_off(self, recwarn):
        """Test that building a function of time Node is exactly the same as
        building a regular Node if function of time Nodes are disabled (but
        that a warning is raised).
        """
        with nengo.Network() as net:
            a = nengo.Node(lambda t: t, size_in=0, size_out=1, label="Stim")

        # Mark the Node as a function of time
        add_spinnaker_params(net.config)
        net.config[a].function_of_time = True

        # Create the model
        model = Model()
        model.config = net.config

        # Build the Node
        nioc = NodeIOController(function_of_time_nodes=False)
        nioc.build_node(model, a)

        # Assert that no new operators were created
        assert model.object_operators == dict()
        assert model.extra_operators == list()

        # This should have raised a warning
        w = recwarn.pop()
        assert "disabled" in str(w.message)
        assert "Stim" in str(w.message)
Esempio n. 6
0
    def test_build_node(self):
        """Test that building a Node does nothing.
        """
        with nengo.Network() as net:
            a = nengo.Node(lambda t, x: x**2, size_in=3, size_out=3)

        # Create the model
        model = Model()
        model.config = net.config

        # Build the Node
        nioc = NodeIOController()
        nioc.build_node(model, a)

        # Assert that no new operators were created
        assert model.object_operators == dict()
        assert model.extra_operators == list()
Esempio n. 7
0
    def test_build_node(self):
        """Test that building a Node does nothing.
        """
        with nengo.Network() as net:
            a = nengo.Node(lambda t, x: x**2, size_in=3, size_out=3)

        # Create the model
        model = Model()
        model.config = net.config

        # Build the Node
        nioc = NodeIOController()
        nioc.build_node(model, a)

        # Assert that no new operators were created
        assert model.object_operators == dict()
        assert model.extra_operators == list()
Esempio n. 8
0
    def test_passthrough_nodes_with_other_nodes(self):
        """Test the handling of passthrough when other Nodes are present."""
        with nengo.Network() as net:
            a = nengo.Node(lambda t: t, size_in=0, size_out=1)
            b = nengo.Node(None, size_in=1, label="Passthrough Node")
            c = nengo.Node(lambda t, x: None, size_in=1, size_out=0)

            a_b = nengo.Connection(a, b)
            b_c = nengo.Connection(b, c)

        # Create a model and build the Nodes
        model = Model()
        model.config = net.config
        nioc = NodeIOController()
        nioc.build_node(model, a)
        nioc.build_node(model, b)
        nioc.build_node(model, c)

        # Check the passthrough Node resulted in a new operator but that the
        # others didn't
        assert a not in model.object_operators
        assert b in model.object_operators
        assert c not in model.object_operators

        # Get the source and ensure that the appropriate object is returned
        with mock.patch.object(nioc, "get_spinnaker_source_for_node") as gssfn:
            spec = nioc.get_node_source(model, b_c)
            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
Esempio n. 9
0
    def test_passthrough_nodes_with_other_nodes(self):
        """Test the handling of passthrough when other Nodes are present."""
        with nengo.Network() as net:
            a = nengo.Node(lambda t: t, size_in=0, size_out=1)
            b = nengo.Node(None, size_in=1, label="Passthrough Node")
            c = nengo.Node(lambda t, x: None, size_in=1, size_out=0)

            a_b = nengo.Connection(a, b)
            b_c = nengo.Connection(b, c)

        # Create a model and build the Nodes
        model = Model()
        model.config = net.config
        nioc = NodeIOController()
        nioc.build_node(model, a)
        nioc.build_node(model, b)
        nioc.build_node(model, c)

        # Check the passthrough Node resulted in a new operator but that the
        # others didn't
        assert a not in model.object_operators
        assert b in model.object_operators
        assert c not in model.object_operators

        # Get the source and ensure that the appropriate object is returned
        with mock.patch.object(nioc, "get_spinnaker_source_for_node") as gssfn:
            spec = nioc.get_node_source(model, b_c)
            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
Esempio n. 10
0
    def test_passthrough_nodes(self, width):
        """Test the handling of passthrough Nodes."""
        with nengo.Network() as net:
            a = nengo.Ensemble(100, width)
            b = nengo.Node(None, size_in=width, label="Passthrough Node")
            c = nengo.Ensemble(100, width)

            a_b = nengo.Connection(a, b)
            b_c = nengo.Connection(b, c)

        # Create a model and build the Node
        model = Model()
        model.config = net.config
        nioc = NodeIOController()
        nioc.build_node(model, b)

        # Check the passthrough Node resulted in a new operator
        assert model.object_operators[b].size_in == b.size_in
        assert model.object_operators[b].transmission_delay == 1
        assert model.object_operators[b].interpacket_pause == 1

        # Get the source and ensure that the appropriate object is returned
        with mock.patch.object(nioc, "get_spinnaker_source_for_node") as gssfn:
            spec = nioc.get_node_source(model, b_c)
            assert spec.target.obj is model.object_operators[b]
            assert spec.target.port is OutputPort.standard

            # Assert this _didn't_ call `get_spinnaker_source_for_node`
            assert not gssfn.called

        # 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

            # Assert this _didn't_ call `get_spinnaker_sink_for_node`
            assert not gssfn.called

        # There should be nothing in the host network
        assert nioc.host_network.all_nodes == list()
        assert nioc.host_network.all_connections == list()
Esempio n. 11
0
    def test_build_node_process_is_not_constant(self):
        """Test that building a Node with a process is not treated the same as
        building a constant valued Node.
        """
        with nengo.Network() as net:
            a = nengo.Node(nengo.processes.Process())

        # Create the model
        model = Model()
        model.config = net.config

        # Build the Node
        nioc = NodeIOController()
        nioc.build_node(model, a)

        # Assert that this added a new operator to the model
        assert model.object_operators[a].function is a.output
        assert model.object_operators[a].period is None

        assert model.extra_operators == list()
Esempio n. 12
0
    def test_build_node_constant_value_is_function_of_time(self):
        """Test that building a Node with a constant value is equivalent to
        building a function of time Node.
        """
        with nengo.Network() as net:
            a = nengo.Node(np.array([0.5, 0.1]))

        # Create the model
        model = Model()
        model.config = net.config

        # Build the Node
        nioc = NodeIOController()
        nioc.build_node(model, a)

        # Assert that this added a new operator to the model
        assert model.object_operators[a].function is a.output
        assert model.object_operators[a].period is model.dt

        assert model.extra_operators == list()
Esempio n. 13
0
    def test_build_node_process_is_not_constant(self):
        """Test that building a Node with a process is not treated the same as
        building a constant valued Node.
        """
        with nengo.Network() as net:
            a = nengo.Node(nengo.processes.Process())

        # Create the model
        model = Model()
        model.config = net.config

        # Build the Node
        nioc = NodeIOController()
        nioc.build_node(model, a)

        # Assert that this added a new operator to the model
        assert model.object_operators[a].function is a.output
        assert model.object_operators[a].period is None

        assert model.extra_operators == list()
Esempio n. 14
0
    def test_build_node_constant_value_is_function_of_time(self):
        """Test that building a Node with a constant value is equivalent to
        building a function of time Node.
        """
        with nengo.Network() as net:
            a = nengo.Node(np.array([0.5, 0.1]))

        # Create the model
        model = Model()
        model.config = net.config

        # Build the Node
        nioc = NodeIOController()
        nioc.build_node(model, a)

        # Assert that this added a new operator to the model
        assert model.object_operators[a].function is a.output
        assert model.object_operators[a].period is model.dt

        assert model.extra_operators == list()
Esempio n. 15
0
    def test_passthrough_nodes(self):
        """Test the handling of passthrough Nodes."""
        with nengo.Network() as net:
            a = nengo.Ensemble(100, 1)
            b = nengo.Node(size_in=1, label="Passthrough Node")
            c = nengo.Ensemble(100, 1)

            a_b = nengo.Connection(a, b)
            b_c = nengo.Connection(b, c)

        # Create a model and build the Node
        model = Model()
        model.config = net.config
        nioc = NodeIOController()
        nioc.build_node(model, b)

        # Check the passthrough Node resulted in a new operator
        assert isinstance(model.object_operators[b], PassthroughNode)

        # Get the source and ensure that the appropriate object is returned
        with mock.patch.object(nioc, "get_spinnaker_source_for_node") as gssfn:
            spec = nioc.get_node_source(model, b_c)
            assert spec.target.obj is model.object_operators[b]
            assert spec.target.port is OutputPort.standard

            # Assert this _didn't_ call `get_spinnaker_source_for_node`
            assert not gssfn.called

        # 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

            # Assert this _didn't_ call `get_spinnaker_sink_for_node`
            assert not gssfn.called

        # There should be nothing in the host network
        assert nioc.host_network.all_nodes == list()
        assert nioc.host_network.all_connections == list()