Esempio n. 1
0
    def record_v(self):
        sim.setup(timestep=1)
        simtime = 100
        input = sim.Population(1, sim.SpikeSourceArray(spike_times=[0, 30]),
                               label="input")
        pop = sim.Population(32, sim.IF_curr_exp(), label="pop")
        sim.Projection(input, pop, sim.AllToAllConnector(),
                       synapse_type=sim.StaticSynapse(weight=5, delay=1))
        pop.record("v")
        sim.run(simtime)

        neo = pop.get_data("all")
        pop.write_data(pickle_path, "all")
        io = PickleIO(filename=pickle_path)
        saved = io.read()[0]
        neo_compare.compare_blocks(neo, saved)
        assert len(neo.segments[0].spiketrains) == 0
        assert len(neo.segments[0].filter(name="v")) > 0
        assert len(neo.segments[0].filter(name="gsyn_exc")) == 0

        v_neo = pop.get_data("v")
        pop.write_data(pickle_path, "v")
        io = PickleIO(filename=pickle_path)
        v_saved = io.read()[0]
        neo_compare.compare_blocks(v_neo, v_saved)
        neo_compare.compare_blocks(v_neo, neo)

        with self.assertRaises(ConfigurationException):
            pop.get_data("spikes")
        with self.assertRaises(ConfigurationException):
            pop.get_data("gsyn_exc")
        with self.assertRaises(ConfigurationException):
            pop.write_data(pickle_path, "spikes")
        with self.assertRaises(ConfigurationException):
            pop.write_data(pickle_path, "gsyn_exc")
    def test_script(self):
        """
        test that tests the printing of v from a pre determined recording
        :return:
        """
        synfire_run.do_run(n_neurons, max_delay=14, time_step=1,
                           neurons_per_core=1, delay=1.7, run_times=[50],
                           spike_path=current_spike_file_path,
                           gsyn_path_exc=current_gsyn_file_path,
                           v_path=current_v_file_path, end_before_print=False)

        spikes_read = synfire_run.get_output_pop_spikes_neo()
        v_read = synfire_run.get_output_pop_voltage_neo()
        gsyn_read = synfire_run.get_output_pop_gsyn_exc_neo()

        io = PickleIO(filename=current_spike_file_path)
        spikes_saved = io.read()[0]
        io = PickleIO(filename=current_v_file_path)
        v_saved = io.read()[0]
        io = PickleIO(filename=current_gsyn_file_path)
        gsyn_saved = io.read()[0]

        neo_compare.compare_blocks(spikes_read, spikes_saved)
        neo_compare.compare_blocks(v_read, v_saved)
        neo_compare.compare_blocks(gsyn_read, gsyn_saved)
    def test_print_voltage(self):
        """
        test that tests the printing of v from a pre determined recording
        :return:
        """
        synfire_run.do_run(n_neurons, max_delay=max_delay, time_step=timestep,
                           neurons_per_core=neurons_per_core, delay=delay,
                           run_times=[runtime], v_path=current_v_file_path)
        v_read = synfire_run.get_output_pop_voltage_neo()

        io = PickleIO(filename=current_v_file_path)
        v_saved = io.read()[0]
        neo_compare.compare_blocks(v_read, v_saved)
        os.remove(current_v_file_path)
Esempio n. 4
0
    def test_script(self):
        """
        test that tests the printing of v from a pre determined recording
        :return:
        """
        try:
            n_neurons = 20  # number of neurons in each population
            current_file_path = os.path.dirname(os.path.abspath(__file__))
            current_spike_file_path = os.path.join(current_file_path,
                                                   "spikes.pickle")
            current_v_file_path = os.path.join(current_file_path, "v.pickle")
            current_gsyn_file_path = os.path.join(current_file_path,
                                                  "gsyn.pickle")
            synfire_run.do_run(n_neurons, max_delay=14, time_step=0.1,
                               neurons_per_core=1, delay=1.7, run_times=[50],
                               spike_path=current_spike_file_path,
                               gsyn_path_exc=current_gsyn_file_path,
                               v_path=current_v_file_path)

            spikes_read = synfire_run.get_output_pop_spikes_neo()
            v_read = synfire_run.get_output_pop_voltage_neo()
            gsyn_read = synfire_run.get_output_pop_gsyn_exc_neo()

            io = PickleIO(filename=current_spike_file_path)
            spikes_saved = io.read()[0]
            io = PickleIO(filename=current_v_file_path)
            v_saved = io.read()[0]
            io = PickleIO(filename=current_gsyn_file_path)
            gsyn_saved = io.read()[0]

            neo_compare.compare_blocks(spikes_read, spikes_saved)
            neo_compare.compare_blocks(v_read, v_saved)
            neo_compare.compare_blocks(gsyn_read, gsyn_saved)

        except SpinnmanTimeoutException as ex:
            # System sometimes times outs
            raise SkipTest(ex)
Esempio n. 5
0
    def test_va_benchmark(self):

        try:
            exc_spikes = do_run()
        # System intentional overload so may error
        except SpinnmanTimeoutException as ex:
            raise SkipTest(ex)
        spike_count = neo_convertor.count_spikes(exc_spikes)
        print(spike_count)
        # CB Jan 14 2019 Result varie between runs
        self.assertLessEqual(2558, spike_count)
        self.assertGreaterEqual(2559, spike_count)
        io = PickleIO(filename=neo_path)
        recorded_spikes = io.read()[0]
        neo_compare.compare_blocks(exc_spikes, recorded_spikes)
Esempio n. 6
0
    def test_get_gsyn(self):
        synfire_run.do_run(n_neurons,
                           max_delay=max_delay,
                           time_step=timestep,
                           neurons_per_core=neurons_per_core,
                           delay=delay,
                           run_times=[runtime],
                           gsyn_path_exc=gsyn_path)
        spikes = synfire_run.get_output_pop_spikes_numpy()
        gsyn = synfire_run.get_output_pop_gsyn_exc_neo()

        self.assertEqual(12, len(spikes))
        spike_checker.synfire_spike_checker(spikes, n_neurons)
        io = PickleIO(filename=gsyn_path)
        gsyn_saved = io.read()[0]
        neo_compare.compare_blocks(gsyn, gsyn_saved)
        os.remove(gsyn_path)
Esempio n. 7
0
 def test_get_gsyn(self):
     try:
         synfire_run.do_run(n_neurons, max_delay=max_delay,
                            time_step=timestep,
                            neurons_per_core=neurons_per_core, delay=delay,
                            run_times=[runtime], gsyn_path_exc=gsyn_path)
         spikes = synfire_run.get_output_pop_spikes_numpy()
         g_syn = synfire_run.get_output_pop_gsyn_exc_numpy()
         spike_checker.synfire_spike_checker(spikes, n_neurons)
         io = PickleIO(filename=gsyn_path)
         gsyn2_neo = io.read()[0]
         gsyn2_numpy = neo_convertor.convert_data(
             gsyn2_neo, run=0, name="gsyn_exc")
         self.assertTrue(numpy.allclose(g_syn, gsyn2_numpy))
         os.remove(gsyn_path)
     except SpinnmanTimeoutException as ex:
         # System intentional overload so may error
         raise SkipTest(ex)
Esempio n. 8
0
    def test_print_voltage(self):
        """
        test that tests the printing of v from a pre determined recording
        :return:
        """
        try:
            synfire_run.do_run(n_neurons,
                               max_delay=max_delay,
                               time_step=timestep,
                               neurons_per_core=neurons_per_core,
                               delay=delay,
                               run_times=[runtime],
                               v_path=current_v_file_path)
            v_read = synfire_run.get_output_pop_voltage_neo()

            io = PickleIO(filename=current_v_file_path)
            v_saved = io.read()[0]
            neo_compare.compare_blocks(v_read, v_saved)
            os.remove(current_v_file_path)
            # System intentional overload so may error
        except SpinnmanTimeoutException as ex:
            raise SkipTest(ex)
    def test_print_spikes(self):
        try:
            synfire_run.do_run(n_neurons,
                               time_step=timestep,
                               max_delay=max_delay,
                               delay=delay,
                               neurons_per_core=neurons_per_core,
                               run_times=[runtime],
                               spike_path=spike_path)
            spikes = synfire_run.get_output_pop_spikes_neo()

            try:
                io = PickleIO(filename=spike_path)
                read_in_spikes = io.read()[0]

                neo_compare.compare_blocks(spikes, read_in_spikes)
            except UnicodeDecodeError:
                raise SkipTest(
                    "https://github.com/NeuralEnsemble/python-neo/issues/529")

        except SpinnmanTimeoutException as ex:
            # System intentional overload so may error
            raise SkipTest(ex)
if __name__ == '__main__':
    # Delayed imports so unit tests do not need them
    from pyNN.utility.plotting import Figure
    import matplotlib.pyplot as plt

    synfire_run.do_run(n_neurons,
                       max_delay=max_delay,
                       time_step=timestep,
                       neurons_per_core=neurons_per_core,
                       delay=delay,
                       run_times=[runtime],
                       gsyn_path_exc=gsyn_path)
    spikes = synfire_run.get_output_pop_spikes_numpy()
    g_syn = synfire_run.get_output_pop_gsyn_exc_numpy()
    spike_checker.synfire_spike_checker(spikes, n_neurons)
    io = PickleIO(filename=gsyn_path)
    gsyn2_neo = io.read()[0]
    gsyn2_numpy = neo_convertor.convert_data(gsyn2_neo, run=0, name="gsyn_exc")
    print(len(spikes))
    Figure(SpynnakerPanel(spikes,
                          yticks=True,
                          xticks=True,
                          markersize=4,
                          xlim=(0, runtime)),
           SpynnakerPanel(gsyn2_neo, yticks=True),
           title="TestPrintGsyn".format(delay),
           annotations="generated by {}".format(__file__))
    plt.show()
    os.remove(gsyn_path)