Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Understanding "time limit" for GenRewire #155

Closed
scott-trinkle opened this issue Mar 12, 2021 · 2 comments
Closed

Understanding "time limit" for GenRewire #155

scott-trinkle opened this issue Mar 12, 2021 · 2 comments

Comments

@scott-trinkle
Copy link

I am attempting to use snap.GenRewire to create an ensemble of thousands of rewired graphs from one base graph and I'm running into a problem with the "time limit."

A simplified example is as follows: I have the adjacency matrix for G as a numpy array, so I have created the following function to create a TUNGraph from the adjacency matrix, rewire the graph with GenRewire, then regenerate an adjacency matrix as a numpy array:

def rewire(G_adj):
    N = G_adj.shape[0]
    G = snap.TUNGraph.New()
    for i in range(N):
        G.AddNode(i)
    for i in range(N):
        for j in range(N):
            if G_adj[i,j] == 1:
                G.AddEdge(i,j)
    G_rewire = snap.GenRewire(G,100)
    G_rewire_adj = np.zeros_like(W)
    for edge in G_rewire.Edges():
        G_rewire_adj[edge.GetSrcNId(),edge.GetDstNId()] = 1
        G_rewire_adj[edge.GetDstNId(),edge.GetSrcNId()] = 1
    return G_rewire_adj

I am then iterating with a for loop to generate each new rewired graph:

G_adj = np.load('path/to/G_adj.npy')
for i in range(1000):
    G_rewired = rewire(G_adj)
    np.save(f'path/to/G_rewired_{i}',G_rewired)

G_adj has 572 nodes and roughly 160000 edges.

The problem I'm running into is that for each iteration, GenRewire prints out its status update with a time code that increases from where the last iteration left off, meaning that even though any given iteration only takes a few seconds, the printed time code quickly reaches the 2h0m mark at which point it seems hard coded to give a "Time limit!" warning and stop rewiring for all future iterations. If I run the code again in the same Python interpreter, all iterations give the "time limit" warning, but if I start a new interpreter, the first iterations proceed as normal until the accumulated time count reaches 2 hours.

Could someone help me understand this behavior? Why is there a connection in the time count between presumably separate Graph constructions / rewirings? Do I need to include some call to clear or delete each graph after I am done with it?

Thanks for your help!

@roks
Copy link
Contributor

roks commented Mar 20, 2021

Yes, GenRewire() has a 2 hour limit. This limit should be restarted for each new call to GenRewire(). The code below, a simplified version of your example, is able to replicate your problem. The timer switches between iterations 83-84 and 254-255. We will investigate the problem.

import snap

def rewire(G_in):
    G = G_in.ConvertGraph(snap.TUNGraph)
    G_rewire = snap.GenRewire(G,1000)
    return G_rewire

G_in = snap.GenFull(snap.TNGraph, 572)
for i in range(500):
    G_rewired = rewire(G_in)
    print(i, G_rewired.GetNodes(), G_rewired.GetEdges())

@roks
Copy link
Contributor

roks commented Mar 21, 2021

There was a problem with the timer overflow for long running processes. This has been fixed in the C++ code. The fix will be available in our next update, which we plan to release in a few weeks.

@roks roks closed this as completed Mar 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants