Repository navigation
Conversation
`find_isomorphisms` bailed out early whenever the *padded* subgraph
partition was longer than the number of matched colors:
elif len(self._sgn_partition) > self.N_node_colors:
elif len(self._sge_partition) > self.N_edge_colors:
However `create_aligned_partitions` pads the subgraph partition with
empty sets so that graph-only colors (colors present in the graph but
absent from the subgraph) line up positionally with the graph
partition. Those empty padding sets made `len(partition)` exceed
`N_*_colors`, so a perfectly valid match was wrongly rejected.
This is why an edgeless subgraph behaved differently with
`edge_match=None` versus `edge_match=lambda e1, e2: True`: the callable
produced a real edge color in the graph that padded the (empty)
subgraph edge partition, tripping the check (networkxgh-8738).
Fix: only bail out when the subgraph has a genuinely non-empty part
beyond the matched colors, i.e. a color that really only the subgraph
has. Padding sets are empty and are correctly ignored.
Add regression tests covering both the edge-color and node-color cases,
including that a subgraph-only color still yields no isomorphisms.
|
Thanks for this bug-fix! The description is clear and the solution is elegant. :) |
|
It feels like the code has a design wart that lead to the bug. Why are we padding the partition? It makes the partition look longer than it really is. Your fix is certainly a good fix. But I'm thinking there might be a way to remove the design wart so a fix isn't needed. That could help avoid some cases with lots of unneeded padding, as well as the These tests are really helpful in pinpointing the trouble. [Added later] What do you think of reverting your fix (back to using |
|
I added some tests of the node color issue. The fix here fixes those problems too. Let me know what you think! (and pull this from your fork to your local branch before |
dschult
left a comment
There was a problem hiding this comment.
I think this is ready.
I approve this PR.
rossbar
left a comment
There was a problem hiding this comment.
LGTM, thanks @deepakganesh78 and @dschult for chasing this down!
Fixes #8738 (the
edge_matchhalf; also fixes the analogous node-color case).Root cause
ISMAGS.find_isomorphismsshort-circuits with:The intent is "some subgraph color doesn't occur in the graph, so no match is possible." But
create_aligned_partitionspads the subgraph partition with empty sets so that graph-only colors (present in the graph, absent from the subgraph) line up positionally against the graph partition. Those empty padding sets makelen(self._sg*_partition)larger thanN_*_colorseven though every subgraph color is present in the graph — so a valid match gets rejected.This is exactly why the reported example behaves inconsistently:
With
edge_match=Nonethe graph edge partition is a single lumped part and nothing gets padded; with a callable, the graph's real edge produces an edge color that pads the (empty) subgraph edge partition, tripping the length check. The same latent bug exists for node colors when the graph has a node color the subgraph lacks.Fix
Only bail out when the subgraph has a genuinely non-empty part beyond the matched colors (a color that really only the subgraph has). Padding sets are empty, so they're correctly ignored:
Tests
Added two regression tests in
TestSubgraphIsomorphism:test_edgeless_subgraph_with_edge_match—edge_match=Noneandedge_match=lambda e1, e2: Truenow both yield[{0: 0}, {1: 0}].test_subgraph_with_graph_only_node_color— a graph-only node color no longer blocks a match, while a genuine subgraph-only color still correctly yields no isomorphisms.Note: this PR intentionally scopes to the
create_aligned_partitionspadding bug. Thecategorical_node_match([...], [None]*0)default-length pitfall discussed in the issue thread is a separate concern and not touched here.