Ejemplo n.º 1
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()
Ejemplo n.º 2
0
    def test_save_and_load(self):
        import pysthal
        from pyhalco_common import Enum
        import pyhalco_hicann_v2 as Coordinate
        from pyhalbe import HICANN
        wafer = pysthal.Wafer(Coordinate.Wafer(3))
        hicann1 = wafer[Coordinate.HICANNOnWafer(Enum(30))]

        for row in Coordinate.iter_all(Coordinate.SynapseRowOnHICANN):
            d_pattern = numpy.random.randint(0, 16, 256)
            d_pattern[d_pattern[0] + 23] = 15
            hicann1.synapses[row].decoders[:] = [
                HICANN.SynapseDecoder(int(ii)) for ii in d_pattern
            ]
            w_pattern = numpy.random.randint(0, 16, 256)
            w_pattern[w_pattern[0] + 23] = 15
            hicann1.synapses[row].weights[:] = [
                HICANN.SynapseWeight(int(ii)) for ii in w_pattern
            ]

        wafer2 = pysthal.Wafer(Coordinate.Wafer(0))
        hicann2 = wafer2[Coordinate.HICANNOnWafer(Enum(42))]
        self.assertNotEqual(str(wafer.status()), str(wafer2.status()))

        for row in Coordinate.iter_all(Coordinate.SynapseRowOnHICANN):
            d1 = hicann1.synapses[row].decoders
            d2 = hicann2.synapses[row].decoders
            self.assertNotEqual(d1, d2)

            w1 = hicann1.synapses[row].weights
            w2 = hicann2.synapses[row].weights
            self.assertNotEqual(w1, w2)

        with tempfile.NamedTemporaryFile() as f:
            wafer.dump(f.name, True)
            wafer2.load(f.name)

        self.assertEqual(wafer.size(), wafer2.size())
        hicann1 = wafer[Coordinate.HICANNOnWafer(Enum(30))]
        hicann2 = wafer2[Coordinate.HICANNOnWafer(Enum(30))]
        self.assertEqual(hicann1.index(), hicann2.index())
        self.assertEqual(str(wafer.status()), str(wafer2.status()))

        for row in Coordinate.iter_all(Coordinate.SynapseRowOnHICANN):
            d1 = hicann1.synapses[row].decoders
            d2 = hicann2.synapses[row].decoders
            self.assertEqual(d1, d2)

            w1 = hicann1.synapses[row].weights
            w2 = hicann2.synapses[row].weights
            self.assertEqual(w1, w2)
Ejemplo n.º 3
0
    def test_has_outbound_mergers(self):
        import pyhalbe
        import pysthal
        from pyhalco_common import Enum
        import pyhalco_hicann_v2 as C

        wafer_c = C.Wafer(33)
        gbitlink_c = C.GbitLinkOnHICANN(Enum(0))
        fpga_on_wafer_c = C.FPGAOnWafer(Enum(0))
        fpga_c = C.FPGAGlobal(fpga_on_wafer_c, wafer_c)
        hicann_cs = [
            C.HICANNGlobal(h, wafer_c) for h in fpga_c.toHICANNOnWafer()
        ]
        hicann_c = hicann_cs[0]
        hicann_on_dnc_c = hicann_c.toHICANNOnWafer().toHICANNOnDNC()
        dnc_on_fpga_c = hicann_c.toDNCOnFPGA()

        w = pysthal.Wafer()
        h = w[hicann_c.toHICANNOnWafer()]
        f = w[fpga_on_wafer_c]

        self.assertFalse(f.hasOutboundMergers())

        f[dnc_on_fpga_c][hicann_on_dnc_c].layer1[
            gbitlink_c] = pyhalbe.HICANN.GbitLink.Direction.TO_DNC
        self.assertTrue(f.hasOutboundMergers())
Ejemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        super(Test_Pyhwdb, self).__init__(*args, **kwargs)
        if IS_PYPLUSPLUS:
            self.WAFER_COORD = coord.Wafer(10)
            self.WAFER_SETUP_TYPE = coord.SetupType.BSSWafer
            self.WAFER_MACU_IP = coord.IPv4.from_string("192.168.10.120")
            self.FPGA_COORD = coord.FPGAOnWafer(0)
            self.FPGA_HIGHSPEED = True
        self.FPGA_IP = coord.IPv4.from_string("192.168.10.1")
        if IS_PYPLUSPLUS:
            self.RETICLE_COORD = coord.DNCOnWafer(coord.common.Enum(0))
            self.RETICLE_TO_BE_POWERED = False
            self.HICANN_COORD = coord.HICANNOnWafer(coord.common.Enum(144))
            self.HICANN_VERSION = 4
            self.HICANN_LABEL = "bla"
            self.ADC_COORD = "B123456"
            self.ADC_MODE = "LOAD_CALIBRATION"
            self.ADC_CHAN = coord.ChannelOnADC(0)
            self.ADC_TRIGGER = coord.TriggerOnADC(1)
        self.ADC_IP = coord.IPv4.from_string("192.168.10.120")
        if IS_PYPLUSPLUS:
            self.ADC_PORT = coord.TCPPort(10101)

        self.DLS_SETUP_ID = "07_20"
        self.HXCUBE_ID = 9
Ejemplo n.º 5
0
    def test_numpy_policies(self):
        import numpy
        import pysthal
        import pyhalco_hicann_v2
        from pyhalbe import HICANN
        w = pysthal.Wafer(pyhalco_hicann_v2.Wafer())
        h = w[pyhalco_hicann_v2.HICANNOnWafer()]

        addrs = numpy.array(numpy.random.randint(64, size=100),
                            dtype=numpy.ushort)
        times = numpy.cumsum(numpy.random.poisson(10.0, size=100)) * 1.e-6
        in_spikes = pysthal.Vector_Spike()
        for addr, t in zip(addrs, times):
            in_spikes.append(pysthal.Spike(HICANN.L1Address(addr), t))

        link = pyhalco_hicann_v2.GbitLinkOnHICANN(3)
        h.sendSpikes(link, in_spikes)
        h.sortSpikes()
        x = h.sentSpikes(link)
        times_t, addrs_t = x.T

        numpy.testing.assert_allclose(times,
                                      times_t,
                                      rtol=0.0,
                                      atol=1.0 / 250e6)
        numpy.testing.assert_array_equal(
            addrs, numpy.array(addrs_t, dtype=numpy.ushort))
Ejemplo n.º 6
0
 def test_dnc_copy(self):
     import copy
     wafer_c = C.Wafer(33)
     w = pysthal.Wafer(wafer_c)
     h_c = C.HICANNGlobal(C.HICANNOnWafer(Enum(297)), wafer_c)
     h = w[h_c.toHICANNOnWafer()]
     d = w[h_c.toFPGAOnWafer()][h_c.toDNCOnFPGA()]
     d2 = copy.deepcopy(d)
     self.assertEqual(d, d2)
     # change something to ensure that it's not a mere pointer copy
     h2 = w[C.HICANNOnWafer(Enum(298))]
     self.assertNotEqual(d, d2)
Ejemplo n.º 7
0
 def test_dnc_pickle(self):
     import pickle
     wafer_c = C.Wafer(33)
     w = pysthal.Wafer(wafer_c)
     h_c = C.HICANNGlobal(C.HICANNOnWafer(Enum(297)), wafer_c)
     h = w[h_c.toHICANNOnWafer()]
     d = w[h_c.toFPGAOnWafer()][h_c.toDNCOnFPGA()]
     d_str = pickle.dumps(d)
     d2 = pickle.loads(d_str)
     self.assertEqual(d, d2)
     # change something to ensure that it's not a mere pointer copy
     h2 = w[C.HICANNOnWafer(Enum(298))]
     self.assertNotEqual(d, d2)
Ejemplo n.º 8
0
 def test_wafer_copy(self):
     import copy
     wafer_c = C.Wafer(33)
     w = pysthal.Wafer(wafer_c)
     h_c = C.HICANNOnWafer(Enum(297))
     h = w[h_c]
     self.assertTrue(h.has_wafer())
     w2 = copy.deepcopy(w)
     self.assertEqual(w, w2)
     h2 = w2[h_c]
     self.assertTrue(h2.has_wafer())
     # change something to ensure that it's not a mere pointer copy
     h.set_neuron_size(2)
     self.assertNotEqual(w, w2)
