I have been trying to use graph-tool (in Mac OSX) to generate random graphs by preserving in- and out-strength of nodes. I think I figured out a way to do that in graph-tool by allowing parallel_edges and setting a degree sampler function. It worked well on a very small graph but stuck for ~10 hours on a graph of 66 nodes of ~1700 edges (probably because the total edge weights are too large?). Could you let me know if this is the correct way to do so in graph-tool? Any way that can make it more efficient? Thanks!
The system did not let me upload documents, so I am listing the first few rows of the edgelist:
The way the current code works is inefficient for such super dense multigraphs (you want 5M edges between 66 nodes), because it first tries to build a seed graph in the same way you would do it for a simple graph. For sparse graphs it makes no difference, but for multigraphs it is quadratic on the edge multiplicities.
You’re better off just starting with your initial multigraph as a seed, and calling random_rewire() on it:
import pandas as pd
from graph_tool.all import *
dfod = pd.read_csv('sample-graph.csv')
g = Graph(directed=True)
for u, v, w in dfod.to_numpy():
g.add_edge_list([(u, v)] * w, hashed=False)
random_rewire(g, self_loops=True, parallel_edges=True)