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()
def test_cout_logging(self): logger.log_to_cout(logger.LogLevel.WARN) logger1 = logger.get("test"); logger2 = logger.get("xyz"); logger3 = logger.get("xyz.test"); logger.set_loglevel(logger2, logger.LogLevel.DEBUG) logger.set_loglevel(logger3, logger.LogLevel.INFO) logger.LOG4CXX_FATAL(logger1, "FATAL") logger.LOG4CXX_ERROR(logger1, "ERROR") logger.LOG4CXX_WARN (logger1, "WARN ") logger.LOG4CXX_INFO (logger1, "INFO ") logger.LOG4CXX_DEBUG(logger1, "DEBUG") logger.LOG4CXX_TRACE(logger1, "TRACE") logger2.FATAL("FATAL") logger2.ERROR("ERROR") logger2.WARN ("WARN ") logger2.INFO ("INFO ") logger2.DEBUG("DEBUG") logger2.TRACE("TRACE") logger.LOG4CXX_FATAL(logger3, "FATAL") logger.LOG4CXX_ERROR(logger3, "ERROR") logger.LOG4CXX_WARN (logger3, "WARN ") logger.LOG4CXX_INFO (logger3, "INFO ") logger.LOG4CXX_DEBUG(logger3, "DEBUG") logger.LOG4CXX_TRACE(logger3, "TRACE")
def init_logger(default_level=pylogging.LogLevel.INFO, defaults=tuple(), add_help=False): """Initialize logging system Arguments: default_level: default log level for the logging system args: list of tuples for channel default values add_help: [bool] print help when called with --help, set to True if you don't have an own parser. Example: init_logger(args, [('sthal', 'INFO'), ('halbe', 'WARN')]) """ parser = argparse.ArgumentParser(description='PSP visualization tool', add_help=add_help) add_logger_options(parser, default_level) parser_args, _ = parser.parse_known_args() pylogging.reset() pylogging.default_config( level=parser_args.loglevel, fname=parser_args.logfile if parser_args.logfile else "", print_location=parser_args.loglocation, color=parser_args.logcolor, date_format=parser_args.logdate_format) for name, level in defaults: pylogging.set_loglevel(pylogging.get(name), to_level(level)) for name, level in parser_args.logchannel: pylogging.set_loglevel(pylogging.get(name), to_level(level))
def test_cout_logging(self): logger.log_to_cout(logger.LogLevel.WARN) logger1 = logger.get("test") logger2 = logger.get("xyz") logger3 = logger.get("xyz.test") logger.set_loglevel(logger2, logger.LogLevel.DEBUG) logger.set_loglevel(logger3, logger.LogLevel.INFO) logger.LOG4CXX_FATAL(logger1, "FATAL") logger.LOG4CXX_ERROR(logger1, "ERROR") logger.LOG4CXX_WARN(logger1, "WARN ") logger.LOG4CXX_INFO(logger1, "INFO ") logger.LOG4CXX_DEBUG(logger1, "DEBUG") logger.LOG4CXX_TRACE(logger1, "TRACE") logger2.FATAL("FATAL") logger2.ERROR("ERROR") logger2.WARN("WARN ") logger2.INFO("INFO ") logger2.DEBUG("DEBUG") logger2.TRACE("TRACE") logger.LOG4CXX_FATAL(logger3, "FATAL") logger.LOG4CXX_ERROR(logger3, "ERROR") logger.LOG4CXX_WARN(logger3, "WARN ") logger.LOG4CXX_INFO(logger3, "INFO ") logger.LOG4CXX_DEBUG(logger3, "DEBUG") logger.LOG4CXX_TRACE(logger3, "TRACE")
def loggerSetLevel(loglevel): # compatibility to old log levels assert loglevel < 5, 'invalid log level' logLevelList = [ pylog.LogLevel.ERROR, pylog.LogLevel.WARN, pylog.LogLevel.INFO, pylog.LogLevel.DEBUG, pylog.LogLevel.TRACE ] logger = pylog.get_root() pylog.set_loglevel(logger, logLevelList[loglevel])
def test_L1_detour_at_side_switch_usage(self): """ [155] 191 [223] 224 225 x226x {227} test detour and predecessor settings at the edge of a wafer """ pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.TRACE) pylogging.set_loglevel(pylogging.get("Calibtic"), pylogging.LogLevel.ERROR) self.marocco.persist = '' # or add test suite TestWithRuntime? runtime = Runtime(self.marocco.default_wafer) pynn.setup(marocco=self.marocco, marocco_runtime=runtime) settings = pysthal.Settings.get() settings.synapse_switches.max_switches_per_column_per_side = 1 settings.crossbar_switches.max_switches_per_row = 1 source = pynn.Population(1, pynn.IF_cond_exp, {}) target1 = pynn.Population(1, pynn.IF_cond_exp, {}) target2 = pynn.Population(1, pynn.IF_cond_exp, {}) proj = pynn.Projection( source, target1, pynn.AllToAllConnector(weights=1.)) proj = pynn.Projection( source, target2, pynn.AllToAllConnector(weights=1.)) source_hicann = C.HICANNOnWafer(Enum(227)) target1_hicann = C.HICANNOnWafer(Enum(155)) target2_hicann = C.HICANNOnWafer(Enum(225)) self.marocco.manual_placement.on_hicann(source, source_hicann) self.marocco.manual_placement.on_hicann(target1, target1_hicann) self.marocco.manual_placement.on_hicann(target2, target2_hicann) disabled_hicanns = [226, 263] wafer = self.marocco.default_wafer self.marocco.defects.set(pyredman.Wafer(runtime.wafer().index())) for hicann in C.iter_all(C.HICANNOnWafer): if hicann.toEnum().value() in disabled_hicanns: self.marocco.defects.wafer().hicanns().disable(C.HICANNGlobal(hicann, wafer)) continue pynn.run(0) pynn.end() for hicann in runtime.wafer().getAllocatedHicannCoordinates(): h = runtime.wafer()[hicann] print(hicann, h.check()) self.assertEqual(h.check(), "")
def init_logger(): layout = pylogging.ColorLayout(True) appender = pylogging.ConsoleAppender(layout) appender.setOption("target", pylogging.ConsoleAppender.getSystemErr()) appender.activateOptions(pylogging.Pool()) l = pylogging.get_root() pylogging.set_loglevel(l, pylogging.LogLevel.DEBUG) l.addAppender(appender)
def test_equality(self): user_strat = placer() default_strat = placer() pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.TRACE) self.assertEqual(user_strat, default_strat) user_strat.m_spiral_center = user_strat.spiral_neighbours self.assertEqual(user_strat, default_strat)
def test_external_sources_projections(self, params): nprojections = params[0] nsources = params[1] print((nprojections, nsources)) """ An external sources has multiple projections so it should be split if it wuld not be of size 1 so unfortunately the users would need to live with that. """ pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.TRACE) pylogging.set_loglevel(pylogging.get("Calibtic"), pylogging.LogLevel.ERROR) pynn.setup(marocco=self.marocco) self.marocco.neuron_placement.default_neuron_size(4) # ensure a limited synapse driver chain length. self.marocco.synapse_routing.driver_chain_length(3) # we expect synapse loss, but we dont care, as the source cant be split. # we want this tests not to throw exceptions. self.marocco.continue_despite_synapse_loss = True target = pynn.Population(1, pynn.IF_cond_exp, {}) hicann = C.HICANNOnWafer(Enum(100)) self.marocco.manual_placement.on_hicann(target, hicann) exsource = pynn.Population(nsources, pynn.SpikeSourcePoisson, {'rate': 1.}) for i in range(nprojections): proj = pynn.Projection(exsource, target, pynn.AllToAllConnector(weights=1.)) # access to proj so flake8 keeps silent proj.size pynn.run(0) pynn.end() results = self.load_results() synapses = results.synapse_routing.synapses() placement = results.placement for dnc in C.iter_all(C.DNCMergerOnWafer): PonDNC = placement.find(dnc) # PopulationOnDNC if PonDNC: ## if driver requirements exceeded, only one source should be ## placed on the DNC, but synapse loss is still expected if (nprojections > 4): # this number is just guessed self.assertTrue(len(PonDNC) <= 1) else: self.assertTrue(len(PonDNC) <= 12)
def test_msg(print_location, date_format): pylogging.reset() layout = pylogging.ColorLayout(True, date_format) layout.setOption("printlocation", str(print_location).lower()) layout.activateOptions() appender = pylogging.ConsoleAppender(layout) appender.setOption("target", pylogging.ConsoleAppender.getSystemErr()) appender.activateOptions() l = pylogging.get_root() pylogging.set_loglevel(l, pylogging.LogLevel.DEBUG) l.addAppender(appender) l = pylogging.get("manual_config") l.warn("time format: {}".format(date_format))
def setUp(self): pylogging.reset() pylogging.default_config(pylogging.LogLevel.ERROR) pylogging.set_loglevel( pylogging.get("marocco"), pylogging.LogLevel.INFO) self.log = pylogging.get(__name__) self.temporary_directory = tempfile.mkdtemp(prefix="marocco-test-") self.marocco = pymarocco.PyMarocco() self.marocco.backend = pymarocco.PyMarocco.None self.marocco.persist = os.path.join( self.temporary_directory, "results.bin") self.marocco.neuron_placement.default_neuron_size(4)
def test_external_sources_drivers(self, nsources): """ A lot external sources are placed no error should be thrown the sources should be split """ pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.DEBUG) pylogging.set_loglevel(pylogging.get("Calibtic"), pylogging.LogLevel.ERROR) pynn.setup(marocco=self.marocco) self.marocco.neuron_placement.default_neuron_size(4) # ensure a limited synapse driver chain length. self.marocco.synapse_routing.driver_chain_length(3) # if synapse loss occours we want to handle it on our own self.marocco.continue_despite_synapse_loss = True target = pynn.Population(1, pynn.IF_cond_exp, {}) hicann = C.HICANNOnWafer(Enum(100)) self.marocco.manual_placement.on_hicann(target, hicann) exsource = pynn.Population(nsources, pynn.SpikeSourcePoisson, {'rate': 1.}) proj = pynn.Projection(exsource, target, pynn.AllToAllConnector(weights=1.)) # access to proj so flake8 keeps silent proj.size pynn.run(0) pynn.end() results = self.load_results() synapses = results.synapse_routing.synapses() placement = results.placement # test for synapse loss self.assertEqual(nsources, synapses.size()) for dnc in C.iter_all(C.DNCMergerOnWafer): PonDNC = placement.find(dnc) # PopulationOnDNC if PonDNC: ## with a neuron size of 4 and a chain length of 3, ## around 12 sources can fit into a merger self.assertTrue(len(PonDNC) <= 12)
def network(self): pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.TRACE) pylogging.set_loglevel(pylogging.get("Calibtic"), pylogging.LogLevel.ERROR) self.pops = [] for i in range(10): pop = pynn.Population(1, pynn.IF_cond_exp, {}) self.pops.append(pop) if (i > 1): proj = pynn.Projection(self.pops[i - 1], self.pops[i], pynn.AllToAllConnector(weights=0.01)) proj # prevent pep8 warning pynn.run(0) pynn.end()
def setUp(self): super(TestMultiHICANN, self).setUp() pylogging.set_loglevel(pylogging.get("Default"), pylogging.LogLevel.ERROR) pylogging.set_loglevel(pylogging.get("sthal"), pylogging.LogLevel.INFO) if None in (self.WAFER, self.HICANN): return self.wafer_c = Coord.Wafer(self.WAFER) self.w = pysthal.Wafer(self.wafer_c) self.h1 = self.w[Coord.HICANNOnWafer(Enum(324))] self.h2 = self.w[Coord.HICANNOnWafer(Enum(120))] self.addCleanup(self.w.disconnect)
def setUp(self): pylogging.reset() pylogging.default_config(pylogging.LogLevel.ERROR) pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.INFO) self.log = pylogging.get(__name__) self.temporary_directory = tempfile.mkdtemp(prefix="marocco-test-") self.marocco = pymarocco.PyMarocco() self.marocco.backend = pymarocco.PyMarocco.Without self.marocco.persist = os.path.join(self.temporary_directory, "results.bin") self.marocco.neuron_placement.default_neuron_size(4) self.marocco.continue_despite_synapse_loss = True self.marocco.calib_backend = pymarocco.PyMarocco.CalibBackend.Default self.marocco.defects.backend = pymarocco.Defects.Backend.Without
def run_placement(self): """ create 10 populations with 1 neuron, connected in a chain """ pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.TRACE) pylogging.set_loglevel(pylogging.get("Calibtic"), pylogging.LogLevel.ERROR) self.pops = [] for i in range(10): pop = pynn.Population(1, pynn.IF_cond_exp, {}) self.pops.append(pop) if (i > 1): proj = pynn.Projection(self.pops[i - 1], self.pops[i], pynn.AllToAllConnector(weights=0.01)) proj # prevent pep8 warning pynn.run(0) pynn.end()
def test_vertical(self): pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.TRACE) marocco = self.marocco user_strat = placer() user_strat.m_hicann_on_wafer_ordering = user_strat.vertical user_strat.m_spiral_center = user_strat.spiral_neighbours marocco.neuron_placement.default_placement_strategy(user_strat) pynn.setup(marocco=marocco) pops = {} pops[0] = pynn.Population(128, pynn.IF_cond_exp, {}) pops[1] = pynn.Population(128, pynn.IF_cond_exp, {}) pops[2] = pynn.Population(128, pynn.IF_cond_exp, {}) proj1 = pynn.Projection(pops[0], pops[1], pynn.OneToOneConnector(weights=0.01)) proj2 = pynn.Projection(pops[1], pops[2], pynn.OneToOneConnector(weights=0.01)) h = {} h[pops[0]] = C.HICANNOnWafer(Enum(100)) # the next free hicann (vertical order) h[pops[1]] = C.HICANNOnWafer(Enum(72)) h[pops[2]] = C.HICANNOnWafer(Enum(48)) marocco.manual_placement.on_hicann(pops[0], h[pops[0]]) pynn.run(0) pynn.end() result = self.load_results() for key in pops: pop = pops[key] for nrn in pop: placement_item, = result.placement.find(nrn) logical_neuron = placement_item.logical_neuron() for denmem in logical_neuron: self.assertEqual(h[pop].toEnum(), denmem.toHICANNOnWafer().toEnum())
def test_external_sources_rates(self, nsources): """ A lot external sources are placed no error should be thrown """ pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.DEBUG) pylogging.set_loglevel(pylogging.get("Calibtic"), pylogging.LogLevel.ERROR) pynn.setup(marocco=self.marocco) self.marocco.neuron_placement.default_neuron_size(4) # ignore the synapse driver chain length. self.marocco.synapse_routing.driver_chain_length(100) # we expect synapse loss, but we dont care. # we want this tests not to throw exceptions. self.marocco.continue_despite_synapse_loss = True target = pynn.Population(1, pynn.IF_cond_exp, {}) hicann = C.HICANNOnWafer(Enum(100)) self.marocco.manual_placement.on_hicann(target, hicann) exsource = pynn.Population(nsources, pynn.SpikeSourcePoisson, {'rate': 1.}) proj = pynn.Projection(exsource, target, pynn.AllToAllConnector(weights=1.)) # access to proj so flake8 keeps silent proj.size pynn.run(0) pynn.end() results = self.load_results() synapses = results.synapse_routing.synapses() self.assertEqual(nsources, synapses.size())
def start(self, logid=None): #if no logpath given don't log if not self.logpath: return # determine fpga ip if self.wafer < 3: # old wafer systems octet3 = self.wafer + 1 octet4 = self.fpga * 2 + 1 else: # new wafer systems octet3 = self.wafer octet4 = self.fpga % 12 * 32 + self.fpga + 1 self.fpga_ip = "192.168." + str(octet3) + "." + str(octet4) #set file id if not logid: now = time.localtime(time.time()) logid = "w{0}h{1}_{2:02d}{3:02d}{4:02d}{5:02d}{6:02d}{7:02d}".format( self.wafer, self.hicann, now[0], now[1], now[2], now[3], now[4], now[5]) #init logger for backend functions #TODO: minimal log format (<function> <start_time> <end_time>) self.func_logger = pylogging.get("Timer") pylogging.write_to_file(self.logpath + "func_time_" + logid + ".log", append=False, logger=self.func_logger) pylogging.set_loglevel(self.func_logger, pylogging.LogLevel.TRACE) self.eth_logger = pylogging.get("hicann-system.CtrlModulePerf") self.usb_logger = pylogging.get("vmodule.usbcomPerf") traffic_appender = pylogging.FileAppender( pylogging.ColorLayout(None), self.logpath + "pure_traffic_" + logid + ".log", False) self.eth_logger.setAdditivity(False) self.eth_logger.addAppender(traffic_appender) self.usb_logger.setAdditivity(False) self.usb_logger.addAppender(traffic_appender) pylogging.set_loglevel(self.usb_logger, pylogging.LogLevel.TRACE) pylogging.set_loglevel(self.eth_logger, pylogging.LogLevel.TRACE) # determine ethernet interface on machine based on wafer id if self.wafer > 4: interface = "skynet0" else: interface = "eth1" #start wireshark thread #TODO: break if tshark throws error self.exit_threads = False if self.wireshark: self.traffic_thread = threading.Thread( target=self.subprocess_thread, args=("sudo tshark -t e -i " + interface + " -f" " 'net " + self.fpga_ip + "' -i usbmon0 > " " " + self.logpath + "raw_traffic_" + logid + ".log", )) self.traffic_thread.start()
def test_file_logging(self): log = os.path.join(self.temp, 'test_file_logging.log') logger.log_to_file(log, logger.LogLevel.WARN) logger1 = logger.get("test"); logger2 = logger.get("xyz"); logger3 = logger.get("xyz.test"); logger.set_loglevel(logger1, logger.LogLevel.WARN) logger.set_loglevel(logger2, logger.LogLevel.DEBUG) logger.set_loglevel(logger3, logger.LogLevel.INFO) logger.LOG4CXX_FATAL(logger1, "FATAL") logger.LOG4CXX_ERROR(logger1, "ERROR") logger.LOG4CXX_WARN (logger1, "WARN") logger.LOG4CXX_INFO (logger1, "INFO") logger.LOG4CXX_DEBUG(logger1, "DEBUG") logger.LOG4CXX_TRACE(logger1, "TRACE") logger2.FATAL("FATAL") logger2.ERROR("ERROR") logger2.WARN ("WARN") logger2.INFO ("INFO") logger2.DEBUG("DEBUG") logger2.TRACE("TRACE") logger.LOG4CXX_FATAL(logger3, "FATAL") logger.LOG4CXX_ERROR(logger3, "ERROR") logger.LOG4CXX_WARN (logger3, "WARN") logger.LOG4CXX_INFO (logger3, "INFO") logger.LOG4CXX_DEBUG(logger3, "DEBUG") logger.LOG4CXX_TRACE(logger3, "TRACE") logger.reset() with open(log) as f: expected = \ """FATAL test FATAL ERROR test ERROR WARN test WARN FATAL xyz FATAL ERROR xyz ERROR WARN xyz WARN INFO xyz INFO DEBUG xyz DEBUG FATAL xyz.test FATAL ERROR xyz.test ERROR WARN xyz.test WARN INFO xyz.test INFO """ self.assertEqualLogLines(expected, f.read())
def test_file_logging(self): log = os.path.join(self.temp, 'test_file_logging.log') logger.log_to_file(log, logger.LogLevel.WARN) logger1 = logger.get("test") logger2 = logger.get("xyz") logger3 = logger.get("xyz.test") logger.set_loglevel(logger1, logger.LogLevel.WARN) logger.set_loglevel(logger2, logger.LogLevel.DEBUG) logger.set_loglevel(logger3, logger.LogLevel.INFO) logger.LOG4CXX_FATAL(logger1, "FATAL") logger.LOG4CXX_ERROR(logger1, "ERROR") logger.LOG4CXX_WARN(logger1, "WARN") logger.LOG4CXX_INFO(logger1, "INFO") logger.LOG4CXX_DEBUG(logger1, "DEBUG") logger.LOG4CXX_TRACE(logger1, "TRACE") logger2.FATAL("FATAL") logger2.ERROR("ERROR") logger2.WARN("WARN") logger2.INFO("INFO") logger2.DEBUG("DEBUG") logger2.TRACE("TRACE") logger.LOG4CXX_FATAL(logger3, "FATAL") logger.LOG4CXX_ERROR(logger3, "ERROR") logger.LOG4CXX_WARN(logger3, "WARN") logger.LOG4CXX_INFO(logger3, "INFO") logger.LOG4CXX_DEBUG(logger3, "DEBUG") logger.LOG4CXX_TRACE(logger3, "TRACE") logger.reset() with open(log) as f: expected = \ """FATAL test FATAL ERROR test ERROR WARN test WARN FATAL xyz FATAL ERROR xyz ERROR WARN xyz WARN INFO xyz INFO DEBUG xyz DEBUG FATAL xyz.test FATAL ERROR xyz.test ERROR WARN xyz.test WARN INFO xyz.test INFO """ self.assertEqualLogLines(expected, f.read())
def test_append_to_logging(self): # Store all Python logging messages in the "records" list import logging records = [] class Handler(logging.Handler): def emit(self, record): records.append({ "name": record.name, "msg": record.msg, "levelno": record.levelno }) root_logger = logging.getLogger("") root_logger.addHandler(Handler()) root_logger.setLevel(logging.NOTSET) # Log messages to the "root" logger logger.append_to_logging("root") self.assertEqual(1, logger.get_root()._get_number_of_appenders()) # Create two test loggers logger1 = logger.get("test1"); logger.set_loglevel(logger1, logger.LogLevel.TRACE) logger2 = logger.get("test2"); logger3 = logger.get("test2.test3"); logger1.FATAL("msg1") logger1.ERROR("msg2") logger1.WARN("msg3") logger1.INFO("msg4") logger1.DEBUG("msg5") logger1.TRACE("msg6") logger2.FATAL("msg1") logger2.ERROR("msg2") logger2.WARN("msg3") logger2.INFO("msg4") logger2.DEBUG("msg5") logger2.TRACE("msg6") logger3.FATAL("msg1") logger3.ERROR("msg2") logger3.WARN("msg3") logger3.INFO("msg4") logger3.DEBUG("msg5") logger3.TRACE("msg6") self.assertEqual([ {'msg': 'msg1', 'levelno': 50, 'name': 'root.test1'}, {'msg': 'msg2', 'levelno': 40, 'name': 'root.test1'}, {'msg': 'msg3', 'levelno': 30, 'name': 'root.test1'}, {'msg': 'msg4', 'levelno': 20, 'name': 'root.test1'}, {'msg': 'msg5', 'levelno': 10, 'name': 'root.test1'}, {'msg': 'msg6', 'levelno': 10, 'name': 'root.test1'}, {'msg': 'msg1', 'levelno': 50, 'name': 'root.test2'}, {'msg': 'msg2', 'levelno': 40, 'name': 'root.test2'}, {'msg': 'msg3', 'levelno': 30, 'name': 'root.test2'}, {'msg': 'msg4', 'levelno': 20, 'name': 'root.test2'}, {'msg': 'msg5', 'levelno': 10, 'name': 'root.test2'}, {'msg': 'msg1', 'levelno': 50, 'name': 'root.test2.test3'}, {'msg': 'msg2', 'levelno': 40, 'name': 'root.test2.test3'}, {'msg': 'msg3', 'levelno': 30, 'name': 'root.test2.test3'}, {'msg': 'msg4', 'levelno': 20, 'name': 'root.test2.test3'}, {'msg': 'msg5', 'levelno': 10, 'name': 'root.test2.test3'} ], records)
def test_file_logging_with_filter(self): logger1 = logger.get("test"); logger2 = logger.get("xyz"); logger3 = logger.get("xyz.test"); logger.set_loglevel(logger1, logger.LogLevel.WARN) logger.set_loglevel(logger2, logger.LogLevel.DEBUG) logger.set_loglevel(logger3, logger.LogLevel.INFO) # Test different filter log = os.path.join(self.temp, 'test_file_logging_with_filter.log') app = logger.append_to_file(log, logger.get_root()) f = logger.LevelRangeFilter() f.setLevelMin(logger.LogLevel.DEBUG) f.setLevelMax(logger.LogLevel.WARN) app.addFilter(f) log2 = os.path.join(self.temp, 'test_file_logging_with_filter2.log') app = logger.append_to_file(log2, logger.get_root()) f = logger.LevelRangeFilter() f.setLevelMin(logger.LogLevel.ERROR) f.setLevelMax(logger.LogLevel.FATAL) app.addFilter(f) log3 = os.path.join(self.temp, 'test_file_logging_with_filter3.log') app = logger.append_to_file(log3, logger2) f = logger.LevelRangeFilter() f.setLevelMin(logger.LogLevel.ERROR) f.setLevelMax(logger.LogLevel.FATAL) app.addFilter(f) for l in (logger1, logger2, logger3): logger.LOG4CXX_FATAL(l, "FATAL") logger.LOG4CXX_ERROR(l, "ERROR") logger.LOG4CXX_WARN (l, "WARN") logger.LOG4CXX_INFO (l, "INFO") logger.LOG4CXX_DEBUG(l, "DEBUG") logger.LOG4CXX_TRACE(l, "TRACE") logger.reset() with open(log) as f: expected = """WARN test WARN WARN xyz WARN INFO xyz INFO DEBUG xyz DEBUG WARN xyz.test WARN INFO xyz.test INFO """ self.assertEqualLogLines(expected, f.read()) with open(log2) as f: expected = """FATAL test FATAL ERROR test ERROR FATAL xyz FATAL ERROR xyz ERROR FATAL xyz.test FATAL ERROR xyz.test ERROR """ self.assertEqualLogLines(expected, f.read()) with open(log3) as f: expected = """FATAL xyz FATAL ERROR xyz ERROR FATAL xyz.test FATAL ERROR xyz.test ERROR """ self.assertEqualLogLines(expected, f.read())
from _hxtorch import * from hxtorch import nn import pylogging as logger logger.reset() logger.default_config(level=logger.LogLevel.WARN) logger.set_loglevel(logger.get("hxtorch"), logger.LogLevel.INFO)
#!/usr/bin/env python import argparse import os import pycalibtic import pylogging pylogging.default_config(date_format='absolute') pylogging.set_loglevel(pylogging.get("Default"), pylogging.LogLevel.INFO) pylogging.set_loglevel(pylogging.get("Calibtic"), pylogging.LogLevel.DEBUG) from pysthal.command_line_util import add_default_coordinate_options def get_calibtic_name(wafer, hicann): wafer_id = wafer.value() hicann_id = hicann.toEnum().value() name = "w{}-h{}".format(int(wafer_id), int(hicann_id)) return name def load_backend(path, ext): """ path: path to calibration files ext: extension of files aka backend type """ if ext == "xml": backend_type = "xml" elif ext == "dat": backend_type = "binary" elif ext == "txt": backend_type = "text"
#!/usr/bin/env python """ Tool that inits a single HICANN """ import argparse import pylogging pylogging.default_config(date_format='absolute') pylogging.set_loglevel(pylogging.get("sthal"), pylogging.LogLevel.INFO) pylogging.set_loglevel(pylogging.get("Default"), pylogging.LogLevel.INFO) pylogging.set_loglevel(pylogging.get("halbe"), pylogging.LogLevel.INFO) from pyhalco_common import Enum import pyhalco_hicann_v2 as C import pysthal def set_floating_gate_to_zero(hicann): """Set all floating gate values to zero""" fgc = hicann.floating_gates for block in C.iter_all(C.FGBlockOnHICANN): blk = fgc[block] for cell in C.iter_all(C.FGCellOnFGBlock): blk.setRaw(cell, 0) if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--wafer', type=int,
def test_append_to_logging(self): # Store all Python logging messages in the "records" list import logging records = [] class Handler(logging.Handler): def emit(self, record): records.append({ "name": record.name, "msg": record.msg, "levelno": record.levelno }) root_logger = logging.getLogger("") root_logger.addHandler(Handler()) root_logger.setLevel(logging.NOTSET) # Log messages to the "root" logger logger.append_to_logging("root") self.assertEqual(1, logger.get_root()._get_number_of_appenders()) # Create two test loggers logger1 = logger.get("test1") logger.set_loglevel(logger1, logger.LogLevel.TRACE) logger2 = logger.get("test2") logger3 = logger.get("test2.test3") logger1.FATAL("msg1") logger1.ERROR("msg2") logger1.WARN("msg3") logger1.INFO("msg4") logger1.DEBUG("msg5") logger1.TRACE("msg6") logger2.FATAL("msg1") logger2.ERROR("msg2") logger2.WARN("msg3") logger2.INFO("msg4") logger2.DEBUG("msg5") logger2.TRACE("msg6") logger3.FATAL("msg1") logger3.ERROR("msg2") logger3.WARN("msg3") logger3.INFO("msg4") logger3.DEBUG("msg5") logger3.TRACE("msg6") self.assertEqual([{ 'msg': 'msg1', 'levelno': 50, 'name': 'root.test1' }, { 'msg': 'msg2', 'levelno': 40, 'name': 'root.test1' }, { 'msg': 'msg3', 'levelno': 30, 'name': 'root.test1' }, { 'msg': 'msg4', 'levelno': 20, 'name': 'root.test1' }, { 'msg': 'msg5', 'levelno': 10, 'name': 'root.test1' }, { 'msg': 'msg6', 'levelno': 10, 'name': 'root.test1' }, { 'msg': 'msg1', 'levelno': 50, 'name': 'root.test2' }, { 'msg': 'msg2', 'levelno': 40, 'name': 'root.test2' }, { 'msg': 'msg3', 'levelno': 30, 'name': 'root.test2' }, { 'msg': 'msg4', 'levelno': 20, 'name': 'root.test2' }, { 'msg': 'msg5', 'levelno': 10, 'name': 'root.test2' }, { 'msg': 'msg1', 'levelno': 50, 'name': 'root.test2.test3' }, { 'msg': 'msg2', 'levelno': 40, 'name': 'root.test2.test3' }, { 'msg': 'msg3', 'levelno': 30, 'name': 'root.test2.test3' }, { 'msg': 'msg4', 'levelno': 20, 'name': 'root.test2.test3' }, { 'msg': 'msg5', 'levelno': 10, 'name': 'root.test2.test3' }], records)
import copy, unittest, random, logging import numpy as np from pymarocco import * from pyhalco_common import Enum from pyhalco_hicann_v2 import * import pyhmf as pynn import pyredman import utils import pylogging, pyhalbe pyhalbe.Debug.change_loglevel(0) pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.INFO) class TestSynapseLoss(unittest.TestCase): def setUp(self, backend=PyMarocco.Without): self.marocco = PyMarocco() self.marocco.backend = backend self.marocco.neuron_placement.default_neuron_size(2) self.marocco.continue_despite_synapse_loss = True self.marocco.synapse_routing.driver_chain_length( SynapseDriverOnQuadrant.size) self.marocco.calib_backend = PyMarocco.CalibBackend.Default self.marocco.defects.backend = Defects.Backend.Without def tearDown(self): pynn.reset() # pynn reset del self.marocco def test_Normal(self):
def test_file_logging_with_filter(self): logger1 = logger.get("test") logger2 = logger.get("xyz") logger3 = logger.get("xyz.test") logger.set_loglevel(logger1, logger.LogLevel.WARN) logger.set_loglevel(logger2, logger.LogLevel.DEBUG) logger.set_loglevel(logger3, logger.LogLevel.INFO) # Test different filter log = os.path.join(self.temp, 'test_file_logging_with_filter.log') app = logger.append_to_file(log, logger.get_root()) f = logger.LevelRangeFilter() f.setLevelMin(logger.LogLevel.DEBUG) f.setLevelMax(logger.LogLevel.WARN) app.addFilter(f) log2 = os.path.join(self.temp, 'test_file_logging_with_filter2.log') app = logger.append_to_file(log2, logger.get_root()) f = logger.LevelRangeFilter() f.setLevelMin(logger.LogLevel.ERROR) f.setLevelMax(logger.LogLevel.FATAL) app.addFilter(f) log3 = os.path.join(self.temp, 'test_file_logging_with_filter3.log') app = logger.append_to_file(log3, logger2) f = logger.LevelRangeFilter() f.setLevelMin(logger.LogLevel.ERROR) f.setLevelMax(logger.LogLevel.FATAL) app.addFilter(f) for l in (logger1, logger2, logger3): logger.LOG4CXX_FATAL(l, "FATAL") logger.LOG4CXX_ERROR(l, "ERROR") logger.LOG4CXX_WARN(l, "WARN") logger.LOG4CXX_INFO(l, "INFO") logger.LOG4CXX_DEBUG(l, "DEBUG") logger.LOG4CXX_TRACE(l, "TRACE") logger.reset() with open(log) as f: expected = """WARN test WARN WARN xyz WARN INFO xyz INFO DEBUG xyz DEBUG WARN xyz.test WARN INFO xyz.test INFO """ self.assertEqualLogLines(expected, f.read()) with open(log2) as f: expected = """FATAL test FATAL ERROR test ERROR FATAL xyz FATAL ERROR xyz ERROR FATAL xyz.test FATAL ERROR xyz.test ERROR """ self.assertEqualLogLines(expected, f.read()) with open(log3) as f: expected = """FATAL xyz FATAL ERROR xyz ERROR FATAL xyz.test FATAL ERROR xyz.test ERROR """ self.assertEqualLogLines(expected, f.read())
#!/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 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()
import argparse parser = argparse.ArgumentParser(description='smoke test for spike input') parser.add_argument('wafer', type=int) parser.add_argument('hicann', type=int) parser.add_argument('--outdir', type=str) parser.add_argument('--calib-path', type=str, default='./') parser.add_argument('--neuron-number', type=int, default=3) args = parser.parse_args() ########### # LOGGING # ########### 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()
import unittest import pylogging import pyhmf as pynn import pyhalbe import pyhalco_common import pyhalco_hicann_v2 as C import numpy as np import debug_config import pymarocco from pymarocco.results import Marocco pylogging.reset() pylogging.default_config(pylogging.LogLevel.INFO) pylogging.set_loglevel(pylogging.get("marocco"), pylogging.LogLevel.DEBUG) def default_marocco(): marocco = pymarocco.PyMarocco() marocco.neuron_placement.default_neuron_size(4) marocco.synapse_routing.driver_chain_length(C.SynapseDriverOnQuadrant.size) marocco.experiment.speedup(10000.) marocco.defects.backend = pymarocco.Defects.Backend.Without return marocco class TestRateDependentInputPlacement(unittest.TestCase): """Test input placement with consider_firing_rate=True for diverse settings"""
print simulator_name import numpy as np import os, sys # NM-PM1 specific initialisation if simulator_name in ("nmpm1", "ess"): import pylogging import pyhmf as pynn from pymarocco import PyMarocco from pyhalbe.Coordinate import SynapseDriverOnHICANN, HICANNGlobal, X, Y, Enum, NeuronOnHICANN import Coordinate as C import pyhalbe import pyredman 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()