Repository navigation
BUG: Fix vf2 handling of isomorphism_iter with isolated subgraph nodes - #8895
Conversation
Peiffap
left a comment
There was a problem hiding this comment.
Left some inline comments but this generally looks good to me!
| d1 = sorted(d for n, d in self.G1.degree) | ||
| d2 = sorted(d for n, d in self.G2.degree) | ||
| if d1 != d2: | ||
| return |
There was a problem hiding this comment.
Non-blocking state-consistency question: this now returns before initialize(), leaving an earlier mapping in place. For example:
gm = nx.isomorphism.GraphMatcher(nx.cycle_graph(3), nx.path_graph(3))
gm.subgraph_is_monomorphic() # True
list(gm.isomorphisms_iter()) # []
gm.mappingThe last line was {} before this change and now retains the monomorphism. The boolean method already has similar early returns, so this is a question about intended reuse behavior. Should the iterator still reset its state, or should retaining the previous mapping be documented and tested?
There was a problem hiding this comment.
This state issue has been a problem with this suite of functions for a while. I shifted the self.initialize()
line to before the checks -- it is not expensive and is needed to reset self.mapping.
But users can still mess up state if they e.g. are iterating over mappings and between iterations they call a method of the same GraphMatcher. We can say "don't do that" -- python dicts say "dont do that" when changing a dict while iterating across it. But I think the better fix is to refactor all the algorithms to have a uniform function interface where each call constructs an internal private class that does the work and is protected from other activity that might mess it up. That approach/discussion is coming once all the algorithms are full-featured. Hopefully this Fall/Winter.
So, for now I'm just moving this one initialize() call, checking that the other public methods do the same early initialize, and relying on folks to not start two concurrent morphism calls with the same GraphMatcher.
Thanks for this!
| d1 = sorted(d for n, d in self.G1.degree) | ||
| d2 = sorted(d for n, d in self.G2.degree) | ||
| if d1 != d2: | ||
| return |
There was a problem hiding this comment.
This state issue has been a problem with this suite of functions for a while. I shifted the self.initialize()
line to before the checks -- it is not expensive and is needed to reset self.mapping.
But users can still mess up state if they e.g. are iterating over mappings and between iterations they call a method of the same GraphMatcher. We can say "don't do that" -- python dicts say "dont do that" when changing a dict while iterating across it. But I think the better fix is to refactor all the algorithms to have a uniform function interface where each call constructs an internal private class that does the work and is protected from other activity that might mess it up. That approach/discussion is coming once all the algorithms are full-featured. Hopefully this Fall/Winter.
So, for now I'm just moving this one initialize() call, checking that the other public methods do the same early initialize, and relying on folks to not start two concurrent morphism calls with the same GraphMatcher.
Thanks for this!
Fixes #8891
This is a corner case when subgraph has an isolated node and graph is subgraph isomorphic (and not isomorphic) to subgraph. The
is_isomorphicmethod correctly returned False, butisomorphisms_itergenerated mappings.Added two tests (one for vf2 and one in
test_common.pyfor all algorithms.