-
-
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
(Digraph) object has no attribute '_adj' (with more info) #2793
Comments
I'm confused... Is this a problem when you The |
|
I haven't had time to look at it thoroughly. But it seems like we need to make sure G.edges and G.nodes are not part of any pickle process. They get recreated when needed. Might be simplest just to have them created every time we use them. But I think a Is this similar to your ideas for a solution? |
I think that the simplest way is to replace the tricky instance variable with lazy-load @Attribute getters. Here is my solution:
|
…used before being completely unpickled. Instance variables have been replaced with @Property setters. Ticket networkx#2793
…used before being completely unpickled. Instance variables have been replaced with @Property getters. Ticket networkx#2793
Here is the pull request, seems to be working: #2796 |
I'm not sure I understand the unpickling problem you are trying to solve. As far as I understand, pickling and unpickling works fine for the NetworkX classes. It just isn't working for your TrackGraph. Is that correct? |
See #2915 which might help fix this problem. |
Related to networkx#3011 and networkx#2885 and maybe networkx#2793
- add tests to show that extensions of base graph classes (only add new functions) should be able to use the Graph.subgraph and Graph.copy methods easily - Remove ReadOnlyGraph class in favor of existing freeze() function - Switch all GraphView classes to generic_graph_view function - Switch all SubGraph classes to subgraph_view function - Introduce deprecated functions that act like the deprecated classes. Still need to: - add docs - add tests - make sure backward compatible and marked as deprecated - remove GraphView and SubGraph construct from rest of codebase - update release docs Fixes networkx#2889 Fixes networkx#2793 Fixes networkx#2796 Fixes networkx#2741
@stablum I have simplified the process for subclassing Graph/DiGraph etc. For starters, get rid of
Please let me know how this conversion goes. I think it makes it much better for you. This is going into NetworkX 2.0 which should be released soon. |
* Simplify the Graphview and SubGraphView system - add tests to show that extensions of base graph classes (only add new functions) should be able to use the Graph.subgraph and Graph.copy methods easily - Remove ReadOnlyGraph class in favor of existing freeze() function - Switch all GraphView classes to generic_graph_view function - Switch all SubGraph classes to subgraph_view function - Introduce deprecated functions that act like the deprecated classes. Still need to: - add docs - add tests - make sure backward compatible and marked as deprecated - remove GraphView and SubGraph construct from rest of codebase - update release docs Fixes #2889 Fixes #2793 Fixes #2796 Fixes #2741 * Ease subclassing for to_(un)directed - add to_directed_class indicator functions to base classes - start deprecating G.fresh_copy - update function.to(un)directed * Remove G.fresh_copy from code replace with __class__ Add deprecation warnings for GraphView classes, ReverseView and SubGraph. Also for fresh_copy function.
* Simplify the Graphview and SubGraphView system - add tests to show that extensions of base graph classes (only add new functions) should be able to use the Graph.subgraph and Graph.copy methods easily - Remove ReadOnlyGraph class in favor of existing freeze() function - Switch all GraphView classes to generic_graph_view function - Switch all SubGraph classes to subgraph_view function - Introduce deprecated functions that act like the deprecated classes. Still need to: - add docs - add tests - make sure backward compatible and marked as deprecated - remove GraphView and SubGraph construct from rest of codebase - update release docs Fixes networkx#2889 Fixes networkx#2793 Fixes networkx#2796 Fixes networkx#2741 * Ease subclassing for to_(un)directed - add to_directed_class indicator functions to base classes - start deprecating G.fresh_copy - update function.to(un)directed * Remove G.fresh_copy from code replace with __class__ Add deprecation warnings for GraphView classes, ReverseView and SubGraph. Also for fresh_copy function.
I'm duplicating the ticket #2741 because I cannot re-open it myself.
While trying
copy.deepcopy
of a graph, I am encountering the following exception:where TrackGraph is a subclass of DiGraph:
Version is the following:
I cannot provide the full code because it's a big project, and I could not isolate the bug in a simpler case.
My hypothesis is that the order in which the unplicking of the attributes happens is relevant.
Apparently one of these attributes is an
OutEdgeView
. I cannot see which attribute because python's pickle is notoriously uninformative during debugging.Anyways, I think that that attribute is being set (and hence
__setstate__
triggered) before _adj or other attributes are set. In that case theOutEdgeView.__setstate__
is faced with an almost empty object, without _adj.Here is a demonstration:
Which produces the following output:
This demonstrates that
foo2.a.foo
is of course not fully restored whenfoo2.a.__setstate__
is triggered. But even worse, aftera
has been restored, it is not set yet tofoo2
, as can be demonstrated byfoo2.b.__setstate__
that cannot accessa
. This seems to be the problem inOutEdgeView
.Opinions?
The text was updated successfully, but these errors were encountered: