def test_make_video(self): temp = get_temp_folder(__file__, "temp_graphviz") fout = os.path.join(temp, "image.png") draw_graph_graphviz([(1, "eee", "red")], [(1, 2, "blue"), (3, 4), (1, 3)], fout) self.assertTrue(os.path.exists(fout)) self.assertTrue(os.path.exists(fout + ".gv"))
def test_graph_distance_bigger(self): from mlstatpy.graph.graphviz_helper import draw_graph_graphviz X = helper.make_tensor_value_info('X', TensorProto.FLOAT, None) # pylint: disable=E1101 Z = helper.make_tensor_value_info('Z', TensorProto.FLOAT, None) # pylint: disable=E1101 node_def = helper.make_node('Neg', ['X'], ['Z'], name='A') graph_def = helper.make_graph([node_def], 'test-model', [X], [Z]) model_def = helper.make_model( graph_def, producer_name='mlprodict', ir_version=7, producer_version='0.1', opset_imports=[helper.make_operatorsetid('', 13)]) node_def1 = helper.make_node('Neg', ['X'], ['Y'], name='A') node_def2 = helper.make_node('Neg', ['Y'], ['Z'], name='B') graph_def = helper.make_graph([node_def1, node_def2], 'test-model', [X], [Z]) model_def2 = helper.make_model( graph_def, producer_name='mlprodict', ir_version=7, producer_version='0.1', opset_imports=[helper.make_operatorsetid('', 13)]) d, graph = onnx_graph_distance(model_def, model_def2) self.assertLess(d, 1) vertices, edges = graph.draw_vertices_edges() gv = draw_graph_graphviz(vertices, edges) self.assertIn("->", gv)
def test_image_video_kohonen(self): temp = get_temp_folder(__file__, "temp_graph_distance") graph1 = [("a", "b"), ("b", "c"), ("b", "d"), ("d", "e"), ("e", "f"), ("b", "f"), ("b", "g"), ("f", "g"), ("a", "g"), ("a", "g"), ("c", "d"), ("d", "g"), ("d", "h"), ("aa", "h"), ("aa", "c"), ("f", "h"), ] graph2 = copy.deepcopy(graph1) + \ [("h", "m"), ("m", "l"), ("l", "C"), ("C", "r"), ("a", "k"), ("k", "l"), ("k", "C"), ] graph1 = GraphDistance(graph1) graph2 = GraphDistance(graph2) graph2["C"].label = "c" store = {} if len(list(graph1.enumerate_all_paths(True))) != 17: raise Exception("expecting 17 here") if len(list(graph2.enumerate_all_paths(True))) != 19: raise Exception("expecting 19 here") distance, graph = graph1.distance_matching_graphs_paths(graph2, use_min=False, store=store) if graph["h"].Label != "h": raise Exception("we expect this node to be merged in the process") if distance is None: raise Exception("expecting something different from None") outfile1 = os.path.join(temp, "unittest_GraphDistance4_sub1.png") outfile2 = os.path.join(temp, "unittest_GraphDistance4_sub2.png") outfilef = os.path.join(temp, "unittest_GraphDistance4_subf.png") if is_travis_or_appveyor() == "travis": warnings.warn("graphviz is not available") return vertices, edges = graph1.draw_vertices_edges() self.assertNotEmpty(vertices) self.assertNotEmpty(edges) draw_graph_graphviz(vertices, edges, outfile1) vertices, edges = graph2.draw_vertices_edges() self.assertNotEmpty(vertices) self.assertNotEmpty(edges) draw_graph_graphviz(vertices, edges, outfile2) self.assertTrue(os.path.exists(outfile2)) vertices, edges = graph.draw_vertices_edges() self.assertNotEmpty(vertices) self.assertNotEmpty(edges) draw_graph_graphviz(vertices, edges, outfilef) self.assertTrue(os.path.exists(outfilef))
def test_image_video_kohonen(self): temp = get_temp_folder(__file__, "temp_graph_distance") graph1 = [ ("a", "b"), ("b", "c"), ("b", "d"), ("d", "e"), ("e", "f"), ("b", "f"), ("b", "g"), ("f", "g"), ("a", "g"), ("a", "g"), ("c", "d"), ("d", "g"), ("d", "h"), ("aa", "h"), ("aa", "c"), ("f", "h"), ] graph2 = copy.deepcopy(graph1) + \ [("h", "m"), ("m", "l"), ("l", "C"), ("C", "r"), ("a", "k"), ("k", "l"), ("k", "C"), ] graph1 = GraphDistance(graph1) graph2 = GraphDistance(graph2) graph2["C"].label = "c" store = {} if len(list(graph1.enumerate_all_paths(True))) != 17: raise Exception("expecting 17 here") if len(list(graph2.enumerate_all_paths(True))) != 19: raise Exception("expecting 19 here") distance, graph = graph1.distance_matching_graphs_paths(graph2, use_min=False, store=store) if graph["h"].Label != "h": raise Exception("we expect this node to be merged in the process") if distance is None: raise Exception("expecting something different from None") outfile1 = os.path.join(temp, "unittest_GraphDistance4_sub1.png") outfile2 = os.path.join(temp, "unittest_GraphDistance4_sub2.png") outfilef = os.path.join(temp, "unittest_GraphDistance4_subf.png") if is_travis_or_appveyor() == "travis": warnings.warn("graphviz is not available") return vertices, edges = graph1.draw_vertices_edges() self.assertNotEmpty(vertices) self.assertNotEmpty(edges) draw_graph_graphviz(vertices, edges, outfile1) vertices, edges = graph2.draw_vertices_edges() self.assertNotEmpty(vertices) self.assertNotEmpty(edges) draw_graph_graphviz(vertices, edges, outfile2) self.assertTrue(os.path.exists(outfile2)) vertices, edges = graph.draw_vertices_edges() self.assertNotEmpty(vertices) self.assertNotEmpty(edges) draw_graph_graphviz(vertices, edges, outfilef) self.assertTrue(os.path.exists(outfilef))
def test_draw_graph_graphviz_no_image(self): res = draw_graph_graphviz([(1, "eee", "red")], [(1, 2, "blue"), (3, 4), (1, 3)], image=None) self.assertIn('[label="eee"', res)