def test_virtual_placement(placer): machine = virtual_machine(width=8, height=8) graph = MachineGraph("Test") virtual_vertex = MachineSpiNNakerLinkVertex(spinnaker_link_id=0) graph.add_vertex(virtual_vertex) extended_machine = MallocBasedChipIdAllocator()(machine, graph) n_keys_map = DictBasedMachinePartitionNKeysMap() inputs = { "MemoryExtendedMachine": machine, "MemoryMachine": machine, "MemoryMachineGraph": graph, "PlanNTimeSteps": 1000, "MemoryMachinePartitionNKeysMap": n_keys_map } algorithms = [placer] xml_paths = [] executor = PACMANAlgorithmExecutor(algorithms, [], inputs, [], [], [], xml_paths) executor.execute_mapping() placements = executor.get_item("MemoryPlacements") placement = placements.get_placement_of_vertex(virtual_vertex) chip = extended_machine.get_chip_at(placement.x, placement.y) assert chip.virtual
def _do_test(self, placer): machine = virtual_machine(width=8, height=8) graph = MachineGraph("Test") vertices = [ SimpleMachineVertex(ResourceContainer(), label="v{}".format(i)) for i in range(100) ] for vertex in vertices: graph.add_vertex(vertex) same_vertices = [ SimpleMachineVertex(ResourceContainer(), label="same{}".format(i)) for i in range(10) ] random.seed(12345) for vertex in same_vertices: graph.add_vertex(vertex) for _i in range(0, random.randint(1, 5)): vertex.add_constraint( SameChipAsConstraint( vertices[random.randint(0, 99)])) n_keys_map = DictBasedMachinePartitionNKeysMap() inputs = { "MemoryExtendedMachine": machine, "MemoryMachine": machine, "MemoryMachineGraph": graph, "PlanNTimeSteps": None, "MemoryMachinePartitionNKeysMap": n_keys_map } algorithms = [placer] xml_paths = [] executor = PACMANAlgorithmExecutor( algorithms, [], inputs, [], [], [], xml_paths) executor.execute_mapping() placements = executor.get_item("MemoryPlacements") for same in same_vertices: print("{0.vertex.label}, {0.x}, {0.y}, {0.p}: {1}".format( placements.get_placement_of_vertex(same), ["{0.vertex.label}, {0.x}, {0.y}, {0.p}".format( placements.get_placement_of_vertex(constraint.vertex)) for constraint in same.constraints])) placement = placements.get_placement_of_vertex(same) for constraint in same.constraints: if isinstance(constraint, SameChipAsConstraint): other_placement = placements.get_placement_of_vertex( constraint.vertex) self.assertTrue( other_placement.x == placement.x and other_placement.y == placement.y, "Vertex was not placed on the same chip as requested")
def test_external_algorithm(self): if not os.access("/bin/sh", os.X_OK): raise self.skipTest("need Bourne shell to run this test") fd, name = tempfile.mkstemp() inputs = {"ExampleFilePath": name} xmlfile = os.path.join(os.path.dirname(__file__), "test_algos.xml") executor = PACMANAlgorithmExecutor( algorithms=["SimpleExternal"], xml_paths=[xmlfile], optional_algorithms=[], inputs=inputs, required_outputs=[], tokens=[], required_output_tokens=[]) executor.execute_mapping() self.assertEqual(executor.get_item("Foo"), name) with os.fdopen(fd) as f: self.assertEqual(f.read(), "foo\n")
def test_external_algorithm(self): if not os.access("/bin/sh", os.X_OK): raise self.skipTest("need Bourne shell to run this test") fd, name = tempfile.mkstemp() inputs = {"ExampleFilePath": name} xmlfile = os.path.join(os.path.dirname(__file__), "test_algos.xml") executor = PACMANAlgorithmExecutor(algorithms=["SimpleExternal"], xml_paths=[xmlfile], optional_algorithms=[], inputs=inputs, required_outputs=[], tokens=[], required_output_tokens=[]) executor.execute_mapping() self.assertEqual(executor.get_item("Foo"), name) with os.fdopen(fd) as f: self.assertEqual(f.read(), "foo\n")
def test_failing_external_algorithm(self): if not os.access("/bin/sh", os.X_OK): raise self.skipTest("need Bourne shell to run this test") fd, name = tempfile.mkstemp() inputs = {"ExampleFilePath": name} xmlfile = os.path.join(os.path.dirname(__file__), "test_algos.xml") executor = PACMANAlgorithmExecutor( algorithms=["FailingExternal"], xml_paths=[xmlfile], optional_algorithms=[], inputs=inputs, required_outputs=[], tokens=[], required_output_tokens=[]) with self.assertRaises( PacmanExternalAlgorithmFailedToCompleteException) as e: executor.execute_mapping() self.assertIn( "Algorithm FailingExternal returned a non-zero error code 1", str(e.exception)) self.assertEqual(executor.get_item("Foo"), None) with os.fdopen(fd) as f: self.assertEqual(f.read(), "foo\n")
def test_optional_workflow(self): """ Tests that an optional algorithm that doesn't do anything doesn't get called """ TestAlgorithm.called = False TestNoChangesAlgorithm.called = False TestAlgorithm3.called = False inputs = {"TestType1": "TestType1"} executor = PACMANAlgorithmExecutor( algorithms=["TestAlgorithm"], optional_algorithms=["TestNoChangesAlgorithm", "TestAlgorithm3"], inputs=inputs, required_outputs=["TestType3"], tokens=[], required_output_tokens=[]) executor.execute_mapping() self.assertTrue(TestAlgorithm.called) self.assertFalse(TestNoChangesAlgorithm.called) self.assertTrue(TestAlgorithm3.called) self.assertEqual(executor.get_item("TestType3"), "TestType3")
def test_optional_workflow(self): """ Tests that an optional algorithm that doesn't do anything doesn't get called """ TestAlgorithm.called = False TestNoChangesAlgorithm.called = False TestAlgorithm3.called = False inputs = {"TestType1": "TestType1"} executor = PACMANAlgorithmExecutor( algorithms=["TestAlgorithm"], optional_algorithms=["TestNoChangesAlgorithm", "TestAlgorithm3"], inputs=inputs, required_outputs=["TestType3"], tokens=[], required_output_tokens=[]) executor.execute_mapping() self.assertTrue(TestAlgorithm.called) self.assertFalse(TestNoChangesAlgorithm.called) self.assertTrue(TestAlgorithm3.called) self.assertEqual(executor.get_item("TestType3"), "TestType3")
def test_failing_external_algorithm(self): if not os.access("/bin/sh", os.X_OK): raise self.skipTest("need Bourne shell to run this test") fd, name = tempfile.mkstemp() inputs = {"ExampleFilePath": name} xmlfile = os.path.join(os.path.dirname(__file__), "test_algos.xml") executor = PACMANAlgorithmExecutor(algorithms=["FailingExternal"], xml_paths=[xmlfile], optional_algorithms=[], inputs=inputs, required_outputs=[], tokens=[], required_output_tokens=[]) with self.assertRaises( PacmanExternalAlgorithmFailedToCompleteException) as e: executor.execute_mapping() self.assertIn( "Algorithm FailingExternal returned a non-zero error code 1", str(e.exception)) self.assertEqual(executor.get_item("Foo"), None) with os.fdopen(fd) as f: self.assertEqual(f.read(), "foo\n")
def __call__(self, nengo_network, machine_time_step, nengo_random_number_generator_seed, decoder_cache, utilise_extra_core_for_output_types_probe, nengo_nodes_as_function_of_time, function_of_time_nodes_time_period, insert_interposers, print_timings, do_timings, xml_paths, pacman_executor_provenance_path, nengo_ensemble_profile, nengo_ensemble_profile_num_samples, receive_buffer_port, receive_buffer_host, minimum_buffer_sdram, maximum_sdram_for_sink_vertex_buffing, using_auto_pause_and_resume, time_between_requests, buffer_size_before_receive, spike_buffer_max_size, variable_buffer_max_size, machine_time_step_in_seconds): # create data holders inputs = dict() algorithms = list() outputs = list() tokens = list() required_tokens = list() optional_algorithms = list() # add nengo_spinnaker_gfe algorithms algorithms.append("NengoApplicationGraphBuilder") if insert_interposers: algorithms.append("NengoUtiliseInterposers") # add nengo_spinnaker_gfe inputs inputs["NengoModel"] = nengo_network inputs["MachineTimeStep"] = machine_time_step inputs["NengoRandomNumberGeneratorSeed"] = ( nengo_random_number_generator_seed) inputs["NengoDecoderCache"] = decoder_cache inputs["NengoUtiliseExtraCoreForProbes"] = ( utilise_extra_core_for_output_types_probe) inputs["NengoNodesAsFunctionOfTime"] = nengo_nodes_as_function_of_time inputs["NengoNodesAsFunctionOfTimeTimePeriod"] = ( function_of_time_nodes_time_period) inputs["NengoEnsembleProfile"] = nengo_ensemble_profile inputs["NengoEnsembleProfileNumSamples"] = ( nengo_ensemble_profile_num_samples) inputs["ReceiveBufferPort"] = receive_buffer_port inputs["ReceiveBufferHost"] = receive_buffer_host inputs["MinBufferSize"] = minimum_buffer_sdram inputs["MaxSinkBuffingSize"] = maximum_sdram_for_sink_vertex_buffing inputs["UsingAutoPauseAndResume"] = using_auto_pause_and_resume inputs["TimeBetweenRequests"] = time_between_requests inputs["BufferSizeBeforeReceive"] = buffer_size_before_receive inputs["SpikeBufferMaxSize"] = spike_buffer_max_size inputs["VariableBufferMaxSize"] = variable_buffer_max_size inputs["MachineTimeStepInSeconds"] = machine_time_step_in_seconds # Execute the algorithms executor = PACMANAlgorithmExecutor( algorithms=algorithms, optional_algorithms=optional_algorithms, inputs=inputs, tokens=tokens, required_output_tokens=required_tokens, xml_paths=xml_paths, required_outputs=outputs, do_timings=do_timings, print_timings=print_timings, provenance_name="nengo_graph_to_application_graph", provenance_path=pacman_executor_provenance_path) executor.execute_mapping() return (executor.get_item("NengoOperatorGraph"), executor.get_item("NengoHostGraph"), executor.get_item("NengoGraphToAppGraphMap"), executor.get_item("AppGraphToNengoOperatorMap"), executor.get_item("NengoRandomNumberGenerator"))