Repository navigation
Add ISMAGS monomorphism support - #8838
Conversation
rossbar
left a comment
There was a problem hiding this comment.
A very nice new feature, thanks @dschult !
Generally LGTM! One high-level interface question - do we intend all_morphisms to be a method that users actually call, or is it more for internal orchestration (i.e. mapping "finding morphisms" to the correct problem type). If it's the latter, I'd vote to make it explicitly private so that users can focus on the direct methods (subgraph_isomorphisms_iter, monomorphisms_iter, etc.).
Not really a blocker, just an attempt to keep the number of ways to access functionality on the ISMAGS class more manageable!
pckroon
left a comment
There was a problem hiding this comment.
I'm very excited to watch the nx ismags development take off from the sidelines, but I really need to admit it's quickly going over my head :)
Time to read up on wikipedia what a monomorphism is...
|
Monomorphism means a not-necessarily-induced-subgraph of The single-edge graph is not isomorphic to the 2-node graph with no edges. But it is monomorphic. |
|
Thanks, learned something new today :) Your explanation is much easier to understand than Wikipedia's. |
|
I did find a few inconsistencies. I'll put them here, but please let me know if you'd prefer them in an issue. Doesn't seem like deal breaking problems though, it seems to be a discrepancy in the symmetry handling between isormorphism and monomorphism.
With However, with |
|
Thanks for this work and for the nice example! Adding an edge to make the full graph, means there aren't any But I am confused by your result that G = nx.empty_graph([(0, 1), (0, 2), (0, 3)])
FG = G.copy()
FG.add_edge(1, 2)
mono_maps = list(nx.isomorphism.ISMAGS(FG, G).monomorphisms_iter(symmetry=True))
mono_maps_all = list(nx.isomorphism.ISMAGS(FG, G).monomorphisms_iter(symmetry=False))
iso_maps = list(nx.isomorphism.ISMAGS(FG, G).subgraph_isomorphisms_iter(symmetry=True))
iso_maps_all = list(nx.isomorphism.ISMAGS(FG, G).subgraph_isomorphisms_iter(symmetry=False))
print(f"{iso_maps=}\n{mono_maps=}")
print(f"\nNo Symmetry Restriction on Maps")
print(f"{iso_maps_all=}\n{mono_maps_all=}")with output: |
|
Not quite. What I do is test the hypothesis that all isomorphisms G = nx.empty_graph([(0, 1), (0, 2), (0, 3)])
S = nx.subgraph({0, 1, 2, 3})
H = G.copy()
H.add_edge(1, 2)
isomorphisms = list(nx.isomorphism.ISMAGS(G, S).isomorphisms_iter(symmetry=False))
monomorphisms = list(nx.isomorphism.ISMAGS(H, S).monomorphisms_iter(symmetry=False))
# Turn the 2 lists-of-dicts into 2 sets-of-frozensets-of-tuples
assert isomorphisms <= monomorphismsSince |
|
I got this working -- after tweaking the code to 1) use Graph instead of empty_graph (which made the nodes into 2-tuples intended to be edges?) and 2) use import networkx as nx
G = nx.Graph([(0, 1), (0, 2), (0, 3)])
S = nx.subgraph(G, {0, 1, 2, 3})
H = G.copy()
H.add_edge(1, 2)
isomorphisms = {frozenset(m.items()) for m in nx.isomorphism.ISMAGS(G, S).isomorphisms_iter(symmetry=False)}
monomorphisms = {frozenset(m.items()) for m in nx.isomorphism.ISMAGS(H, S).monomorphisms_iter(symmetry=False)}
print(f"{isomorphisms=}\n{monomorphisms=}")
assert isomorphisms <= monomorphismsI get 6 mappings for both isomorphisms and monomorphisms (and they are equal). |
|
Apologies for not checking my code more carefully, and thanks for taking a look. Anyway, for any simple graph I throw at it, |
This PR adds support for monomorphism checking with ISMAGS.
That means we can iterate over monomorphisms and get only one
morphisms for each group of morphisms that are symmetrically the same.
The symmetries are found in the subgraph and used to restrict reported
monomorphisms.
The monomorphism code is intertwined with the isomorphisms using
ifclauses and operator function
SG_fitsandmono_fitsfunctions.That reduces a lot of duplicate code -- but might affect performance.
I did run a profiler and found that creating
gn2_candswas poorly behavedso rewrote those loops. I'm sure more can be done for optimization.
But this at least gets the functionality in place.