Ejemplo n.º 9
0
 def test_wafer_pickle(self):
     import pickle
     wafer_c = C.Wafer(33)
     w = pysthal.Wafer(wafer_c)
     h_c = C.HICANNOnWafer(Enum(297))
     h = w[h_c]
     self.assertTrue(h.has_wafer())
     w_str = pickle.dumps(w)
     w2 = pickle.loads(w_str)
     self.assertEqual(w, w2)
     h2 = w2[h_c]
     self.assertTrue(h2.has_wafer())
     # change something to ensure that it's not a mere pointer copy
     h.set_neuron_size(2)
     self.assertNotEqual(w, w2)
Ejemplo n.º 10
0
    def test_common_FPGA_config(self):
        import pysthal
        import pyhalco_hicann_v2
        w = pysthal.Wafer(pyhalco_hicann_v2.Wafer())
        s1 = w.commonFPGASettings()
        s2 = w.commonFPGASettings()
        s1.setPLL(200.0e6)
        self.assertEqual(s1.getPLL(), s2.getPLL())
        s3 = w.commonFPGASettings()
        self.assertEqual(s1.getPLL(), s3.getPLL())

        for pll in (100.0e6, 150.0e6, 200.0e6, 250.0e6):
            s1.setPLL(pll)

        for pll in (53.0e6, 32.0e6, 430.e6, 170.e6):
            self.assertRaises(ValueError, s1.setPLL, pll)
Ejemplo n.º 11
0
 def test_wafer_dumpnload(self):
     import tempfile
     wafer_c = C.Wafer(33)
     w = pysthal.Wafer(wafer_c)
     h_c = C.HICANNOnWafer(Enum(297))
     h = w[h_c]
     with tempfile.NamedTemporaryFile() as f:
         w.dump(f.name, True)
         w2 = pysthal.Wafer(wafer_c)
         w2.load(f.name)
     self.assertEqual(w, w2)
     h2 = w2[h_c]
     self.assertTrue(h2.has_wafer())
     # change something to ensure that it's not a mere pointer copy
     h.set_neuron_size(2)
     self.assertNotEqual(w, w2)
Ejemplo n.º 12
0
    def setUp(self):
        super(TestMultiHICANN, self).setUp()

        pylogging.set_loglevel(pylogging.get("Default"), pylogging.LogLevel.ERROR)
        pylogging.set_loglevel(pylogging.get("sthal"), pylogging.LogLevel.INFO)

        if None in (self.WAFER, self.HICANN):
            return

        self.wafer_c = Coord.Wafer(self.WAFER)

        self.w = pysthal.Wafer(self.wafer_c)
        self.h1 = self.w[Coord.HICANNOnWafer(Enum(324))]
        self.h2 = self.w[Coord.HICANNOnWafer(Enum(120))]

        self.addCleanup(self.w.disconnect)
Ejemplo n.º 13
0
    def test_custom_db(self):
        db = pyhwdb.database()
        wafer = pyhwdb.WaferEntry()
        wafer.setup_type = coord.SetupType.BSSWafer
        wafer_coord = coord.Wafer(10)
        db.add_wafer_entry(wafer_coord, wafer)
        fpga = pyhwdb.FPGAEntry()
        fpga_coord = coord.FPGAGlobal(coord.FPGAOnWafer(0), wafer_coord)
        db.add_fpga_entry(fpga_coord, fpga)

        licenses, tres = generate_license_strings(db)
        # licenses is generated from set -> order not guaranteed
        self.assertTrue(licenses == "Licenses=W10F0,W10T8"
                        or licenses == "Licenses=W10T8,W10F0")
        self.assertTrue(
            tres == "AccountingStorageTRES=License/W10F0,License/W10T8"
            or tres == "AccountingStorageTRES=License/W10T8,License/W10F0")

        try:
            tmpdirname = tempfile.mkdtemp()
            lic_tmp_file = os.path.join(tmpdirname, str(uuid.uuid4()))
            tres_tmp_file = os.path.join(tmpdirname, str(uuid.uuid4()))

            create_license_files(db, lic_tmp_file, tres_tmp_file)

            with open(lic_tmp_file, "r") as file:
                content = file.read()
                self.assertTrue(
                    any(lic in content for lic in
                        ["Licenses=W10F0,W10T8", "Licenses=W10T8,W10F0"]))

            with open(tres_tmp_file, "r") as file:
                content = file.read()
                self.assertTrue(
                    any(tres in content for tres in [
                        "AccountingStorageTRES=License/W10F0,License/W10T8",
                        "AccountingStorageTRES=License/W10T8,License/W10F0"
                    ]))
        finally:
            shutil.rmtree(tmpdirname)
