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
Conversation
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.
Shoot, this fails due to mutating input arguments (such as consuming iterators). |
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! |
If backends want to leverage `nodes_or_number`, they'll need to use it themselves.
Is this ready to merge/review? Are there other things to add? |
These changes will be necessary when networkx/networkx#7066 is merged.
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
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`
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.