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.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 ################### # PYNN (==pyhmf) # ################### used_hicann = C.HICANNGlobal(C.HICANNOnWafer(C.Enum(args.hicann)), C.Wafer(args.wafer))
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)
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() h276.drivers().disable(SynapseDriverOnHICANN(C.Enum(6))) h276.drivers().disable(SynapseDriverOnHICANN(C.Enum(20))) h276.drivers().disable(SynapseDriverOnHICANN(C.Enum(102))) h276.drivers().disable(SynapseDriverOnHICANN(C.Enum(104))) marocco.defects.inject(HICANNGlobal(Enum(276)), h276) h277 = pyredman.Hicann() #h277.drivers().disable(SynapseDriverOnHICANN(C.Enum(2))) marocco.defects.inject(HICANNGlobal(Enum(277)), h277)
import numpy as np import pyhmf as pynn from pymarocco import PyMarocco import Coordinate as C from pysthal.command_line_util import init_logger init_logger("ERROR", [('sthal', 'INFO')]) marocco = PyMarocco() marocco.default_wafer = C.Wafer(30) marocco.calib_path = "/wang/data/calibration/brainscales/wip" marocco.defects.path = marocco.calib_path marocco.backend = PyMarocco.Hardware marocco.persist = "exercise_01.xml.gz" marocco.checkl1locking = PyMarocco.CheckButIgnore marocco.verification = PyMarocco.Skip pynn.setup(marocco=marocco) neuron_parameters = { 'cm': 0.2, # nF 'v_reset': -30, # mV 'v_rest': -20, # mV 'v_thresh': -16, # mV 'e_rev_I': -40, # mV 'e_rev_E': 0, # mV 'tau_m': 10, # ms 'tau_refrac': 1, # ms 'tau_syn_E': 5, # ms 'tau_syn_I': 5, # ms }
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)