示例#1
0
def set_digital_weights(weights, projection, bss_runtime, digital_w=15):
    total_in, total_out = weights.shape

    original_decoders = {}

    rtime_res = bss_runtime.results()
    synapses = rtime_res.synapse_routing.synapses()
    proj_items = synapses.find(projection)

    for _item in proj_items:
        syn = _item.hardware_synapse()
        pre = _item.source_neuron().neuron_index()
        post = _item.target_neuron().neuron_index()
        w = weights[pre, post]

        proxy = bss_runtime.wafer()[syn.toHICANNOnWafer()].synapses[syn]
        if syn not in original_decoders:
            original_decoders[syn] = copy.copy(proxy.decoder)

        if np.isnan(w):
            proxy.weight = HICANN.SynapseWeight(0)
            ### SETTING SYNAPSE TO DISABLED DECODER, DISABLING SYNAPSE
            proxy.decoder = SYNAPSE_DECODER_DISABLED_SYNAPSE
        elif w <= 0.0:
            proxy.weight = HICANN.SynapseWeight(0)
            proxy.decoder = original_decoders[syn]
        else:
            proxy.weight = HICANN.SynapseWeight(digital_w)
            proxy.decoder = original_decoders[syn]
    def test_array_operators(self):
        from pyhalbe import HICANN
        from pyhalco_common import Enum
        import pyhalco_hicann_v2 as Coordinate
        quad = HICANN.NeuronQuad()

        neuron = HICANN.Neuron()
        neuron.enable_aout(True)

        quad[Coordinate.NeuronOnQuad(Enum(0))] = neuron
        self.assertTrue(quad[Coordinate.NeuronOnQuad(Enum(0))].enable_aout())
        self.assertFalse(quad[Coordinate.NeuronOnQuad(Enum(1))].enable_aout())
        self.assertFalse(quad[Coordinate.NeuronOnQuad(Enum(2))].enable_aout())
        self.assertFalse(quad[Coordinate.NeuronOnQuad(Enum(3))].enable_aout())

        quad[Coordinate.NeuronOnQuad(Enum(1))].enable_aout(True)
        self.assertTrue(quad[Coordinate.NeuronOnQuad(Enum(0))].enable_aout())
        self.assertTrue(quad[Coordinate.NeuronOnQuad(Enum(1))].enable_aout())
        self.assertFalse(quad[Coordinate.NeuronOnQuad(Enum(2))].enable_aout())
        self.assertFalse(quad[Coordinate.NeuronOnQuad(Enum(3))].enable_aout())

        x = quad[Coordinate.NeuronOnQuad(Enum(2))]
        x.enable_aout(True)
        self.assertTrue(quad[Coordinate.NeuronOnQuad(Enum(0))].enable_aout())
        self.assertTrue(quad[Coordinate.NeuronOnQuad(Enum(1))].enable_aout())
        self.assertTrue(quad[Coordinate.NeuronOnQuad(Enum(2))].enable_aout())
        self.assertFalse(quad[Coordinate.NeuronOnQuad(Enum(3))].enable_aout())
示例#3
0
def set_digital_weights(in_mtx, projections, total_in, total_out, bss_runtime, digital_w=15):
    n_per_out = total_out // len(projections[0])

    original_decoders = {}
    for i, prjs in enumerate(projections):
        for j, p in enumerate(prjs):
            rtime_res = bss_runtime.results()
            synapses = rtime_res.synapse_routing.synapses()
            proj_items = synapses.find(p)

            for _item in proj_items:
                syn = _item.hardware_synapse()
                pre = _item.source_neuron().neuron_index()
                post = _item.target_neuron().neuron_index()

                post += j * n_per_out
                w = in_mtx[pre, post]

                proxy = runtime.wafer()[syn.toHICANNOnWafer()].synapses[syn]
                if syn not in original_decoders:
                    original_decoders[syn] = copy.copy(proxy.decoder)

                if np.isnan(w):
                    proxy.weight = HICANN.SynapseWeight(0)
                    ### SETTING SYNAPSE TO DISABLED DECODER, DISABLING SYNAPSE
                    proxy.decoder = SYNAPSE_DECODER_DISABLED_SYNAPSE
                elif w <= 0.0:
                    proxy.weight = HICANN.SynapseWeight(0)
                    proxy.decoder = original_decoders[syn]
                else:
                    proxy.weight = HICANN.SynapseWeight(digital_w)
                    proxy.decoder = original_decoders[syn]
