Skip to content

Conversation

@eriknw
Copy link
Contributor

@eriknw eriknw commented Apr 17, 2025

These changes are intended to unblock #7902 (CC @rossbar) and to try to make dispatch tests more maintainable (see #7904).

This actually took a lot of experimentation, and I suspect there's even more debt we could pay off, but I think this is a nice increment. To summarize:

We are more methodological about when we create two different arguments to run with the backend and with networkx. As before, we run with networkx and compare results when the result is a graph. In this case, we check that the output graphs match exactly, and return the networkx graph in order to preserve iteration order (b/c some tests are sensitive). We are more careful about doing this when functions mutate input graphs--we now ensure that input graphs are different when calling the function with both the backend and with networkx. @rossbar, I think this is why the latest attempted "fix" for #7902 didn't work--an input graph was mutated, then used in a subsequent call.

This PR deletes a lot of weird, bespoke code that I suspect nobody understands and is likely to be difficult to maintain. This code was originally added so tests would pass. Now we have a different (and less bespoke) way for tests to pass.

This also adds a feature: we compare that input graphs are (very loosely) equal for functions that mutate input graphs. This makes the tests more strict and may affect backends.

Generally, making any changes to this code has a risk of affecting backends. nx-cugraph has a few test failures when run against this PR, but I think at least some are true failures.

This code is still more complicated than I would prefer, but we're doing something pretty complex, and I believe enabling backends to run networkx tests is worth the trouble.

@eriknw eriknw added type: Bug fix type: Maintenance Dispatching Related to dispatching and backend support labels Apr 17, 2025
@eriknw
Copy link
Contributor Author

eriknw commented Apr 18, 2025

No changes to nx-parallel tests when run with this PR.


@np_random_state(3)
@nx._dispatchable(returns_graph=True)
@nx._dispatchable(preserve_edge_attrs={"G": {"weight": 1}}, returns_graph=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Recall that whenever we see the pattern preserve_edge_attrs={"G": {"weight": 1}}, this means that is it using "weight" edge attributes implicitly, and the function may be a good candidate to add e.g. weight="weight" argument to.

Copy link
Contributor

@rossbar rossbar left a comment

Choose a reason for hiding this comment

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

This LGTM, thanks for the iterations @eriknw !

Copy link
Member

@dschult dschult left a comment

Choose a reason for hiding this comment

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

Thanks @eriknw for this cleanup and improvement!

@dschult dschult merged commit 70a51fc into networkx:main Apr 18, 2025
39 checks passed
@jarrodmillman jarrodmillman added this to the 3.5 milestone May 29, 2025
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: Bug fix type: Maintenance

Development

Successfully merging this pull request may close these issues.

4 participants