#7608: upgrade NetworkX to version 1.0.1
---------------------------------+------------------------------------------
   Reporter:  ylchapuy           |       Owner:  jason       
       Type:  enhancement        |      Status:  needs_review
   Priority:  major              |   Milestone:  sage-4.3.4  
  Component:  graph theory       |    Keywords:              
     Author:  Gregory McWhirter  |    Upstream:  N/A         
   Reviewer:  Minh Van Nguyen    |      Merged:              
Work_issues:                     |  
---------------------------------+------------------------------------------
Changes (by newvalueoldvalue):

  * reviewer:  => Minh Van Nguyen
  * author:  => Gregory McWhirter


Comment:

 The reason why gsmcwhirter's patch
 [http://trac.sagemath.org/sage_trac/attachment/ticket/7608/trac_7608
 -networkx-folded.patch trac_7608-networkx-folded.patch] is so large is
 that most of it is about removing trailing white spaces. Maybe I don't
 understand pickling enough to see why gsmcwhirter doesn't provide any
 (valid) examples in the following code:
 {{{
 +class NetworkXGraphDeprecated(SageObject):
 +    """
 +    Class for unpickling old networkx.XGraph formats
 +
 +    DOCTEST:
 +        sage: import sage.graphs.base.graph_backends
 +    """
 +
 +    def __init__(self):
 +        """
 +        Issue deprecation warnings for the old networkx XGraph formats
 +        """
 +        import warnings
 +        from sage.misc.misc import deprecation
 +        warnings.warn("Your graph object is saved in an old format since
 networkx\
 +                    was updated to 1.0.1. You can re-save your graph by
 typing\
 +                    graph.save(filename) to make this warning go away.",
 +                    DeprecationWarning, stacklevel=2)
 +        deprecation("Your graph object is saved in an old format since
 networkx\
 +                    was updated to 1.0.1. You can re-save your graph by
 typing\
 +                    graph.save(filename) to make this warning go away.")
 +
 +    def mutate(self):
 +        """
 +        Change the old networkx XGraph format into the new one.
 +
 +        OUTPUT:
 +
 +        - The networkx.Graph or networkx.MultiGraph corresponding to the
 +          unpickled data.
 +        """
 +        import networkx
 +        new_adj = {}
 +
 +        for node1, edges in self.adj.iteritems():
 +            new_adj[node1] = {}
 +            for node2, weights in edges.iteritems():
 +                new_adj[node1][node2] = {}
 +                if weights is not None:
 +                    try:
 +                        for weight in weights:
 +                            new_adj[node1][node2][weight] = {}
 +                    except TypeError:
 +                        new_adj[node1][node2]['weight'] = weight
 +
 +        if self.multiedges:
 +            G = networkx.MultiGraph(new_adj)
 +        else:
 +            G = networkx.Graph(new_adj)
 +
 +        return G
 +
 +class NetworkXDiGraphDeprecated(SageObject):
 +    """
 +    Class for unpickling old networkx.XDiGraph formats
 +
 +    DOCTEST:
 +        sage: import sage.graphs.base.graph_backends
 +    """
 +
 +    def __init__(self):
 +        """
 +        Issue deprecation warnings for the old networkx XDiGraph formats
 +        """
 +        import warnings
 +        from sage.misc.misc import deprecation
 +        warnings.warn("Your digraph object is saved in an old format
 since networkx\
 +                    was updated to 1.0.1. You can re-save your digraph by
 typing\
 +                    digraph.save(filename) to make this warning go
 away.",
 +                    DeprecationWarning, stacklevel=2)
 +        deprecation("Your digraph object is saved in an old format since
 networkx\
 +                    was updated to 1.0.1. You can re-save your digraph by
 typing\
 +                    digraph.save(filename) to make this warning go
 away.")
 +
 +    def mutate(self):
 +        """
 +        Change the old networkx XDiGraph format into the new one.
 +
 +        OUTPUT:
 +
 +        - The networkx.DiGraph or networkx.MultiDiGraph corresponding to
 the
 +          unpickled data.
 +        """
 +        import networkx
 +        new_adj = {}
 +
 +        for node1, edges in self.adj.iteritems():
 +            new_adj[node1] = {}
 +            for node2, weights in edges.iteritems():
 +                new_adj[node1][node2] = {}
 +                if weights is not None:
 +                    try:
 +                        for weight in weights:
 +                            new_adj[node1][node2][weight] = {}
 +                    except TypeError:
 +                        new_adj[node1][node2]['weight'] = weight
 +
 +        if self.multiedges:
 +            G = networkx.MultiDiGraph(new_adj)
 +        else:
 +            G = networkx.DiGraph(new_adj)
 +
 +        return G
 +
 +from sage.structure.sage_object import register_unpickle_override
 +register_unpickle_override('networkx.xgraph','XGraph',
 NetworkXGraphDeprecated)
 +register_unpickle_override('networkx.xdigraph','XDiGraph',
 NetworkXDiGraphDeprecated)
 }}}
 [http://www.sagemath.org/doc/developer/conventions.html This section] of
 the Developer's Guide explains the policy regarding doctests and examples.
 See also [http://www.sagemath.org/doc/developer/trac.html these
 guidelines]. You need to explain why the following functions don't have
 doctests/examples:
 {{{
 +    def _iterator_in_edges_with_labels(self, vertices):
 +        """
 +        Iterate over the incoming edges incident to a sequence of
 vertices.
 +        Special case, only for internal use.
 +        """
 +        try:
 +            assert(not isinstance(self._nxg, (NetworkXGraphDeprecated,
 NetworkXDiGraphDeprecated)))
 +        except AssertionError:
 +            self._nxg = self._nxg.mutate()
 +
 +        for u,v,d in self._nxg.in_edges_iter(vertices,data=True):
 +            yield (u,v,d.get('weight',None))
 }}}
 and
 {{{
 +    def _iterator_out_edges_with_labels(self, vertices):
 +        """
 +        Iterate over the outbound edges incident to a sequence of
 vertices.
 +        Special case, only for internal use.
 +        """
 +        try:
 +            assert(not isinstance(self._nxg, (NetworkXGraphDeprecated,
 NetworkXDiGraphDeprecated)))
 +        except AssertionError:
 +            self._nxg = self._nxg.mutate()
 +
 +        for u,v,d in self._nxg.out_edges_iter(vertices,data=True):
 +            yield (u,v,d.get('weight',None))
 }}}
 Nevertheless, the proposed changes to upgrade NetworkX to 1.0.1 have been
 in demand for a long time. I'm happy with the changes, but you need to
 address the issues I listed above.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/7608#comment:30>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to