示例#4
0
    def set_digital_weights(self,
                            digital_weight=15,
                            zero_all=False,
                            blacklists={}):
        runtime = self.BSS_runtime
        original_decoders = {}
        for k in sorted(self._projections.keys()):
            proj = self._projections[k]
            if proj._digital_weights_ is None:
                continue

            dw_sum = 0
            to = self.get_target_pop_name(k)
            fr = self.get_source_pop_name(k)
            [raw_fr, raw_to] = k.split(' to ')
            min_w, max_w = proj.w_min, proj.w_max
            rtime_res = runtime.results()
            synapses = rtime_res.synapse_routing.synapses()
            proj_items = synapses.find(proj)
            digital_w = digital_weight if proj._digital_weights_ is None \
                        else proj._digital_weights_
            fr_black = blacklists.get(raw_fr, {})
            to_black = blacklists.get(raw_to, {})
            for proj_item in proj_items:
                synapse = proj_item.hardware_synapse()

                pre = proj_item.source_neuron().neuron_index()
                post = proj_item.target_neuron().neuron_index()

                thr = (min_w + max_w) / 2.0
                mw = proj.__weight_matrix[pre, post]
                if np.isnan(mw):
                    dw = 0.0
                else:
                    if mw < thr or zero_all or \
                        pre in fr_black or post in to_black:
                        dw = 0.0
                    else:
                        dw = digital_w

                dw_sum += int(dw > 0)

                proxy = runtime.wafer()[
                    synapse.toHICANNOnWafer()].synapses[synapse]

                if synapse not in original_decoders:
                    original_decoders[synapse] = copy.copy(proxy.decoder)

                if dw > 0:
                    proxy.weight = HICANN.SynapseWeight(dw)
                    proxy.decoder = original_decoders[synapse]
                else:
                    print("++--++ DISABLE_SYNAPSE --++--")
                    print("pre, post, mw = {}, {}, {}".format(pre, post, mw))
                    proxy.weight = HICANN.SynapseWeight(0)
                    proxy.decoder = self.SYNAPSE_DECODER_DISABLED_SYNAPSE
                    print("--++-- END OF DISABLE_SYNAPSE ++--++")
示例#5
0
    def set_denmem_quads(self, neuron, **kwargs):
        nquad = HICANN.NeuronQuad()

        for qq in range(Coordinate.QuadOnHICANN.end):
            HICANN.set_denmem_quad(self.h, Coordinate.QuadOnHICANN(qq), nquad)

        # All other neurons keep the default values
        nactive = nquad[neuron.toNeuronOnQuad()]

        for key, value in kwargs.iteritems():
            getattr(nactive, key)(value)

        HICANN.set_denmem_quad(self.h, neuron.toQuadrantOnHICANN(), nquad)
示例#6
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)
示例#7
0
    def get_trace(self, adc_channel, trace_length):
        HICANN.flush(self.h)

        conf = ADC.Config(trace_length, Coordinate.ChannelOnADC(adc_channel),
                          Coordinate.TriggerOnADC(0))
        ADC.config(self.adc, conf)
        ADC.trigger_now(self.adc)

        trace = ADC.get_trace(self.adc)

        v = -0.00066535 * trace + 2.02391
        t = np.arange(trace.size) * 1 / 96e6

        return (trace, v, t)
