예제 #1
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") )
예제 #2
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)
예제 #3
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)
예제 #4
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(), "")
예제 #5
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')
예제 #6
0
    def random_network(self):
        pynn.setup(marocco=self.marocco)

        NUM_POPS = random.randint(10, 100)
        POP_SIZE = random.randint(1, 100)
        PROJ_PROB = 0.2

        pops = [ pynn.Population(POP_SIZE, pynn.EIF_cond_exp_isfa_ista) for x in
                range(NUM_POPS) ]

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

        for src in pops:
            for trg in pops:
                target_type = 'inhibitory' if random.random() < 0.2 else 'excitatory'
                if random.random() < PROJ_PROB:
                    pynn.Projection(src, trg, connector, target=target_type)

        pynn.run(1)
        pynn.end()

        stats = self.marocco.getStats()
        print("python synapse loss: ", stats.getSynapseLoss())
예제 #7
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)
    def test_hw_merging_spl1_should_merge_some(self):
        """
        some DNCs shall be merged, but not all, because of syndriver
        requirements on each NB. 2 neurons will be placed (same HICANN).
        A fully connected network is built.
        This results in 8*2 = 16 synapses being routed to each neuron.
        With neuron size 4 and chain length 3 -> 12 synapses can be realised
        on each neuron. As a result at maximum 12 synapses shall be on the
        same L1Route. The merger tries to merge them and will fail, then spit
        it and merge 8 to each merger [3,5].

        The result is a better L1 utilisation compared to one-to-one mapping,
        2 instead of 8 routes, while staying within hardware constrains,
        compared to merge all (16 synapses requiring 4 drivers, 1 driver will
        be lost).
        """
        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_as_possible)
        # restrict to 3 driver, so that this test is hardware agnostic
        self.marocco.synapse_routing.driver_chain_length(3)

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

        for p in pops:
            for other_p in pops:
                pynn.Projection(p, other_p, pynn.AllToAllConnector(weights=1.))

        pynn.run(0)
        pynn.end()

        merged_dncs = [3, 3, 3, 3, 5, 5, 5, 5]

        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()

            # some DNCs shall be merged.
            dnc = C.DNCMergerOnHICANN(merged_dncs[pop.euter_id()])
            self.assertEqual(hicann, address.toHICANNOnWafer())
            self.assertEqual(dnc, address.toDNCMergerOnHICANN())
            self.assertEqual(C.DNCMergerOnWafer(dnc, hicann),
                             address.toDNCMergerOnWafer())
예제 #9
0
    def test_small_network(self, neuron_size):
        self.marocco.neuron_placement.default_neuron_size(neuron_size)
        pynn.setup(marocco=self.marocco)

        target = pynn.Population(1, pynn.IF_cond_exp, {})
        p1 = pynn.Population(2, pynn.SpikeSourceArray, {'spike_times': [1.]})
        p2 = pynn.Population(5, pynn.IF_cond_exp, {})
        pops = [target, p1, p2]
        proj1 = pynn.Projection(p1, target,
                                pynn.AllToAllConnector(weights=0.004))
        proj2 = pynn.Projection(p2, target,
                                pynn.AllToAllConnector(weights=0.004))
        projections = [proj1, proj2]

        pynn.run(0)
        pynn.end()

        results = self.load_results()

        self.assertEqual(sum(map(len, pops)), len(list(results.placement)))
        for pop in pops:
            for n in xrange(len(pop)):
                items = results.placement.find(pop[n])
                self.assertTrue(isinstance(items, list))
                self.assertEqual(1, len(items))
                item = items[0]

                bio_neuron = item.bio_neuron()
                self.assertEqual(pop.euter_id(), bio_neuron.population())
                self.assertEqual(n, bio_neuron.neuron_index())

                logical_neuron = item.logical_neuron()
                if pop.celltype == pynn.SpikeSourceArray:
                    self.assertTrue(logical_neuron.is_external())
                    self.assertIsNone(item.neuron_block())
                else:
                    self.assertFalse(logical_neuron.is_external())
                    self.assertIsNotNone(item.neuron_block())
                    self.assertEqual(neuron_size, logical_neuron.size())

                # Every placed population should have an address.
                self.assertIsNotNone(item.dnc_merger())
                address = item.address()
                self.assertIsNotNone(address)
