def pytest_runtest_setup(item): engine_marker = item.get_marker("engine") if engine_marker is not None: engines = engine_marker.args engine_marker = engine_marker.args[0] if item.callspec.params['engine'] not in engines: pytest.skip("test requires engine %s" % engine_marker) for uid in list(micropsi_runtime.nodenets.keys()): micropsi_runtime.stop_nodenetrunner(uid) for uid in list(micropsi_runtime.nodenets.keys()): micropsi_runtime.delete_nodenet(uid) for uid in list(micropsi_runtime.worlds.keys()): micropsi_runtime.delete_world(uid) for item in os.listdir(testpath): path = os.path.join(testpath, item) if os.path.isdir(path): shutil.rmtree(path) else: os.remove(path) open(os.path.join(testpath, '__init__.py'), 'w').close() os.mkdir(os.path.join(testpath, 'worlds')) os.mkdir(os.path.join(testpath, 'nodenets')) os.mkdir(os.path.join(testpath, 'nodenets', '__autosave__')) os.mkdir(os.path.join(testpath, 'nodetypes')) os.mkdir(os.path.join(testpath, 'recipes')) os.mkdir(os.path.join(testpath, 'operations')) os.mkdir(os.path.join(testpath, 'nodetypes', 'Test')) open(os.path.join(testpath, 'nodetypes', 'Test', '__init__.py'), 'w').close() micropsi_runtime.reload_code() micropsi_runtime.logger.clear_logs() micropsi_runtime.set_runner_properties(0, True) set_logging_levels()
def test_plot_from_nodefunc(test_nodenet, resourcepath): import os from random import random from time import sleep nodenet = micropsi.get_nodenet(test_nodenet) vizapi = nodenet.netapi.vizapi activations = [random() for i in range(256)] plot = vizapi.NodenetPlot(plotsize=(2, 2)) plot.add_activation_plot(activations) filepath = os.path.join(resourcepath, "plot.png") returnpath = plot.save_to_file(filepath) assert os.path.abspath(returnpath) == os.path.abspath(filepath) assert os.path.isfile(filepath) os.remove(filepath) os.mkdir(os.path.join(resourcepath, 'plotter')) nodetype_file = os.path.join(resourcepath, "plotter", "nodetypes.json") nodefunc_file = os.path.join(resourcepath, "plotter", "nodefunctions.py") with open(nodetype_file, 'w') as fp: fp.write("""{"Plotter": { "name": "Plotter", "slottypes": [], "nodefunction_name": "plotfunc", "gatetypes": [], "parameters": ["plotpath"]}}""") with open(nodefunc_file, 'w') as fp: fp.write(""" def plotfunc(netapi, node=None, **params): import os from random import random filepath = os.path.join(params['plotpath'], 'plot.png') activations = [random() for i in range(256)] plot = netapi.vizapi.NodenetPlot(plotsize=(2, 2)) plot.add_activation_plot(activations) plot.save_to_file(filepath) """) micropsi.reload_native_modules() node = nodenet.netapi.create_node("Plotter", None, name="Plotter") node.set_parameter("plotpath", resourcepath) micropsi.start_nodenetrunner(test_nodenet) sleep(2) micropsi.stop_nodenetrunner(test_nodenet) assert micropsi.MicropsiRunner.last_nodenet_exception == {} assert os.path.isfile(os.path.join(resourcepath, "plot.png"))
def stop_calculation(nodenet_uid): return runtime.stop_nodenetrunner(nodenet_uid)
def stop_nodenetrunner(nodenet_uid): return runtime.stop_nodenetrunner(nodenet_uid)
def stop_calculation(nodenet_uid): """ Stop the given nodenet's calculation""" return runtime.stop_nodenetrunner(nodenet_uid)