예제 #1
0
    def test_assembly(self):

        size_a = random.randint(1, 1000)
        size_b = random.randint(1, 1000)

        pop_a = pyhmf.Population(size_a, pyhmf.IF_cond_exp)
        pop_b = pyhmf.Population(size_b, pyhmf.IF_cond_exp)
        pop_c = pyhmf.Population(1, pyhmf.IF_cond_exp)

        view = pop_b[0:random.randint(1, size_b)]

        text = '%ds till the end' % (size_a + size_b)

        construction_styles = [
            pyhmf.Assembly(pop_a, view, label=text),
            pyhmf.Assembly([pop_a, view], label=text),
            pyhmf.Assembly((pop_a, view), label=text)
        ]

        for asm in construction_styles:
            self.assertEqual(len(asm), len(list(asm.__iter__())))
            self.assertEqual(len(asm), len(list(asm.all())))
            self.assertEqual(size_a + len(view), len(asm))
            self.assertEqual(size_a + len(view), asm.size)
            self.assertEqual(text, asm.label)

        # some more tests ;)
        pyhmf.Assembly(pop_a),
        pyhmf.Assembly(pop_a, label=text),
        pyhmf.Assembly([pop_a]),
        pyhmf.Assembly([pop_a], label=text),
        pyhmf.Assembly(pop_c, label=text),
예제 #2
0
    def test_projection_weights(self):
        import numpy
        from numpy.testing import assert_equal,  assert_almost_equal, assert_array_equal
        import pyhmf as pynn
        
        size = (100, 300)
        noC = size[0] * size[1]

        p1, p2 = pynn.Population(size[0], pynn.EIF_cond_exp_isfa_ista), pynn.Population(size[1], pynn.EIF_cond_exp_isfa_ista)

        prj1 = pynn.Projection(p1, p2, pynn.AllToAllConnector() )

        prj1.setWeights(4.0)
        assert_array_equal(numpy.ones(noC)  * 4.0, prj1.getWeights())
        assert_array_equal(numpy.ones(size) * 4.0, prj1.getWeights("matrix") )
        
        prj1.setWeights( numpy.ones(noC)   * 3.0 )
        assert_array_equal(numpy.ones(noC)  * 3.0, prj1.getWeights() )
        assert_array_equal(numpy.ones(size) * 3.0, prj1.getWeights("matrix") )

        prj1.setWeights( numpy.ones(size)  * 2.0 )
        assert_array_equal(numpy.ones(noC)  * 2.0, prj1.getWeights() )
        assert_array_equal(numpy.ones(size) * 2.0, prj1.getWeights("matrix") )

        prj2 = pynn.Projection(p1, p2, pynn.AllToAllConnector(delays = 2.5, weights = numpy.ones(size)))

        assert_array_equal(numpy.ones(noC)  * 2.5, prj2.getDelays() )
        assert_array_equal(numpy.ones(size) * 2.5, prj2.getDelays("matrix") )
        assert_array_equal(numpy.ones(noC)  * 1.0, prj2.getWeights() )
        assert_array_equal(numpy.ones(size) * 1.0, prj2.getWeights("matrix") )
예제 #3
0
    def test_issue2048(self):
        if self.API_VERSION == "0.8":

            def generate_spike_times(i_range):
                return [
                    pyNN.parameters.Sequence(
                        numpy.add.accumulate(
                            numpy.random.exponential(10.0, size=10)))
                    for i in i_range
                ]

            p = pyhmf.Population(
                30, pyhmf.SpikeSourceArray(spike_times=generate_spike_times))
        elif self.API_VERSION == "0.7":

            def generate_spike_times(i_range):
                return [
                    numpy.add.accumulate(
                        numpy.random.exponential(10.0, size=10))
                    for i in i_range
                ]

            p = pyhmf.Population(
                30, pyhmf.SpikeSourceArray,
                {'spike_times': generate_spike_times(list(range(30)))})
