def test_mcs_match(data): """ Test against networkx reference implementation using graphs that are subgraphs without considering symmetry. """ attrs = data.draw(st.one_of(st.none(), ATTRS)) if attrs is None: node_match = lambda n1, n2: True attrs = [] else: node_match = nx.isomorphism.categorical_node_match( attrs, [None] * len(attrs)) graph = data.draw(MCS_BUILDER) if graph: nodes = data.draw( st.sets(st.sampled_from(list(graph.nodes)), max_size=len(graph))) else: nodes = [] subgraph = graph.subgraph(nodes) note(("Graph nodes", graph.nodes(data=True))) note(("Graph edges", graph.edges(data=True))) note(("Subgraph nodes", subgraph.nodes(data=True))) note(("Subgraph edges", subgraph.edges(data=True))) ref_time = perf_counter() expected = make_into_set(MCS(graph, subgraph, attributes=attrs)) ref_time -= perf_counter() a_ism_time = perf_counter() ismags = vermouth.ismags.ISMAGS(graph, subgraph, node_match=node_match) asymmetric = make_into_set(ismags.largest_common_subgraph(False)) a_ism_time -= perf_counter() s_ism_time = perf_counter() ismags = vermouth.ismags.ISMAGS(graph, subgraph, node_match=node_match) symmetric = make_into_set(ismags.largest_common_subgraph(True)) s_ism_time -= perf_counter() note(("Symmetric", symmetric)) note(("Asymmetric", asymmetric)) note(("Expected", expected)) if a_ism_time < ref_time: event('Asymmetric ISMAGS faster than reference') if s_ism_time < a_ism_time: event('Symmetric ISMAGS faster than asymmetric') if s_ism_time < ref_time: event('Symmetric ISMAGS faster than reference') assert asymmetric == expected or not expected assert symmetric <= asymmetric
def test_mcs_nonmatch(graph, subgraph, attrs): """ Test against networkx reference implementation using graphs that are probably not subgraphs without considering symmetry. """ if attrs is None: node_match = lambda n1, n2: True attrs = [] else: node_match = nx.isomorphism.categorical_node_match( attrs, [None] * len(attrs)) note(("Graph nodes", graph.nodes(data=True))) note(("Graph edges", graph.edges(data=True))) note(("Subgraph nodes", subgraph.nodes(data=True))) note(("Subgraph edges", subgraph.edges(data=True))) ref_time = perf_counter() expected = make_into_set(MCS(graph, subgraph, attributes=attrs)) ref_time -= perf_counter() a_ism_time = perf_counter() ismags = vermouth.ismags.ISMAGS(graph, subgraph, node_match=node_match) asymmetric = make_into_set(ismags.largest_common_subgraph(False)) a_ism_time -= perf_counter() s_ism_time = perf_counter() ismags = vermouth.ismags.ISMAGS(graph, subgraph, node_match=node_match) symmetric = make_into_set(ismags.largest_common_subgraph(True)) s_ism_time -= perf_counter() note(("Symmetric", symmetric)) note(("Asymmetric", asymmetric)) note(("Expected", expected)) if a_ism_time < ref_time: event('Asymmetric ISMAGS faster than reference') if s_ism_time < a_ism_time: event('Symmetric ISMAGS faster than asymmetric') if s_ism_time < ref_time: event('Symmetric ISMAGS faster than reference') assert asymmetric == expected or not expected assert symmetric <= asymmetric