rustworkx
rustworkx copied to clipboard
[joss] Generators are inconsistent in what node payload they produce
Graph generators are inconsistent in what node payload they add. Compare these:
rx.undirected_gnm_random_graph(5,5).nodes()
[0, 1, 2, 3, 4]
rx.generators.mesh_graph(5).nodes()
[None, None, None, None, None]
I am not surprised about this because the graph creation API seems to mandate specifying a node payload in most cases. Will this become a problem in the future if the payload format gets standardized? There are reasons for having standards for node "attributes" (single payload in retworkx)—for example, in practical network analysis, it is extremely useful to be able to give nodes names, and refer to them by name instead of index. Thus in some libraries, there is a standardized "name" attribute.
Consider trying to create a small graph like this:

Unless I am missing something, we need at least three lines to achieve this:
small_graph = rx.PyDiGraph()
small_graph.add_nodes_from([None] * 3)
small_graph.add_edges_from_no_data([(0,1)])
Here, I do not see a way around specifying the node payload explicitly. Is there one? Even though I simply wanted to specify the number of nodes (to include the one isolated node), I had to produce a payload list.
On a related note, I such a multi-line way to create a graph quite cumbersome, although that might be because I am too used to Mathematica. Python is usually quite verbose, and not that pleasant to use interactively. Nevertheless, it would be nice to be able to create such a small graph with a one-liner, e.g. to count how many times it occurs as an induced subgraph.