def set_sthal_params(wafer, gmax, gmax_div):
    """
    synaptic strength:
    gmax: 0 - 1023, strongest: 1023
    gmax_div: 2 - 30, strongest: 2
    """

    # for all HICANNs in use
    for hicann in wafer.getAllocatedHicannCoordinates():

        fgs = wafer[hicann].floating_gates

        # set parameters influencing the synaptic strength
        for block in iter_all(FGBlockOnHICANN):
            fgs.setShared(block, HICANN.shared_parameter.V_gmax0, gmax)
            fgs.setShared(block, HICANN.shared_parameter.V_gmax1, gmax)
            fgs.setShared(block, HICANN.shared_parameter.V_gmax2, gmax)
            fgs.setShared(block, HICANN.shared_parameter.V_gmax3, gmax)

        for driver in iter_all(SynapseDriverOnHICANN):
            for row in iter_all(RowOnSynapseDriver):
                wafer[hicann].synapses[driver][row].set_gmax_div(
                    HICANN.GmaxDiv(gmax_div))

        # don't change values below
        for ii in xrange(fgs.getNoProgrammingPasses()):
            cfg = fgs.getFGConfig(Enum(ii))
            cfg.fg_biasn = 0
            cfg.fg_bias = 0
            fgs.setFGConfig(Enum(ii), cfg)

        for block in iter_all(FGBlockOnHICANN):
            fgs.setShared(block, HICANN.shared_parameter.V_dllres, 275)
            fgs.setShared(block, HICANN.shared_parameter.V_ccas, 800)
示例#9
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))
    def test_parameter_to_string(self, param):
        from pyhalbe import HICANN
        enum = getattr(HICANN, param)

        for name, parameter in enum.names.items():
            if '__' not in name:
                self.assertEqual(name, HICANN.to_string(parameter))
示例#11
0
def zero_digital_weights(projections,
                         total_in,
                         total_out,
                         bss_runtime,
                         digital_w=15):
    n_per_out = total_out // len(projections[0])
    in_mtx = np.zeros((total_in, total_out))
    for i, prjs in enumerate(projections):
        for j, p in enumerate(prjs):
            c0 = j * n_per_out
            c1 = c0 + n_per_out
            in_mtx[i, c0:c1] = p.getWeights(format='array')
    out_mtx = in_mtx.copy()

    whr = np.where(~np.isnan(out_mtx))
    zeros = np.where(np.random.uniform(0.0, 1.0, size=whr[0].shape) <= 1.0)
    rows, cols = whr[0][zeros], whr[1][zeros]
    out_mtx[rows, cols] = 0

    original_decoders = {}
    for i, prjs in enumerate(projections):
        for j, p in enumerate(prjs):
            rtime_res = bss_runtime.results()
            synapses = rtime_res.synapse_routing.synapses()
            proj_items = synapses.find(p)

            for _item in proj_items:
                syn = _item.hardware_synapse()
                pre = _item.source_neuron().neuron_index()
                post = _item.target_neuron().neuron_index()

                post += j * n_per_out
                w = out_mtx[pre, post]

                proxy = runtime.wafer()[syn.toHICANNOnWafer()].synapses[syn]
                if syn not in original_decoders:
                    original_decoders[syn] = copy.copy(proxy.decoder)

                if np.isnan(w) or w <= 0.0:
                    proxy.weight = HICANN.SynapseWeight(0)
                    ### SETTING SYNAPSE TO DISABLED DECODER, DISABLING SYNAPSE
                    proxy.decoder = SYNAPSE_DECODER_DISABLED_SYNAPSE
                else:
                    proxy.weight = HICANN.SynapseWeight(digital_w)
                    proxy.decoder = original_decoders[syn]

    return out_mtx
示例#12
0
    def set_analog(self, analog, neuron):
        # Configure analog output
        aout = HICANN.Analog()
        aout.enable(analog)

        if (int(neuron.y()) > 0):
            if (int(neuron.x()) % 2):
                aout.set_membrane_bot_odd(analog)
            else:
                aout.set_membrane_bot_even(analog)
        else:
            if (int(neuron.x()) % 2):
                aout.set_membrane_top_odd(analog)
            else:
                aout.set_membrane_top_even(analog)

        HICANN.set_analog(self.h, aout)
