making graphviz_layout reproducible

103 views
Skip to first unread message

michaelm...@mac.com

unread,
Mar 18, 2015, 11:43:42 AM3/18/15
to networkx...@googlegroups.com
Hi all,

I've developed a script that uses networkx to produce graphs of molecular sequence data (http://www.evoinformatics.eu/fitchi.htm). For the sake of reproducibility I was aiming to make my script deterministic, but noticed that graphviz_layout produces different node positions when I run the same input multiple times. I figured out that the reason for this is not the heuristic nature of neato, but that the function edges_iter() and nodes() in graph.py return edges and nodes in different (random) order each time I run it. I managed to obtain reproducible graphs only after I modified graph.py so that edges and nodes are sorted before they are returned, and I would like to propose these changes to graph.py:

on lines 585, replace

return list(self.nodes_iter(data=data))

with

return sorted(list(self.nodes_iter(data=data)))

and add

nodes_nbrs = sorted(nodes_nbrs)

on line 1099


I have little experience with networkx, so there may be good reasons not to make these changes, but if there aren't, I would welcome these changes.

Cheers,
Michael

Aric Hagberg

unread,
Mar 18, 2015, 11:56:25 AM3/18/15
to networkx...@googlegroups.com
We can't sort the nodes since they may not be orderable (only required
to be hashable).

We did recently implement an OrderedGraph class so if you get the
latest development version of NetworkX you can replace
Graph()->OrderedGraph() and the output order will be determined by the
order the nodes and edges are added to the graph.

If I remember right some of the graphviz algorithms use random initial
placement of nodes (might be controllable) so this might not
completely solve your problem.

Aric
> --
> You received this message because you are subscribed to the Google Groups
> "networkx-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to networkx-discu...@googlegroups.com.
> To post to this group, send email to networkx...@googlegroups.com.
> Visit this group at http://groups.google.com/group/networkx-discuss.
> For more options, visit https://groups.google.com/d/optout.

michaelm...@mac.com

unread,
Mar 19, 2015, 11:13:54 AM3/19/15
to networkx...@googlegroups.com
Hi Aric,

with the tests that I ran, neato actually produced the same result multiple times, so I guess the OrderedGraph class would actually solve my problem.

However, I can't get the developer version networkx-2.0.dev_20150319145438 to run. It requires pydot, pydotplus, or pydot_ng (which networkx 1.9.1 didn't), and none of these seem to work for me. If I install pydot, I get this
and for pydotplus or pydot_ng I get this error
(regardless of whether I use Graph or OrderedGraph).

Are there plans to make a 2.0 pre-release anytime soon?

Thanks,
Michael
Reply all
Reply to author
Forward
0 new messages