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

Generator prevent the program from receiving system signals like CTRL-C #1193

Open
Edisonliiii opened this issue Mar 6, 2024 · 2 comments
Open

Comments

@Edisonliiii
Copy link

I attached my code and my platform information

from time import sleep

import networkit as nk
import torch
from torch_geometric.data import Data
from torch_geometric.utils.convert import from_networkit

glist = []
er_model = nk.generators.ErdosRenyiGenerator(80, 4 / 80)
for i in range(5000):
    nk_g = er_model.generate()
    pyg_e, _ = from_networkit(nk_g)
    glist.append(Data(x=torch.zeros(80, requires_grad=False), edge_index=pyg_e))

for i, g in enumerate(glist):
    sleep(1)
    print(f"iter: {i}, {g}")

Software:

System Software Overview:

  System Version: macOS 12.7.3 (21H1015)
  Kernel Version: Darwin 21.6.0

I am using the latest version of networkit installed via pip.

Problem and how to reproduce:

The program can not be terminated by sending ctrl-C signal. If I use NetworkX to generate graph and turn it into Networkit graph object, everything is ok. For example, if I replace nk_g = er_model.generate() by
nk_g=nk.nxadapter.nx2nk(nx.erdos_renyi_graph(80, 4 / 80)), then there is no problem at all.

Please help me locate if the problem is on networkit or torch geometrics.

@fabratu
Copy link
Member

fabratu commented Mar 11, 2024

Hi,

I tested your code above and removed the Pytorch code (basically just doing the network generation) and added a print after each generation. There, SIGINT calls are received:

...
generated
generated
^Cgenerated
libc++abi: terminating due to uncaught exception of type Aux::SignalHandling::InterruptException: Received CTRL+C/SIGINT
libc++abi: terminating due to uncaught exception of type Aux::SignalHandling::InterruptException: Received CTRL+C/SIGINT
libc++abi: terminating due to uncaught exception of type Aux::SignalHandling::InterruptException: Received CTRL+C/SIGINT
libc++abi: terminating due to uncaught exception of type Aux::SignalHandling::InterruptException: Received CTRL+C/SIGINT
libc++abi: terminating due to uncaught exception of type Aux::SignalHandling::InterruptException: Received CTRL+C/SIGINT
[1]    75689 abort      python sigint.py

So it's likely part of Pytorch. My system is a 14.4 macOS with Python 3.12 (using NetworKit 11.0).

@Edisonliiii
Copy link
Author

Edisonliiii commented Mar 15, 2024

I guess it is not caused by Pytorch. I very roughly check the source code of used functions of networkit, it looks like that some of the graph generating functions are using parallel edge generators. If you can change ErdosRenyiGenerator to other generators, the spotted problem might disappear. But if you use the BarabasiAlbertGenerator , the problem will appear. Since BarabasiAlbertGenerator and ErdosRenyiGenerator are generating graphs in a similar way.

I guess one reason you can not see the problem is that you are not yet accessing those generated graph instances.

I slighly update the test case, hopefully can provide more clues

from time import sleep

import networkit as nk

# import torch
# from torch_geometric.data import Data
# from torch_geometric.utils.convert import from_networkit

glist = []
er_model = nk.generators.ErdosRenyiGenerator(80, 4 / 80)
for i in range(5):
    nk_g = er_model.generate()
    # pyg_e, _ = from_networkit(nk_g)
    glist.append(nk_g)
    # glist.append(Data(x=torch.zeros(80, requires_grad=False), edge_index=pyg_e))
    sleep(1)
    print(f"iter: {i}, {nk_g}")

for i, g in enumerate(glist):
    sleep(1)
    print(f"iter: {i}, {g}")

The python's main function can normally accept the signals up until the first for-loop finish running. If the program progresses into the second for-loop, the main function will not accept the signals anymore. In this way, it will repeat the same issue I raised in the initial post.

One ugly turn-around is that you can manually reclaim the ownership of signal handlers. But I am sure it's not the right way to resolve it.

Actually, I am not fully confident to say if the problem is on torch or networkit, but let's take a look the above code first.

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