Example #1
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)
def default_marocco():
    marocco = pymarocco.PyMarocco()
    marocco.neuron_placement.default_neuron_size(4)
    marocco.synapse_routing.driver_chain_length(C.SynapseDriverOnQuadrant.size)
    marocco.experiment.speedup(10000.)
    marocco.defects.backend = pymarocco.Defects.Backend.Without

    return marocco
Example #3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--prob', default=0.1, type=float)
    parser.add_argument('--N',  default=5000, type=int)

    args = parser.parse_args()

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

    start = datetime.now()
    r = RandomNetwork(args.N, args.prob, marocco)
    r.build()
    mid = datetime.now()
    r.run()
    end = datetime.now()

    result = {
        "model" : "random_network",
        "task" : "N{}_p{}".format(args.N, args.prob),
        "timestamp" : datetime.now().isoformat(),
        "results" : [
            {"type" : "performance",
             "name" : "setup_time",
             "value" : (end-mid).total_seconds(),
             "units" : "s",
             "measure" : "time"
         },
            {"type" : "performance",
             "name" : "total_time",
             "value" : (end-start).total_seconds(),
             "units" : "s",
             "measure" : "time"
         },
            {"type" : "performance",
             "name" : "synapses",
             "value" : marocco.stats.getSynapses()
         },
            {"type" : "performance",
             "name" : "neurons",
             "value" : marocco.stats.getNumNeurons()
         },
            {"type" : "performance",
             "name" : "synapse_loss",
             "value" : marocco.stats.getSynapseLoss()
         },
            {"type" : "performance",
             "name" : "synapse_loss_after_l1",
             "value" : marocco.stats.getSynapseLossAfterL1Routing()
         }
        ]
    }

    with open("random_N{}_p{}_results.json".format(args.N, args.prob), 'w') as outfile:
        json.dump(result, outfile)
def ESS_available():
    try:
        marocco = pymarocco.PyMarocco()
        marocco.backend = pymarocco.PyMarocco.ESS
        pynn.setup(marocco=marocco)
        pynn.run(1.)
        return True
    except RuntimeError as err:
        if str(err) == "ESS not available (compile with ESS)":
            return False
        else:
            raise err
Example #5
0
    def setUp(self):
        init_logger("INFO", [
            ("marocco", "DEBUG"),
        ])

        self.log = pylogging.get(__name__)
        self.temporary_directory = tempfile.mkdtemp(prefix="marocco-test-")

        self.marocco = pymarocco.PyMarocco()
        self.marocco.backend = pymarocco.PyMarocco.Without
        self.marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default
        self.marocco.defects.backend = pymarocco.Defects.Backend.Without
        self.marocco.persist = os.path.join(self.temporary_directory,
                                            "results.bin")
Example #6
0
    def setUp(self):
        pylogging.reset()
        pylogging.default_config(pylogging.LogLevel.ERROR)
        pylogging.set_loglevel(
            pylogging.get("marocco"), pylogging.LogLevel.INFO)

        self.log = pylogging.get(__name__)
        self.temporary_directory = tempfile.mkdtemp(prefix="marocco-test-")

        self.marocco = pymarocco.PyMarocco()
        self.marocco.backend = pymarocco.PyMarocco.None
        self.marocco.persist = os.path.join(
            self.temporary_directory, "results.bin")
        self.marocco.neuron_placement.default_neuron_size(4)
Example #7
0
    def setUp(self):
        init_logger("INFO", [
            ("marocco", "DEBUG"),
        ])

        self.log = pylogging.get(__name__)
        self.temporary_directory = tempfile.mkdtemp(prefix="marocco-test-")

        self.marocco = pymarocco.PyMarocco()
        self.marocco.backend = pymarocco.PyMarocco.None
        self.marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default
        self.marocco.defects.backend = pymarocco.Defects.Backend.None
        self.marocco.neuron_placement.skip_hicanns_without_neuron_blacklisting(
            False)
        self.marocco.persist = os.path.join(self.temporary_directory,
                                            "results.bin")
Example #8
0
    def test_Addition(self):
        import pymarocco

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

        pynn.setup(marocco=marocco)

        p1 = pynn.Population(100, pynn.IF_cond_exp)
        p2 = pynn.Population(100, pynn.IF_cond_exp)

        p = p1 + p2

        self.assertEqual(len(p), len(p1) + len(p2))

        pynn.run(1000)
    def setUp(self):
        pylogging.reset()
        pylogging.default_config(pylogging.LogLevel.ERROR)
        pylogging.set_loglevel(pylogging.get("marocco"),
                               pylogging.LogLevel.INFO)

        self.log = pylogging.get(__name__)
        self.temporary_directory = tempfile.mkdtemp(prefix="marocco-test-")

        self.marocco = pymarocco.PyMarocco()
        self.marocco.backend = pymarocco.PyMarocco.Without
        self.marocco.persist = os.path.join(self.temporary_directory,
                                            "results.bin")
        self.marocco.neuron_placement.default_neuron_size(4)
        self.marocco.continue_despite_synapse_loss = True
        self.marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default
        self.marocco.defects.backend = pymarocco.Defects.Backend.Without
