networkx BipartiteGraph

43 views
Skip to first unread message

Antonio Rojas

unread,
Dec 14, 2017, 4:57:25 AM12/14/17
to sage-...@googlegroups.com
Hi all,
In Arch we have upgraded networkx to version 2. This comes with major
API changes that affect Sage's interface, and I'm currently trying to fix
these issues. I'm struggling with a particular issue with bipartite
graphs. In pure ipython, this code gives:

In [1]: import networkx
In [2]: A=networkx.complete_bipartite_graph(2,3)
In [3]: list(A.edges())
Out[3]: [(0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4)]

The exact same code in Sage gives:

sage: import networkx
sage: A=networkx.complete_bipartite_graph(2,3)
sage: list(A.edges())
[(0, 0), (0, 1), (0, 2), (1, 1), (1, 2)]

As you can see, Sage has shifted the second set of vertices to start at 0
instead of 2, so of course this is not a bipartite graph anymore. This
seems strange since there is no Sage code involved in these commands at
first sight.
Can someone point me to the Sage code that modifies networkx's output so
I can look into it?

Thanks.

Dima Pasechnik

unread,
Dec 14, 2017, 5:34:03 AM12/14/17
to sage-devel
Probably networkx calls some not so basic functionality of Python, which works differently in Sage.
It seems that the only way to find out is to look at such places in networkx's code.

 
Thanks.

Vincent Delecroix

unread,
Dec 14, 2017, 6:11:31 AM12/14/17
to sage-...@googlegroups.com
What about

sage: A = networkx.complete_bipartite_graph(2r, 3r)

Antonio Rojas

unread,
Dec 14, 2017, 6:29:33 AM12/14/17
to sage-...@googlegroups.com
El Thu, 14 Dec 2017 11:09:17 +0000, Vincent Delecroix escribió:

> What about
>
> sage: A = networkx.complete_bipartite_graph(2r, 3r)

That works correctly:

sage: A=networkx.complete_bipartite_graph(2r,3r)
sage: list(A.edges())

Dima Pasechnik

unread,
Dec 14, 2017, 6:49:24 AM12/14/17
to sage-devel
Great, thanks, Vincent!

I have created https://trac.sagemath.org/ticket/24374 to track the updating.

Dima Pasechnik

unread,
Dec 15, 2017, 6:27:38 AM12/15/17
to sage-devel
As expected, it's a networkx bug, that I am proposing them to fix in
Reply all
Reply to author
Forward
0 new messages