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_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 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_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()
 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()
    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_reset(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.reset()
     self.assertEqual(
         pynn.simulator.state.neuron_placement.id2hwenum(0),
         self.permutation[0])
     pynn.end()
예제 #9
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()
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_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()
 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()
예제 #15
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
예제 #16
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_maxsize_neuronpermuation():
     pynn.setup(neuronPermutation=range(halco.AtomicNeuronOnDLS.size))
 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()
예제 #19
0
start = 1
stop = 500
n = 5
listcond = np.linspace(1, 1000, n)
listi = np.linspace(start, stop, n)
np.save('conds.npy', listcond)
np.save('cur.npy', listi)
freq = np.zeros((n, n))
thres = 400
LL = []
for i in range(n):
    L = []
    for j in range(n):
        cur = int(listi[i])
        cond = int(listcond[j])
        pynn.setup()
        # Preparing the neuron to receive synaptic inputs requires the configuration
        # of additional circuits. The additional settings include technical parameters
        # for bringing the circuit to its designed operating point as well as
        # configuration with a direct biological equivalent.
        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,
예제 #20
0
 def setUp(self):
     pynn.setup(enable_neuron_bypass=True)
 def test_short_neuronpermuation():
     pynn.setup(neuronPermutation=[0, 3, 6])
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 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())
 def test_default_setup():
     pynn.setup()
 def test_non_unique_permutation(self):
     with self.assertRaises(ValueError):
         pynn.setup(neuronPermutation=[8, 8, 8])
예제 #26
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()))
 def test_negative_index(self):
     with self.assertRaises(ValueError):
         pynn.setup(neuronPermutation=[-1])
 def test_too_large_index(self):
     with self.assertRaises(ValueError):
         pynn.setup(neuronPermutation=[halco.AtomicNeuronOnDLS.size + 1])
 def test_too_large_neuronpermuation(self):
     with self.assertRaises(ValueError):
         pynn.setup(neuronPermutation=range(halco.AtomicNeuronOnDLS.size +
                                            1))
 def test_empty():
     pynn.setup()
     pynn.run(0.2)
     pynn.end()