示例#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()
示例#2
0
    def setUp(self):
        super(MaroccoFixture, self).setUp()
        self.marocco = PyMarocco()
        self.marocco.backend = PyMarocco.Without
        self.marocco.calib_backend = PyMarocco.CalibBackend.Default
        self.marocco.defects.backend = Defects.Backend.Without
        self.marocco.merger_routing.strategy(
            self.marocco.merger_routing.minimize_number_of_sending_repeaters)

        sim.setup(marocco=self.marocco)
示例#3
0
    def setUp(self):
        super(MaroccoFixture, self).setUp()
        self.marocco = PyMarocco()
        self.marocco.backend = PyMarocco.None
        self.marocco.calib_backend = PyMarocco.CalibBackend.Default
        self.marocco.defects.backend = Defects.Backend.None
        self.marocco.merger_routing.strategy(
            self.marocco.merger_routing.minimize_number_of_sending_repeaters)
        self.marocco.neuron_placement.skip_hicanns_without_neuron_blacklisting(
            False)

        sim.setup(marocco=self.marocco)
    def test(self):

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

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

        pynn.setup(marocco=marocco)

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

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

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

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

        pynn.run(10000)
        pynn.end()
示例#5
0
    def test_popview_combinations(self, view_number):
        # tests all possible combinations of mask lengths for different number of PopulationViews
        import pylogging
        from pymarocco import PyMarocco, Defects
        from pymarocco.results import Marocco
        pop_size = 5
        hicanns = [C.HICANNOnWafer(Enum(180 + view)) for view in range(view_number)]
        # generate possible mask lengths for Population Views
        pool = tuple(i for i in range(1, pop_size - view_number + 2))
        # generate all possible mask lengths for each PopulationView for a given total number of neurons
        # [[lengths_of_Popviews],number_of_used_neurons]
        view_lengths = [([], 0)]
        for _ in range(view_number):
            view_lengths = [(x+[y], csum+y) for x, csum in view_lengths for y in pool if csum <= pop_size - y]
        neurons = list(range(pop_size))
        for length in view_lengths:
            marocco = PyMarocco()
            marocco.backend = PyMarocco.Without
            marocco.persist = "results.bin"
            marocco.defects.backend = Defects.Backend.Without
            neuron_size = 4
            marocco.neuron_placement.default_neuron_size(neuron_size)
            pynn.setup(marocco=marocco)

            pop = pynn.Population(pop_size, pynn.IF_cond_exp, {})
            pop_views = []
            index = 0
            for view in range(view_number):
                # generate PopulationViews with all possible mask lengths
                # no permutations of neurons are tested
                pop_views.append(pynn.PopulationView(pop,neurons[index:index+length[0][view]]))
                marocco.manual_placement.on_hicann(pop_views[view],hicanns[view])
                index += length[0][view]

            pynn.run(0)
            pynn.end()
            results = Marocco.from_file(marocco.persist)

            for view in range(view_number):
                for nrn in pop_views[view]:
                    placement_item, = results.placement.find(nrn)
                    logical_neuron = placement_item.logical_neuron()
                    for denmem in logical_neuron:
                        self.assertEqual(hicanns[view], denmem.toHICANNOnWafer())
示例#6
0
def run():
    results = []
    for num_pops in [1, 10, 25, 50, 100, 200, 300, 400]:
        for pop_size in [1, 16, 32, 64, 96]:
            marocco = PyMarocco()
            result = build_network(num_pops, pop_size, marocco)
            results.append(result)
            logging.info(results[-1])

    return numpy.array(results)