示例#13
0
    def test_synapse_access(self):
        import pysthal
        import numpy
        import pyhalco_common
        import pyhalco_hicann_v2
        from pyhalbe import HICANN

        d_patterns = {}
        w_patterns = {}

        hicann = pysthal.HICANN()
        for row in pyhalco_common.iter_all(
                pyhalco_hicann_v2.SynapseRowOnHICANN):
            d_pattern = numpy.random.randint(0, 16, 256)
            d_patterns[row] = d_pattern
            hicann.synapses[row].decoders[:] = [
                HICANN.SynapseDecoder(int(ii)) for ii in d_pattern
            ]

            w_pattern = [
                HICANN.SynapseWeight(int(ii))
                for ii in numpy.random.randint(0, 16, 256)
            ]
            w_patterns[row] = w_pattern
            hicann.synapses[row].weights[:] = w_pattern

        for drv in pyhalco_common.iter_all(
                pyhalco_hicann_v2.SynapseDriverOnHICANN):
            double_row = hicann.synapses.getDecoderDoubleRow(drv)
            for x in (pyhalco_common.top, pyhalco_common.bottom):
                row = pyhalco_hicann_v2.SynapseRowOnHICANN(drv, x)
                data = numpy.array([int(ii) for ii in double_row[x.value()]])
                if not numpy.all(data == d_patterns[row]):
                    err = "Missmatch in decoder values: {!s} != {!s} in {!s}".format(
                        data, d_patterns[row], row)
                    self.fail(err)

        for syn in pyhalco_common.iter_all(pyhalco_hicann_v2.SynapseOnHICANN):
            hicann.synapses[syn]
示例#14
0
    def test_SweepNeurons(self):
        """When the exponential term of a neuron is disabled and firing is off
        V_t should not have any effect on the rest potential."""

        # FIXME: Differs from HICANN to HICANN, this needs connection database
        analog = Coordinate.AnalogOnHICANN(0)
        adc_channel = 3
        bigcap = True
        trace_length = 1950

        neurons = [Coordinate.NeuronOnHICANN(Enum(ii)) for ii in range(512)]

        threshold_voltages = np.arange(0, 1024, step=20, dtype=np.ushort)
        membrane = np.zeros((len(neurons), threshold_voltages.size))

        nconf = HICANN.NeuronConfig()
        nconf.bigcap[int(top)] = bigcap
        nconf.bigcap[int(bottom)] = bigcap
        HICANN.set_neuron_config(self.h, nconf)

        for ii, V_t in enumerate(threshold_voltages):

            fgctrl = HICANN.FGControl()

            for nrn in neurons:
                fgctrl.setNeuron(nrn, HICANN.neuron_parameter.V_t, V_t)
                fgctrl.setNeuron(nrn, HICANN.neuron_parameter.I_bexp, 0)

            for block in [
                    Coordinate.FGBlockOnHICANN(Enum(xx)) for xx in range(4)
            ]:
                HICANN.set_fg_values(self.h, block, fgctrl.getBlock(block))

            for jj, neuron in enumerate(neurons):
                self.set_denmem_quads(neuron, enable_aout=True)
                self.set_analog(analog, neuron)

                trace, v, t = self.get_trace(adc_channel, trace_length)
                membrane[jj, ii] = v.mean()

        if False:
            import pylab
            import matplotlib

            fig, ax = pylab.subplots()
            cax = ax.imshow(membrane.T,
                            interpolation='nearest',
                            cmap=matplotlib.cm.coolwarm)
            fig.colorbar(cax, orientation='horizontal')
            fig.show()

        # Case 1: Radically different behaviour between upper neurons and lower neurons.
        std = membrane.std(axis=1)
        self.assertAlmostEqual(std[:256].mean(), std[256:].mean(), places=2)

        # Case 2: Ideally we would want uniform behaviour for all values of V_t.
        self.assertLess(membrane.mean(axis=0).std(), 0.05)