예제 #10
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)))
예제 #11
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)
    def test_cluster_target(self):
        marocco = self.marocco

        user_strat = placer()
        user_strat.m_spiral_center = user_strat.spiral_neighbours_target
        marocco.neuron_placement.default_placement_strategy(user_strat)

        pynn.setup(marocco=marocco)

        pops = {}
        pops[0] = pynn.Population(1, pynn.IF_cond_exp, {})
        pops[1] = pynn.Population(1, pynn.IF_cond_exp, {})
        pops[2] = pynn.Population(1, pynn.IF_cond_exp, {})

        proj1 = pynn.Projection(pops[0], pops[1],
                                pynn.AllToAllConnector(weights=0.01))
        proj2 = pynn.Projection(pops[1], pops[2],
                                pynn.AllToAllConnector(weights=0.01))

        h = {}
        h[pops[0]] = C.HICANNOnWafer(Enum(100))
        # average positon of target
        h[pops[1]] = C.HICANNOnWafer(Enum(102))
        h[pops[2]] = C.HICANNOnWafer(Enum(102))
        marocco.manual_placement.on_hicann(pops[0], h[pops[0]])
        marocco.manual_placement.on_hicann(pops[2], h[pops[2]])

        pynn.run(0)
        pynn.end()

        result = self.load_results()
        for key in pops:
            pop = pops[key]
            for nrn in pop:
                placement_item, = result.placement.find(nrn)
                logical_neuron = placement_item.logical_neuron()
                for denmem in logical_neuron:
                    self.assertEqual(h[pop].toEnum(),
                                     denmem.toHICANNOnWafer().toEnum())
예제 #14
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)
예제 #15
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())
    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)
예제 #17
0
    def setUp(self):
        super(TrivialNetworkFixture, self).setUp()

        target = sim.Population(1, sim.EIF_cond_exp_isfa_ista)
        source = sim.Population(1, sim.EIF_cond_exp_isfa_ista)

        self.chip = HICANNGlobal(Enum(3))
        self.marocco.manual_placement.on_hicann(target, self.chip)
        self.marocco.manual_placement.on_hicann(source, self.chip)
        self.marocco.continue_despite_synapse_loss = True

        connector = sim.AllToAllConnector(allow_self_connections=True,
                                          weights=1.)
        sim.Projection(source, target, connector, target='excitatory')

        self.synapses = 1
    def network(self):
        pylogging.set_loglevel(pylogging.get("marocco"),
                               pylogging.LogLevel.TRACE)
        pylogging.set_loglevel(pylogging.get("Calibtic"),
                               pylogging.LogLevel.ERROR)

        self.pops = []
        for i in range(10):
            pop = pynn.Population(1, pynn.IF_cond_exp, {})
            self.pops.append(pop)
            if (i > 1):
                proj = pynn.Projection(self.pops[i - 1], self.pops[i],
                                       pynn.AllToAllConnector(weights=0.01))
                proj  # prevent pep8 warning
        pynn.run(0)
        pynn.end()