def main():
    """
    create small network with synapse loss.  The synapse loss happens due to a
    maximum syndriver chain length of 5 and only 4 denmems per neuron.  After
    mapping, the synapse loss per projection is evaluated and plotted for one
    projection.  The sum of lost synapses per projection is compared to the
    overall synapse loss returnd by the mapping stats.
    """
    marocco = PyMarocco()
    marocco.neuron_placement.default_neuron_size(4)
    marocco.synapse_routing.driver_chain_length(5)
    marocco.continue_despite_synapse_loss = True
    marocco.calib_backend = PyMarocco.CalibBackend.Default
    marocco.neuron_placement.skip_hicanns_without_neuron_blacklisting(False)

    pynn.setup(marocco=marocco)

    neuron = pynn.Population(50, pynn.IF_cond_exp)
    source = pynn.Population(50, pynn.SpikeSourcePoisson, {'rate' : 2})

    connector = pynn.FixedProbabilityConnector(
            allow_self_connections=True,
            p_connect=0.5,
            weights=0.00425)
    proj_stim = pynn.Projection(source, neuron, connector, target="excitatory")
    proj_rec = pynn.Projection(neuron, neuron, connector, target="excitatory")

    pynn.run(1)

    print marocco.stats

    total_syns = 0
    lost_syns = 0
    for proj in [proj_stim, proj_rec]:
        l,t = projectionwise_synapse_loss(proj, marocco)
        total_syns += t
        lost_syns += l

    assert total_syns == marocco.stats.getSynapses()
    assert lost_syns == marocco.stats.getSynapseLoss()

    plot_projectionwise_synapse_loss(proj_stim, marocco)
    pynn.end()
示例#8
0
def main():
    """
    create small network with synapse loss.  The synapse loss happens due to a
    maximum syndriver chain length of 5 and only 4 denmems per neuron.  After
    mapping, the synapse loss per projection is evaluated and plotted for one
    projection.  The sum of lost synapses per projection is compared to the
    overall synapse loss returnd by the mapping stats.
    """
    marocco = PyMarocco()
    marocco.neuron_placement.default_neuron_size(4)
    marocco.synapse_routing.driver_chain_length(5)
    marocco.continue_despite_synapse_loss = True
    marocco.calib_backend = PyMarocco.CalibBackend.Default
    marocco.neuron_placement.skip_hicanns_without_neuron_blacklisting(False)

    pynn.setup(marocco=marocco)

    neuron = pynn.Population(50, pynn.IF_cond_exp)
    source = pynn.Population(50, pynn.SpikeSourcePoisson, {'rate': 2})

    connector = pynn.FixedProbabilityConnector(allow_self_connections=True,
                                               p_connect=0.5,
                                               weights=0.00425)
    proj_stim = pynn.Projection(source, neuron, connector, target="excitatory")
    proj_rec = pynn.Projection(neuron, neuron, connector, target="excitatory")

    pynn.run(1)

    print marocco.stats

    total_syns = 0
    lost_syns = 0
    for proj in [proj_stim, proj_rec]:
        l, t = projectionwise_synapse_loss(proj, marocco)
        total_syns += t
        lost_syns += l

    assert total_syns == marocco.stats.getSynapses()
    assert lost_syns == marocco.stats.getSynapseLoss()

    plot_projectionwise_synapse_loss(proj_stim, marocco)
    pynn.end()
示例#9
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)
示例#10
0
class MaroccoFixture(unittest.TestCase):
    def setUp(self):
        super(MaroccoFixture, self).setUp()
        self.marocco = PyMarocco()
        self.marocco.backend = PyMarocco.Without
        self.marocco.calib_backend = PyMarocco.CalibBackend.Default
        self.marocco.defects.backend = Defects.Backend.Without
        self.marocco.merger_routing.strategy(
            self.marocco.merger_routing.minimize_number_of_sending_repeaters)

        sim.setup(marocco=self.marocco)

    def tearDown(self):
        super(MaroccoFixture, self).tearDown()
        # sim.reset() only needed for multiple run() in the same session
        sim.end()

    def stats(self):
        return self.marocco.getStats()
示例#11
0
    def test_defaultNeuronSize(self):
        """tests whether whether only the supported neuron sizes are allowed"""
        marocco = PyMarocco()
        p = marocco.neuron_placement

        # has to be larger than zero
        self.assertRaises(OverflowError, p.default_neuron_size, -1)
        self.assertRaises(ValueError, p.default_neuron_size, 0)

        for s in range(1, 65):
            if (s % 2 == 0):
                p.default_neuron_size(s)
                self.assertEqual(s, p.default_neuron_size())
            else:
                self.assertRaises(ValueError, p.default_neuron_size, s)

        # not larger than 64
        self.assertRaises(ValueError, p.default_neuron_size, 65)
        self.assertRaises(ValueError, p.default_neuron_size, 68)
