Skip to content

[BUG][PERF] Fix ISMAGS directed matching and monomorphism overhead - #8900

Merged
MridulS merged 5 commits into
networkx:mainfrom
Peiffap:codex/ismags-monomorphism-fixes
Sep 8, 2026
Merged

MridulS merged 5 commits into
networkx:mainfrom
Peiffap:codex/ismags-monomorphism-fixes

Conversation

@Peiffap

@Peiffap Peiffap commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

Fix a few ISMAGS issues found after #8838, with one commit per fix:

  • 0be5f6ab4: Apply the candidate sets for incoming edges. These were computed but not used, allowing incorrect mappings for directed graphs. Add tests for edge existence, edge colors and multiedge counts.
  • e6a85d93b: Skip computing not_gn_nbrs when finding monomorphisms. Nonneighbors only need to be checked for isomorphism and induced subgraph isomorphism.
  • 4ade591e4: Fix a test assertion that always passed for Graph and DiGraph without checking the number of mappings.
  • 8f31c83b0: Clarify the monomorphism docstrings and add an example showing how symmetries of the subgraph affect the number of mappings.
  • aa6d9a2ab: Remove the unused self_ge_partition variable.

For example, this used to return True, although G contains no directed cycle of length 3:

G = nx.DiGraph([(1, 3), (2, 3), (3, 1), (3, 2)])
S = nx.DiGraph([(0, 1), (1, 2), (2, 0)])
nx.isomorphism.ISMAGS(G, S).subgraph_is_isomorphic()  # Now False

Finding all monomorphisms of path_graph(2) in path_graph(10000) took 2.78 s before and 0.15 s after, with the same 19,998 mappings (median of three runs, Python 3.14, symmetry=False).

Tests: 1,568 passed, 740 expected failures; all pre-commit checks passed.

AI assisted with the changes, which were checked with regression tests, doctests and benchmarks.

@Peiffap Peiffap changed the title Fix ISMAGS directed matching and monomorphism overhead [BUG][PERF] Fix ISMAGS directed matching and monomorphism overhead Sep 6, 2026
@Peiffap
Peiffap marked this pull request as ready for review September 6, 2026 18:21
@Peiffap
Peiffap requested a review from dschult September 6, 2026 18:28
@dschult

dschult commented Sep 7, 2026

Copy link
Copy Markdown
Member

I cant read this PR description. Can you write it in your own words?

@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.

Thanks @Peiffap for this PR!

Looking at each commit individually was very helpful.
Thanks for finding the omitted code handling incoming edges,
And for updating the tests to reflect that problem, for removing both extraneous unused variables and for not assigning variables in every case when only used in certain cases. And thanks very much for the documentation rewording about monomorphism!

All of these are good changes and the PR is ready to merge!

@Peiffap

Peiffap commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

I cant read this PR description. Can you write it in your own words?

Seems like the per-commit structure was helpful so I kept that, but tried wording things differently. Thanks for the review and for all your work on matching recently!

@MridulS

MridulS commented Sep 8, 2026

Copy link
Copy Markdown
Member

Hmm looks like the benchmarks are timing out, we can look at them in another PR!

@MridulS
MridulS merged commit 675034a into networkx:main Sep 8, 2026
45 of 49 checks passed
@dschult dschult added this to the 3.7 milestone Sep 8, 2026
@Peiffap
Peiffap deleted the codex/ismags-monomorphism-fixes branch September 9, 2026 15:00
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