def test_valid_clique_coord(self): k = nx.complete_graph(15) m = 4 # Find embedding pg = pegasus_graph(m, coordinates=True) embedding = find_clique_embedding(k, target_graph=pg) self.assertTrue(is_valid_embedding(embedding, k, pg))
def test_k_parameter_int(self): k_int = 5 m = 3 # Find embedding pg = pegasus_graph(m, coordinates=True) embedding = find_clique_embedding(k_int, target_graph=pg) self.assertTrue(is_valid_embedding(embedding, nx.complete_graph(k_int), pg))
def test_valid(self): k2 = nx.complete_graph(2) emb = {0: [0], 1: [1]} verify_embedding(emb, k2, k2) self.assertTrue(is_valid_embedding(emb, k2, k2)) for err in diagnose_embedding(emb, k2, k2): raise err[0](*err[1:])
def test_k_parameter_list(self): k_nodes = ['one', 'two', 'three'] m = 4 # Find embedding pg = pegasus_graph(m, coordinates=True) embedding = find_clique_embedding(k_nodes, target_graph=pg) self.assertTrue(is_valid_embedding(embedding, nx.complete_graph(k_nodes), pg))
def test_invalid_node(self): k2 = nx.complete_graph(2) emb = {0: [0], 1: [2]} self.assertRaises(InvalidNodeError, lambda: verify_embedding(emb, k2, k2)) self.assertFalse(is_valid_embedding(emb, k2, k2)) etypes = set() for err in diagnose_embedding(emb, k2, k2): etypes.add(err[0]) self.assertEqual(etypes, {InvalidNodeError})
def test_chain_overlap(self): k2 = nx.complete_graph(2) emb = {0: [0], 1: [0, 1]} self.assertRaises(ChainOverlapError, lambda: verify_embedding(emb, k2, k2)) self.assertFalse(is_valid_embedding(emb, k2, k2)) etypes = set() for err in diagnose_embedding(emb, k2, k2): etypes.add(err[0]) self.assertEqual(etypes, {ChainOverlapError})
def test_missing_chain(self): k2 = nx.complete_graph(2) emb = {0: [0]} self.assertRaises(MissingChainError, lambda: verify_embedding(emb, k2, k2)) self.assertFalse(is_valid_embedding(emb, k2, k2)) etypes = set() for err in diagnose_embedding(emb, k2, k2): etypes.add(err[0]) self.assertEqual(etypes, {MissingChainError})
def test_chain_disconnect(self): k2 = nx.complete_graph(2) p3 = nx.path_graph(3) emb = {0: [1], 1: [0, 2]} self.assertRaises(DisconnectedChainError, lambda: verify_embedding(emb, k2, p3)) self.assertFalse(is_valid_embedding(emb, k2, p3)) etypes = set() for err in diagnose_embedding(emb, k2, p3): etypes.add(err[0]) self.assertEqual(etypes, {DisconnectedChainError})
def test_chain_overlap_with_edges(self): #this is made for compatibility with minorminer; to verify that "overlapped #embeddings" don't report spurious MissingEdgeErrors k5 = nx.complete_graph(5) k4 = nx.complete_graph(4) emb = {i: [i % 4, (i + 1) % 4] for i in k5} self.assertRaises(ChainOverlapError, lambda: verify_embedding(emb, k5, k4)) self.assertFalse(is_valid_embedding(emb, k5, k4)) etypes = set() for err in diagnose_embedding(emb, k5, k4): etypes.add(err[0]) self.assertEqual(etypes, {ChainOverlapError})
def test_clique_incomplete_graph(self): k = 5 m = 2 # Nodes in a known K5 embedding # Note: {0: [14, 32], 1: [33, 15], 2: [16, 34], 3: [35, 17], 4: [36, 12]} known_embedding_nodes = {14, 32, 33, 15, 16, 34, 35, 17, 36, 12} # Create graph with missing nodes incomplete_pg = pegasus_graph(m) removed_nodes = set(incomplete_pg.nodes) - known_embedding_nodes incomplete_pg.remove_nodes_from(removed_nodes) # See if clique embedding is found embedding = find_clique_embedding(k, target_graph=incomplete_pg) self.assertTrue(is_valid_embedding(embedding, nx.complete_graph(k), incomplete_pg))
def test_clique_missing_edges(self): k = 9 m = 2 pg = pegasus_graph(m) #pick a random ordering of the edges edges = list(pg.edges()) shuffle(edges) K = nx.complete_graph(k) #now delete edges, one at a time, until we can no longer embed K with self.assertRaises(ValueError): while 1: (u, v) = edges.pop() pg.remove_edge(u, v) # See if clique embedding is found embedding = find_clique_embedding(k, target_graph=pg) self.assertTrue(is_valid_embedding(embedding, K, pg))