def test_weight(self):
        proj = pynn.Projection(self.pop1, self.pop1, pynn.AllToAllConnector())
        self.assertEqual(proj.get("weight", format="array"), 0)
        pynn.run(None)
        pynn.simulator.state.projections = []
        synapse = pynn.standardmodels.synapses.StaticSynapse(weight=32)
        proj = pynn.Projection(self.pop1, self.pop2, pynn.AllToAllConnector(),
                               synapse_type=synapse)
        self.assertEqual(proj.get("weight", format="array"), 32)
        proj.set(weight=42.5)
        self.assertEqual(proj.get("weight", format="array"), 42)
        proj.set(weight=43)
        self.assertEqual(proj.get("weight", format="list"), [(0, 0, 43)])
        with self.assertRaises(ValueError):
            proj.set(weight=64)
        with self.assertRaises(ValueError):
            proj.set(weight=-1)

        proj = pynn.Projection(self.pop3, self.pop4, pynn.AllToAllConnector(),
                               synapse_type=synapse)
        connection_list = [(0, 0, 32), (1, 0, 32),
                           (0, 1, 32), (1, 1, 32),
                           (0, 2, 32), (1, 2, 32)]
        self.assertEqual(proj.get("weight", format="list"), connection_list)

        proj = pynn.Projection(self.pop4, self.pop3, pynn.AllToAllConnector(),
                               synapse_type=synapse)
        connection_list = [(0, 0, 32), (1, 0, 32), (2, 0, 32),
                           (0, 1, 32), (1, 1, 32), (2, 1, 32)]
        self.assertEqual(proj.get("weight", format="list"), connection_list)
        pynn.run(None)
예제 #2
0
    def test_bypass(self):
        # Create network with single SpikeSourceArray which projects on a
        # single HX neuron
        spikes_in = self.poisson_spike_train(self.rate)
        input_pop = pynn.Population(1,
                                    pynn.cells.SpikeSourceArray,
                                    cellparams={"spike_times": spikes_in})

        output_pop = pynn.Population(1, pynn.cells.HXNeuron())
        output_pop.record(["spikes"])

        synapse = pynn.standardmodels.synapses.StaticSynapse(weight=63)
        pynn.Projection(input_pop,
                        output_pop,
                        pynn.AllToAllConnector(),
                        synapse_type=synapse)

        # Run experiment on chip
        pynn.run(self.runtime)

        # Make sure that at least 98% (estimate considering typical spike
        # loss) of the spikes are read back and that the time difference
        # between them is less than 0.01ms
        spikes_out = output_pop.get_data().segments[0].spiketrains[0].magnitude

        # Add a small number such that timestamps with a '5' the third decimal
        # place are rounded up to the next higher (and not to the next even)
        # number
        input_set = set(np.round(spikes_in + 1e-9, 2))
        output_set = set(np.round(spikes_out + 1e-9, 2))
        assert len(input_set - output_set) / len(input_set) < 0.02
예제 #3
0
    def test_number_of_spike_trains(self):
        """
        Here we test that only spikes are recorded for the neurons we set in
        the spike recording mode.
        """

        runtime = 0.5  # ms
        pop_size = 4

        pops = []
        pops.append(pynn.Population(pop_size, pynn.cells.HXNeuron()))
        pops.append(pynn.Population(pop_size, pynn.cells.HXNeuron()))
        pops.append(pynn.Population(pop_size, pynn.cells.HXNeuron()))

        # Once record whole population, once subset and once no neurons
        pops[0].record(['spikes'])
        pynn.PopulationView(pops[1], [0]).record(['spikes'])

        # Spike input
        input_pop = pynn.Population(1, pynn.cells.SpikeSourceArray(
            spike_times=np.arange(0.1, runtime, runtime / 10)))
        for pop in pops:
            pynn.Projection(input_pop, pop, pynn.AllToAllConnector(),
                            synapse_type=StaticSynapse(weight=63))

        pynn.run(runtime)

        # Assert correct number of recorded spike trains
        self.assertEqual(len(pops[0].get_data().segments[0].spiketrains),
                         pop_size)
        self.assertEqual(len(pops[1].get_data().segments[0].spiketrains), 1)
        self.assertEqual(len(pops[2].get_data().segments[0].spiketrains), 0)