Example #10
0
def ESS_available():
    try:
        import pymarocco
        marocco = pymarocco.PyMarocco()
        marocco.backend = pymarocco.PyMarocco.ESS
        marocco.continue_despite_synapse_loss = True
        marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default
        marocco.defects.backend = pymarocco.Defects.Backend.Without
        marocco.hicann_configurator = pysthal.HICANNConfigurator()

        pynn.setup(marocco=marocco)
        pynn.run(1.)
        return True
    except RuntimeError as err:
        if str(err) == "ESS not available (compile with ESS)":
            return False
        else:
            raise err
Example #11
0
    def test_FromListConnector(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
        pop = pynn.Population(N, model)

        connlist = [(0, 1, 0.1, 0.1), (0, 2, 0.1, 0.1), (0, 3, 0.1, 0.1)]
        connector_e = pynn.FromListConnector(connlist)
        proj_e = pynn.Projection(pop, pop, connector_e, target='excitatory')

        pynn.run(100)
Example #12
0
    def test_Constructor(self):
        import pymarocco

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

        pynn.setup(marocco=marocco)

        NPOP = 100
        popus = [
            pynn.Population(random.randint(10, 100), pynn.IF_cond_exp)
            for x in range(0, NPOP)
        ]
        a = pynn.Assembly(*popus)

        size = sum([len(p) for p in popus])
        self.assertEqual(len(a), size)

        pynn.run(1000)
    def runTest(self):
        pylogging.reset()
        pylogging.default_config(pylogging.LogLevel.INFO)

        marocco = pymarocco.PyMarocco()
        marocco.neuron_placement.default_neuron_size(8)
        marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default
        marocco.defects.backend = pymarocco.Defects.Backend.Without
        marocco.hicann_configurator = pysthal.HICANNConfigurator()
        marocco.continue_despite_synapse_loss = True
        marocco.backend = pymarocco.PyMarocco.ESS
        marocco.experiment_time_offset = 5e-7

        n_exc = 100  # Number of excitatory neurons per group

        sim_duration = 200.

        pp_start = 50.  # start = center of pulse-packet

        weight_exc = 0.002  # uS weight for excitatory to excitatory connections
        # (double than in reference paper)

        pynn.setup(
            max_delay=20.,
            marocco=marocco,
        )

        # v_thresh close to v_rest to make sure there are some spikes
        neuron_params = {
            'v_rest': -65.,
            'v_thresh': -62.5,
        }

        exc_pop = pynn.Population(n_exc, pynn.IF_cond_exp, neuron_params)
        exc_pop.record()
        pop_stim = pynn.Population(n_exc, pynn.SpikeSourceArray,
                                   {'spike_times': [pp_start]})
        conn = pynn.FixedNumberPreConnector(60, weights=weight_exc, delays=20.)
        pynn.Projection(pop_stim, exc_pop, conn, target='excitatory')

        pynn.run(sim_duration)
        pynn.end()
Example #14
0
def ESS_available():
    try:
        import pymarocco
        marocco = pymarocco.PyMarocco()
        marocco.backend = pymarocco.PyMarocco.ESS
        marocco.neuron_placement.skip_hicanns_without_neuron_blacklisting(
            False)
        marocco.continue_despite_synapse_loss = True
        marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default
        marocco.defects.backend = pymarocco.Defects.Backend.None
        marocco.hicann_configurator = pymarocco.PyMarocco.HICANNConfigurator

        pynn.setup(marocco=marocco)
        pynn.run(1.)
        return True
    except RuntimeError as err:
        if err.message == "ESS not available (compile with ESS)":
            return False
        else:
            raise err
Example #15
0
    def test_cell_ids(self):
        """
        tests that [Population,PopulationView,Assembly].getSpikes() uses the
        expected cell ids, cf. issue #1955
        """

        import pymarocco

        marocco = pymarocco.PyMarocco()
        marocco.backend = pymarocco.PyMarocco.ESS
        marocco.experiment_time_offset = 5.e-7
        marocco.neuron_placement.skip_hicanns_without_neuron_blacklisting(
            False)
        marocco.continue_despite_synapse_loss = True
        marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default
        marocco.defects.backend = pymarocco.Defects.Backend.None
        marocco.hicann_configurator = pymarocco.PyMarocco.HICANNConfigurator

        setup_params = dict()
        if pynn.__name__ == "pyhmf":
            setup_params['marocco'] = marocco

        pynn.setup(**setup_params)

        # dummy target population
        p_dummy = pynn.Population(10, pynn.IF_cond_exp)

        # 1st Input Population
        p1 = pynn.Population(10, pynn.SpikeSourceArray)
        input_spikes1 = np.arange(1, 11., 1.).reshape(10, 1)
        for n, spikes in enumerate(input_spikes1):
            p1[n:n + 1].set('spike_times', spikes.tolist())

        # 2nd Input Population
        p2 = pynn.Population(10, pynn.SpikeSourceArray)
        input_spikes2 = np.arange(11., 21., 1.).reshape(10, 1)
        for n, spikes in enumerate(input_spikes2):
            p2[n:n + 1].set('spike_times', spikes.tolist())

        p1.record()
        p2.record()

        # dummy connections otherwise input populations are not mapped.
        pynn.Projection(p1, p_dummy, pynn.OneToOneConnector())
        pynn.Projection(p2, p_dummy, pynn.OneToOneConnector())

        pynn.run(25.)

        # check that cell ids refer to the index in the Population.
        s_p1 = p1.getSpikes()
        s_p1 = s_p1[np.argsort(s_p1[:, 1])]  # sort by time
        self.assertTrue(np.array_equal(range(10), s_p1[:, 0]))

        s_p2 = p2.getSpikes()
        s_p2 = s_p2[np.argsort(s_p2[:, 1])]  # sort by time
        self.assertTrue(np.array_equal(range(10), s_p2[:, 0]))

        # for PopulationViews we also expect the index in the parent Population
        self.assertEqual(set(p2[0:1].getSpikes()[:, 0]), set(range(1)))
        self.assertEqual(set(p2[1:3].getSpikes()[:, 0]), set(range(1, 3)))

        # In Assemblies, the cell id is equal to an offset given by the sum of
        # the Population sizes of the previous items (Population or
        # PopulationView), plus the index within in the Population.
        a = pynn.Assembly(p2[0:5], p1)
        s_a = a.getSpikes()
        # when sorted, ids should be: range(10,20) + range(5)
        s_a = s_a[np.argsort(s_a[:, 1])]  # sort by time
        self.assertTrue(np.array_equal(range(10, 20) + range(5), s_a[:, 0]))
 def setUp(self, backend=pymarocco.PyMarocco.Without):
     self.marocco = pymarocco.PyMarocco()
     self.marocco.backend = backend
Example #17
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--linearsize', '-l', default=5, type=int)
    parser.add_argument('--dimension', '-d', type=int, default=2)
    parser.add_argument('--nbiasneurons', '-b', type=int, default=1)
    parser.add_argument('--nsources', '-n', type=int, default=20)
    parser.add_argument('--ksources', '-k', type=int, default=5)
    parser.add_argument('--sourcerate', '-r', type=float, default=20.)
    parser.add_argument('--duplicates', '-p', type=int, default=1)
    parser.add_argument('--wafer', '-w', type=int, default=33)
    parser.add_argument('--shuffle_switches',
                        dest='shuffle_switches',
                        type=lambda x: bool(distutils.util.strtobool(x)),
                        default='false')
    parser.add_argument('--name', type=str, default='ising_network')

    args = parser.parse_args()

    taskname = "l{}_d{}_b{}_n{}_k{}_p{}_w{}_s{}".format(
        args.linearsize, args.dimension, args.nbiasneurons, args.nsources,
        args.ksources, args.duplicates, args.wafer, args.shuffle_switches)

    marocco = pymarocco.PyMarocco()
    marocco.continue_despite_synapse_loss = True
    marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default
    marocco.default_wafer = C.Wafer(args.wafer)
    marocco.calib_path = "/wang/data/calibration/brainscales/default"
    marocco.defects_path = "/wang/data/calibration/brainscales/default"
    marocco.l1_routing.shuffle_switches(args.shuffle_switches)
    marocco.persist = "results_{}_{}.xml.gz".format(args.name, taskname)

    start = datetime.now()
    r = IsingNetwork(marocco,
                     linearsize=args.linearsize,
                     dimension=args.dimension,
                     nbiasneurons=args.nbiasneurons,
                     nsources=args.nsources,
                     ksources=args.ksources,
                     sourcerate=args.sourcerate,
                     duplicates=args.duplicates)
    r.build()
    mid = datetime.now()
    try:
        r.run()
        totsynapses = marocco.stats.getSynapses()
        totneurons = marocco.stats.getNumNeurons()
        lostsynapses = marocco.stats.getSynapseLoss()
        lostsynapsesl1 = marocco.stats.getSynapseLossAfterL1Routing()
    except RuntimeError:
        # couldn't place all populations
        totsynapses = 1
        totneurons = 1
        lostsynapses = 1
        lostsynapsesl1 = 1
    end = datetime.now()

    result = {
        "model":
        args.name,
        "task":
        taskname,
        "timestamp":
        datetime.now().isoformat(),
        "results": [{
            "type": "performance",
            "name": "setup_time",
            "value": (end - mid).total_seconds(),
            "units": "s",
            "measure": "time"
        }, {
            "type": "performance",
            "name": "total_time",
            "value": (end - start).total_seconds(),
            "units": "s",
            "measure": "time"
        }, {
            "type": "performance",
            "name": "synapses",
            "value": totsynapses
        }, {
            "type": "performance",
            "name": "neurons",
            "value": totneurons
        }, {
            "type": "performance",
            "name": "synapse_loss",
            "value": lostsynapses
        }, {
            "type": "performance",
            "name": "synapse_loss_after_l1",
            "value": lostsynapsesl1
        }]
    }

    with open("{}_{}_results.json".format(result["model"], result["task"]),
              'w') as outfile:
        json.dump(result, outfile)
Example #18
0
    def test_basic(self):
        """
        tests whether synapses with short term plasticity are routed correctly.

        Build a minimal network with 1 neuron and 3 spike sources each
        connecting to with a different STP setting (depression, facilitation,
        static) to the neuron.
        Then check that the 3 synapses are routed via 3 different synaspe
        drivers and that STP mode of the synapse drivers is as expected.
        """
        marocco = pymarocco.PyMarocco()
        marocco.backend = pymarocco.PyMarocco.None
        marocco.neuron_placement.default_neuron_size(4)
        marocco.wafer_cfg = os.path.join(self.temporary_directory, "wafer.bin")
        marocco.persist = os.path.join(self.temporary_directory, "results.bin")
        used_hicann = HICANNGlobal(Enum(0))

        pynn.setup(marocco=marocco)

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

        # place to a certain HICANN to be able to extract config data afterwards
        marocco.manual_placement.on_hicann(p1, used_hicann)

        s1 = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 5.})
        s2 = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 5.})
        s3 = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 5.})

        depression = pynn.SynapseDynamics(fast=pynn.TsodyksMarkramMechanism(
            U=0.4, tau_rec=200., tau_facil=0.))
        facilitation = pynn.SynapseDynamics(fast=pynn.TsodyksMarkramMechanism(
            U=0.4, tau_rec=0., tau_facil=200.))
        static = None
        prj1 = pynn.Projection(s1,
                               p1,
                               pynn.OneToOneConnector(weights=0.05),
                               synapse_dynamics=depression,
                               target="excitatory")
        prj2 = pynn.Projection(s2,
                               p1,
                               pynn.OneToOneConnector(weights=0.05),
                               synapse_dynamics=facilitation,
                               target="excitatory")
        prj3 = pynn.Projection(s3,
                               p1,
                               pynn.OneToOneConnector(weights=0.05),
                               synapse_dynamics=static,
                               target="excitatory")

        p1.record()

        pynn.run(1.)

        h = debug_config.load_hicann_cfg(marocco.wafer_cfg, used_hicann)

        # There should be 3 active drivers with 3 different STP modes
        drivers = {}
        num_active_drivers = 0
        for driver in iter_all(SynapseDriverOnHICANN):
            drv_cfg = h.synapses[driver]
            if drv_cfg.is_enabled():
                num_active_drivers += 1
                if drv_cfg.is_stf():
                    drivers['facilitation'] = driver
                elif drv_cfg.is_std():
                    drivers['depression'] = driver
                else:
                    drivers['static'] = driver

        self.assertEqual(num_active_drivers, 3)
        self.assertEqual(len(drivers), 3)

        results = Marocco.from_file(marocco.persist)
        # check that synapses are on the drivers with the correct mode
        for src, mode in [(s1, 'depression'), (s2, 'facilitation'),
                          (s3, 'static')]:
            items = list(results.placement.find(src[0]))
            self.assertEqual(1, len(items))
            item = items[0]
            addr = item.address().toL1Address()
            syns = debug_config.find_synapses(h.synapses, drivers[mode], addr)
            self.assertEqual(len(syns),
                             1)  # the addr of the source should be found once
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--prob', default=0.1, type=float)
    parser.add_argument('--N', default=5000, type=int)
    parser.add_argument('--name', default="random_network", type=str)
    parser.add_argument('--defects_path', type=str)
    parser.add_argument('--wafer', '-w', type=int, default=24)

    args = parser.parse_args()

    taskname = "N{}_p{}_wafer{}".format(args.N, args.prob, args.wafer)

    marocco = pymarocco.PyMarocco()
    marocco.continue_despite_synapse_loss = True
    marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default
    marocco.calib_path = "/wang/data/calibration/brainscales/default"
    marocco.default_wafer = C.Wafer(args.wafer)
    marocco.defects.backend = Defects.Backend.XML

    if args.defects_path:
        marocco.defects.path = args.defects_path
    else:
        marocco.defects.path = "/wang/data/commissioning/BSS-1/rackplace/" + str(
            args.wafer) + "/derived_plus_calib_blacklisting/current"

    marocco.persist = "results_{}_{}.xml.gz".format(args.name, taskname)

    start = datetime.now()
    r = RandomNetwork(args.N, args.prob, marocco)
    r.build()
    mid = datetime.now()
    try:
        r.run()
        totsynapses = marocco.stats.getSynapses()
        totneurons = marocco.stats.getNumNeurons()
        lostsynapses = marocco.stats.getSynapseLoss()
        lostsynapsesl1 = marocco.stats.getSynapseLossAfterL1Routing()
    except RuntimeError:
        # couldn't place all populations
        totsynapses = 1
        totneurons = 1
        lostsynapses = 1
        lostsynapsesl1 = 1

    end = datetime.now()

    result = {
        "model": args.name,
        "task": taskname,
        "timestamp": datetime.now().isoformat(),
        "results": [
            {"type": "performance",
             "name": "setup_time",
             "value": (end - mid).total_seconds(),
             "units": "s",
             "measure": "time"
             },
            {"type": "performance",
             "name": "total_time",
             "value": (end - start).total_seconds(),
             "units": "s",
             "measure": "time"
             },
            {"type": "performance",
             "name": "synapses",
             "value": totsynapses
             },
            {"type": "performance",
             "name": "neurons",
             "value": totneurons
             },
            {"type": "performance",
             "name": "synapse_loss",
             "value": lostsynapses
             },
            {"type": "performance",
             "name": "synapse_loss_after_l1",
             "value": lostsynapsesl1
             }
        ]
    }

    with open("{}_{}_results.json".format(result["model"], result["task"]),
              'w') as outfile:
        json.dump(result, outfile)
