Repository navigation
Conversation
This also enables automatically converting backend graphs to networkx graphs
Schefflera-Arboricola
left a comment
There was a problem hiding this comment.
Doesn't backend=None makes more sense than backend="networkx"?
It seems more intuitive to use backend=None instead of backend="networkx" because NetworkX is the primary/main library and not a backend in the traditional sense. Using None as the default value can clearly indicate that the main NetworkX implementation will be used. But, having "networkx" instead of None in the backend_priority list does make more sense, but as you mentioned above, including "networkx" in the nx.config.backend_priority list essentially truncates the list, making everything to the right of "networkx" irrelevant. So, why even allow it to be added in the middle? A more elegant alternative to handle this could be to have a flag like fallback_to_nx(I'm not sure if currently this can be used with backend_priority) that will indicate if a user wants to fallback to networkx's implementation or get a NetworkXNotImplemented error at the end of trying all backends in the backend_priority list. And, again "networkx" is not a backend so we probably shouldn't allow it to be passed in the "backend"_priority list but instead have a fallback option. But, I would really like to understand if there are any specific use cases that motivate this change.
Thank you :)
|
Thanks for the comment and questions @Schefflera-Arboricola! Several great discussion points.
Using nx.pagerank(Gspam) # 1
nx.pagerank(Gspam, backend="networkx") # 2
nx.pagerank(Gspam, backend=None) # 3
nx.pagerank(Gspam, backend="eggs") # 4
Hence, I think You are astute to bring up fallback behavior. This deserves careful consideration. Currently, fallback behavior only exists when testing with a backend. We could introduce fallback behavior in this or a subsequent PR by falling back to NetworkX if What would people like to see? I can add "fallback to networkx" behavior to this PR since it's related, or I can wait to add it to a new PR. |
|
Update doc and added a test 😄 |
| if not backends: | ||
| # Fast path if no backends are installed | ||
| if backend is not None: | ||
| if backend is not None and backend != "networkx": |
There was a problem hiding this comment.
@MridulS, here is the fix for the issue you called out today. And to reiterate: if no backends are installed (not counting networkx), the fast path of lines 776-779 is still taken.
|
Closing. Part of and superseded by #7585 |
backend="networkx"is now valid when calling functions, which will automatically convert backend graphs to networkx graphs."networkx"may also be given innx.config.backend_priorityeven though this is kind of silly right now (it's silly b/c it is equivalent to deleting everything to the right of "networkx" and "networkx" from the config). If"networkx"is a valid (if still special) backend name, then it's reasonable to support it innx.config.backend_priorityand allowing it to be used may be a useful pattern in the future.I'm not sure whether to include
"networkx"innx.config.backends.I also updated some error messages and variable names.
I tested this locally via
Details
but should probably add a test or two. Oops.Test and doc added.CC @rlratzel