Skip to content

Allow backend graphs to be tested as compatible NetworkX graphs - #7600

Open
eriknw wants to merge 15 commits into
networkx:mainfrom
eriknw:test_backend_graph_classes
Open

eriknw wants to merge 15 commits into
networkx:mainfrom
eriknw:test_backend_graph_classes

Conversation

@eriknw

@eriknw eriknw commented Aug 15, 2024

Copy link
Copy Markdown
Contributor

Previously, running networkx tests with backends allowed backend algorithms to be tested. This PR makes it so that backend graph classes can be tested directly by e.g. running tests in networkx/classes/ or running dispatchable functions with backend graphs using the default networkx implementation.

This uses trickery with __new__, so there may be a few rough edges, although it seemed to work quite well overall in my experiments. Another approach could be to monkey patch e.g. nx.Graph = backend_interface.Graph, but I think this approach would also need to update all modules where Graph was imported and functions that use Graph as a default argument. The approach with __new__ does not test subclassing.

For CI, I only run tests in networkx.classes for the sake of time. I ran all tests locally. The only failures were a couple doctests that print the repr of type(G).

CC @aMahanna; you may find this useful.

CC @rlratzel; this may be useful for testing nx-cugraph graphs for networkx compatibility.

@eriknw eriknw added type: Enhancements Dispatching Related to dispatching and backend support labels Aug 15, 2024
@eriknw eriknw added this to the 3.4 milestone Aug 15, 2024
@eriknw eriknw removed this from the 3.4 milestone Sep 8, 2024
Perhaps it makes the most sense to test with the default "networkx" implementation
for everything when using a backend graph as a networkx graph since this will
exercise the graph the most.
rapids-bot Bot pushed a commit to rapidsai/cugraph that referenced this pull request Sep 24, 2024
…workX Graph classes, needed for zero code change graph generators (#4629)

This is an alternative approach to #4558 for enabling GPU-accelerated NetworkX to "just work". It has similarities to #4558. I opted to make separate classes such as `ZeroGraph`, which I think makes for cleaner separation and gives us and users more control.

There are a few lingering TODOs and code comments to tidy up, but I don't think there are any show-stoppers. I have not updated methods (such as `number_of_nodes`) to optimistically try to use GPU if possible, b/c this is not strictly necessary, but we should update these soon.

I have run NetworkX tests with these classes using networkx/networkx#7585 and networkx/networkx#7600. We need the behavior in 7585, and 7600 is only useful for testing.

There are only 3 new failing tests, and 3 tests that hang (I'll run them overnight to see if they finish). Here's a test summary:
```
5548 passed, 24 skipped, 16 xfailed, 25 xpassed
```
Note that 25 tests that were failing now pass. I have not investigated test failures, xfails, or xpasses yet. I would like to add tests too.

We rely heavily on the networkx cache. I think this is preferred.

It is late for me. I will describe and show how and why this works later.

I opted for `zero=` and `ZeroGraph`, because I find them delightful! Renaming is trivial if other terms are preferred.

CC @quasiben

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

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

URL: #4629

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dispatching Related to dispatching and backend support type: Enhancements

Development

Successfully merging this pull request may close these issues.

1 participant