예제 #19
0
    def test_TwoNeuron(self):
        if True:
            pynn.setup(marocco=self.marocco)

            # create neuron with v_rest below v_thresh
            target = pynn.Population(1, pynn.EIF_cond_exp_isfa_ista)

            N = 16  # number of source populations
            NEURON_SIZE = 4  # default neuron size

            self.marocco.neuron_placement.default_neuron_size(NEURON_SIZE)

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

            # place target on HICANN 0
            target_chip = self.chip(0)
            self.marocco.manual_placement.on_hicann(target, target_chip)

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

            for pop in p:
                proj = pynn.Projection(pop,
                                       target,
                                       connector,
                                       target='excitatory')

                # place source neuron
                target_chip = self.chip(1)
                self.marocco.manual_placement.on_hicann(pop, target_chip)

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

            # expected number of needed SynapseDrivers is given by the number
            # of source neurons divided by half the neuron size (half the
            # denmem is only reachable via the other synapse array) and divided
            # by two (two sources can connect via a single SynapseDriver).
            EXPECTED_NUM_SYNAPSEDRIVER = N / (NEURON_SIZE / 2) / 2
            print 'EXPECTED %d' % EXPECTED_NUM_SYNAPSEDRIVER

            # make sure we have no synapse loss
            self.assertEqual(0, self.marocco.stats.getSynapseLoss())
예제 #20
0
    def test_synapses(self):
        pynn.setup(marocco=self.marocco)

        target = pynn.Population(1, pynn.IF_cond_exp, {})
        source = pynn.Population(2, pynn.SpikeSourceArray,
                                 {'spike_times': [1.]})

        proj = pynn.Projection(source, target,
                               pynn.AllToAllConnector(weights=0.004))

        pynn.run(0)
        pynn.end()

        results = self.load_results()

        synapses = results.synapse_routing.synapses()
        self.assertEqual(2, synapses.size())
        self.assertEqual(2, len(list(synapses)))

        target_item, = results.placement.find(target[0])

        for neuron in source:
            # Return all synapses connecting the specified neurons.
            items = synapses.find(neuron, target[0])
            self.assertTrue(isinstance(items, list))
            self.assertEqual(1, len(items))
            self.assertIn(items[0].hardware_synapse().toNeuronOnWafer(),
                          list(target_item.logical_neuron()))

            # Should also work if we explicitly specify the projection.
            items = synapses.find(proj, neuron, target[0])
            self.assertTrue(isinstance(items, list))
            self.assertEqual(1, len(items))
            self.assertIn(items[0].hardware_synapse().toNeuronOnWafer(),
                          list(target_item.logical_neuron()))

            # There should be no results for the wrong direction.
            items = synapses.find(target[0], neuron)
            self.assertTrue(isinstance(items, list))
            self.assertEqual(0, len(items))

        # Return all synapses that represent the given projection.
        items = synapses.find(proj)
        self.assertTrue(isinstance(items, list))
        self.assertEqual(2, len(items))
    def run_placement(self):
        """
        create 10 populations with 1 neuron, connected in a chain
        """
        pylogging.set_loglevel(pylogging.get("marocco"),
                               pylogging.LogLevel.TRACE)
        pylogging.set_loglevel(pylogging.get("Calibtic"),
                               pylogging.LogLevel.ERROR)

        self.pops = []
        for i in range(10):
            pop = pynn.Population(1, pynn.IF_cond_exp, {})
            self.pops.append(pop)
            if (i > 1):
                proj = pynn.Projection(self.pops[i - 1], self.pops[i],
                                       pynn.AllToAllConnector(weights=0.01))
                proj  # prevent pep8 warning
        pynn.run(0)
        pynn.end()
예제 #22
0
    def test_ManualPlacement(self):
        marocco = PyMarocco()

        N = 10

        pops = []
        for ii in range(N):
            p = pynn.Population(random.randint(1, 10), pynn.EIF_cond_exp_isfa_ista)
            marocco.manual_placement.on_hicann(p, HICANNOnWafer())
            pops.append(p)

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

        proj = pynn.Projection(pops[0], pops[1], connector, target='excitatory')

        with self.assertRaises(exceptions.IndexError) as e:
            marocco.stats.getWeights(proj)