Ejemplo n.º 14
0
def main():
    parser = argparse.ArgumentParser()
    # scale factor of the whole network compared to the original one
    parser.add_argument('--scale', default=0.01, type=float)
    # size of one neueron in hw neurons
    parser.add_argument('--n_size', default=4, type=int)
    parser.add_argument('--k_scale', type=float)  # scale of connections

    # wafer defects that should be considered in the mapping
    parser.add_argument('--wafer', '-w', type=int, default=24)

    # specific path where the defect parts of the wafer are saved
    # if nothing specified, current defects of the given wafer are used
    parser.add_argument('--defects_path', type=str)
    parser.add_argument('--ignore_blacklisting',
                        type=str2bool,
                        nargs='?',
                        default=False,
                        const=True)
    parser.add_argument('--name', type=str,
                        default='cortical_column_network')  # name
    parser.add_argument('--placer', type=str, default='byNeuron')
    parser.add_argument('--seed', default=0, type=int)
    args = parser.parse_args()

    # k_scale is set to "scale" by deflaut
    if not args.k_scale:
        args.k_scale = args.scale

    taskname = "scale{}_k-scale{}_nsize{}_wafer{}_ignoreBlacklsiting{}".format(
        args.scale, args.k_scale, args.n_size, args.wafer,
        args.ignore_blacklisting)

    marocco = PyMarocco()
    marocco.neuron_placement.default_neuron_size(args.n_size)

    if (args.ignore_blacklisting):
        marocco.defects.backend = Defects.Backend.Without
    else:
        marocco.defects.backend = Defects.Backend.XML

    marocco.skip_mapping = False
    marocco.backend = PyMarocco.Without

    marocco.continue_despite_synapse_loss = True
    marocco.default_wafer = C.Wafer(args.wafer)  # give wafer args
    marocco.calib_backend = PyMarocco.CalibBackend.Default
    marocco.calib_path = "/wang/data/calibration/brainscales/default"

    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"

    # c 4189 no specification
    #taskname += "_c4189_"

    # strategy
    marocco.merger_routing.strategy(  # is now default
        marocco.merger_routing.minimize_as_possible)
    #taskname += "_minimAsPoss"
    '''
    # placement strategy
    user_strat = placer()
    taskname += "_placer"
    '''

    if args.placer == "byNeuron":
        user_strat = placer_neuron_cluster()  # cluster by neurons
        taskname += "_byNeuron"
        marocco.neuron_placement.default_placement_strategy(user_strat)

    if args.placer == "byEnum":
        user_strat = placer_enum_IDasc()  # cluster by neurons
        taskname += "_byEnum"
        marocco.neuron_placement.default_placement_strategy(user_strat)

    if args.placer == "constrained":
        # needed for 5720 with patch set 36(best results) or ps 50
        from pymarocco_runtime import ConstrainedNeuronClusterer as placer_neuron_resizer

        user_strat = placer_neuron_resizer()
        taskname += "_constrained"
        marocco.neuron_placement.default_placement_strategy(user_strat)

    # give marocco the format of the results file
    taskname += str(datetime.now())
    marocco.persist = "results_{}_{}.xml.gz".format(args.name, taskname)

    start = datetime.now()
    r = CorticalNetwork(marocco,
                        scale=args.scale,
                        k_scale=args.k_scale,
                        seed=args.seed)
    r.build()
    mid = datetime.now()
    try:
        r.run()
        totsynapses = marocco.stats.getSynapses()
        totneurons = marocco.stats.getNumNeurons()
        lostsynapses = marocco.stats.getSynapseLoss()
        lostsynapsesl1 = marocco.stats.getSynapseLossAfterL1Routing()
        perPopulation = r.getLoss(marocco)
        print("Losses: ", lostsynapses, " of ", totsynapses, " L1Loss:",
              lostsynapsesl1, " Relative:", lostsynapses / float(totsynapses))

    except RuntimeError as err:
        # couldn't place all populations
        totsynapses = 1
        totneurons = 1
        lostsynapses = 1
        lostsynapsesl1 = 1
        logger.error(err)
    end = datetime.now()
    print("time:", end - start)
    result = {
        "model":
        args.name,
        "task":
        taskname,
        "scale":
        args.scale,
        "k_scale":
        args.k_scale,
        "n_size":
        args.n_size,
        "wafer":
        args.wafer,
        "ignore_blacklisting":
        args.ignore_blacklisting,
        "timestamp":
        datetime.now().isoformat(),
        "placer":
        args.placer,
        "perPopulation":
        perPopulation,
        "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)
Ejemplo n.º 15
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)
    parser.add_argument('--defects_path', type=str)
    parser.add_argument('--wafer', '-w', type=int, default=24)

    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{}_wafer{}".format(args.N, args.K, args.L, 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 = 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)
