def test_overflow(self):
        pynn.setup(neuronPermutation=self.permutation)

        pynn.Population(len(self.permutation), pynn.cells.HXNeuron())
        with self.assertRaises(ValueError):
            pynn.Population(1, pynn.cells.HXNeuron())
        pynn.end()
Ejemplo n.º 2
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
Ejemplo n.º 4
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
 def test_renewed_setup(self):
     pynn.setup(neuronPermutation=self.permutation)
     pynn.Population(1, pynn.cells.HXNeuron())
     self.assertEqual(
         pynn.simulator.state.neuron_placement.id2hwenum(0),
         self.permutation[0])
     pynn.end()
     pynn.setup()
     pynn.Population(1, pynn.cells.HXNeuron())
     self.assertEqual(
         pynn.simulator.state.neuron_placement.id2hwenum(0), 0)
     pynn.end()
Ejemplo n.º 6
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 test_default(self):
     pynn.setup()
     pop = pynn.Population(2, pynn.cells.HXNeuron(self.coco))
     self.assertTrue(np.array_equal(pop.get("leak_i_bias"), [555, 0]))
     self.assertTrue(
         np.array_equal(pop.get("threshold_v_threshold"), [0, 123]))
     pynn.end()
 def test_permutation(self):
     coord = halco.AtomicNeuronOnDLS(halco.common.Enum(8))
     neuron = lola.AtomicNeuron()
     neuron.leak.i_bias = 666
     pynn.setup(neuronPermutation=[8])
     pop = pynn.Population(1, pynn.cells.HXNeuron({coord: neuron}))
     self.assertEqual(pop.get("leak_i_bias"), 666)
     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()
Ejemplo n.º 10
0
def get_neuron_population(size: int) -> pynn.Population:
    """
    Minimal helper function:
    Construct a neuron population to be used within this experiment.
    :param size: Population size
    :return: Neuron population
    """
    return pynn.Population(size, pynn.cells.HXNeuron)
    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 setUp(self):
        pynn.setup()
        self.pop = pynn.Population(2, pynn.cells.HXNeuron(
            threshold_v_threshold=200, threshold_enable=200))
        self.neurons = [None] * self.pop.size

        for idx, item in enumerate(self.pop.celltype.parameter_space):
            neuron = pynn.cells.HXNeuron.create_hw_entity(item)
            self.neurons[idx] = neuron
    def test_mixed_celltypes(self):
        pynn.setup(neuronPermutation=self.permutation)

        pynn.Population(1, pynn.cells.SpikeSourceArray(spike_times=[0]))
        pynn.Population(2, pynn.cells.HXNeuron())
        pynn.Population(1, pynn.cells.SpikeSourceArray(spike_times=[0]))
        pynn.Population(1, pynn.cells.HXNeuron())

        self.assertEqual(
            pynn.simulator.state.neuron_placement.id2hwenum(1),
            self.permutation[0])
        self.assertEqual(
            pynn.simulator.state.neuron_placement.id2hwenum(2),
            self.permutation[1])
        self.assertEqual(
            pynn.simulator.state.neuron_placement.id2hwenum(4),
            self.permutation[2])

        pynn.end()
Ejemplo n.º 14
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
Ejemplo n.º 15
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()
 def test_accessors(self):
     self.assertEqual(self.hxpop2.get("threshold_v_threshold"), 200)
     self.assertEqual(
         self.hxpop3.get(["threshold_v_threshold", "leak_i_bias"]),
         [300, 100])
     self.assertTrue(self.hxpop3.get("exponential_enable"), True)
     self.assertTrue(np.array_equal(
         self.hxpop4.get("leak_i_bias"), [100, 150]))
     self.assertEqual(self.hxpop4[0:1].get("leak_i_bias"), 100)
     self.assertEqual(self.hxpop4[0].leak_i_bias, 100)
     self.assertEqual(self.hxpop4[1:2].get("leak_i_bias"), 150)
     self.assertEqual(self.hxpop4[1].leak_i_bias, 150)
     self.assertTrue(np.array_equal(
         self.hxpop5.get("leak_i_bias"), [100, 200]))
     self.assertEqual(
         self.sapop1.get("spike_times"), parameters.Sequence([0, 1, 2]))
     self.assertEqual(
         self.sapop1[0].spike_times, parameters.Sequence([0, 1, 2]))
     self.assertTrue(np.array_equal(
         self.sapop2.get("spike_times"),
         [parameters.ArrayParameter([0, 1, 2]),
          parameters.ArrayParameter([3, 4, 5])]))
     self.assertEqual(
         self.sapop2[0].spike_times, parameters.Sequence([0, 1, 2]))
     self.assertEqual(
         self.sapop2[1].spike_times, parameters.Sequence([3, 4, 5]))
     mypop = pynn.Population(3, pynn.cells.HXNeuron())
     mypop.set(leak_i_bias=400)
     mypop[0:2].set(leak_i_bias=150)
     self.assertTrue(
         np.array_equal(mypop.get("leak_i_bias"), [150, 150, 400]))
     mypop.set(leak_i_bias=[100, 200, 300])
     self.assertTrue(
         np.array_equal(mypop.get("leak_i_bias"), [100, 200, 300]))
     mypop[1].leak_i_bias = 350
     self.assertTrue(
         np.array_equal(mypop.get("leak_i_bias"), [100, 350, 300]))
     mypop.set(exponential_enable=True)
     mypop[1, 2].set(exponential_enable=False)
     self.assertTrue(np.array_equal(
         mypop.get("exponential_enable"),
         [True, False, False]))
     mypop.set(leak_i_bias=123)
     mypop[0, 2].set(exponential_enable=True, leak_i_bias=100)
     self.assertTrue(np.array_equal(
         mypop.get(["leak_i_bias", "exponential_enable"]),
         [[100, 123, 100], [True, False, True]]))
Ejemplo n.º 17
0
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):
     pynn.setup()
     self.hxpop1 = pynn.Population(1, pynn.cells.HXNeuron())
     self.hxpop2 = pynn.Population(
         5, pynn.cells.HXNeuron(threshold_v_threshold=200))
     self.hxpop3 = pynn.Population(
         3, pynn.cells.HXNeuron(
             threshold_v_threshold=300,
             leak_i_bias=100,
             exponential_enable=True))
     self.hxpop4 = pynn.Population(
         2, pynn.cells.HXNeuron(leak_i_bias=[100, 150]))
     # test old API support
     self.hxpop5 = pynn.Population(
         2, pynn.cells.HXNeuron, cellparams={'leak_i_bias': [100, 200]})
     self.sapop1 = pynn.Population(
         1, pynn.cells.SpikeSourceArray(spike_times=[0, 1, 2]))
     self.sapop2 = pynn.Population(
         2, pynn.cells.SpikeSourceArray(spike_times=[[0, 1, 2], [3, 4, 5]]))
    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()
 def test_not_configurable(self):
     with self.assertRaises(errors.NonExistentParameterError):
         pynn.Population(
             1, pynn.cells.HXNeuron(event_routing_analog_output=0))
     with self.assertRaises(errors.NonExistentParameterError):
         pynn.Population(
             1, pynn.cells.HXNeuron(event_routing_enable_digital=False))
     with self.assertRaises(errors.NonExistentParameterError):
         pynn.Population(
             1, pynn.cells.HXNeuron(leak_reset_i_bias_source_follower=0))
     with self.assertRaises(errors.NonExistentParameterError):
         pynn.Population(
             1, pynn.cells.HXNeuron(readout_enable_amplifier=True))
     with self.assertRaises(errors.NonExistentParameterError):
         pynn.Population(
             1, pynn.cells.HXNeuron(readout_source="something"))
     with self.assertRaises(errors.NonExistentParameterError):
         pynn.Population(
             1, pynn.cells.HXNeuron(readout_enable_buffered_access=True))
     with self.assertRaises(errors.NonExistentParameterError):
         pynn.Population(
             1, pynn.cells.HXNeuron(readout_i_bias=1000))
 def test_missing_coco_entries(self):
     pynn.setup()
     pynn.Population(2, pynn.cells.HXNeuron(self.coco))
     with self.assertRaises(KeyError):
         pynn.Population(1, pynn.cells.HXNeuron(self.coco))
     pynn.end()