예제 #23
0
    def test_dijkstra_routing(self):
        """
        Integration test for Dijkstra-based L1 routing.

        Sets up a convoluted case that requires a convex route (which would
        not work using the backbone router).

         .------->------+
        167 168 169 170 |
                    206 v
            240 241 242 |
             ^---<------+
        """
        pynn.setup(marocco=self.marocco)

        source = pynn.Population(1, pynn.IF_cond_exp, {})
        target = pynn.Population(1, pynn.IF_cond_exp, {})
        proj = pynn.Projection(
            source, target, pynn.AllToAllConnector(weights=0.004))

        source_hicann = C.HICANNOnWafer(Enum(167))
        target_hicann = C.HICANNOnWafer(Enum(240))
        self.marocco.manual_placement.on_hicann(source, source_hicann)
        self.marocco.manual_placement.on_hicann(target, target_hicann)

        allowed_hicanns = [206] + list(range(167, 171)) + list(range(240, 243))
        wafer = self.marocco.default_wafer
        self.marocco.defects.set(pyredman.Wafer())
        for hicann in C.iter_all(C.HICANNOnWafer):
            if hicann.toEnum().value() in allowed_hicanns:
                continue
            self.marocco.defects.wafer().hicanns().disable(C.HICANNGlobal(hicann, wafer))

        self.marocco.l1_routing.algorithm(self.marocco.l1_routing.dijkstra)

        pynn.run(0)
        pynn.end()

        results = self.load_results()

        synapses = results.synapse_routing.synapses()
        self.assertEqual(1, synapses.size())
예제 #24
0
    def build(self):

        # Set the neurons
        self.neurons = pynn.Population(self.N, self.model)

        # in the fully visible BM there each neuron projects to each neuron
        # 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.neurons,
                        self.neurons,
                        connector,
                        target='excitatory')
        pynn.Projection(self.neurons,
                        self.neurons,
                        connector,
                        target='inhibitory')
예제 #25
0
    def build(self):
        weights = self._create_nn_unit_weights(self.linearsize, self.dimension)

        self.neurons = [
            pynn.Population(1, self.model)
            for _ in range(self.linearsize**self.dimension)
        ]
        self.exsources = pynn.Population(self.nsources,
                                         pynn.SpikeSourcePoisson,
                                         {'rate': self.sourcerate})
        self.insources = pynn.Population(self.nsources,
                                         pynn.SpikeSourcePoisson,
                                         {'rate': self.sourcerate})
        self.biasneurons = pynn.Population(self.nbiasneurons, self.model)

        connector = pynn.FixedNumberPreConnector(n=self.ksources, weights=0.3)
        proj = pynn.Projection(self.exsources,
                               self.neurons,
                               connector,
                               target='excitatory',
                               rng=pynn.NativeRNG(42))
        proj = pynn.Projection(self.exsources,
                               self.neurons,
                               connector,
                               target='inhibitory',
                               rng=pynn.NativeRNG(42))

        connector = pynn.FixedNumberPreConnector(n=self.nbiasneurons,
                                                 weights=0.4)
        proj = pynn.Projection(self.biasneurons,
                               self.neurons,
                               connector,
                               target='inhibitory',
                               rng=pynn.NativeRNG(42))

        for ipre, ipost, w in weights:
            connector = pynn.AllToAllConnector(weights=1)
            proj = pynn.Projection(self.neurons[ipre],
                                   self.neurons[ipost],
                                   connector,
                                   target="excitatory")