def main(params: dict):
    pynn.setup()

    nrn = pynn.Population(1, pynn.cells.HXNeuron(**params))
    nrn.record(["spikes", "v"])

    spike_times = [0.01, 0.03, 0.05, 0.07, 0.09, 0.11, 0.13, 0.15, 0.17, 0.19]
    pop_input = pynn.Population(20,
                                pynn.cells.SpikeSourceArray,
                                cellparams={"spike_times": spike_times})

    synapse = pynn.standardmodels.synapses.StaticSynapse(weight=63)
    pynn.Projection(pop_input,
                    nrn,
                    pynn.AllToAllConnector(),
                    synapse_type=synapse)

    pynn.run(0.2)

    spiketrain = nrn.get_data("spikes").segments[0].spiketrains[0]
    mem_v = nrn.get_data("v").segments[0]
    membrane_times, membrane_voltage = zip(*mem_v.filter(name="v")[0])

    pynn.end()

    # Plot data
    plt.figure()
    plt.xlabel("Time [ms]")
    plt.ylabel("Membrane Potential [LSB]")
    plt.plot(membrane_times, membrane_voltage)
    plt.savefig("plot_external_input.pdf")
    plt.close()

    return spiketrain
    def test_injected_config():
        pynn.setup(injected_config=pynn.InjectedConfiguration(
            pre_non_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()}))
        pynn.run(None)
        pynn.end()

        pynn.setup(injected_config=pynn.InjectedConfiguration(
            post_non_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()
                               }))
        pynn.run(None)
        pynn.end()

        pynn.setup(injected_config=pynn.InjectedConfiguration(
            pre_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()}))
        pynn.run(None)
        pynn.end()

        pynn.setup(injected_config=pynn.InjectedConfiguration(
            post_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()}))
        pynn.run(None)
        pynn.end()

        pynn.setup(injected_config=pynn.InjectedConfiguration(
            pre_non_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()},
            post_non_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()},
            pre_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()},
            post_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()}))
        pynn.run(None)
        pynn.end()
 def test_number_of_neurons(self):
     # TODO: grenade routing backend does not support 512 neurons?
     for n_neurons in [1, 16, 32, 64, 128, 256]:
         with self.subTest(n_neurons=n_neurons):
             pynn.setup()
             pynn.Population(n_neurons, pynn.cells.HXNeuron())
             pynn.run(None)
             pynn.end()
 def test_delay(self):
     proj = pynn.Projection(self.pop1, self.pop2, pynn.AllToAllConnector())
     self.assertEqual(proj.get("delay", format="array"), [0])
     proj.set(delay=0)
     self.assertEqual(proj.get("delay", format="array"), [0])
     with self.assertRaises(ValueError):
         proj.set(delay=1)
     pynn.run(None)
예제 #8
0
def main():
    """
    Run a minimal pyNN-based experiment: Connect two neuron populations
    and run an emulation. More elaborate examples of using BrainScaleS-2
    through the pyNN-API can be found here:
    https://github.com/electronicvisions/pynn-brainscales/tree/master/brainscales2/examples
    """
    pynn.setup()
    neurons_1 = get_neuron_population(2)
    neurons_2 = get_neuron_population(3)
    pynn.Projection(neurons_1, neurons_2, pynn.AllToAllConnector())
    pynn.run(0.2)
    pynn.end()
예제 #9
0
    def test_timing_of_spikes(self):
        """
        Test whether the output spikes have approximately the same timing as
        the input spikes.
        """

        runtime = 100  # ms
        n_spikes = 1000

        pop_1 = pynn.Population(1, pynn.cells.HXNeuron())
        pop_1.record('spikes')
        pop_2 = pynn.Population(1, pynn.cells.HXNeuron())
        pop_2.record('spikes')

        # Inject spikes
        spikes_1 = np.arange(0.1, runtime, runtime / n_spikes)
        input_pop_1 = pynn.Population(1, pynn.cells.SpikeSourceArray(
            spike_times=spikes_1))
        pynn.Projection(input_pop_1, pop_1, pynn.AllToAllConnector(),
                        synapse_type=StaticSynapse(weight=63))
        # Take midpoints of spikes_1 to have some variation in timing and
        spikes_2 = (spikes_1[:-1] + spikes_1[1:]) / 2
        input_pop_2 = pynn.Population(1, pynn.cells.SpikeSourceArray(
            spike_times=spikes_2))
        pynn.Projection(input_pop_2, pop_2, pynn.AllToAllConnector(),
                        synapse_type=StaticSynapse(weight=63))

        pynn.run(runtime)

        # Make sure that at least 98% (estimate considering typical spike
        # loss) of the spikes are read back and that the time difference
        # between them is less than 0.01ms.
        # To accomplish that we round the spike times to two decimal places
        # and then compare the sets of the input and output spike times.
        # By default numpy does not round '5' to the next higher number but
        # to the next even number, e.g. np.round(2.5) == 2. Therefore, we
        # add a small number such that timestamps with a '5' at the third
        # decimal place are rounded up to the next higher (and not even) number
        input_set_1 = set(np.round(spikes_1 + 1e-9, 2))
        output_set_1 = set(np.round(
            pop_1.get_data().segments[0].spiketrains[0].magnitude + 1e-9, 2))
        self.assertLess(len(input_set_1 - output_set_1) / len(input_set_1),
                        0.02)

        input_set_2 = set(np.round(spikes_2 + 1e-9, 2))
        output_set_2 = set(np.round(
            pop_2.get_data().segments[0].spiketrains[0].magnitude + 1e-9, 2))
        self.assertLess(len(input_set_2 - output_set_2) / len(input_set_2),
                        0.02)
def get_isi(tau_ref: int):
    pynn.setup()
    cell_params.update({"refractory_period_refractory_time": tau_ref})
    pop = pynn.Population(1, pynn.cells.HXNeuron(**cell_params))
    pop.record("spikes")
    pynn.run(0.2)

    spikes = pop.get_data("spikes").segments[0].spiketrains[0]
    if len(spikes) == 0:
        return 0
    isi = np.zeros(len(spikes) - 1)
    for i in range(len(spikes) - 1):
        isi[i] = spikes[i + 1] - spikes[i]

    pynn.end()

    return np.mean(isi)
    def setUp(self):
        self.bg_props = dict(
            start=1,  # ms
            rate=20e3,  # Hz
            duration=100  # ms
        )
        # Emulate the network 1ms longer than Poisson stimulation, in order to
        # convince oneself that the stimulation ends properly.
        self.runtime = self.bg_props["start"] + self.bg_props["duration"] + 1

        # The refractory time was found to must be set slightly larger 0 (DAC
        # value) to achieve a short time on hardware (cf. #3741).
        neuron_params = {"refractory_period_refractory_time": 5}

        # By enabling the bypass mode, the neuron should spike at the income of
        # each event.
        pynn.setup(enable_neuron_bypass=True)

        pop1 = pynn.Population(1, pynn.cells.HXNeuron(**neuron_params))
        pop2 = pynn.Population(1, pynn.cells.HXNeuron(**neuron_params))
        pop1.record(["spikes"])
        pop2.record(["spikes"])
        src = pynn.Population(1,
                              pynn.cells.SpikeSourcePoisson(**self.bg_props))

        pynn.Projection(src,
                        pop1,
                        pynn.AllToAllConnector(),
                        synapse_type=StaticSynapse(weight=63))
        pynn.Projection(src,
                        pop2,
                        pynn.AllToAllConnector(),
                        synapse_type=StaticSynapse(weight=63))

        pynn.run(self.runtime)

        self.spiketrain1 = pop1.get_data("spikes").segments[0].spiketrains[0]
        self.spiketrain2 = pop2.get_data("spikes").segments[0].spiketrains[0]
        pynn.reset()

        self.rate3 = 10e3
        src.set(rate=self.rate3)
        pynn.run(self.runtime)
        self.spiketrain3 = pop1.get_data("spikes").segments[1].spiketrains[0]
        pynn.end()
    def test_coco_extraction(self):
        builder = sta.PlaybackProgramBuilderDumper()
        an_coord0 = halco.AtomicNeuronOnDLS(halco.common.Enum(0))
        an_coord1 = halco.AtomicNeuronOnDLS(halco.common.Enum(1))
        neuron0 = lola.AtomicNeuron()
        neuron0.leak.i_bias = 666
        neuron1 = lola.AtomicNeuron()
        neuron1.leak.i_bias = 420
        builder.write(an_coord0, neuron0)
        builder.write(an_coord1, neuron1)

        common_config = hal.CommonNeuronBackendConfig()
        common_config.clock_scale_fast = 3
        common_coord = halco.CommonNeuronBackendConfigOnDLS()
        builder.write(common_coord, common_config)

        full_coco = {}
        with tempfile.TemporaryDirectory() as tempdir:
            filename = os.path.join(tempdir, "dump")
            with open(filename, "wb") as fd:
                fd.write(sta.to_binary(builder.done()))
            full_coco = pynn.helper.coco_from_file(filename)
        self.assertTrue(an_coord0 in full_coco)
        self.assertTrue(an_coord1 in full_coco)
        hx_coco = pynn.helper.filter_atomic_neuron(full_coco)
        self.assertTrue(an_coord0 in hx_coco)
        self.assertTrue(an_coord1 in hx_coco)
        self.assertFalse(common_coord in hx_coco)
        remainder_coco = pynn.helper.filter_non_atomic_neuron(full_coco)
        self.assertFalse(an_coord0 in remainder_coco)
        self.assertTrue(common_coord in remainder_coco)
        self.assertEqual(remainder_coco[common_coord].clock_scale_fast, 3)

        pynn.setup()
        pop = pynn.Population(2, pynn.cells.HXNeuron(hx_coco))
        self.assertTrue(numpy.array_equal(pop.get("leak_i_bias"), [666, 420]))
        pynn.run(None)
        pynn.end()
