def test_value_sink_init():
    probe = mock.Mock(name="Probe")
    probe.size_in = 3
    probe.sample_every = 0.0043

    v = ValueSink(probe, 0.001)
    assert v.probe is probe
    assert v.size_in == 3
    assert v.sample_every == 4
Beispiel #2
0
def test_value_sink_after_simulation_not_already_probed(size_in, n_steps):
    """Test that the post-simulation function reads back from the recording
    region and formats the data correctly.
    """
    probe = mock.Mock()
    probe.size_in = size_in
    probe.sample_every = None

    # Create a value sink with a dummy recording region
    v = ValueSink(probe, 0.001)
    v.recording_region_mem = mock.Mock()
    v.recording_region_mem.read.return_value = \
        b'\xff\xff\x00\x00\x00\x00\xff\xff'

    # Create a mock simulator which can be modified to store the probe data
    sim = mock.Mock()
    sim.data = dict()
    v.after_simulation(None, sim, n_steps)

    assert sim.data[probe].shape == (n_steps, size_in)
Beispiel #3
0
    def build_node_probe(self, model, probe):
        """Modify the model to build the Probe."""
        # Create a new ValueSink for the probe and add this to the model.
        model.object_operators[probe] = ValueSink(probe, model.dt)

        # Create a new connection from the Node to the Probe and then get the
        # model to build this.
        seed = model.seeds[probe]
        conn = nengo.Connection(probe.target,
                                probe,
                                synapse=probe.synapse,
                                seed=seed,
                                add_to_container=False)
        model.make_connection(conn)
Beispiel #4
0
def test_value_sink_after_simulation_already_probed():
    """Test that the post-simulation function reads back from the recording
    region and formats the data correctly and that the existing probe data is
    extended when probing has already occurred.
    """
    probe = mock.Mock()
    probe.size_in = 2
    probe.sample_every = None

    # Create a value sink with a dummy recording region
    v = ValueSink(probe, 0.001)
    v.recording_region_mem = mock.Mock()
    v.recording_region_mem.read.return_value = \
        b'\xff\xff\x00\x00\x00\x00\xff\xff'

    # Create a mock simulator which can be modified to store the probe data
    sim = mock.Mock()
    sim.data = dict()
    sim.data[probe] = np.zeros((10, 2))
    v.after_simulation(None, sim, 1)

    assert sim.data[probe].shape == (11, 2)
    assert np.all(sim.data[probe][:10] == np.zeros((10, 2)))