Ejemplo n.º 16
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)
    parser.add_argument('--defects_path', type=str)
    parser.add_argument('--wafer', '-w', type=int, default=24)

    args = parser.parse_args()

    taskname = "num_layers{}_neurons_per_layer{}_conn_prob{}_wafer{}".format(
        args.num_layers, args.neurons_per_layer, args.conn_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 = 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))
Ejemplo n.º 17
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)
    parser.add_argument('--defects_path', type=str)
    parser.add_argument('--wafer', '-w', type=int, default=24)

    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{}_wafer{}".format(args.N, args.Nhidden, 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 = 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)
Ejemplo n.º 18
0
import os

import numpy as np

import pyhalbe
import pysthal
from pyhalco_common import Enum, iter_all
import pyhalco_hicann_v2 as Coordinate

# Set up shortcuts
HICANN = pyhalbe.HICANN

# Choose coordinates
NRN = 0

wafer_c = Coordinate.Wafer(0)
hicann_c = Coordinate.HICANNOnWafer(Enum(84))
neuron_c = Coordinate.NeuronOnHICANN(Enum(NRN))

import argparse
parser = argparse.ArgumentParser()
parser.add_argument("in_addr", type=int)
parser.add_argument("vertical", type=str, choices=["top", "bottom"])
args = parser.parse_args()

bg_addr = pyhalbe.HICANN.L1Address(0)
in_addr_int = args.in_addr
in_addr = pyhalbe.HICANN.L1Address(in_addr_int)

# Get wafer and HICANN
wafer = pysthal.Wafer(wafer_c)
Ejemplo n.º 19
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('--kbiasneurons', '-b', type=int, default=1)
    parser.add_argument('--nbiasneurons', '-nb', type=int, default=1)
    parser.add_argument('--nsources', '-n', type=int, default=500)
    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=24)
    parser.add_argument('--name', type=str, default='ising_network')
    parser.add_argument('--defects_path', type=str)

    args = parser.parse_args()

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

    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.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 = IsingNetwork(marocco,
                     linearsize=args.linearsize,
                     dimension=args.dimension,
                     nbiasneurons=args.nbiasneurons,
                     kbiasneurons=args.kbiasneurons,
                     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)
Ejemplo n.º 20
0
    def setUp(self):
        if 'nose' in list(sys.modules.keys()):
            # ugly hack to support nose-based execution...
            self.FPGA_IP = '0.0.0.0'
            self.PMU_IP = '0.0.0.0'
            self.HICANN = 0
            self.DNC = 1
            self.FPGA = 0
            self.LOGLEVEL = 2
            self.ON_WAFER = False
            self.WAFER = 0

        import pyhalco_hicann_v2 as Coordinate
        from pyhalbe import Handle, HICANN, FPGA, Debug
        # The module pyhalbe.apicheck wraps pyhalbe for hardware-less
        # apichecks. It will be enabled only if the environment variable
        # PYHALBE_API_CHECK is set to true. The attribute "enabled" will be set
        # accordingly. KHS.
        import pyhalbe_apicheck as apicheck

        from pyhalco_common import Enum
        highspeed = True
        arq = True
        hicann_num = 1
        fpga_ip = Coordinate.IPv4.from_string(self.FPGA_IP)
        pmu_ip = Coordinate.IPv4.from_string(self.pmu_IP)
        if self.LOGLEVEL >= 0:
            Debug.change_loglevel(self.LOGLEVEL)

        self.dnc = Coordinate.DNCOnFPGA(Enum(self.DNC))
        self.hicann = Coordinate.HICANNOnDNC(Enum(self.HICANN))
        self.f = Coordinate.FPGAGlobal(Enum(self.FPGA),
                                       Coordinate.Wafer(Enum(self.WAFER)))

        self.fpga = Handle.createFPGAHw(self.f, fpga_ip, self.dnc,
                                        self.ON_WAFER, hicann_num, pmu_ip)
        self.addCleanup(Handle.freeFPGAHw, self.fpga)

        self.h = self.fpga.get(self.dnc, self.hicann)
        if self.ON_WAFER:
            self.h0 = self.fpga.get(self.dnc, Coordinate.HICANNOnDNC(Enum(0)))
            self.h1 = self.fpga.get(self.dnc, Coordinate.HICANNOnDNC(Enum(1)))
            self.h2 = self.fpga.get(self.dnc, Coordinate.HICANNOnDNC(Enum(2)))
            self.h3 = self.fpga.get(self.dnc, Coordinate.HICANNOnDNC(Enum(3)))
            self.h4 = self.fpga.get(self.dnc, Coordinate.HICANNOnDNC(Enum(4)))
            self.h5 = self.fpga.get(self.dnc, Coordinate.HICANNOnDNC(Enum(5)))
            self.h6 = self.fpga.get(self.dnc, Coordinate.HICANNOnDNC(Enum(6)))
            self.h7 = self.fpga.get(self.dnc, Coordinate.HICANNOnDNC(Enum(7)))

        self.apicheck = apicheck.enabled()
        if apicheck.enabled():  # equals PYHALBE_API_CHECK
            # With hardware access disabled pyhalbe functions return anything
            # but the expected, i.e. all unittest assertions naturally fail.
            # I.e. for a functional API check they have to be disabled. KHS.
            apicheck.monkeyPatch(
                self, 'assert'
            )  # disables all functions in self that start with "assert"

        # ECM says: this should be part of the tests... automatic resets during construction isn't very "standalone"
        # OR it is necessary and in this case it should be a member function and documented somehow.
        # FPGA reset
        FPGA.reset(self.fpga)
        HICANN.init(self.h, False)
        if self.ON_WAFER:
            HICANN.init(self.h0, False)
            HICANN.init(self.h1, False)
            HICANN.init(self.h2, False)
            HICANN.init(self.h3, False)
            HICANN.init(self.h4, False)
            HICANN.init(self.h5, False)
            HICANN.init(self.h6, False)
            HICANN.init(self.h7, False)
    def run_experiment(self,
                       marocco,
                       n_stim,
                       rate,
                       poisson=True,
                       shuffle=False):
        """
        runs experiment with `n_stim` SpikeSources, firing at
        `rate` Hz, all connected to 1 neuron.
        returns a  result dictionary, with keys `hicanns` and `fpgas`, each
        containing used FPGA/HICANN coords and number of sources mapped per
        FPGA/HICANN.
        further params:
        poisson - if True, use SpikeSourcePoisson, else use SpikeSourceArrays
                  with regular firing
        shuffle - if True, the spike times used for SpikeSourceArray are
                  shuffled, i.e. they are not sorted. Only valid if
                  poisson=True)
        """

        sim_duration = 200.
        marocco.persist = os.path.join(self.temporary_directory, "results.bin")
        pynn.setup(marocco=marocco)

        exc_pop = pynn.Population(1, pynn.IF_cond_exp, {})

        # place target onto a hicann in the center of reticle and at the border of the wafer
        # such that hicanns from the same reticle are used with preference (1 reticle -> same fpga)
        marocco.manual_placement.on_hicann(
            exc_pop, C.HICANNOnWafer(pyhalco_common.Enum(1)))

        if poisson:
            pop_stim = pynn.Population(n_stim, pynn.SpikeSourcePoisson, {
                'rate': rate,
                'duration': sim_duration
            })
        else:
            pop_stim = pynn.Population(n_stim, pynn.SpikeSourceArray)
            for i in range(n_stim):
                isi = 1.e3 / rate
                spike_times = np.arange((i + 1) * 1. / n_stim * isi,
                                        sim_duration, isi)
                if shuffle:
                    np.random.shuffle(spike_times)
                pop_stim[i:i + 1].set('spike_times', spike_times.tolist())
        a2a = pynn.AllToAllConnector(weights=0.001, delays=2.)
        pynn.Projection(pop_stim, exc_pop, a2a, target='excitatory')
        pynn.run(sim_duration)

        results = Marocco.from_file(marocco.persist)
        hicanns = {}  # count number of stimuli mapped on Hicann
        fpgas = {}  # count number of stimuli mapped on fpga
        for idx in range(len(pop_stim)):
            items = list(results.placement.find(pop_stim[idx]))
            # stim nrns are only placed once per wafer
            self.assertEqual(1, len(items))
            address = items[0].address()
            hicann_str = str(address.toHICANNOnWafer())
            hicanns[hicann_str] = hicanns.get(hicann_str, 0) + 1
            hicann_global = C.HICANNGlobal(address.toHICANNOnWafer(),
                                           C.Wafer())
            fpga_str = str(hicann_global.toFPGAGlobal())
            fpgas[fpga_str] = fpgas.get(fpga_str, 0) + 1

        pynn.end()
        return dict(hicanns=hicanns, fpgas=fpgas)