예제 #13
0
def main(params: dict):
    pynn.setup()

    nrn = pynn.Population(1, pynn.cells.HXNeuron(**params))
    nrn.record(["spikes", "v"])

    spike_times = [0.01, 0.03, 0.05, 0.07, 0.09, 0.11, 0.13, 0.15, 0.17, 0.19]
    pop_input = pynn.Population(20, pynn.cells.SpikeSourceArray,
                                cellparams={"spike_times": spike_times})

    synapse = pynn.standardmodels.synapses.StaticSynapse(weight=63)
    pynn.Projection(pop_input, nrn, pynn.AllToAllConnector(),
                    synapse_type=synapse)

    pynn.run(0.2)

    spiketrain = nrn.get_data("spikes").segments[0].spiketrains[0]
    mem_v = nrn.get_data("v").segments[0]
    membrane_times, membrane_voltage = zip(*mem_v.filter(name="v")[0])

    pynn.end()

    return spiketrain, membrane_times, membrane_voltage
예제 #14
0
def main(params: dict):
    log = pynn.logger.get("leak_over_threshold")
    pynn.setup()

    pop2 = pynn.Population(2, pynn.cells.HXNeuron(**params))
    pop1 = pynn.Population(1, pynn.cells.HXNeuron(**params))

    pop1.record(["spikes", "v"])
    pop2.record("spikes")
    pynn.run(0.2)

    spikes1 = pop1.get_data("spikes").segments[0]
    spikes2 = pop2.get_data("spikes").segments[0]

    # TODO: Find out how to extract neuron ids.
    for i, spiketrain in enumerate(spikes2.spiketrains):
        log.INFO("Number of Spikes of Neuron {}: ".format(i + 1),
                 len(spiketrain))
        log.INFO("Spiketimes of Neuron {}: ".format(i + 1), spiketrain)

    spiketimes = spikes1.spiketrains[0]
    log.INFO("Number of spikes of single recorded neuron: ", len(spiketimes))
    log.INFO("Spiketimes of recorded neuron: ", spiketimes)

    mem_v = pop1.get_data("v").segments[0]
    times, membrane = zip(*mem_v.filter(name="v")[0])
    log.INFO("Number of MADC Samples: ", len(times))

    plt.figure()
    plt.xlabel("Time [ms]")
    plt.ylabel("Membrane Potential [LSB]")
    plt.plot(times, membrane)
    plt.savefig("plot_leak_over_threshold.pdf")
    plt.close()

    pynn.end()
