aplbrain / grandiso-networkx

Performant, pure-Python subgraph isomorphism and monomorphism search (aka "motif search")
Apache License 2.0
56 stars 10 forks source link

`find_motifs_iter`: report best match #44

Open aleclearmind opened 3 months ago

aleclearmind commented 3 months ago

In case of no results, it's still useful to have something to report to the user.

Our specific use case is the following: we use grandiso in our test framework (which involves graphs). In case of test failure (no graph match), we currently get no information and the developer needs to figure out on its own the problem. With this patch, we can provide the developers with a pair of colored graphs reporting the best match we found before giving up, which usually enables the developer to rapidly highlight the problem by looking at uncolored nodes.

It's not perfect and I'm open to feedback on the metric to establish the best match and to more Pythonic ways to report the best match (currently it uses a one-element list as an "out" parameter).

Note the leftmost white node, it's the source of the mismatch: