Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare graphs for generator functions when running tests with backend #7066

Merged
merged 8 commits into from Dec 7, 2023

Conversation

eriknw
Copy link
Contributor

@eriknw eriknw commented Oct 26, 2023

This is an alternative to #7063 and is much more general.

The backend testing infrastructure can call backend graph generator functions such as circular_ladder_graph, and it converts the backend Graph to a networkx Graph. This is a great way to test backend generators! However, sometimes iteration order is different when using the converted backend graph. So, our solution here is to also call the original networkx function when the return type is a Graph, compare results, then use the result from networkx to allow tests to pass. We use a series of assertions to help backend implementers identify differences.

This is an alternative to networkx#7063.

The backend testing infrastructure can call backend graph generator functions
such as `circular_ladder_graph`, and it converts the backend Graph to a networkx
Graph. This is a great way to test backend generators! However, sometimes iteration
order is different when using the converted backend graph. So, our solution here
is to *also* call the original networkx function when the return type is a Graph,
compare results, then use the result from networkx to allow tests to pass.
We use a series of assertions to help backend implementers identify differences.
@eriknw
Copy link
Contributor Author

eriknw commented Oct 26, 2023

Shoot, this fails due to mutating input arguments (such as consuming iterators).

@eriknw
Copy link
Contributor Author

eriknw commented Oct 27, 2023

Alright, this is passing CI now!

You can see how much more complicated this is to do compared to #7063. The benefit should also be clear: this caught several bugs! I had to update the dispatch decorator many places. Hopefully this isn't too much of a maintenance burden--if a function starts to fail, perhaps just add it to the ignore set.

Heh, the benefit of #7063 is also clear: it's simple!

networkx/utils/backends.py Outdated Show resolved Hide resolved
@dschult
Copy link
Member

dschult commented Nov 28, 2023

Is this ready to merge/review? Are there other things to add?

@eriknw
Copy link
Contributor Author

eriknw commented Nov 29, 2023

Is this ready to merge/review? Are there other things to add?

This should be ready to merge now. I just updated difference to reflect the change made in #7092 (although I'm not sure the test added in #7092 does a good job--the previous commit passed CI too).

eriknw added a commit to eriknw/cugraph that referenced this pull request Nov 30, 2023
@MridulS MridulS merged commit 5d2bd43 into networkx:main Dec 7, 2023
38 checks passed
@jarrodmillman jarrodmillman added this to the 3.3 milestone Dec 7, 2023
rapids-bot bot pushed a commit to rapidsai/cugraph that referenced this pull request Dec 12, 2023
These changes will be necessary when networkx/networkx#7066 is merged.

Authors:
  - Erik Welch (https://github.com/eriknw)

Approvers:
  - Rick Ratzel (https://github.com/rlratzel)

URL: #4028
cvanelteren pushed a commit to cvanelteren/networkx that referenced this pull request Apr 22, 2024
networkx#7066)

* Compare graphs for generator functions when running tests with backend

This is an alternative to networkx#7063.

The backend testing infrastructure can call backend graph generator functions
such as `circular_ladder_graph`, and it converts the backend Graph to a networkx
Graph. This is a great way to test backend generators! However, sometimes iteration
order is different when using the converted backend graph. So, our solution here
is to *also* call the original networkx function when the return type is a Graph,
compare results, then use the result from networkx to allow tests to pass.
We use a series of assertions to help backend implementers identify differences.

* Handle the edge cases and fix mistakes that were found

* Add comment

* Don't skip for `star_graph`

* Move `@nodes_or_number` after `@nx._dispatch`

If backends want to leverage `nodes_or_number`, they'll need to use it themselves.

* Don't preserve attributes in `difference`
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.

None yet

4 participants