예제 #15
0
        # With this first projection, we connect the external spike source to the
        # observed on-chip neuron population.
        pynn.Projection(exc_stim_pop, stimulated_p,
                        pynn.AllToAllConnector(),
                        synapse_type=StaticSynapse(weight=63),
                        receptor_type="excitatory")

        # Create off-chip populations serving as inhibitory external spike sources.
        inh_spiketimes = [0.03]
        inh_stim_pop = pynn.Population(1, SpikeSourceArray(spike_times=inh_spiketimes))

        pynn.Projection(inh_stim_pop, stimulated_p,
                        pynn.AllToAllConnector(),
                        synapse_type=StaticSynapse(weight=63),
                        receptor_type="inhibitory")
        '''
        # You may play around with the parameters in this experiment to achieve
        # different traces. Try to stack multiple PSPs, try to make the neurons spike,
        # try to investigate differences between individual neuron instances,
        # be creative!
        pynn.run(0.1)
        times, data = plot_membrane_dynamics(stimulated_p)
        L.append(data)
        pynn.end()
        if i == 0 and j == 0:
            np.save('times.npy', times)
    LL.append(L)
    plt.savefig('v' + str(i) + '.pdf')
np.save('LL.npy', np.array(LL))
plt.show()
def main():
    main_log = pynn.logger.get("internal_projections_main")

    pynn.setup()

    lot_values = {
        "threshold_v_threshold": 400,
        "leak_v_leak": 1022,
        "leak_i_bias": 420,
        "leak_enable_division": True,
        "reset_v_reset": 50,
        "reset_i_bias": 950,
        "reset_enable_multiplication": True,
        "threshold_enable": True,
        "membrane_capacitance_capacitance": 10,
        "refractory_period_refractory_time": 95
    }

    cell_params = deepcopy(lot_values)
    cell_params.update({
        "leak_v_leak": 650,
        "reset_v_reset": 650,
        "excitatory_input_enable": True,
        "excitatory_input_i_bias_tau": 150,
        "excitatory_input_i_bias_gm": 200,
        # FIXME: replace by i_drop_input and i_shift_reference
        # "excitatory_input_v_syn": 700})
    })

    # not leak over threshold
    pop1 = pynn.Population(1,
                           pynn.standardmodels.cells.HXNeuron(**cell_params))

    # leak over threshold
    pop2 = pynn.Population(100,
                           pynn.standardmodels.cells.HXNeuron(**lot_values))

    pop1.record(["spikes", "v"])
    pop2.record("spikes")

    synapse = pynn.standardmodels.synapses.StaticSynapse(weight=63)
    pynn.Projection(pop2, pop1, pynn.AllToAllConnector(), synapse_type=synapse)

    pynn.run(0.2)

    spiketimes1 = pop1.get_data("spikes").segments[0].spiketrains[0]
    main_log.INFO("Spiketimes of first neuron: ", spiketimes1)

    spikes2 = pop2.get_data("spikes").segments[0]
    spikenumber2 = 0
    for i in range(len(pop2)):
        spikes = len(spikes2.spiketrains[i])
        spikenumber2 += spikes
    main_log.INFO("Number of spikes from pop2: ", spikenumber2)

    mem_v = pop1.get_data("v").segments[0]
    membrane_times, membrane_voltage = zip(*mem_v.filter(name="v")[0])

    pynn.end()

    # Plot data
    plt.figure()
    plt.xlabel("Time [ms]")
    plt.ylabel("Membrane Potential [LSB]")
    plt.plot(membrane_times, membrane_voltage)
    plt.savefig("plot_internal_projections.pdf")
    plt.close()

    return len(spiketimes1)
 def test_identical_connection(self):
     pynn.Projection(self.pop1, self.pop2, pynn.AllToAllConnector())
     pynn.Projection(self.pop1, self.pop2, pynn.AllToAllConnector())
     pynn.run(None)
 def test_empty():
     pynn.setup()
     pynn.run(0.2)
     pynn.end()
예제 #19
0
 def tearDown(self):
     pynn.run(None)
     pynn.end()