示例#15
0
    def setup(self, timestep=1.0, min_delay=1.0, per_sim_params={}, **kwargs):
        setup_args = {'timestep': timestep, 'min_delay': min_delay}
        self._extra_config = per_sim_params

        if self.sim_name == BSS:  #do extra setup for BrainScaleS
            wafer = per_sim_params.get("wafer", None)
            marocco = per_sim_params.get("marocco", PyMarocco())
            if wafer is not None:
                sys.stdout.write("Specifying Wafer %d\n\n" % wafer)
                sys.stdout.flush()
                per_sim_params.pop('wafer')
                self.BSS_wafer = C.Wafer(int(wafer))
                marocco.default_wafer = self.BSS_wafer
                self._wafer = WAL(wafer_id=wafer)

            runtime = Runtime(marocco.default_wafer)
            setup_args['marocco_runtime'] = runtime
            self.BSS_runtime = runtime

            calib_path = per_sim_params.get(
                "calib_path", "/wang/data/calibration/brainscales/wip")
            #  "/wang/data/calibration/brainscales/current")

            marocco.calib_path = calib_path
            marocco.defects.path = marocco.calib_path
            # marocco.verification = PyMarocco.Skip
            # marocco.checkl1locking = PyMarocco.SkipCheck
            marocco.continue_despite_synapse_loss = True
            per_sim_params.pop('calib_path', None)

            setup_args['marocco'] = marocco
            self.marocco = marocco
            self.SYNAPSE_DECODER_DISABLED_SYNAPSE = HICANN.SynapseDecoder(1)

        for k in per_sim_params:
            setup_args[k] = per_sim_params[k]

        self._setup_args = setup_args

        self._sim.setup(**setup_args)

        # sys.exit(0)

        if self.sim_name == BSS:
            self._BSS_set_sthal_params(gmax=1023, gmax_div=1)
示例#16
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)
示例#17
0
wafer = int(os.environ.get("WAFER", 33))
marocco = PyMarocco()
marocco.backend = PyMarocco.Hardware

marocco.default_wafer = C.Wafer(wafer)
runtime = Runtime(marocco.default_wafer)

# calib_path = "/wang/data/calibration/brainscales/WIP-2018-09-18"
# marocco.calib_path = calib_path
# marocco.defects.path = marocco.calib_path

marocco.verification = PyMarocco.Skip
marocco.checkl1locking = PyMarocco.SkipCheck
marocco.continue_despite_synapse_loss = True

SYNAPSE_DECODER_DISABLED_SYNAPSE = HICANN.SynapseDecoder(1)

### ====================== NETWORK CONSTRUCTION =========================== ###
sim.setup(timestep=1.0, min_delay=1.0, marocco=marocco, marocco_runtime=runtime)

e_rev = 92  # mV
# e_rev = 500.0 #mV

