connector = pynn.AllToAllConnector(weights=1)

duration = 1500.0

# initialize without spike times
stimulus_exc = pynn.Population(1, pynn.SpikeSourceArray, {'spike_times': []})
stimulus_neuron = stimulus_exc[0]

projections = [
    pynn.Projection(stimulus_exc, pop, connector, target='excitatory'),
]

#  ——— run mapping —————————————————————————————————————————————————————————————

marocco.skip_mapping = False
marocco.backend = PyMarocco.None

pynn.reset()
pynn.run(duration)

#  ——— change low-level parameters before configuring hardware —————————————————

def set_sthal_params(wafer, gmax, gmax_div):
    """
    synaptic strength:
    gmax: 0 - 1023, strongest: 1023
    gmax_div: 1 - 15, strongest: 1
    """

    # for all HICANNs in use
Exemplo n.º 2
0
                            sim.AllToAllConnector(), target='excitatory')
    exc_wta_proj.append(proj)

    proj = sim.Projection(inh_mid_pop, mid_pops[idx], 
                            sim.AllToAllConnector(), target='inhibitory')
    inh_wta_proj.append(proj)


# import sys
# sys.exit(0)

### ====================== PERFORM MAPPING =========================== ###
seed = 0
marocco.l1_routing.shuffle_switches_seed(seed)

marocco.skip_mapping = False
marocco.backend = PyMarocco.None

sim.reset()
sim.run(duration)

### ==================== DO A FIRST HARDWARE RUN ======================= ###

wafer = runtime.wafer()
hicanns_in_use = wafer.getAllocatedHicannCoordinates()

print("\n\n\n\n")
print(hicanns_in_use)

# for p in mid_pops:
    # if p.hicann is None:
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)