Ejemplo n.º 22
0
#!/usr/bin/env python

import sys
import argparse
import pylogging
from halbe_convert_coordinate import add_coordinate
from pyhalco_common import Enum
import pyhalco_hicann_v2 as C

WAFER = C.Wafer()


def f_wafer(coord):
    global WAFER
    WAFER = coord
    return []


def f_fpga(coord):
    gcoord = C.FPGAGlobal(coord, WAFER)
    result = []
    for dnc_f in C.iter_all(C.DNCOnFPGA):
        dnc = dnc_f.toDNCOnWafer(gcoord)
        result += hicanns_on_dnc(dnc)
    return result


def f_dnc(dnc):
    gdnc = C.DNCGlobal(dnc, WAFER)
    return hicanns_on_dnc(gdnc)
#!/usr/bin/env python

import pyhalco_hicann_v2 as C
from pyredman.load import load

backend = load.HicannWithBackend("./", C.HICANNGlobal())
backend.save()

backend = load.WaferWithBackend("./", C.Wafer())
backend.save()
Ejemplo n.º 24
0
                        type=int,
                        default=125,
                        help="Used Pll frequency (in MHz)")
    parser.add_argument('-zs',
                        '--zero-synapses',
                        action='store_true',
                        dest='zero_syn',
                        help="set synapse values to zero")
    parser.add_argument('-z',
                        '--zero-floating-gate',
                        action='store_true',
                        dest='zero_fg',
                        help="set floating gate values to zero")

    args = parser.parse_args()
    wafer_c = C.Wafer(args.wafer)
    hicann_c = C.HICANNOnWafer(Enum(args.hicann))
    fpga_c = hicann_c.toFPGAOnWafer()
    dnc_c = fpga_c.toDNCOnWafer()

    wafer = pysthal.Wafer(wafer_c)
    wafer.drop_defects()

    fpga = wafer[fpga_c]
    pll_frequency = args.pll * 1e6
    fpga.commonFPGASettings().setPLL(pll_frequency)
    fpga.commonFPGASettings().setSynapseArrayReset(args.zero_syn)
    hicann = wafer[hicann_c]

    if args.zero_fg:
        set_floating_gate_to_zero(hicann)
#!/usr/bin/env python
"""
Tool to print nice informations about coodinates

usage example: ./convert_coordinate.py --hicann 0 --hicann 5,5 --reticle 1
"""

import argparse
import sys
import pyhalco_hicann_v2 as Coordinate
import pylogging
from pyhalco_common import X, Y, Enum, iter_all

WAFER = Coordinate.Wafer(10) # Show some new wafer as default

def add_coordinate(parser, arg_name, CoordinateType, formatter):
    if hasattr(CoordinateType, "x_type") and hasattr(CoordinateType, "y_type"):
        def parse_arg(arg):
            tmp = arg.split(",")
            if len(tmp) == 1:
                coord = CoordinateType(Enum(int(tmp[0])))
            elif len(tmp) == 2:
                x, y = tmp
                coord = CoordinateType(X(int(x)), Y(int(y)))
            else:
                raise argparse.ArgumentTypeError(
                        "Please provide {0} <x,y> or {0} <enum>".format(
                            arg_name))
            return formatter(coord)
        metavar = '<enum>|<x>,<y>'
    else: