-
-
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
retain adjacency order in nx-loopback copy of networkx graph #7432
Conversation
If this copy code works for nx-loopback -- I think we should update the copy methods in the base classes to ensure that the neighbor/adjacency order is maintained when users do Would maintaining the adjacency order during |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
Using a similar approach for G.copy
to maintain order makes sense to me--just be sure to add a remark to the next release notes.
This also seems to fix the long time for the nx-loopback tests. It is still about 8 secs (~10-15%) longer to run, but not multiple minutes.
Where do you see this? "dispatch" CI still takes several minutes. I have not experimented with this locally yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a naive question: does the loopback interface need to explicitly copy at all? In principle, the dispatching is handled by looking up the __networkx_backend__
attr on the instance, so can't that just be added to the input graph instance without any copying? In other words, the convert_from_nx
function might look something like:
def convert_from_nx(graph, *, ...):
graph.__networkx_backend__ = "nx-loopback"
return graph
I guess the main issue is that this wouldn't probe the kwarg values of convert_from_nx
... is that right? Are those probed now (i.e. taken from the @_dispatch
decorator values)?
On the copy question: +1 from me for refactoring copy to preserve ordering - that makes a lot of sense as of Python 3.7!
The timing results I was getting are apparently a "feature" of my local testing environment. I would like some help in getting my environment set up better. Running
I do not have networkx installed in this mamba environment. I have used So... How do i run pytest on the whole repo using nx-loopback as my backend? |
I've now found that I can get while adding If I specify a file/directory within networkx it works with or without [Found the trouble. I had an unstaged python file that set backend information in the repo's directory. When using |
…vert_and_call_for_test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @dschult !
networkx/classes/digraph.py
Outdated
for prop in ["edges", "out_edges", "degree", "out_degree", "in_degree"]: | ||
if prop in od: | ||
del od[prop] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like "adj"
and "succ"
could just be added to this list to save a few lines, but there's no reason to do so other than style. Just thought I'd mention!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, this is pretty slick! It took me a little while to convince myself that inner/outer data dicts were handled correctly for multigraphs, but it's straightforward enough. The comments were helpful regarding ensuring that certain dicts be the same.
…x#7432) * retain adj-order in nx-loopback copy of networkx graph * rewrite copy logic * fix buggy assignment to _adj, rewrite if-structure for nx-loopbak convert_and_call_for_test * check if CI uses nx-loopback by halting tests if the graph isn't copied. * enable nx-loopback again * gather and unify property resetting
This rewrites the copy functionality within nx-loopback to ensure that the neighbor order is the same in the copy. Instead of copying edges, this copies adjacencies (careful to ensure opposite representations of an edge point to the same datadict).
The result is that the incoming PR for fixing colliders and v-structures passes its tests.
Also, dfs_labeled_edges test passes. In fact all the topological sort functions that were excluded pass the tests as well, though I'm not sure whether we should still exclude them from the nx-loopback tests because I don't know what the issue was regarding the function changing the original graph. E.g. maybe we shouldn't be copying the graph at all since it needs to be changed.
~~This also seems to fix the long time for the nx-loopback tests. It is still about 8 secs (~10-15%) longer to run, but not multiple minutes. Almost all of that is due to using
G._adj
directly instead ofadd_edges_from
andG.edges
.~~ [Edit: error on my part caused mistaken speed results. With the change it is the same speed as it was.]@eriknw can you look at my comments near the top of the diff:
I think the topo sort maybe) [A: Only the dfs_labeled_edges is fixed by the order of edges in loopback. The rest stay in place.]G = nx.complement(A)
. But I'm not sure how that helps the code near the comment about AntiGraph. [A: Removing comment about AntiGraph]