示例#12
0
def setup_marocco(wafer=37):
    """Setup hardwarm mapping on a wafer. Defaults to 37"""
    marocco = PyMarocco()
    marocco.neuron_placement.default_neuron_size(4)
    marocco.neuron_placement.minimize_number_of_sending_repeaters(False)
    marocco.merger_routing.strategy(marocco.merger_routing.one_to_one)

    marocco.bkg_gen_isi = 125
    marocco.pll_freq = 125e6

    marocco.backend = PyMarocco.Hardware
    marocco.calib_backend = PyMarocco.XML
    marocco.defects.path = marocco.calib_path = "/wang/data/calibration/brainscales/default-2017-09-26-1"
    marocco.defects.backend = Defects.XML
    marocco.default_wafer = C.Wafer(int(os.environ.get("WAFER", wafer)))
    marocco.param_trafo.use_big_capacitors = True
    marocco.input_placement.consider_firing_rate(True)
    marocco.input_placement.bandwidth_utilization(0.8)
    return marocco
    def test(self):

        marocco = PyMarocco()

        useOne = HICANNOnWafer(Enum(276))
        useTwo = HICANNOnWafer(Enum(277))
        use = [useOne, useTwo]
        use_tpl = tuple(use)

        # place a population to a single HICANN (scalar parameter)
        pop = pynn.Population(10, pynn.IF_cond_exp, {})
        marocco.manual_placement.on_hicann(pop, useOne)

        # place a population onto multiple HICANNs
        # using a Python list()
        pop = pynn.Population(10, pynn.IF_cond_exp, {})
        marocco.manual_placement.on_hicann(pop, use)

        # place a population onto multiple HICANNs
        # using a Python tuple()
        pop = pynn.Population(10, pynn.IF_cond_exp, {})
        marocco.manual_placement.on_hicann(pop, use_tpl)
示例#14
0
    def test_addWithNeuronSize(self):
        """tests manual placement with custom neuron size"""

        marocco = PyMarocco()

        useOne = HICANNOnWafer(Enum(276))
        useTwo = HICANNOnWafer(Enum(277))
        use = [useOne, useTwo]

        # place a population to a single HICANN (scalar parameter)
        pop = pynn.Population(10, pynn.IF_cond_exp, {})
        marocco.manual_placement.on_hicann(pop, useOne, 8)

        # place a population onto multiple HICANNs
        pop = pynn.Population(10, pynn.IF_cond_exp, {})
        marocco.manual_placement.on_hicann(pop, use, 4)

        # only set the neuron size for the population, but no HICANN.
        marocco.manual_placement.with_size(pop, 12)

        self.assertRaises(ValueError, marocco.manual_placement.with_size, pop,
                          1)
示例#15
0
    pylogging.set_loglevel(pylogging.get("Default"), pylogging.LogLevel.INFO)
    pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.DEBUG)
    pylogging.set_loglevel(pylogging.get("sthal.HICANNConfigurator.Time"), pylogging.LogLevel.DEBUG)

    h = pyredman.Hicann()

    def initBackend(fname):
        lib = pyredman.loadLibrary(fname)
        backend = pyredman.loadBackend(lib)
        if not backend:
            raise Exception('unable to load %s' % fname)
        return backend

    neuron_size = 4

    marocco = PyMarocco()
    marocco.placement.setDefaultNeuronSize(neuron_size)
    marocco.placement.use_output_buffer7_for_dnc_input_and_bg_hack = True
    marocco.placement.minSPL1 = False
    if simulator_name == "ess":
        marocco.backend = PyMarocco.ESS
        marocco.calib_backend = PyMarocco.Default
    else:
        marocco.backend = PyMarocco.Hardware
        marocco.calib_backend = PyMarocco.XML
    marocco.calib_path = "/wang/data/calibration/wafer_0"

    marocco.roqt = "demo.roqt"
    marocco.bio_graph = "demo.dot"

    h276 = pyredman.Hicann()
示例#16
0
                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

############################################################################
############################################################################
############################################################################

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)
import pyhmf as pynn
#import pyNN.nest as pynn
from pymarocco import PyMarocco, Defects
import pylogging
import Coordinate as C
import pysthal

# configure logging
pylogging.reset()
pylogging.default_config(level=pylogging.LogLevel.INFO,
        fname="logfile.txt",
        dual=False)

# Mapping config
marocco = PyMarocco()
marocco.backend = PyMarocco.ESS # choose Executable System Specification instead of real hardware
marocco.calib_backend = PyMarocco.CalibBackend.Default
marocco.defects.backend = Defects.Backend.None
marocco.neuron_placement.skip_hicanns_without_neuron_blacklisting(False)
marocco.hicann_configurator = pysthal.HICANNConfigurator()
marocco.experiment_time_offset = 5.e-7 # can be low for ESS, as no repeater locking required
marocco.neuron_placement.default_neuron_size(4) # default number of hardware neuron circuits per pyNN neuron
marocco.persist = "nmpm1_adex_neuron_ess.bin"
marocco.param_trafo.use_big_capacitors = False

# set-up the simulator
pynn.setup(marocco=marocco)

neuron_count = 1 # size of the Population we will create
示例#18
0
logger = pylogging.get("guidebook")

neuron_parameters = {
    'cm': 0.2,
    'v_reset': -70.,
    'v_rest': -20.,
    'v_thresh': -10,
    'e_rev_I': -100.,
    'e_rev_E': 60.,
    'tau_m': 20.,
    'tau_refrac': 0.1,
    'tau_syn_E': 5.,
    'tau_syn_I': 5.,
}

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

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

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

pop.record()
pop.record_v()

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

connector = pynn.AllToAllConnector(weights=1)
示例#19
0
import pyhmf as pynn
from pymarocco import PyMarocco
import pylogging, pyhalbe
pyhalbe.Debug.change_loglevel(2)
pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.TRACE)
pylogging.set_loglevel(pylogging.get("sthal"), pylogging.LogLevel.DEBUG)

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

pynn.setup(marocco=marocco)

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

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

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

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

pynn.run(10000)
pynn.end()
#!/usr/bin/env python

import pyhmf as pynn
import Coordinate as C
from pymarocco import PyMarocco, Defects
from pymarocco.results import Marocco

import pylogging
for domain in ["Calibtic", "marocco"]:
    pylogging.set_loglevel(pylogging.get(domain), pylogging.LogLevel.INFO)

marocco = PyMarocco()
marocco.calib_backend = PyMarocco.CalibBackend.Default
marocco.defects.backend = Defects.Backend.None
marocco.neuron_placement.skip_hicanns_without_neuron_blacklisting(False)
marocco.persist = "results.xml.gz"
pynn.setup(marocco = marocco)

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

marocco.manual_placement.on_hicann(pop, C.HICANNOnWafer(C.X(5), C.Y(5)), 4)

pynn.run(10)
pynn.end()

results = Marocco.from_file(marocco.persist)

for neuron in pop:
    for item in results.placement.find(neuron):
        for denmem in item.logical_neuron():
            print denmem
import os
import numpy as np
import pyhmf as pynn
from pymarocco import PyMarocco
from pymarocco.runtime import Runtime
from pymarocco.results import Marocco
from pyhalco_common import Enum
from pyhalco_hicann_v2 import HICANNOnWafer, Wafer
import pysthal
from pysthal.command_line_util import init_logger

init_logger("WARN", [("guidebook", "DEBUG"), ("marocco", "DEBUG"),
                     ("Calibtic", "DEBUG"), ("sthal", "INFO")])

marocco = PyMarocco()
runtime = Runtime(Wafer(int(os.environ.get("WAFER", 22))))
pynn.setup(marocco=marocco, marocco_runtime=runtime)

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

neuron_parameters = {
    'cm': 0.2,
    'v_reset': -70.,
    'v_rest': -20.,
    'v_thresh': -10,
    'e_rev_I': -100.,
    'e_rev_E': 60.,
    'tau_m': 20.,
    'tau_refrac': 0.1,
    'tau_syn_E': 5.,
logger = pylogging.get("guidebook")

neuron_parameters = {
    'cm': 0.2,
    'v_reset': -70.,
    'v_rest': -20.,
    'v_thresh': -10,
    'e_rev_I': -100.,
    'e_rev_E': 60.,
    'tau_m': 20.,
    'tau_refrac': 0.1,
    'tau_syn_E': 5.,
    'tau_syn_I': 5.,
}

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

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

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

pop.record()
pop.record_v()

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

connector = pynn.AllToAllConnector(weights=1)
示例#23
0
def run_mapping(calib_dir, output_dir, wafer, hicann, skip_neurons, params):
    """
    :type hicann: HICANNOnWafer
    :param params: dictionary containing neuron parameters
    :param skip_neurons: number of non-functional dummy neurons to insert
    """

    from pymarocco import PyMarocco
    from pymarocco.results import Marocco
    from pymarocco.coordinates import BioNeuron
    import pyhmf as pynn
    import pysthal

    logger = setup_logger()

    marocco = PyMarocco()
    marocco.neuron_placement.default_neuron_size(
        utils.get_nested(params, "neuron.size", default=4))
    marocco.neuron_placement.restrict_rightmost_neuron_blocks(True)
    marocco.neuron_placement.minimize_number_of_sending_repeaters(False)
    marocco.backend = PyMarocco.None
    marocco.calib_backend = PyMarocco.XML
    marocco.calib_path = calib_dir
    marocco.param_trafo.use_big_capacitors = False
    marocco.persist = os.path.join(output_dir, "marocco.xml.gz")
    marocco.wafer_cfg = os.path.join(output_dir, "wafer_cfg.bin")
    marocco.default_wafer = wafer

    # FIXME: remove?
    marocco.param_trafo.alpha_v = 1000.0
    marocco.param_trafo.shift_v = 0.0

    pynn.setup(marocco=marocco)

    synaptic_input = {}
    for input_type, input_params in params["synaptic_input"].iteritems():
        if not utils.get_nested(input_params, "enabled", default=True):
            logger.info(
                "skipping disabled {!r} synaptic input".format(input_type))
            continue

        spike_times = utils.get_nested(input_params,
                                       "spike_times",
                                       default=None)
        if spike_times:
            start = spike_times["start"]
            stop = spike_times["stop"]
            step = spike_times["step"]
            spike_times = np.arange(start, stop, step)
            input_pop_model = pynn.SpikeSourceArray
            input_pop_params = {"spike_times": spike_times}
        else:
            raise NotImplementedError(
                "unknown config for {!r} synaptic input".format(input_type))

        logger.info(
            ("{!r} synaptic input will come from "
             "{} with parameters {!r}").format(input_type,
                                               input_pop_model.__name__,
                                               input_pop_params))
        synaptic_input[input_type] = pynn.Population(1, input_pop_model,
                                                     input_pop_params)

    neuron_params = utils.get_nested(params, "neuron.parameters")
    neuron_model = getattr(
        pynn, utils.get_nested(params, "neuron.model", default="IF_cond_exp"))

    logger.info("target population is {} neuron with parameters {!r}".format(
        neuron_model.__name__, neuron_params))

    # Force marocco to give us a different neuron by inserting
    # `Neuron_Number - 1` dummy neurons.
    populations = []
    for ii in range(0, skip_neurons + 1):
        populations.append(pynn.Population(1, neuron_model, neuron_params))
        marocco.manual_placement.on_hicann(populations[-1], hicann)
    target_pop = populations[-1]

    for input_type, input_pop in synaptic_input.iteritems():
        multiplicity = utils.get_nested(params,
                                        "synaptic_input",
                                        input_type,
                                        "multiplicity",
                                        default=1)
        assert multiplicity >= 1
        weight = utils.get_nested(params, "synaptic_input", input_type,
                                  "weight")
        con = pynn.AllToAllConnector(weights=weight)
        logger.info(("connecting {!r} synaptic input "
                     "to target population with weight {} "
                     "via {} projections").format(input_type, weight,
                                                  multiplicity))
        for _ in xrange(multiplicity):
            pynn.Projection(input_pop, target_pop, con, target=input_type)

    pynn.run(params["duration"])
    pynn.end()

    wafer_cfg = pysthal.Wafer()
    wafer_cfg.load(marocco.wafer_cfg)
    results = Marocco.from_file(marocco.persist)
    return (BioNeuron(target_pop[0]), results, wafer_cfg)
logger = pylogging.get("guidebook")

neuron_parameters = {
    'cm': 0.2,
    'v_reset': -70.,
    'v_rest': -20.,
    'v_thresh': -10,
    'e_rev_I': -100.,
    'e_rev_E': 60.,
    'tau_m': 20.,
    'tau_refrac': 0.1,
    'tau_syn_E': 5.,
    'tau_syn_I': 5.,
}

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

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

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

pop.record()
pop.record_v()

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

connector = pynn.AllToAllConnector(weights=1)
示例#25
0
    def test(self):

        import pyhmf as sim
        from pymarocco import PyMarocco
        marocco = PyMarocco()
        sim.setup(marocco=marocco)
示例#26
0
#!/usr/bin/env python

import pyhmf as pynn
import Coordinate as C
from pymarocco import PyMarocco
from pymarocco.results import Marocco

import pylogging
for domain in ["Calibtic", "marocco"]:
    pylogging.set_loglevel(pylogging.get(domain), pylogging.LogLevel.INFO)

marocco = PyMarocco()
marocco.persist = "results.bin"
pynn.setup(marocco=marocco)

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

marocco.manual_placement.on_hicann(pop, C.HICANNOnWafer(C.X(5), C.Y(5)), 4)

pynn.run(10)
pynn.end()

results = Marocco.from_file(marocco.persist)

for neuron in pop:
    for item in results.placement.find(neuron):
        for denmem in item.logical_neuron():
            print denmem
def run_mapping(calib_dir, output_dir, wafer, hicann, skip_neurons, params):
    """
    :type hicann: HICANNOnWafer
    :param params: dictionary containing neuron parameters
    :param skip_neurons: number of non-functional dummy neurons to insert
    """

    from pymarocco import PyMarocco
    from pymarocco.results import Marocco
    from pymarocco.coordinates import BioNeuron
    import pyhmf as pynn
    import pysthal

    logger = setup_logger()

    marocco = PyMarocco()
    marocco.neuron_placement.default_neuron_size(
        utils.get_nested(params, "neuron.size", default=4))
    marocco.neuron_placement.restrict_rightmost_neuron_blocks(True)
    marocco.neuron_placement.minimize_number_of_sending_repeaters(False)
    marocco.backend = PyMarocco.None
    marocco.calib_backend = PyMarocco.XML
    marocco.calib_path = calib_dir
    marocco.param_trafo.use_big_capacitors = False
    marocco.persist = os.path.join(output_dir, "marocco.xml.gz")
    marocco.wafer_cfg = os.path.join(output_dir, "wafer_cfg.bin")
    marocco.default_wafer = wafer

    # FIXME: remove?
    marocco.param_trafo.alpha_v = 1000.0
    marocco.param_trafo.shift_v = 0.0

    pynn.setup(marocco=marocco)

    synaptic_input = {}
    for input_type, input_params in params["synaptic_input"].iteritems():
        if not utils.get_nested(input_params, "enabled", default=True):
            logger.info(
                "skipping disabled {!r} synaptic input".format(input_type))
            continue

        spike_times = utils.get_nested(
            input_params, "spike_times", default=None)
        if spike_times:
            start = spike_times["start"]
            stop = spike_times["stop"]
            step = spike_times["step"]
            spike_times = np.arange(start, stop, step)
            input_pop_model = pynn.SpikeSourceArray
            input_pop_params = {"spike_times": spike_times}
        else:
            raise NotImplementedError(
                "unknown config for {!r} synaptic input".format(input_type))

        logger.info(
            ("{!r} synaptic input will come from "
             "{} with parameters {!r}").format(
                input_type, input_pop_model.__name__, input_pop_params))
        synaptic_input[input_type] = pynn.Population(
            1, input_pop_model, input_pop_params)

    neuron_params = utils.get_nested(params, "neuron.parameters")
    neuron_model = getattr(pynn, utils.get_nested(
        params, "neuron.model", default="IF_cond_exp"))

    logger.info(
        "target population is {} neuron with parameters {!r}".format(
            neuron_model.__name__, neuron_params))

    # Force marocco to give us a different neuron by inserting
    # `Neuron_Number - 1` dummy neurons.
    populations = []
    for ii in range(0, skip_neurons + 1):
        populations.append(pynn.Population(
            1, neuron_model, neuron_params))
        marocco.manual_placement.on_hicann(populations[-1], hicann)
    target_pop = populations[-1]

    for input_type, input_pop in synaptic_input.iteritems():
        multiplicity = utils.get_nested(
            params, "synaptic_input", input_type, "multiplicity",
            default=1)
        assert multiplicity >= 1
        weight = utils.get_nested(
            params, "synaptic_input", input_type, "weight")
        con = pynn.AllToAllConnector(weights=weight)
        logger.info(
            ("connecting {!r} synaptic input "
             "to target population with weight {} "
             "via {} projections").format(
                 input_type, weight, multiplicity))
        for _ in xrange(multiplicity):
            pynn.Projection(input_pop, target_pop, con, target=input_type)

    pynn.run(params["duration"])
    pynn.end()

    wafer_cfg = pysthal.Wafer()
    wafer_cfg.load(marocco.wafer_cfg)
    results = Marocco.from_file(marocco.persist)
    return (BioNeuron(target_pop[0]), results, wafer_cfg)
logger = pylogging.get("guidebook")

neuron_parameters = {
    'cm': 0.2,
    'v_reset': -70.,
    'v_rest': -20.,
    'v_thresh': -10,
    'e_rev_I': -100.,
    'e_rev_E': 60.,
    'tau_m': 20.,
    'tau_refrac': 0.1,
    'tau_syn_E': 5.,
    'tau_syn_I': 5.,
}

marocco = PyMarocco()
marocco.neuron_placement.default_neuron_size(4)
marocco.neuron_placement.minimize_number_of_sending_repeaters(False)
marocco.merger_routing.strategy(marocco.merger_routing.one_to_one)

marocco.bkg_gen_isi = 125
marocco.pll_freq = 125e6

marocco.backend = PyMarocco.Hardware
marocco.calib_backend = PyMarocco.XML
marocco.defects.path = marocco.calib_path = "/wang/data/calibration/ITL_2016"
marocco.defects.backend = Defects.XML
marocco.default_wafer = C.Wafer(33)
marocco.param_trafo.use_big_capacitors = True
marocco.input_placement.consider_firing_rate(True)
marocco.input_placement.bandwidth_utilization(0.8)
logger = pylogging.get("guidebook")

neuron_parameters = {
    'cm': 0.2,
    'v_reset': -70.,
    'v_rest': -20.,
    'v_thresh': -10,
    'e_rev_I': -100.,
    'e_rev_E': 60.,
    'tau_m': 20.,
    'tau_refrac': 0.1,
    'tau_syn_E': 5.,
    'tau_syn_I': 5.,
}

marocco = PyMarocco()
marocco.neuron_placement.default_neuron_size(4)
marocco.neuron_placement.minimize_number_of_sending_repeaters(False)
marocco.merger_routing.strategy(marocco.merger_routing.one_to_one)

marocco.bkg_gen_isi = 125
marocco.pll_freq = 125e6

marocco.backend = PyMarocco.Hardware
marocco.calib_backend = PyMarocco.XML
marocco.defects.path = marocco.calib_path = "/wang/data/calibration/brainscales/default-2017-09-26-1"
marocco.defects.backend = Defects.XML
marocco.default_wafer = C.Wafer(int(os.environ.get("WAFER", 33)))
marocco.param_trafo.use_big_capacitors = True
marocco.input_placement.consider_firing_rate(True)
marocco.input_placement.bandwidth_utilization(0.8)
logger = pylogging.get("guidebook")

neuron_parameters = {
    'cm': 0.2,
    'v_reset': -70.,
    'v_rest': -20.,
    'v_thresh': -10,
    'e_rev_I': -100.,
    'e_rev_E': 60.,
    'tau_m': 20.,
    'tau_refrac': 0.1,
    'tau_syn_E': 5.,
    'tau_syn_I': 5.,
}

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

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

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

pop.record()
pop.record_v()

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

connector = pynn.AllToAllConnector(weights=1)
示例#31
0
the default calibration.
"""

import pyhmf as pynn
#import pyNN.nest as pynn
from pymarocco import PyMarocco
import pylogging

# configure logging
pylogging.reset()
pylogging.default_config(level=pylogging.LogLevel.INFO,
                         fname="logfile.txt",
                         dual=False)

# Mapping config
marocco = PyMarocco()
marocco.backend = PyMarocco.ESS  # choose Executable System Specification instead of real hardware
marocco.experiment_time_offset = 5.e-7  # can be low for ESS, as no repeater locking required
marocco.neuron_placement.default_neuron_size(
    4)  # default number of hardware neuron circuits per pyNN neuron

# set-up the simulator
pynn.setup(marocco=marocco)

neuron_count = 1  # size of the Population we will create

# Set the neuron model class
neuron_model = pynn.EIF_cond_exp_isfa_ista  # an Adaptive Exponential I&F Neuron

neuron_parameters = {
    'a': 4.0,  # adaptation variable a in nS
示例#32
0
"""

import pyhmf as pynn
#import pyNN.nest as pynn
from pymarocco import PyMarocco, Defects
import pylogging
import pysthal

# configure logging
pylogging.reset()
pylogging.default_config(level=pylogging.LogLevel.INFO,
                         fname="logfile.txt",
                         dual=False)

# Mapping config
marocco = PyMarocco()
marocco.backend = PyMarocco.ESS  # choose Executable System Specification instead of real hardware
marocco.calib_backend = PyMarocco.CalibBackend.Default
marocco.defects.backend = Defects.Backend.None
marocco.hicann_configurator = pysthal.HICANNConfigurator()
marocco.experiment_time_offset = 5.e-7  # can be low for ESS, as no repeater locking required
marocco.neuron_placement.default_neuron_size(
    4)  # default number of hardware neuron circuits per pyNN neuron
marocco.persist = "nmpm1_adex_neuron_ess.bin"
marocco.param_trafo.use_big_capacitors = False

# set-up the simulator
pynn.setup(marocco=marocco)

neuron_count = 1  # size of the Population we will create
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)
pylogging.set_loglevel(pylogging.get("Default"), pylogging.LogLevel.INFO)
pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.DEBUG)
pylogging.set_loglevel(pylogging.get("control"), pylogging.LogLevel.DEBUG)
pylogging.set_loglevel(pylogging.get("sthal.HICANNConfigurator.Time"),
                       pylogging.LogLevel.DEBUG)