Ejemplo n.º 22
0
 stimulated_p = pynn.Population(
     1,
     pynn.cells.HXNeuron(
         # Leak potential, range: 300-1000
         leak_v_leak=800,
         # Leak conductance, range: 0-1022 increase -> time constant decrease
         leak_i_bias=cond,
         # Threshold potential, range: 0-600
         threshold_v_threshold=400,
         # Reset potential, range: 300-1000
         reset_v_reset=600,
         # Membrane capacitance, range: 0-63  increase->increase time constant 63-->2.4pF
         membrane_capacitance_capacitance=63,
         # Refractory time, range: 0-255
         refractory_period_refractory_time=120,
         # Enable reset on threshold crossing
         threshold_enable=True,
         # Reset conductance, range: 0-1022
         reset_i_bias=1022,
         # Enable strengthening of reset conductance
         reset_enable_multiplication=True,
         # -- Parameters for synaptic inputs -- #
         # Enable synaptic stimulation
         excitatory_input_enable=False,
         inhibitory_input_enable=False,
         # Strength of synaptic inputs
         excitatory_input_i_bias_gm=1022,
         inhibitory_input_i_bias_gm=1022,
         # Synaptic time constants
         excitatory_input_i_bias_tau=200,
         inhibitory_input_i_bias_tau=200,
         # Technical parameters
         excitatory_input_i_drop_input=300,
         inhibitory_input_i_drop_input=300,
         excitatory_input_i_shift_reference=300,
         inhibitory_input_i_shift_reference=300))
 def test_permutation_mismatch(self):
     pynn.setup(neuronPermutation=[8, 14])
     with self.assertRaises(KeyError):
         pynn.Population(2, pynn.cells.HXNeuron(self.coco))
     pynn.end()
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_user_overwrite(self):
     pynn.setup()
     pop = pynn.Population(
         2, pynn.cells.HXNeuron(self.coco, leak_i_bias=[100, 150]))
     self.assertTrue(np.array_equal(pop.get("leak_i_bias"), [100, 150]))
     pynn.end()
 def setUp(self):
     pynn.setup()
     self.pop1 = pynn.Population(1, pynn.cells.HXNeuron())
     self.pop2 = pynn.Population(1, pynn.cells.HXNeuron())
     self.pop3 = pynn.Population(2, pynn.cells.HXNeuron())
     self.pop4 = pynn.Population(3, pynn.cells.HXNeuron())
