Skip to content

Fix edge case in ISMAGS symmetry detection - #8055

Merged
dschult merged 2 commits into
networkx:mainfrom
Peiffap:bugfix/ismags
May 26, 2025
Merged

dschult merged 2 commits into
networkx:mainfrom
Peiffap:bugfix/ismags

Conversation

@Peiffap

@Peiffap Peiffap commented May 20, 2025

Copy link
Copy Markdown
Member

Fixes #4915.

Paraphrasing the original issue (#4915): there is an error in the ISMAGS implementation. For some specific cases it trips an AssertionError. This happens for graphs of this shape, where all nodes and edges are equivalent.

5 - 4 \     / 12 - 13
       0 - 3
9 - 8 /     \ 16 - 17

During symmetry detection/analysis, nodes 0 and 3 are coupled and no longer equivalent. At that point, {4, 8} and {12, 16} are no longer equivalent, and neither are {5, 9} and {13, 17}. Coupling 4 then refining results in 5 and 9 getting their own partitions, but not 13 and 17.
This results in tripping the following assert:

assert all(
len(t_p) == len(b_p) for t_p, b_p in zip(top_partitions, bottom_partitions)
)

The good news is that this case cannot result in new symmetries, so it can be safely changed to an if not cond: return [], cosets.

This fix is a straight port of the one in marrink-lab/vermouth-martinize@d5be20b, with permission from the original author.
It replaces the assertion by the aforementioned if block and adds the minimal test case above (which fails on networkx/main) to the test suite.

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This essentially ports over the fix from marrink-lab/vermouth-martinize#338 . I'm no ISMAGs expert, but given the discussion over there this seems like a reasonable fix. Thanks for hunting it down @Peiffap !

@Peiffap

Peiffap commented May 24, 2025

Copy link
Copy Markdown
Member Author

There are some other changes in the original repo where its implementation has diverged, but they're fairly minor. Would synchronizing the two be something to do here or in a separate PR?

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

Let's do the other changes in a separate PR. (I'm not actually sure what those other changes would be, but we've got approvals here, so let's get these in. :)

@dschult
dschult merged commit 9e33b11 into networkx:main May 26, 2025
@Peiffap
Peiffap deleted the bugfix/ismags branch May 27, 2025 13:05
@jarrodmillman jarrodmillman added this to the 3.5 milestone May 29, 2025
amcandio pushed a commit to amcandio/networkx that referenced this pull request Jul 20, 2025
* Fix edge case in ISMAGS symmetry detection

Co-authored-by: Peter Kroon <[email protected]>

* Add viz to ISMAGS edge case test

---------

Co-authored-by: Peter Kroon <[email protected]>
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.

ISMAGS trips AssertionError for specific symmetry patterns

5 participants