Example #20
0
 def setUp(self, backend=pymarocco.PyMarocco.None):
     self.marocco = pymarocco.PyMarocco()
     self.marocco.backend = backend
Example #21
0
    def test_basic(self):
        """
        tests the routing and parameter trafo of a IF_multicond_exp neuron
        with 4 different synaptic input settings.

        For 4 synaptic targets and hardware neuron size 4, the mapping of
        synapse types is as follows:
        Denmem:       | 0 | 1 |
        Synapse Type: |0 1|2 3| (left and right input)

        Build a minimal network with 1 neuron and 4 spike sources each
        connecting to different synaptic target on the neuron. Then check that
        the configuration of the synapse driver and synapses is as expected.
        Furthermore, check that the different parameters for e_rev and tau_syn
        are correctly transformed by getting the FG values (qualitatively).
        """
        marocco = pymarocco.PyMarocco()
        marocco.backend = pymarocco.PyMarocco.Without
        marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default
        marocco.defects.backend = pymarocco.Defects.Backend.Without

        marocco.neuron_placement.default_neuron_size(4)
        marocco.wafer_cfg = os.path.join(self.temporary_directory, "wafer.bin")
        marocco.persist = os.path.join(self.temporary_directory, "results.bin")
        used_hicann = HICANNGlobal(Enum(0))

        pynn.setup(marocco=marocco)
        p1 = pynn.Population(1, pynn.IF_multicond_exp)
        # we use 4 different time constants and reversal potentials
        p1.set('e_rev', [0., -10, -80, -100])
        p1.set('tau_syn', [2, 3, 4, 5])

        # place to a certain HICANN to be able to extract config data afterwards
        topleft = NeuronOnWafer(NeuronOnHICANN(X(0), Y(0)), used_hicann)
        logical_neuron = LogicalNeuron.rectangular(topleft, size=4)
        marocco.manual_placement.on_neuron(p1, logical_neuron)

        s1 = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 5.})
        s2 = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 5.})
        s3 = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 5.})
        s4 = pynn.Population(1, pynn.SpikeSourcePoisson, {'rate': 5.})

        prj1 = pynn.Projection(s1,
                               p1,
                               pynn.OneToOneConnector(weights=0.01),
                               target="0")
        prj2 = pynn.Projection(s2,
                               p1,
                               pynn.OneToOneConnector(weights=0.01),
                               target="1")
        prj3 = pynn.Projection(s3,
                               p1,
                               pynn.OneToOneConnector(weights=0.01),
                               target="2")
        prj4 = pynn.Projection(s4,
                               p1,
                               pynn.OneToOneConnector(weights=0.01),
                               target="3")

        p1.record()

        pynn.run(1.)

        h = debug_config.load_hicann_cfg(marocco.wafer_cfg, used_hicann)

        # routing config
        active_drivers = []
        driver_c = None
        for driver in iter_all(SynapseDriverOnHICANN):
            drv_cfg = h.synapses[driver]
            if drv_cfg.is_enabled():
                active_drivers.append(drv_cfg)
                driver_c = driver
        assert len(active_drivers) == 1
        act_drv = active_drivers[0]

        # two different synaptic input sides are used on the synapse driver
        syn_input_top = debug_config.get_syn_in_side(
            act_drv[RowOnSynapseDriver(top)])
        syn_input_bot = debug_config.get_syn_in_side(
            act_drv[RowOnSynapseDriver(bottom)])
        self.assertNotEqual(syn_input_top, syn_input_bot)

        # assumed column and input side:
        exptected_mapping = [(s1, SynapseColumnOnHICANN(0), left),
                             (s2, SynapseColumnOnHICANN(0), right),
                             (s3, SynapseColumnOnHICANN(1), left),
                             (s4, SynapseColumnOnHICANN(1), right)]

        results = Marocco.from_file(marocco.persist)
        for (src, col, side) in exptected_mapping:
            items = list(results.placement.find(src[0]))
            self.assertEqual(1, len(items))
            item = items[0]
            addr = item.address().toL1Address()
            syns = debug_config.find_synapses(h.synapses, driver_c, addr)
            self.assertEqual(1, len(syns))
            syn = syns[0]
            # check synapse column
            self.assertEqual(syn.toSynapseColumnOnHICANN(), col)
            # check synaptic input side
            row_addr = syn.toSynapseRowOnHICANN()
            self.assertEqual(
                debug_config.get_syn_in_side(
                    act_drv[row_addr.toRowOnSynapseDriver()]), side)

        # FG values
        nrn_left = NeuronOnHICANN(X(0), Y(0))
        nrn_right = NeuronOnHICANN(X(1), Y(0))
        fgs = h.floating_gates

        # e_rev params are montonic decreasing
        E1 = fgs.getNeuron(nrn_left, nrn_param.E_synx)
        E2 = fgs.getNeuron(nrn_left, nrn_param.E_syni)
        E3 = fgs.getNeuron(nrn_right, nrn_param.E_synx)
        E4 = fgs.getNeuron(nrn_right, nrn_param.E_syni)
        E = [E1, E2, E3, E4]
        for k, l in zip(E, E[1:]):
            self.assertGreater(k, l)

        # tau_syn params are montonic increasing
        T1 = fgs.getNeuron(nrn_left, nrn_param.V_syntcx)
        T2 = fgs.getNeuron(nrn_left, nrn_param.V_syntci)
        T3 = fgs.getNeuron(nrn_right, nrn_param.V_syntcx)
        T4 = fgs.getNeuron(nrn_right, nrn_param.V_syntci)
        T = [T1, T2, T3, T4]
        # HICANN V4: The lower the DAC-Value, the higher the time constant
        for k, l in zip(T, T[1:]):
            self.assertGreater(k, l)
Example #22
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--N',
                        default=10,
                        type=int,
                        help='Edge size of the visible layer. \
                        The number of neurons in the visible\
                        layer is hence NxN')
    parser.add_argument('--K',
                        default=8,
                        type=int,
                        help='Edge size of the local receptive fields.\
                        K has to be larger than N.')
    parser.add_argument('--L',
                        default=10,
                        type=int,
                        help='Number of neurons in the label layer.')
    parser.add_argument('--name', default="fullyVisibleBm_network", type=str)

    args = parser.parse_args()

    # The edge size of the visible layer has to be larger or equal
    # than the edge size of the receptive fields
    if args.N < args.K:
        sys.exit('The edge size of the visible layer {0}'
                 ' has to be larger than the edge size {1}'
                 ' of the local receptive '
                 ' fields!'.format(args.N, args.K))

    taskname = "N{}_K{}_L{}".format(args.N, args.K, args.L)

    marocco = pymarocco.PyMarocco()
    marocco.continue_despite_synapse_loss = True
    marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default
    marocco.calib_path = "/wang/data/calibration/brainscales/default"
    marocco.defects_path = "/wang/data/calibration/brainscales/default"
    marocco.persist = "results_{}_{}.xml.gz".format(args.name, taskname)

    start = datetime.now()
    r = rbmLocalReceptiveFieldsNetwork(args.N, args.K, args.L, marocco)
    r.build()
    mid = datetime.now()
    try:
        r.run()
        totsynapses = marocco.stats.getSynapses()
        totneurons = marocco.stats.getNumNeurons()
        lostsynapses = marocco.stats.getSynapseLoss()
        lostsynapsesl1 = marocco.stats.getSynapseLossAfterL1Routing()
    except RuntimeError:
        # couldn't place all populations
        totsynapses = 1
        totneurons = 1
        lostsynapses = 1
        lostsynapsesl1 = 1

    end = datetime.now()

    result = {
        "model":
        args.name,
        "task":
        taskname,
        "timestamp":
        datetime.now().isoformat(),
        "results": [{
            "type": "performance",
            "name": "setup_time",
            "value": (end - mid).total_seconds(),
            "units": "s",
            "measure": "time"
        }, {
            "type": "performance",
            "name": "total_time",
            "value": (end - start).total_seconds(),
            "units": "s",
            "measure": "time"
        }, {
            "type": "performance",
            "name": "synapses",
            "value": totsynapses
        }, {
            "type": "performance",
            "name": "neurons",
            "value": totneurons
        }, {
            "type": "performance",
            "name": "synapse_loss",
            "value": lostsynapses
        }, {
            "type": "performance",
            "name": "synapse_loss_after_l1",
            "value": lostsynapsesl1
        }]
    }

    with open("{}_{}_results.json".format(result["model"], result["task"]),
              'w') as outfile:
        json.dump(result, outfile)
Example #23
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--K', default=20, type=int)
    parser.add_argument('--N', default=500, type=int)
    parser.add_argument('--name', default="random_network", type=str)

    args = parser.parse_args()

    taskname = "N{}_K{}".format(args.N, args.K)

    marocco = pymarocco.PyMarocco()
    marocco.continue_despite_synapse_loss = True
    marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default
    marocco.calib_path = "/wang/data/calibration/brainscales/default"
    marocco.defects_path = "/wang/data/calibration/brainscales/default"
    marocco.persist = "results_{}_{}.xml.gz".format(args.name, taskname)

    start = datetime.now()
    r = pfeilsNoiseNetwork(args.N, args.K, marocco)
    r.build()
    mid = datetime.now()
    try:
        r.run()
        totsynapses = marocco.stats.getSynapses()
        totneurons = marocco.stats.getNumNeurons()
        lostsynapses = marocco.stats.getSynapseLoss()
        lostsynapsesl1 = marocco.stats.getSynapseLossAfterL1Routing()
    except RuntimeError:
        # couldn't place all populations
        totsynapses = 1
        totneurons = 1
        lostsynapses = 1
        lostsynapsesl1 = 1

    end = datetime.now()

    result = {
        "model":
        args.name,
        "task":
        taskname,
        "timestamp":
        datetime.now().isoformat(),
        "results": [{
            "type": "performance",
            "name": "setup_time",
            "value": (end - mid).total_seconds(),
            "units": "s",
            "measure": "time"
        }, {
            "type": "performance",
            "name": "total_time",
            "value": (end - start).total_seconds(),
            "units": "s",
            "measure": "time"
        }, {
            "type": "performance",
            "name": "synapses",
            "value": totsynapses
        }, {
            "type": "performance",
            "name": "neurons",
            "value": totneurons
        }, {
            "type": "performance",
            "name": "synapse_loss",
            "value": lostsynapses
        }, {
            "type": "performance",
            "name": "synapse_loss_after_l1",
            "value": lostsynapsesl1
        }]
    }

    with open("{}_{}_results.json".format(result["model"], result["task"]),
              'w') as outfile:
        json.dump(result, outfile)