예제 #4
0
    def test_popview_on_hicann(self, size):
        pynn.setup(marocco=self.marocco)
        neuron_size = 4
        self.marocco.neuron_placement.default_neuron_size(neuron_size)
        hicann = C.HICANNOnWafer(Enum(122))
        hicann_1 = C.HICANNOnWafer(Enum(123))
        hicann_2 = C.HICANNOnWafer(Enum(124))
        hicann_3 = C.HICANNOnWafer(Enum(125))
        pop = pynn.Population(size, pynn.IF_cond_exp, {})
        pop_1 = pynn.Population(size, pynn.IF_cond_exp, {})
        pop_view = pynn.PopulationView(pop,list(range(0,size,2)))
        pop_view_1 = pynn.PopulationView(pop,list(range(1,size,2)))
        pop_1_view = pynn.PopulationView(pop_1,list(range(1,size//2)))
        pop_1_view_1 = pynn.PopulationView(pop_1,list(range(size-2,size//2,-1)))
        pop_auto_placement = pynn.PopulationView(pop_1,[0,size//2,size-1])
        self.marocco.manual_placement.on_hicann(pop_view, hicann)
        self.marocco.manual_placement.on_hicann(pop_view_1, hicann_1)
        self.marocco.manual_placement.on_hicann(pop_1_view, hicann_2)
        self.marocco.manual_placement.on_hicann(pop_1_view_1, hicann_3)

        if neuron_size * size//2 > C.NeuronOnHICANN.enum_type.size:
            with self.assertRaises(RuntimeError):
                pynn.run(0)
                pynn.end()
            return

        pynn.run(0)
        pynn.end()

        results = self.load_results()

        for nrn in pop_view:
            placement_item, = results.placement.find(nrn)
            logical_neuron = placement_item.logical_neuron()
            for denmem in logical_neuron:
                self.assertEqual(hicann, denmem.toHICANNOnWafer())

        for nrn in pop_view_1:
            placement_item, = results.placement.find(nrn)
            logical_neuron = placement_item.logical_neuron()
            for denmem in logical_neuron:
                self.assertEqual(hicann_1, denmem.toHICANNOnWafer())

        for nrn in pop_1_view:
            placement_item, = results.placement.find(nrn)
            logical_neuron = placement_item.logical_neuron()
            for denmem in logical_neuron:
                self.assertEqual(hicann_2, denmem.toHICANNOnWafer())

        for nrn in pop_1_view_1:
            placement_item, = results.placement.find(nrn)
            logical_neuron = placement_item.logical_neuron()
            for denmem in logical_neuron:
                self.assertEqual(hicann_3, denmem.toHICANNOnWafer())

        for nrn in pop_auto_placement:
            placement_item, = results.placement.find(nrn)
            logical_neuron = placement_item.logical_neuron()
            for denmem in logical_neuron:
                self.assertIsNotNone(denmem.toHICANNOnWafer())
예제 #5
0
 def test_issue2051(self):
     p1 = pyhmf.Population(1000, pyhmf.EIF_cond_exp_isfa_ista)
     p2 = pyhmf.Population(1000, pyhmf.EIF_cond_exp_isfa_ista)
     if self.API_VERSION == "0.8":
         prj = pyhmf.Projection(p1, p2, pyhmf.AllToAllConnector(),
                                pyhmf.StaticSynapse(weight=0.05, delay=0.5))
         params = {
             'U': 0.04,
             'tau_rec': 100.0,
             'tau_facil': 1000.0,
             'weight': 0.01
         }
         facilitating = pyhmf.TsodyksMarkramSynapse(**params)
         prj = pyhmf.Projection(
             p1,
             p2,
             pyhmf.FixedProbabilityConnector(p_connect=0.1),
             synapse_type=facilitating)
     elif self.API_VERSION == "0.7":
         prj = pyhmf.Projection(
             p1, p2, pyhmf.AllToAllConnector(weights=0.05, delays=0.5))
         params = {'U': 0.04, 'tau_rec': 100.0, 'tau_facil': 1000.0}
         facilitating = pyhmf.SynapseDynamics(
             fast=pyhmf.TsodyksMarkramMechanism(**params))
         prj = pyhmf.Projection(p1,
                                p2,
                                pyhmf.FixedProbabilityConnector(
                                    p_connect=0.1, weights=0.01),
                                synapse_dynamics=facilitating)
예제 #6
0
 def test_issue2053(self):
     p1 = pyhmf.Population(1000, pyhmf.EIF_cond_exp_isfa_ista)
     p2 = pyhmf.Population(1000, pyhmf.EIF_cond_exp_isfa_ista)
     rand_distr = numpy.zeros(1000)
     if self.API_VERSION == "0.8":
         prj = pyhmf.Projection(p1, p2, pyhmf.AllToAllConnector(),
                                pyhmf.StaticSynapse(weight=0.05, delay=0.5))
         prj.get('weight', format='list', with_address=False)
         prj.set(delay=rand_distr)
         prj.set(tau_rec=50.0)
         prj.save('weight', 'exc_weights.txt', format='array')
         prj.save('all', 'exc_conn.txt', format='list')
         weights, delays = prj.get(['weight', 'delay'], format='array')
         prj.set(weight=rand_distr, delay=0.4)
     elif self.API_VERSION == "0.7":
         prj = pyhmf.Projection(
             p1, p2, pyhmf.AllToAllConnector(weights=0.05, delays=0.5))
         prj.getWeights(format='list')
         prj.randomizeDelays(rand_distr)
         prj.setSynapseDynamics('tau_rec', 50.0)
         prj.printWeights('exc_weights.txt', format='array')
         prj.saveConnections('exc_conn.txt')
         weights, delays = prj.getWeights('array'), prj.getDelays('array')
         prj.randomizeWeights(rand_distr)
         prj.setDelays(0.4)
예제 #7
0
    def test_with_size(self):
        pynn.setup(marocco=self.marocco)
        default_size = 4
        self.marocco.neuron_placement.default_neuron_size(default_size)

        sizes = {}

        pop = pynn.Population(1, pynn.IF_cond_exp, {})
        sizes[pop] = default_size

        pop = pynn.Population(1, pynn.IF_cond_exp, {})
        self.marocco.manual_placement.with_size(pop, 2)
        sizes[pop] = 2

        pop = pynn.Population(1, pynn.IF_cond_exp, {})
        self.marocco.manual_placement.with_size(pop, 6)
        sizes[pop] = 6

        pynn.run(0)
        pynn.end()

        results = self.load_results()

        for pop, size in sizes.items():
            placement_item, = results.placement.find(pop[0])
            logical_neuron = placement_item.logical_neuron()
            self.assertEqual(size, logical_neuron.size())
예제 #8
0
    def test(self):

        import pyhmf as pynn
        from pymarocco import PyMarocco
        import pylogging, pyhalbe
        pyhalbe.Debug.change_loglevel(2)
        pylogging.set_loglevel(pylogging.get("marocco"),
                               pylogging.LogLevel.TRACE)
        pylogging.set_loglevel(pylogging.get("sthal"),
                               pylogging.LogLevel.DEBUG)

        marocco = PyMarocco()
        marocco.neuron_placement.default_neuron_size(4)

        pynn.setup(marocco=marocco)

        neuron1 = pynn.Population(1, pynn.IF_cond_exp)

        inh = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times': [0]})
        exc = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times': [0]})
        exc_2 = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times': [0]})
        exc_3 = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times': [0]})

        c_exc = pynn.FixedProbabilityConnector(p_connect=1.0, weights=1)

        proj1 = pynn.Projection(inh, neuron1, c_exc, target='excitatory')
        proj2 = pynn.Projection(exc, neuron1, c_exc, target='excitatory')
        proj3 = pynn.Projection(exc_2, neuron1, c_exc, target='excitatory')
        proj4 = pynn.Projection(exc_3, neuron1, c_exc, target='inhibitory')

        pynn.run(10000)
        pynn.end()
예제 #9
0
    def build(self):

        # Set the neurons
        self.neuronsVisible = pynn.Population(self.Nvisible, self.model)
        self.neuronsHidden = pynn.Population(self.Nhidden, self.model)

        # in the fully connected rbm each neuron from the visible layer
        # projects to each neuron of the hidden layer (and vice versa)
        # both inhibitory and excitatory to enable switching the sing of the
        # connection during eventual training
        # self connections are excluded
        # This model only sets the skeleton of the BM without the noise sources
        connector = pynn.AllToAllConnector(weights=0.003,
                                           allow_self_connections=False)
        pynn.Projection(self.neuronsVisible,
                        self.neuronsHidden,
                        connector,
                        target='excitatory')
        pynn.Projection(self.neuronsVisible,
                        self.neuronsHidden,
                        connector,
                        target='inhibitory')
        pynn.Projection(self.neuronsHidden,
                        self.neuronsVisible,
                        connector,
                        target='excitatory')
        pynn.Projection(self.neuronsHidden,
                        self.neuronsVisible,
                        connector,
                        target='inhibitory')
예제 #10
0
    def test_get_denmems(self):
        pop_size = 2

        for neuron_size in [4, 8, 12, 16, 32]:
            self.marocco.neuron_placement.default_neuron_size(neuron_size)

            pynn.setup(marocco=self.marocco)

            target = pynn.Population(pop_size, pynn.IF_cond_exp, {})

            populations = [target]
            for i in range(3):
                p1 = pynn.Population(pop_size, pynn.SpikeSourceArray,
                                     {'spike_times': [1.]})
                p2 = pynn.Population(pop_size, pynn.IF_cond_exp, {})
                pynn.Projection(p1, target,
                                pynn.OneToOneConnector(weights=0.004))
                pynn.Projection(p2, target,
                                pynn.OneToOneConnector(weights=0.004))

                populations.append(p2)

            pynn.run(0)
            pynn.end()

            mapstats = self.marocco.getStats()

            results = Marocco.from_file(self.marocco.persist)
            for pop in populations:
                for nrn in range(pop_size):
                    for item in results.placement.find(pop[nrn]):
                        self.assertFalse(item.logical_neuron().is_external())
                        self.assertEqual(neuron_size,
                                         item.logical_neuron().size())
예제 #11
0
def build_network(num_pops, pop_size, marocco):
    from pymarocco import PyMarocco
    import pyhmf as pynn

    logging.info("num_pops: %d, pop_size: %d, total size: %d" %
                 (num_pops, pop_size, num_pops * pop_size))

    pynn.setup(marocco=marocco)

    pops = [
        pynn.Population(pop_size, pynn.EIF_cond_exp_isfa_ista)
        for x in range(num_pops)
    ]

    for idx, pop in enumerate(pops):
        connector = pynn.AllToAllConnector(allow_self_connections=True,
                                           weights=1.)

        # build ring like network topology
        pynn.Projection(pop,
                        pops[(idx + 1) % len(pops)],
                        connector,
                        target='excitatory')

        # add poisson stimulus
        source = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 2})

        pynn.Projection(source, pop, connector, target='excitatory')

    pynn.run(1)
    pynn.end()

    stats = marocco.getStats()
    loss = float(stats.getSynapseLoss()) / stats.getSynapses()
    return (num_pops, pop_size, loss)
예제 #12
0
    def test_min_spl1_should_allow_external_input_on_same_chip(self):
        """
        Even when the rightmost neuron block / DNC merger is not reserved for external input, it
        should be possible to place external input on the same chip.
        """
        pynn.setup(marocco=self.marocco)
        neuron_size = 4
        self.marocco.neuron_placement.default_neuron_size(neuron_size)
        self.marocco.merger_routing.strategy(
            self.marocco.merger_routing.minimize_number_of_sending_repeaters)
        # Do not reserve rightmost neuron block / DNC merger for external input.
        self.marocco.neuron_placement.restrict_rightmost_neuron_blocks(False)

        hicann = C.HICANNOnWafer(C.Enum(123))
        pops = []
        # All but the first neuron block are occupied.
        for nb in range(1, C.NeuronBlockOnHICANN.end):
            pop = pynn.Population(1, pynn.IF_cond_exp, {})
            self.marocco.manual_placement.on_neuron_block(
                pop, C.NeuronBlockOnWafer(C.NeuronBlockOnHICANN(nb), hicann))
            pops.append(pop)
        in_pop = pynn.Population(1, pynn.SpikeSourceArray, {})
        self.marocco.manual_placement.on_hicann(in_pop, hicann)

        pynn.run(0)
        pynn.end()

        results = self.load_results()

        for pop in pops:
            nrn = pop[0]
            placement_item, = results.placement.find(nrn)
            logical_neuron = placement_item.logical_neuron()
            self.assertEqual(neuron_size, logical_neuron.size())
            for denmem in logical_neuron:
                self.assertEqual(hicann, denmem.toHICANNOnWafer())
            address = placement_item.address()

            # All used neuron blocks should be connected to a single DNC merger.
            dnc = C.DNCMergerOnHICANN(3)
            self.assertEqual(hicann, address.toHICANNOnWafer())
            self.assertEqual(dnc, address.toDNCMergerOnHICANN())
            self.assertEqual(C.DNCMergerOnWafer(dnc, hicann),
                             address.toDNCMergerOnWafer())

        nrn = in_pop[0]
        placement_item, = results.placement.find(nrn)
        logical_neuron = placement_item.logical_neuron()
        self.assertTrue(logical_neuron.is_external())
        address = placement_item.address()

        # External input should be on the leftmost DNC merger, since all other
        # mergers do not have direct access to a background generator.
        dnc = C.DNCMergerOnHICANN(0)
        self.assertEqual(hicann, address.toHICANNOnWafer())
        self.assertEqual(dnc, address.toDNCMergerOnHICANN())
        self.assertEqual(C.DNCMergerOnWafer(dnc, hicann),
                         address.toDNCMergerOnWafer())
예제 #13
0
    def test_L1_detour_at_side_switch_usage(self):
        """
                                  [155]
                                   191
            [223]  224  225 x226x {227}

            test detour and predecessor settings at the edge of a wafer

        """

        pylogging.set_loglevel(pylogging.get("marocco"),
                               pylogging.LogLevel.TRACE)
        pylogging.set_loglevel(pylogging.get("Calibtic"),
                               pylogging.LogLevel.ERROR)

        self.marocco.persist = ''  # or add test suite TestWithRuntime?

        runtime = Runtime(self.marocco.default_wafer)
        pynn.setup(marocco=self.marocco, marocco_runtime=runtime)

        settings = pysthal.Settings.get()

        settings.synapse_switches.max_switches_per_column_per_side = 1
        settings.crossbar_switches.max_switches_per_row = 1

        source = pynn.Population(1, pynn.IF_cond_exp, {})
        target1 = pynn.Population(1, pynn.IF_cond_exp, {})
        target2 = pynn.Population(1, pynn.IF_cond_exp, {})

        proj = pynn.Projection(
            source, target1, pynn.AllToAllConnector(weights=1.))
        proj = pynn.Projection(
            source, target2, pynn.AllToAllConnector(weights=1.))

        source_hicann = C.HICANNOnWafer(Enum(227))
        target1_hicann = C.HICANNOnWafer(Enum(155))
        target2_hicann = C.HICANNOnWafer(Enum(225))

        self.marocco.manual_placement.on_hicann(source, source_hicann)
        self.marocco.manual_placement.on_hicann(target1, target1_hicann)
        self.marocco.manual_placement.on_hicann(target2, target2_hicann)

        disabled_hicanns = [226, 263]
        wafer = self.marocco.default_wafer
        self.marocco.defects.set(pyredman.Wafer(runtime.wafer().index()))
        for hicann in C.iter_all(C.HICANNOnWafer):
            if hicann.toEnum().value() in disabled_hicanns:
                self.marocco.defects.wafer().hicanns().disable(C.HICANNGlobal(hicann, wafer))
            continue

        pynn.run(0)
        pynn.end()

        for hicann in runtime.wafer().getAllocatedHicannCoordinates():
            h = runtime.wafer()[hicann]
            print(hicann, h.check())
            self.assertEqual(h.check(), "")
예제 #14
0
    def test_projections(self):
        pynn.setup(marocco=self.marocco)

        target = pynn.Population(1, pynn.IF_cond_exp, {})
        pop_a = pynn.Population(2, pynn.SpikeSourceArray,
                                {'spike_times': [1.]})
        pop_b = pynn.Population(1, pynn.SpikeSourceArray,
                                {'spike_times': [2.]})
        pop_ab = pynn.Assembly()
        pop_ab += pop_a
        pop_ab += pop_b

        con = pynn.AllToAllConnector(weights=0.004)
        proj_a = pynn.Projection(pop_a, target, con)
        proj_b = pynn.Projection(pop_b, target, con)
        proj_ab = pynn.Projection(pop_ab, target, con)

        pynn.run(0)
        pynn.end()

        results = self.load_results()
        synapses = results.synapse_routing.synapses()

        items_a = synapses.find(proj_a)
        self.assertEqual(2, len(items_a))

        items_b = synapses.find(proj_b)
        self.assertEqual(1, len(items_b))

        items_ab = synapses.find(proj_ab)
        self.assertEqual(3, len(items_ab))

        def to_hw_synapses(items):
            hw_synapses = set()
            for item in items:
                synapse = item.hardware_synapse()
                if synapse:
                    hw_synapses.add(synapse)
            return hw_synapses

        hw_a = to_hw_synapses(items_a)
        hw_b = to_hw_synapses(items_b)
        hw_ab = to_hw_synapses(items_ab)
        self.assertTrue(hw_a.isdisjoint(hw_b))
        self.assertTrue(hw_a.isdisjoint(hw_ab))
        self.assertTrue(hw_b.isdisjoint(hw_ab))

        for source_neuron in pop_a:
            items = synapses.find(proj_ab, source_neuron, target[0])
            self.assertEqual(1, len(items))
            self.assertTrue(hw_ab.issuperset(to_hw_synapses(items)))

        for source_neuron in pop_b:
            items = synapses.find(proj_ab, source_neuron, target[0])
            self.assertEqual(1, len(items))
            self.assertTrue(hw_ab.issuperset(to_hw_synapses(items)))
예제 #15
0
    def test_issue2046(self):
        if self.API_VERSION in ("0.7", "0.8"):
            # PyNN 0.7 style, deprecated but still supported in 0.8
            p = pyhmf.Population(1000, pyhmf.IF_cond_exp, {'tau_m': 12.0, 'cm': 0.8})

        if self.API_VERSION == "0.8":
            p = pyhmf.Population(1000, pyhmf.IF_cond_exp(**{'tau_m': 12.0, 'cm': 0.8}))

            cell_type = pyhmf.IF_cond_exp(tau_m=12.0, cm=0.8)
            p = pyhmf.Population(1000, cell_type)
예제 #16
0
    def test_issue1565(self):
        # although there is only 1 synapse column per neuron (of size 2), a 2nd synapse is used
        self.marocco.neuron_placement.default_neuron_size(2)
        con = pynn.FixedProbabilityConnector(p_connect=1.0, weights=0.004)

        pynn.setup(marocco=self.marocco)
        pop1 = pynn.Population(10, pynn.IF_cond_exp, {})
        ipu1 = pynn.Population(2, pynn.SpikeSourceArray, {'spike_times': []})
        pro1 = pynn.Projection(ipu1, pop1, con, target='excitatory')
        pynn.run(0)
예제 #17
0
    def test_min_spl1_is_nongreedy_when_pops_are_placed_to_nbs(self, nbs):
        """
        See above.  Instead of a single population placed to the HICANN, populations are placed to
        specific neuron blocks.
        """
        pynn.setup(marocco=self.marocco)
        neuron_size = 4
        self.marocco.neuron_placement.default_neuron_size(neuron_size)
        self.marocco.merger_routing.strategy(
            self.marocco.merger_routing.minimize_number_of_sending_repeaters)
        self.marocco.neuron_placement.restrict_rightmost_neuron_blocks(True)

        hicann = C.HICANNOnWafer(C.Enum(123))
        pops = []
        for nb in nbs:
            pop = pynn.Population(1, pynn.IF_cond_exp, {})
            self.marocco.manual_placement.on_neuron_block(
                pop, C.NeuronBlockOnWafer(C.NeuronBlockOnHICANN(nb), hicann))
            pops.append(pop)
        in_pop = pynn.Population(1, pynn.SpikeSourceArray, {})
        self.marocco.manual_placement.on_hicann(in_pop, hicann)

        pynn.run(0)
        pynn.end()

        results = self.load_results()

        for pop in pops:
            nrn = pop[0]
            placement_item, = results.placement.find(nrn)
            logical_neuron = placement_item.logical_neuron()
            self.assertEqual(neuron_size, logical_neuron.size())
            for denmem in logical_neuron:
                self.assertEqual(hicann, denmem.toHICANNOnWafer())
            address = placement_item.address()

            # All used neuron blocks should still be connected to a single DNC merger.
            dnc = C.DNCMergerOnHICANN(3)
            self.assertEqual(hicann, address.toHICANNOnWafer())
            self.assertEqual(dnc, address.toDNCMergerOnHICANN())
            self.assertEqual(C.DNCMergerOnWafer(dnc, hicann),
                             address.toDNCMergerOnWafer())

        nrn = in_pop[0]
        placement_item, = results.placement.find(nrn)
        logical_neuron = placement_item.logical_neuron()
        self.assertTrue(logical_neuron.is_external())
        address = placement_item.address()

        # External input should be on the rightmost DNC merger since that is tried first.
        dnc = C.DNCMergerOnHICANN(7)
        self.assertEqual(hicann, address.toHICANNOnWafer())
        self.assertEqual(dnc, address.toDNCMergerOnHICANN())
        self.assertEqual(C.DNCMergerOnWafer(dnc, hicann),
                         address.toDNCMergerOnWafer())
예제 #18
0
    def test_TwoNeuron(self):
        if True:
            pynn.setup(marocco=self.marocco)

            # create neuron with v_rest below v_thresh
            source = pynn.Population(1, pynn.EIF_cond_exp_isfa_ista, {
                'v_rest': -50.,
                'v_thresh': -60.,
                'v_reset': -70.6,
            })

            N = 8  # number of target populations

            p = [
                pynn.Population(1, pynn.EIF_cond_exp_isfa_ista)
                for i in range(N)
            ]

            # place source on HICANN 0
            source_hicann = self.chip(0)
            self.marocco.manual_placement.on_hicann(source, source_hicann)

            # place targets on all HICANNs on same reticle but random neurons
            nrns = self.shuffle(255)
            for ii, pop in enumerate(p):
                hicann = HICANNGlobal(X(int(source_hicann.x()) + ii % 4),
                                      Y(int(source_hicann.y()) + ii // 4))
                self.marocco.manual_placement.on_hicann(pop, hicann)
                print(pop, hicann)

            connector = pynn.AllToAllConnector(allow_self_connections=True,
                                               weights=1.)

            store = []
            # connect source to targets
            for trg in p:
                proj = pynn.Projection(source,
                                       trg,
                                       connector,
                                       target='excitatory')
                weights = copy.deepcopy(proj.getWeights())
                store.append((proj, weights))

            # start simulation
            pynn.run(10)  # in ms
            pynn.end()

            # make sure we have no synapse loss
            self.assertEqual(0, self.marocco.stats.getSynapseLoss())

            # assert weights are the same (at least as long as we don't send be
            # the transformed digital weights)
            for proj, weights in store:
                self.assertEqual(self.marocco.stats.getWeights(proj), weights)
    def test_external_sources_projections(self, params):
        nprojections = params[0]
        nsources = params[1]
        print((nprojections, nsources))
        """
            An external sources has multiple projections
            so it should be split if it wuld not be of size 1
            so unfortunately the users would need to live with that.
        """
        pylogging.set_loglevel(pylogging.get("marocco"),
                               pylogging.LogLevel.TRACE)
        pylogging.set_loglevel(pylogging.get("Calibtic"),
                               pylogging.LogLevel.ERROR)

        pynn.setup(marocco=self.marocco)
        self.marocco.neuron_placement.default_neuron_size(4)

        # ensure a limited synapse driver chain length.
        self.marocco.synapse_routing.driver_chain_length(3)

        # we expect synapse loss, but we dont care, as the source cant be split.
        # we want this tests not to throw exceptions.
        self.marocco.continue_despite_synapse_loss = True

        target = pynn.Population(1, pynn.IF_cond_exp, {})
        hicann = C.HICANNOnWafer(Enum(100))
        self.marocco.manual_placement.on_hicann(target, hicann)

        exsource = pynn.Population(nsources, pynn.SpikeSourcePoisson,
                                   {'rate': 1.})
        for i in range(nprojections):
            proj = pynn.Projection(exsource, target,
                                   pynn.AllToAllConnector(weights=1.))

        # access to proj so flake8 keeps silent
        proj.size

        pynn.run(0)
        pynn.end()

        results = self.load_results()
        synapses = results.synapse_routing.synapses()
        placement = results.placement

        for dnc in C.iter_all(C.DNCMergerOnWafer):
            PonDNC = placement.find(dnc)  # PopulationOnDNC
            if PonDNC:
                ## if driver requirements exceeded, only one source should be
                ## placed on the DNC, but synapse loss is still expected
                if (nprojections > 4):  # this number is just guessed
                    self.assertTrue(len(PonDNC) <= 1)
                else:
                    self.assertTrue(len(PonDNC) <= 12)
예제 #20
0
    def test_loss_in_wafer_routing(self, mode):
        h0 = HICANNGlobal(HICANNOnWafer(Enum(0)), Wafer(33))
        h1 = HICANNGlobal(HICANNOnWafer(Enum(1)), Wafer(33))

        # disable all horizontal buses on h0
        hicann = pyredman.Hicann()
        for hbus in iter_all(HLineOnHICANN):
            hicann.hbuses().disable(hbus)
        self.marocco.defects.set(pyredman.Wafer())
        self.marocco.defects.wafer().inject(h0, hicann)

        pynn.setup(marocco=self.marocco)
        n1 = 100
        n2 = 100
        p1 = pynn.Population(n1, pynn.EIF_cond_exp_isfa_ista)
        p2 = pynn.Population(n2, pynn.EIF_cond_exp_isfa_ista)

        self.marocco.manual_placement.on_hicann(p1, h0)
        self.marocco.manual_placement.on_hicann(p2, h1)

        n_post = 10
        if mode == "Population":
            src = p1
            tgt = p2
            exp_loss = len(src) * n_post
        elif mode == "PopulationView":
            src = p1[n1 // 2:n1]
            tgt = p2[n2 // 2:n2]
            exp_loss = len(src) * n_post
        elif mode == "Assembly":
            src = pynn.Assembly(p1, p2)
            tgt = p2
            exp_loss = len(p1) * n_post

        conn = pynn.FixedNumberPostConnector(n_post,
                                             allow_self_connections=True,
                                             weights=1.)
        proj = pynn.Projection(src, tgt, conn, target='excitatory')

        pynn.run(100)
        pynn.end()

        # check stats
        self.assertEqual(exp_loss,
                         self.marocco.stats.getSynapseLossAfterL1Routing())
        self.assertEqual(exp_loss, self.marocco.stats.getSynapseLoss())

        # check weight matrices
        orig_weights = proj.getWeights(format="array")
        mapped_weights = self.marocco.stats.getWeights(proj)
        lost_syns = np.logical_and(np.isfinite(orig_weights),
                                   np.isnan(mapped_weights))
        self.assertEqual(exp_loss, np.count_nonzero(lost_syns))
예제 #21
0
    def big_network(self):
        pynn.setup(marocco=self.marocco)

        synapses = 0
        numberOfPopulations = random.randint(100, 150)
        logging.debug("number of populations: %d" % (numberOfPopulations))
        #print "numPops: %d" % (numberOfPopulations)

        # FIXME: spuouriously fails, why?
        #pops = [ Population(random.randint(50, 85), EIF_cond_exp_isfa_ista) for x in
        #range(numberOfPopulations) ]
        pops = [
            pynn.Population(80, pynn.EIF_cond_exp_isfa_ista)
            for x in range(numberOfPopulations)
        ]

        for idx, pop in enumerate(pops):

            connectorE = pynn.FixedProbabilityConnector(
                p_connect=0.20, allow_self_connections=True, weights=1.)

            connectorI = pynn.FixedProbabilityConnector(
                p_connect=0.10, allow_self_connections=True, weights=1.)

            # build ring like network topology
            proj = pynn.Projection(pop,
                                   pops[(idx + 1) % len(pops)],
                                   connectorE,
                                   target='excitatory')
            synapses += np.count_nonzero(proj.getWeights())

            proj = pynn.Projection(pop,
                                   pops[(idx + 1) % len(pops)],
                                   connectorI,
                                   target='inhibitory')
            synapses += np.count_nonzero(proj.getWeights())

            # add poisson stimulus
            source = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 2})

            proj = pynn.Projection(source,
                                   pop,
                                   connectorE,
                                   target='excitatory')
            synapses += np.count_nonzero(proj.getWeights())

        pynn.run(100)
        pynn.end()

        logging.debug("synapses counted in python: %d", synapses)
        return synapses
예제 #22
0
    def test_issue1681(self):
        con = pynn.FixedProbabilityConnector(p_connect=1.0, weights=0.004)

        pynn.setup(marocco=self.marocco)
        pop1 = pynn.Population(10, pynn.IF_cond_exp, {})
        ipu1 = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times': []})
        pro1 = pynn.Projection(ipu1, pop1, con, target='excitatory')

        # Issue 1681 "IndexError after mapping ends" is triggered by adding a
        # population after a projection:
        # Expected Output: NO ERROR
        # Actual Output: "IndexError: vector::_M_range_check" (i.e. abnormal termination)
        pop2 = pynn.Population(10, pynn.IF_cond_exp, {})
        pynn.run(0)
예제 #23
0
    def test_projection(self):
        size_a = random.randint(1, 1000)
        size_b = random.randint(1, 1000)

        pop_a = pyhmf.Population(size_a, pyhmf.IF_cond_exp)
        pop_b = pyhmf.Population(size_b, pyhmf.IF_cond_exp)

        pro = pyhmf.Projection(pop_a, pop_b, pyhmf.AllToAllConnector())

        # ECM: iteration over Connections?
        #self.assertEqual(len(pro), len(list(pro.__iter__())))
        #self.assertEqual(len(pro), len(list(pro.all())))
        self.assertEqual(size_a * size_b, len(pro))
        self.assertEqual(size_a * size_b, pro.size)
    def test_external_sources_drivers(self, nsources):
        """
            A lot external sources are placed
            no error should be thrown
            the sources should be split
        """
        pylogging.set_loglevel(pylogging.get("marocco"),
                               pylogging.LogLevel.DEBUG)
        pylogging.set_loglevel(pylogging.get("Calibtic"),
                               pylogging.LogLevel.ERROR)

        pynn.setup(marocco=self.marocco)
        self.marocco.neuron_placement.default_neuron_size(4)

        # ensure a limited synapse driver chain length.
        self.marocco.synapse_routing.driver_chain_length(3)

        # if synapse loss occours we want to handle it on our own
        self.marocco.continue_despite_synapse_loss = True

        target = pynn.Population(1, pynn.IF_cond_exp, {})
        hicann = C.HICANNOnWafer(Enum(100))
        self.marocco.manual_placement.on_hicann(target, hicann)

        exsource = pynn.Population(nsources, pynn.SpikeSourcePoisson,
                                   {'rate': 1.})
        proj = pynn.Projection(exsource, target,
                               pynn.AllToAllConnector(weights=1.))

        # access to proj so flake8 keeps silent
        proj.size

        pynn.run(0)
        pynn.end()

        results = self.load_results()
        synapses = results.synapse_routing.synapses()
        placement = results.placement

        # test for synapse loss
        self.assertEqual(nsources, synapses.size())

        for dnc in C.iter_all(C.DNCMergerOnWafer):
            PonDNC = placement.find(dnc)  # PopulationOnDNC
            if PonDNC:
                ## with a neuron size of 4 and  a chain length of 3,
                ## around 12 sources can fit into a merger
                self.assertTrue(len(PonDNC) <= 12)
예제 #25
0
    def test_popview_external_source(self):
        pynn.setup(marocco=self.marocco)
        neuron_size = 4
        self.marocco.neuron_placement.default_neuron_size(neuron_size)

        size = 10
        pop_ext = pynn.Population(size, pynn.SpikeSourcePoisson, {'rate':2})
        pop_ext_1 = pynn.Population(size, pynn.SpikeSourcePoisson, {'rate':2})
        pop = pynn.Population(size, pynn.IF_cond_exp, {})
        connector = pynn.AllToAllConnector(weights=1)
        projections = [
            pynn.Projection(pop_ext, pop, connector, target='excitatory'),
            pynn.Projection(pop_ext_1, pop, connector, target='excitatory'),
        ]
        hicann = C.HICANNOnWafer(Enum(121))
        hicann_1 = C.HICANNOnWafer(Enum(122))

        pop_view = pynn.PopulationView(pop_ext,list(range(1,size,2)))
        pop_view_1 = pynn.PopulationView(pop_ext,list(range(0,size,2)))
        pop_1_view = pynn.PopulationView(pop_ext_1,list(range(1,size//2)))
        pop_1_view_1 = pynn.PopulationView(pop_ext_1,list(range(size-2,size//2,-1)))
        pop_1_auto_placement = pynn.PopulationView(pop_ext_1,[0,size//2,size-1])

        self.marocco.manual_placement.on_hicann(pop_view, hicann)
        self.marocco.manual_placement.on_hicann(pop_view_1, hicann_1)
        self.marocco.manual_placement.on_hicann(pop_1_view, hicann)
        self.marocco.manual_placement.on_hicann(pop_1_view_1, hicann_1)

        pynn.run(0)
        pynn.end()

        results = self.load_results()

        for nrn in pop_view:
            placement_item, = results.placement.find(nrn)
            self.assertEqual(hicann, placement_item.dnc_merger().toHICANNOnWafer())
        for nrn in pop_view_1:
            placement_item, = results.placement.find(nrn)
            self.assertEqual(hicann_1, placement_item.dnc_merger().toHICANNOnWafer())
        for nrn in pop_1_view:
            placement_item, = results.placement.find(nrn)
            self.assertEqual(hicann, placement_item.dnc_merger().toHICANNOnWafer())
        for nrn in pop_1_view_1:
            placement_item, = results.placement.find(nrn)
            self.assertEqual(hicann_1, placement_item.dnc_merger().toHICANNOnWafer())
        for nrn in pop_1_auto_placement:
            placement_item, = results.placement.find(nrn)
            self.assertIsNotNone(placement_item.dnc_merger().toHICANNOnWafer())
예제 #26
0
    def test(self):

        wafer = 99999  # a wafer for which no redman data is availale
        hicann = 82
        neuron_number = 12

        marocco = PyMarocco()
        marocco.neuron_placement.default_neuron_size(4)
        marocco.backend = PyMarocco.Without
        marocco.default_wafer = C.Wafer(wafer)

        used_hicann = C.HICANNGlobal(C.HICANNOnWafer(Enum(hicann)),
                                     C.Wafer(wafer))

        used_hicann  # prevent pep8 warning of unused variable

        pynn.setup(marocco=marocco)

        pop = pynn.Population(1, pynn.IF_cond_exp)
        topleft = C.NeuronOnWafer(C.NeuronOnHICANN(X(neuron_number), Y(0)),
                                  C.HICANNOnWafer(Enum(hicann)))
        logical_neuron = LogicalNeuron.rectangular(topleft, size=4)
        marocco.manual_placement.on_neuron(pop, logical_neuron)

        with self.assertRaises(RuntimeError):
            pynn.run(0)
            pynn.end()
예제 #27
0
    def test_on_neurons(self, pop_size):
        pynn.setup(marocco=self.marocco)

        pop = pynn.Population(pop_size, pynn.IF_cond_exp, {})
        neuron_block = C.NeuronBlockOnWafer(C.NeuronBlockOnHICANN(3))
        logical_neurons = [
            (LogicalNeuron.on(neuron_block)
             .add(C.NeuronOnNeuronBlock(X(3), Y(0)), 2)
             .add(C.NeuronOnNeuronBlock(X(3), Y(1)), 2)
             .done()),
            (LogicalNeuron.on(neuron_block)
             .add(C.NeuronOnNeuronBlock(X(11), Y(0)), 2)
             .add(C.NeuronOnNeuronBlock(X(11), Y(1)), 2)
             .done()),
        ]
        self.marocco.manual_placement.on_neuron(pop, logical_neurons)

        if pop_size != len(logical_neurons):
            with self.assertRaises(RuntimeError):
                pynn.run(0)
                pynn.end()
            return

        pynn.run(0)
        pynn.end()

        results = self.load_results()

        for nrn, logical_neuron in zip(pop, logical_neurons):
            placement_item, = results.placement.find(nrn)
            self.assertEqual(logical_neuron, placement_item.logical_neuron())
예제 #28
0
    def test_on_neuron_block(self, size):
        pynn.setup(marocco=self.marocco)
        neuron_size = 4
        self.marocco.neuron_placement.default_neuron_size(neuron_size)

        neuron_block = C.NeuronBlockOnWafer(C.NeuronBlockOnHICANN(3))
        pop = pynn.Population(size, pynn.IF_cond_exp, {})
        self.marocco.manual_placement.on_neuron_block(pop, neuron_block)

        if neuron_size * size > C.NeuronOnNeuronBlock.enum_type.size:
            with self.assertRaises(RuntimeError):
                pynn.run(0)
                pynn.end()
            return

        pynn.run(0)
        pynn.end()

        results = self.load_results()

        for nrn in pop:
            placement_item, = results.placement.find(nrn)
            logical_neuron = placement_item.logical_neuron()
            self.assertEqual(neuron_size, logical_neuron.size())
            for denmem in logical_neuron:
                self.assertEqual(neuron_block, denmem.toNeuronBlockOnWafer())
예제 #29
0
    def test_popview_on_neuron(self):
        pynn.setup(marocco=self.marocco)

        pop = pynn.Population(4, pynn.IF_cond_exp, {})
        neuron_block = C.NeuronBlockOnWafer(C.NeuronBlockOnHICANN(3))
        neuron_block_1 = C.NeuronBlockOnWafer(C.NeuronBlockOnHICANN(2))
        logical_neuron = (LogicalNeuron.on(neuron_block)
                          .add(C.NeuronOnNeuronBlock(X(3), Y(0)), 2)
                          .add(C.NeuronOnNeuronBlock(X(3), Y(1)), 2)
                          .done())
        logical_neuron_1 = (LogicalNeuron.on(neuron_block_1)
                          .add(C.NeuronOnNeuronBlock(X(4), Y(0)), 2)
                          .add(C.NeuronOnNeuronBlock(X(4), Y(1)), 2)
                          .done())

        popview = pynn.PopulationView(pop,[0])
        popview_1 = pynn.PopulationView(pop,[2])
        popview_auto_placement= pynn.PopulationView(pop,[1,3])
        self.marocco.manual_placement.on_neuron(popview, logical_neuron)
        self.marocco.manual_placement.on_neuron(popview_1, logical_neuron_1)

        pynn.run(0)
        pynn.end()

        results = self.load_results()

        placement_item, = results.placement.find(popview[0])
        self.assertEqual(logical_neuron, placement_item.logical_neuron())
        placement_item, = results.placement.find(popview_1[0])
        self.assertEqual(logical_neuron_1, placement_item.logical_neuron())
        for nrn in popview_auto_placement:
            placement_item, = results.placement.find(nrn)
            self.assertIsNotNone(placement_item.logical_neuron())
예제 #30
0
    def test_Constructor(self):
        import numpy
        import pymarocco

        marocco = pymarocco.PyMarocco()
        marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default

        pynn.setup(marocco=marocco)

        N = 10
        model = pynn.IF_cond_exp
        selector = numpy.array(
            [random.choice([True, False]) for x in range(0, N)])
        pop = pynn.Population(N, model)
        pv = pynn.PopulationView(pop, selector)

        self.assertEqual(len(pv), len(numpy.where(selector == True)[0]))

        # now a selection with wrong size is given
        wrong_selector = numpy.array(
            [random.choice([True, False]) for x in range(0, 2 * N)])
        with self.assertRaises(RuntimeError):
            pv = pynn.PopulationView(pop, wrong_selector)

        pynn.run(100)