pylogging.set_loglevel(pylogging.get("sthal.HICANNConfigurator"),
                       pylogging.LogLevel.DEBUG)
pylogging.set_loglevel(pylogging.get("Calibtic"), pylogging.LogLevel.DEBUG)
pylogging.set_loglevel(pylogging.get("halbe"), pylogging.LogLevel.INFO)
pylogging.set_loglevel(pylogging.get("hicann-system"), pylogging.LogLevel.INFO)

####################
# MAROCCO SETTINGS #
####################

marocco = PyMarocco()
marocco.placement.setDefaultNeuronSize(4)
marocco.placement.use_output_buffer7_for_dnc_input_and_bg_hack = True
marocco.placement.minSPL1 = False
marocco.backend = PyMarocco.None  # .ESS, .Hardware
marocco.calib_backend = PyMarocco.XML
marocco.calib_path = args.calib_path
marocco.param_trafo.use_big_capacitors = False
marocco.roqt = "demo.roqt"
marocco.bio_graph = "demo.dot"
marocco.wafer_cfg = "wafer.dat"

# Set voltages in mV
marocco.param_trafo.alpha_v = 1.0
marocco.param_trafo.shift_v = 0.0
示例#35
0
import pyhmf as pynn
from pymarocco import PyMarocco
from pymarocco.runtime import Runtime
from pymarocco.results import Marocco
import Coordinate as C
import pysthal
from pysthal.command_line_util import init_logger

init_logger("WARN", [
    ("guidebook", "DEBUG"),
    ("marocco", "DEBUG"),
    ("Calibtic", "DEBUG"),
    ("sthal", "INFO")
])

marocco = PyMarocco()
runtime = Runtime(C.Wafer(int(os.environ.get("WAFER", 22))))
pynn.setup(marocco=marocco, marocco_runtime=runtime)

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

neuron_parameters = {
    'cm': 0.2,
    'v_reset': -70.,
    'v_rest': -20.,
    'v_thresh': -10,
    'e_rev_I': -100.,
    'e_rev_E': 60.,
    'tau_m': 20.,
    'tau_refrac': 0.1,
    'tau_syn_E': 5.,