Example #24
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--num_layers', default=2, type=int)
    parser.add_argument('--conn_prob', default=1., type=float)
    parser.add_argument('--neurons_per_layer', default=200, type=int)
    parser.add_argument('--name',
                        default="feedforward_layered_network",
                        type=str)

    args = parser.parse_args()

    taskname = "num_layers{}_neurons_per_layer{}_conn_prob{}".format(
        args.num_layers, args.neurons_per_layer, args.conn_prob)

    marocco = pymarocco.PyMarocco()
    marocco.continue_despite_synapse_loss = True
    marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default
    marocco.calib_path = "/wang/data/calibration/brainscales/default"
    marocco.defects_path = "/wang/data/calibration/brainscales/default"
    marocco.persist = "results_{}_{}.xml.gz".format(args.name, taskname)

    start = datetime.now()
    r = FeedforwardNetwork(args.num_layers, args.conn_prob,
                           args.neurons_per_layer, marocco)
    r.build()
    mid = datetime.now()
    try:
        r.run()
        totsynapses = marocco.stats.getSynapses()
        totneurons = marocco.stats.getNumNeurons()
        lostsynapses = marocco.stats.getSynapseLoss()
        lostsynapsesl1 = marocco.stats.getSynapseLossAfterL1Routing()
    except RuntimeError:
        # couldn't place all populations
        totsynapses = 1
        totneurons = 1
        lostsynapses = 1
        lostsynapsesl1 = 1

    end = datetime.now()

    result = {
        "model":
        args.name,
        "task":
        taskname,
        "timestamp":
        datetime.now().isoformat(),
        "results": [
            {
                "type": "performance",
                "name": "setup_time",
                "value": (end - mid).total_seconds(),
                "units": "s",
                "measure": "time"
            },
            {
                "type": "performance",
                "name": "total_time",
                "value": (end - start).total_seconds(),
                "units": "s",
                "measure": "time"
            },
            {
                "type": "performance",
                "name": "synapses",
                "value": totsynapses
            },
            {
                "type": "performance",
                "name": "neurons",
                "value": totneurons
            },
            {
                "type": "performance",
                "name": "synapse_loss",
                "value": lostsynapses
            },
            {
                "type": "performance",
                "name": "synapse_loss_after_l1",
                "value": lostsynapsesl1
            },
        ],
    }

    with open("{}_{}_results.json".format(result["model"], result["task"]),
              'w') as outfile:
        json.dump(result, outfile)

    print(
        "{}\n{}\nSynapses lost: {}; L1 synapses lost: {}; relative synapse lost: {}"
        .format(sys.argv, taskname, lostsynapses, lostsynapsesl1,
                float(lostsynapses) / totsynapses))
Example #25
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--N', default=5000, type=int,
                        help='The number of the neurons in the visible layer')
    parser.add_argument('--Nhidden', default=0, type=int,
                        help='The number of the neurons in the hidden layer. '
                             'If 0 or not specified then the number of hidden '
                             'neurons equals the number of visible neurons.')
    parser.add_argument('--name', default="fullyVisibleBm_network", type=str)

    args = parser.parse_args()

    # If the number of hidden neurons is not specified then it should be equal
    # to the number of visibel neurons
    if args.Nhidden == 0:
        args.Nhidden = args.N

    taskname = "Nvisible{}_Nhidden{}".format(args.N, args.Nhidden)

    marocco = pymarocco.PyMarocco()
    marocco.continue_despite_synapse_loss = True
    marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default
    marocco.calib_path = "/wang/data/calibration/brainscales/default"
    marocco.defects_path = "/wang/data/calibration/brainscales/default"
    marocco.persist = "results_{}_{}.xml.gz".format(args.name, taskname)

    start = datetime.now()
    r = rbmNetwork(args.N, args.Nhidden, marocco)
    r.build()
    mid = datetime.now()
    try:
        r.run()
        totsynapses = marocco.stats.getSynapses()
        totneurons = marocco.stats.getNumNeurons()
        lostsynapses = marocco.stats.getSynapseLoss()
        lostsynapsesl1 = marocco.stats.getSynapseLossAfterL1Routing()
    except RuntimeError:
        # couldn't place all populations
        totsynapses = 1
        totneurons = 1
        lostsynapses = 1
        lostsynapsesl1 = 1

    end = datetime.now()

    result = {
        "model": args.name,
        "task": taskname,
        "timestamp": datetime.now().isoformat(),
        "results": [
            {"type": "performance",
             "name": "setup_time",
             "value": (end - mid).total_seconds(),
             "units": "s",
             "measure": "time"
             },
            {"type": "performance",
             "name": "total_time",
             "value": (end - start).total_seconds(),
             "units": "s",
             "measure": "time"
             },
            {"type": "performance",
             "name": "synapses",
             "value": totsynapses
             },
            {"type": "performance",
             "name": "neurons",
             "value": totneurons
             },
            {"type": "performance",
             "name": "synapse_loss",
             "value": lostsynapses
             },
            {"type": "performance",
             "name": "synapse_loss_after_l1",
             "value": lostsynapsesl1
             }
        ]
    }

    with open("{}_{}_results.json".format(result["model"], result["task"]),
              'w') as outfile:
        json.dump(result, outfile)
Example #26
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--num_layers', default=2, type=int)
    parser.add_argument('--conn_prob', default = 1., type=float)
    parser.add_argument('--neurons_per_layer', default = 200, type=int)

    args = parser.parse_args()

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

    start = datetime.now()
    r = LayeredFeedforwardNetwork(args.num_layers, args.conn_prob, args.neurons_per_layer, marocco)
    r.build()
    mid = datetime.now()
    r.run()
    end = datetime.now()

    result = {
        "model" : "random_network",
        "num_layers": args.num_layers,
        "syn_loss": float(marocco.stats.getSynapseLoss())/marocco.stats.getSynapses(),
        "conn_prob": args.conn_prob,
        "neurons_per_layer": args.neurons_per_layer,
        "task" : "num_layers{}_conn_prob{}_neurons_per_layer{}".format(args.num_layers,\
                                                 args.conn_prob, args.neurons_per_layer),
        "timestamp" : datetime.now().isoformat(),
        "results" : [
            {"type" : "performance",
             "name" : "setup_time",
             "value" : (end-mid).total_seconds(),
             "units" : "s",
             "measure" : "time"
         },
            {"type" : "performance",
             "name" : "total_time",
             "value" : (end-start).total_seconds(),
             "units" : "s",
             "measure" : "time"
         },
            {"type" : "performance",
             "name" : "synapses",
             "value" : marocco.stats.getSynapses()
         },
            {"type" : "performance",
             "name" : "neurons",
             "value" : marocco.stats.getNumNeurons()
         },
            {"type" : "performance",
             "name" : "synapse_loss",
             "value" : marocco.stats.getSynapseLoss()
         },
            {"type" : "performance",
             "name" : "synapse_loss_after_l1",
             "value" : marocco.stats.getSynapseLossAfterL1Routing()
         }
        ]
    }

    with open("feedforward_layered_num_layers{}_conn_prob{}neurons_per_layer{}_results.json".format(args.num_layers,\
                                                   args.conn_prob, args.neurons_per_layer), 'w') as outfile:
        json.dump(result, outfile)