예제 #26
0
    def build(self):
        weights = self._create_nn_unit_weights(self.linearsize, self.dimension)

        self.neurons = [
            pynn.Population(1, self.model)
            for _ in range(self.linearsize**self.dimension)
        ]
        self.noise = pynn.Population(self.nsources, pynn.IF_cond_exp)
        self.biasneurons = pynn.Population(self.nbiasneurons, self.model)

        connector = pynn.FixedNumberPreConnector(n=30,
                                                 weights=0.3,
                                                 allow_self_connections=False)
        pynn.Projection(self.noise, self.noise, connector, target='inhibitory')

        connector = pynn.FixedNumberPreConnector(n=self.ksources, weights=0.3)
        pynn.Projection(self.noise,
                        self.neurons,
                        connector,
                        target='excitatory',
                        rng=pynn.NativeRNG(42))
        pynn.Projection(self.noise,
                        self.neurons,
                        connector,
                        target='inhibitory',
                        rng=pynn.NativeRNG(43))

        connector = pynn.FixedNumberPreConnector(n=self.kbiasneurons,
                                                 weights=0.4)
        pynn.Projection(self.biasneurons,
                        self.neurons,
                        connector,
                        target='inhibitory',
                        rng=pynn.NativeRNG(44))

        for ipre, ipost, w in weights:
            connector = pynn.AllToAllConnector(weights=1)
            pynn.Projection(self.neurons[ipre],
                            self.neurons[ipost],
                            connector,
                            target="excitatory")
    def test_external_sources_rates(self, nsources):
        """
            A lot external sources are placed
            no error should be thrown
        """
        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)

        # ignore the synapse driver chain length.
        self.marocco.synapse_routing.driver_chain_length(100)

        # we expect synapse loss, but we dont care.
        # 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.})
        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()

        self.assertEqual(nsources, synapses.size())
예제 #28
0
    def test_projection(self):

        path = tempfile.mkstemp()[1]

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

        dist = pyhmf.RandomDistribution(rng=pyhmf.NativeRNG(1337))

        conn_pyhmf = pyhmf.AllToAllConnector(weights=dist, delays=42)
        proj_pyhmf = pyhmf.Projection(
                pyhmf.Population(size_a, pyhmf.IF_cond_exp),
                pyhmf.Population(size_b, pyhmf.IF_cond_exp),
                conn_pyhmf)
        
        proj_pyhmf.saveConnections(getattr(pyhmf, self.file_type)(path, 'w'))

        conn_pynn = pynn.FromFileConnector(getattr(pynn.recording.files, self.file_type)(path))
        proj_pynn = pynn.Projection(
                pynn.Population(size_a, pynn.IF_cond_exp),
                pynn.Population(size_b, pynn.IF_cond_exp),
                conn_pynn)

        numpy.testing.assert_equal(proj_pyhmf.getWeights(format='array'), proj_pynn.getWeights(format='array'))
예제 #29
0
        for r, c, w, d in l:
            start_w[pre, post * n_per_mid + c] = w

        print(pre, ' to ', post, 'conns = ', len(l))
        conn_lists.append(l)
        prj = sim.Projection(in_pops[pre], mid_pops[post], 
                sim.FromListConnector(l), target='excitatory')
        p.append(prj)
    projs.append(p)


exc_wta_proj = []
inh_wta_proj = []
for idx in range(n_mid):
    proj = sim.Projection(mid_pops[idx], inh_mid_pop, 
                            sim.AllToAllConnector(), target='excitatory')
    exc_wta_proj.append(proj)

    proj = sim.Projection(inh_mid_pop, mid_pops[idx], 
                            sim.AllToAllConnector(), target='inhibitory')
    inh_wta_proj.append(proj)


# import sys
# sys.exit(0)

### ====================== PERFORM MAPPING =========================== ###
seed = 0
marocco.l1_routing.shuffle_switches_seed(seed)

marocco.skip_mapping = False
marocco = PyMarocco()
marocco.default_wafer = Wafer(int(os.environ.get("WAFER", 33)))
runtime = Runtime(marocco.default_wafer)
pynn.setup(marocco=marocco, marocco_runtime=runtime)

#  ——— set up network ——————————————————————————————————————————————————————————

pop = pynn.Population(1, pynn.IF_cond_exp, neuron_parameters)

pop.record()
pop.record_v()

hicann = HICANNOnWafer(Enum(297))
marocco.manual_placement.on_hicann(pop, hicann)

connector = pynn.AllToAllConnector(weights=1)

exc_spike_times = [
    250,
    500,
    520,
    540,
    1250,
]

inh_spike_times = [
    750,
    1000,
    1020,
    1040,
    1250,