Ejemplo n.º 27
0
    def setUp(self):
        pynn.setup()

        self.pops_in = dict()

        # SpikeSourceArray
        self.spike_times = [0.01, 0.03, 0.05, 0.07, 0.09]
        self.spike_times2 = [0.01, 0.03, 0.05, 0.07, 0.09, 0.1]

        self.pops_in['in1'] = pynn.Population(
            1,
            pynn.cells.SpikeSourceArray(spike_times=self.spike_times)
        )
        self.pops_in['npin1'] = pynn.Population(
            1,
            pynn.cells.SpikeSourceArray(spike_times=np.array(self.spike_times))
        )
        self.pops_in['sein1'] = pynn.Population(
            1,
            pynn.cells.SpikeSourceArray(
                spike_times=parameters.Sequence(self.spike_times))
        )

        self.pops_in['in2'] = pynn.Population(
            2,
            pynn.cells.SpikeSourceArray(spike_times=self.spike_times)
        )
        self.pops_in['npin2'] = pynn.Population(
            2,
            pynn.cells.SpikeSourceArray(spike_times=np.array(self.spike_times))
        )
        self.pops_in['sein2'] = pynn.Population(
            2,
            pynn.cells.SpikeSourceArray(
                spike_times=parameters.Sequence(self.spike_times))
        )

        self.pops_in['in2var'] = pynn.Population(
            2,
            pynn.cells.SpikeSourceArray(
                spike_times=[self.spike_times, self.spike_times2])
        )
        self.pops_in['npin2var'] = pynn.Population(
            2,
            pynn.cells.SpikeSourceArray(
                spike_times=[np.array(self.spike_times),
                             np.array(self.spike_times2)])
        )
        self.pops_in['sein2var'] = pynn.Population(
            2,
            pynn.cells.SpikeSourceArray(
                spike_times=[parameters.Sequence(self.spike_times),
                             parameters.Sequence(self.spike_times2)])
        )

        self.pops_in['in2equal'] = pynn.Population(
            2,
            pynn.cells.SpikeSourceArray(spike_times=[self.spike_times] * 2)
        )
        self.pops_in['npin2equal'] = pynn.Population(
            2,
            pynn.cells.SpikeSourceArray(
                spike_times=[np.array(self.spike_times)] * 2)
        )
        self.pops_in['sein2equal'] = pynn.Population(
            2,
            pynn.cells.SpikeSourceArray(
                spike_times=[parameters.Sequence(self.spike_times)] * 2)
        )

        self.pops_in['mixedtypein3equal'] = pynn.Population(
            3,
            pynn.cells.SpikeSourceArray(
                spike_times=[
                    self.spike_times,
                    parameters.Sequence(self.spike_times),
                    np.array(self.spike_times)
                ])
        )
        self.pops_in['mixedtypein3var'] = pynn.Population(
            3,
            pynn.cells.SpikeSourceArray(
                spike_times=[
                    self.spike_times,
                    parameters.Sequence(self.spike_times2),
                    np.array(self.spike_times)])
        )

        # SpikeSourcePoisson
        poisson_properties = dict(rate=1e4, start=0, duration=10)
        self.pops_in['poisson1'] = pynn.Population(
            1,
            pynn.cells.SpikeSourcePoisson(**poisson_properties)
        )
        self.pops_in['poisson2'] = pynn.Population(
            2,
            pynn.cells.SpikeSourcePoisson(**poisson_properties)
        )

        # Target Populations
        self.pops = []
        self.pops.append(pynn.Population(1, pynn.cells.HXNeuron()))
        self.pops.append(pynn.Population(2, pynn.cells.HXNeuron()))
pynn.setup()

# In the current state, we only expose the neuron type 'HXNeuron',
# which allows low-level access to all circuit parameters. It can be
# configured by passing initial values to the respective Population.
# Each Population may consist of multiple neurons (in this case: one),
# all sharing the same parameters.
# Circuit parameters control the dynamic behavior of the neuron as well as
# static configuration. Most of them are either boolean or given in units of
# 'LSB' for chip-internal Digital-to-Analog converters - they have no direct
# biological translation.
# For this first example, you may alter the leak potential and observe
# the response of the analog neuron's resting potential.
pop = pynn.Population(1, pynn.cells.HXNeuron(
    # Leak potential, range: 300-1000
    leak_v_leak=700,
    # Leak conductance, range: 0-1022
    leak_i_bias=1022))

# The chip contains a fast Analog-to-Digital converter. It can be used to
# record different observables of a single analog neuron - most importantly
# the membrane potential.
#
# The chip additionally includes slower, parallel ADCs which will allow for
# parallel access to analog signals in multiple neurons. Support for this
# ADC will be integrated in future versions of our pyNN-Api.
pop.record(["v"])

# Calling pynn.run(time_in_ms) will as a first step apply the static
# configuration to the neuromorphic substrate. As a second step, the network
# is evolved for a given amount of time and neurons are stimulated by any