Repository navigation
fix: handle empty candidate sets in ISMAGS.largest_common_subgraph - #8890
Merged
Merged
Conversation
dschult
reviewed
Sep 3, 2026
dschult
left a comment
Member
There was a problem hiding this comment.
Thanks for this! Unfortunately this doesn't cover all the cases that the old code covered. The nodes can have no candidates due to either node color or number of self-loops. suggestions below.
| assert ismags._sgn_partition == [{1}, {0}, {2}] | ||
| assert ismags._gn_partition == [{5}, set(), set(), {2}] | ||
|
|
||
| def test_no_common_colors(self): |
Member
There was a problem hiding this comment.
Let's test for colors and self-loops. Both conditions will result in nodes with no candidates.
Something like:
def test_color_mismatches(self):
# see gh-8885
graph = nx.path_graph(5)
subgraph = nx.path_graph(5)
for n in subgraph:
subgraph.nodes[n]["color"] = "blue"
# check that normal case works as expected
ismags = iso.ISMAGS(graph, subgraph)
assert list(ismags.largest_common_subgraph()) == [{i: i for i in subgraph}]
# check case when a subgraph node has no candidate color match
nodematch = nx.isomorphism.categorical_node_match("color", None)
ismags = iso.ISMAGS(graph, subgraph, node_match=nodematch)
assert list(ismags.largest_common_subgraph()) == []
# check case when a subgraph node has no candidate sue to selfloops
for n in graph:
graph.add_edge(n, n)
ismags = iso.ISMAGS(graph, subgraph)
assert list(ismags.largest_common_subgraph()) == []
dschult
approved these changes
Sep 11, 2026
dschult
left a comment
Member
There was a problem hiding this comment.
I took the liberty of adding a few corner case tests for largest common subgraph:
- null graphs
- small empty graphs (that either do or don't have color mismatches)
- I changed the PR test of multi-node but no color matches to test both color matches and self-loop matches.
For the fix itself, I updated the if-clause to check for self-loop and/or color no-matches and I tightened up comments somewhat.
I approve this PR. Thanks @mturac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #8885
largest_common_subgraph()crashes withValueError: min() iterable argument is emptywhen subgraph and graph dont share any node colors. the guard on line 839 was checkingany(candidate_sets.values())wich is allways truthy because the values are singleton sets even when the inner frozenset is empty.fixed it to check
any(to_be_mapped)insted — if theres nothing to map, yield nothing and return. added two tests for the case where no colors overlap.