Skip to content

Add examples to docstrings of subgraph_(iso/monomorphism) methods - #7622

Merged
jarrodmillman merged 9 commits into
networkx:mainfrom
rossbar:doc/subgraph-iter-examples
Oct 10, 2024
Merged

jarrodmillman merged 9 commits into
networkx:mainfrom
rossbar:doc/subgraph-iter-examples

Conversation

@rossbar

@rossbar rossbar commented Sep 6, 2024

Copy link
Copy Markdown
Contributor

Addresses #7615

Adds examples to the subgraph_is_(iso/mono)morphic and subgraph_(iso/mono)morophism_iter to highlight the role that argument order plays when constructing the GraphMatcher objects.

After some back and forth, I ultimately decided to do a separate docstring for each of the 8 methods. This means I added stubs for the DiGraphMatcher methods for the sole purpose of updating the docstrings. I had tried adding both a directed and undirected example to the GraphMatcher methods (which are then inherited and thus don't need to be duplicated), but decided against it for the subjective reason that I thought the examples section got too long when I did so. One solution would be to make shorter examples... I'm happy to give that a stab as well if it's preferred --- feedback welcome!

This PR also includes a few minor rst cleanups and comment removals.

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
I found a typo. And I wonder if we can make the nodes more clearly part of G or H by avoiding small integers for one of the graphs. see below

Comment on lines +981 to +982
>>> G = nx.DiGraph([(1, 2), (2, 1), (2, 3), (3, 2)])
>>> H = nx.DiGraph(nx.path_graph(5))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nodes here make it hard to see if a mapping is from H to G or from G to H.
Could we use G = nx.DiGraph([("A", "B"), ("B", "C"), ("B", "A"), ("C", "B")])?
Then the result is something like: {0: 'A', 1: 'B', 2: 'C'}

Another choice could be: G = nx.DiGraph([(101, 102), (102, 101), (102, 103), (103, 102)])

Also, would it be simpler to make the graphs directed paths:

G = nx.DiGraph([("A", "B"), ("B", "C")])
H = nx.DiGraph(nx.path_graph(5).edges)

But maybe that isn't simpler... it removes one direction from each node-pair. But the constructor syntax is longer.

@rossbar
rossbar force-pushed the doc/subgraph-iter-examples branch from b204ba5 to 21f88d8 Compare September 9, 2024 18:56

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry that I didn't catch this before. But the last three intro phrases for examples are "Check whether...." when they should be "Yield ... mappings ".

@jarrodmillman
jarrodmillman self-requested a review October 10, 2024 15:58
@jarrodmillman jarrodmillman added this to the 3.4 milestone Oct 10, 2024
@jarrodmillman
jarrodmillman requested a review from dschult October 10, 2024 17:46
@jarrodmillman
jarrodmillman merged commit af435c2 into networkx:main Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants