Skip to content

Dict error when adding and removing nodes from hypergraph #42

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

Open
GitKalo opened this issue May 19, 2025 · 0 comments
Open

Dict error when adding and removing nodes from hypergraph #42

GitKalo opened this issue May 19, 2025 · 0 comments

Comments

@GitKalo
Copy link

GitKalo commented May 19, 2025

I have noticed a strange KeyError that occurs sometimes when I use the hg.degree_distribution() function. I minimal example reproducing the result is below (it seems random, does not happen every time):

from hypergraphx.generation import random_hypergraph

N = 20
ks_mean = {2: 5, 4: 2}
ms = {2: 20, 4: 10}
hg = random_hypergraph(N, ms)

for e in hg.get_edges(size=hg.max_size()) :
    for sub_size in range(2, hg.max_size()) :
        hg.add_edges(combinations(e, sub_size))

hg.remove_edges(hg.get_edges(size=3))

My observations so far are that this is related to adding and then removing edges, so perhaps something related to how newly added edges (or perhaps when added twice?) are stored in the dictionaries. To validate this, note that the issue disappears if we change the line calling hg.add_edges() with the following:

for edge in combinations(e, sub_size) :
    if not hg.check_edge(edge) :
        hg.add_edge(edge)

This error only occurs when adding and removing edges smaller than the hg.max_size(), i.e. size 3 edges in the example above. And there is no error if we do not remove edges.

I can debug this further in the source code if you have no idea what the cause might be.

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

1 participant