base_params = {
    # 'cm': 0.1,  # nF
    # 'v_reset': -70.,  # mV
    # 'v_rest': -65.,  # mV
    # 'v_thresh': -55.,  # mV
    # 'tau_m': 20.,  # ms
    # 'tau_refrac': 1.,  # ms
    # 'tau_syn_E': 5.0,  # ms
        for block in iter_all(FGBlockOnHICANN):
            fgs.setShared(block, HICANN.shared_parameter.V_dllres, 275)
            fgs.setShared(block, HICANN.shared_parameter.V_ccas, 800)


# call at least once
set_sthal_params(runtime.wafer(), gmax=1023, gmax_div=2)

#  ——— configure hardware ——————————————————————————————————————————————————————

for proj in projections:
    proj_items = runtime.results().synapse_routing.synapses().find(proj)
    for proj_item in proj_items:
        synapse = proj_item.hardware_synapse()
        proxy = runtime.wafer()[synapse.toHICANNOnWafer()].synapses[synapse]
        proxy.weight = HICANN.SynapseWeight(15)

marocco.skip_mapping = True
marocco.backend = PyMarocco.Hardware

fgs = runtime.wafer()[hicann].floating_gates

calibrated_E_l_DACs = {}

for neuron in pop:
    for item in runtime.results().placement.find(neuron):
        for denmem in item.logical_neuron():
            calibrated_E_l_DACs[denmem] = fgs.getNeuron(denmem, HICANN.E_l)

for n, delta_E_l_DAC in enumerate([-200, -100, 0, 100, 200]):
                wafer[hicann].synapses[driver][row].set_gmax_div(
                    C.left, gmax_div)
                wafer[hicann].synapses[driver][row].set_gmax_div(
                    C.right, gmax_div)

set_sthal_params(runtime.wafer(), gmax=1023, gmax_div=1)

#  ——— configure hardware ——————————————————————————————————————————————————————

marocco.skip_mapping = True
marocco.backend = PyMarocco.Hardware
# Full configuration during first step
marocco.hicann_configurator = PyMarocco.HICANNv4Configurator

for digital_weight in [5, 10, 15]:
    logger.info("running measurement with digital weight {}".format(digital_weight))
    for proj in projections:
        proj_item, = runtime.results().synapse_routing.synapses().find(proj)
        synapse = proj_item.hardware_synapse()

        proxy = runtime.wafer()[synapse.toHICANNOnWafer()].synapses[synapse]
        proxy.weight = HICANN.SynapseWeight(digital_weight)

    pynn.run(duration)
    np.savetxt("membrane_w{}.txt".format(digital_weight), pop.get_v())
    np.savetxt("spikes_w{}.txt".format(digital_weight), pop.getSpikes())
    pynn.reset()

    # only change digital parameters from now on
    marocco.hicann_configurator = PyMarocco.NoResetNoFGConfigurator
示例#20
0
        for block in iter_all(FGBlockOnHICANN):
            fgs.setShared(block, HICANN.shared_parameter.V_dllres, 275)
            fgs.setShared(block, HICANN.shared_parameter.V_ccas, 800)


# call at least once
set_sthal_params(runtime.wafer(), gmax=1023, gmax_div=2)

#  ——— configure hardware ——————————————————————————————————————————————————————

marocco.skip_mapping = True
marocco.backend = PyMarocco.Hardware

# magic number from marocco
SYNAPSE_DECODER_DISABLED_SYNAPSE = HICANN.SynapseDecoder(1)

original_decoders = {}

for digital_weight in [None, 0, 5, 10, 15]:
    logger.info(
        "running measurement with digital weight {}".format(digital_weight))
    for proj in projections:
        proj_items = runtime.results().synapse_routing.synapses().find(proj)
        for proj_item in proj_items:
            synapse = proj_item.hardware_synapse()

            proxy = runtime.wafer()[
                synapse.toHICANNOnWafer()].synapses[synapse]

            # make a copy of the original decoder value
    def test_numpy_construtors(self):
        from pyhalbe import HICANN, std

        pattern = [True, False, False, True] * 4
        self.assertEqual(std.Array_Bool_16(pattern)[:], pattern)
        self.assertEqual(HICANN.SynapseSwitchRow(pattern)[:], pattern)
示例#22
0
    def test_BGToNeuronMembrane(self):
        """Try to send periodic events from a background generator to a neuron.
        Please note that this test relies on the default config values in most objects
        and only changes those necessary to run the test."""

        weight = 15
        period = 700 * 2
        event = HICANN.L1Address(0)
        offevent = HICANN.L1Address(55)

        trace_length = 19500

        exc = True
        inh = False
        E_syn = (570, 570)

        firing = False
        firingevent = HICANN.L1Address(42)

        # FIXME: Differs from HICANN to HICANN, this needs connection database
        analog = Coordinate.AnalogOnHICANN(1)
        adc_channel = 7

        neuron = Coordinate.NeuronOnHICANN(Enum(15))
        vline = Coordinate.VLineOnHICANN(28)  # or 60, 92, 124
        driver = Coordinate.SynapseDriverOnHICANN(Y(111), left)
        synapse_row = Coordinate.SynapseRowOnHICANN(driver, top)

        ##############################
        #  set floating gate values  #
        ##############################

        fgcfg = HICANN.FGConfig()
        fgctrl = HICANN.FGControl()

        # Set same reverse potential for both synaptic inputs (for all neurons)
        for ii in range(512):
            nrn = Coordinate.NeuronOnHICANN(Enum(ii))
            fgctrl.setNeuron(nrn, HICANN.neuron_parameter.E_synx, E_syn[0])
            fgctrl.setNeuron(nrn, HICANN.neuron_parameter.E_syni, E_syn[1])
            fgctrl.setNeuron(nrn, HICANN.neuron_parameter.I_bexp, 0)

        for block in Coordinate.iter_all(Coordinate.FGBlockOnHICANN):
            HICANN.set_fg_config(self.h, block, fgcfg)
        HICANN.set_fg_values(self.h, fgctrl)

        ##############################
        #  set global neuron config  #
        ##############################

        nconf = HICANN.NeuronConfig()
        nconf.bigcap[int(top)] = True
        nconf.bigcap[int(bottom)] = True
        HICANN.set_neuron_config(self.h, nconf)

        #################
        #  set mergers  #
        #################

        dnc = HICANN.DNCMergerLine()
        for i in range(8):
            mer = Coordinate.DNCMergerOnHICANN(i)
            dnc[mer].slow = True
            dnc[mer].config = HICANN.Merger.RIGHT_ONLY

        # Tree defaults to one on one passthrough (forward downwards)
        tree = HICANN.MergerTree()

        HICANN.set_dnc_merger(self.h, dnc)
        HICANN.set_merger_tree(self.h, tree)

        ##########################
        #  background generator  #
        ##########################

        # We use one background generator to provide events
        gens = HICANN.BackgroundGeneratorArray()
        g = gens[7]
        g.enable(True)
        g.random(False)
        g.period(period)
        g.address(event)
        HICANN.set_background_generator(self.h, gens)

        # Forward its output to this HICANN
        srepeater = Coordinate.OutputBufferOnHICANN(7).repeater()

        sr = HICANN.HorizontalRepeater()
        sr.setOutput(right)

        HICANN.set_repeater(self.h, srepeater.horizontal(), sr)

        ###############################################
        #  connect via Crossbars and SynapseSwitches  #
        ###############################################

        hline = srepeater.toHLineOnHICANN()

        cb = HICANN.Crossbar()
        cb.set(vline, hline, True)

        HICANN.set_crossbar_switch_row(
            self.h, hline, vline.toSideHorizontal(),
            cb.get_row(hline, vline.toSideHorizontal()))

        # Connect VLine to synapse driver
        sw = HICANN.SynapseSwitch()
        sw.set(vline, driver.toHLineOnHICANN(), True)

        HICANN.set_syndriver_switch_row(
            self.h, driver.toSynapseSwitchRowOnHICANN(),
            sw.get_row(driver.toSynapseSwitchRowOnHICANN()))

        ########################
        #  set synapse driver  #
        ########################

        drv = HICANN.SynapseDriver()
        drv.set_l1()
        drv[top].set_syn_in(left, exc)
        drv[top].set_syn_in(right, inh)
        drv[bottom].set_syn_in(left, exc)
        drv[bottom].set_syn_in(right, inh)

        HICANN.set_synapse_driver(self.h, driver, drv)

        decoders = HICANN.DecoderDoubleRow()
        weights = HICANN.WeightRow()

        # Reset decoders and weights to 'off' state
        for ii in range(2):
            for jj in range(256):
                decoders[ii][jj] = offevent.getSynapseDecoderMask()

        for ii in range(256):
            weights[ii] = 0

        # Only enable decoders/weights for background generator and neuron
        decoders[0][int(neuron.x())] = event.getSynapseDecoderMask()
        weights[int(neuron.x())] = weight

        HICANN.set_decoder_double_row(self.h, driver, decoders)
        HICANN.set_weights_row(self.h, synapse_row, weights)

        ###################
        #  get ADC trace  #
        ###################

        self.set_denmem_quads(neuron,
                              address=firingevent,
                              activate_firing=firing,
                              enable_aout=True)
        self.set_analog(analog, neuron)
        trace, v, t = self.get_trace(adc_channel, trace_length)

        if False:
            import pylab
            fig, ax = pylab.subplots()
            ax.plot(t, v)
            pylab.show()

        ## Case 1: Sometimes the membrane seems 'stuck' at 1.2V
        self.assertNotAlmostEqual(v.mean(), 1.2, places=1)
        self.assertGreater(v.std(), 0.01)