-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Understanding nx-loopback graph conversion #7428
Comments
I just saw this issue. The loopback graph classes use the dispatching metadata that indicate what data is used. For example, if only This file should probably be moved, as it's pretty hard to find. Note that there is an "ignore" list at the top of this function that skips the usual conversion for a handful of functions. For example, |
for reference #7398 (comment) |
Thanks @eriknw This might be a case we want to add to the ignore list -- thanks for that too. Also, it looks like @Schefflera-Arboricola I think if we use the min/max functions we would need to use the sorted route. But it seems to me that if we just take the raw adj/edge data, the order should be unchanged even across all operating systems. The trick lies in the strange and sometimes-hard-to-predict way that the adjacency data structure reports the edge order. We have to preserve the adjacency dict ordering to preserve the edge reporting order. Python keeps dict-order fixed across OSs now, so it "should" work if we are careful about adjacencies when we copy. But my intuition could be wrong too. :) |
This is a question about backend conversions -- so not directly related to nx-loopback, but I'm hoping it is causing errors for nx-loopback so I can solve them. :) This refers to the code in @eriknw For functions that mutate an incoming graph, the But assumptions are made about G1 that may depend on the backend graph type storage. For example, We need to be very careful when replacing data-guts of a networkx graph with those of another -- there are dependencies between e.g. Thanks! |
Thanks for taking a close look and asking good questions. Much of the code here is pragmatic and often regarded as technical debt. Typically, a good way to see why code like this exists is to delete some of it and see what tests break. It's very possible we should be more careful when updating the original graph attributes (such as |
OK... Thanks for that clarification -- and that correction pointing out that G1 is actually a networkx graph arising by converting the backend graph used by the backend back to nx. This helped me understand what is going on better. I still have a question though:
Tracking down the nx-loopback issues along with tracking through this conversion path helped me find two errors when copying the guts of G1 into G2.
I will update #7432 to make nx-loopback maintain edge order. Not sure yet whether changes to the cached property resetting will be in that PR or another. [Edit: I put the changes to fix the cached properties too.] Thanks! |
I'm having trouble figuring out how the
nx-loopback
backend converts the graph during testing.It appears that the order of the nodes and edges change between running a doctest with vs without the nx-loopback backend. So I went looking for where/how the
nx-loopback
backend converts the graph during testing. I could not find anydispatcher
object for thenx-loopback
backend. I also looked for any code that tested for loopback to see if there is a hardcoded conversion/copying of the graph. And while I found a place wherecopy(graph)
is used, it doesn't seem to be relevant to this test -- and I looked atcopy(graph)
manually and it doesn't cause the change in order I see when using nx-loopback.The case I have been working with/testing is in a doctest, in case that matters.
I put the following in an example in a docstring (inside dag.py in my case):
Running
pytest --doctest-modules --pyargs networkx/algorithms/dag.py
produces:Running
NETWORKX_TEST_BACKEND=nx-loopback pytest --doctest-modules --pyargs networkx/algorithms/dag.py
produces:The order of the nodes in the G.pred dict change.
So, what is actually happening to
G
when the nx-loopback backend is used? Thanks!The text was updated successfully, but these errors were encountered: