Skip to content

Dict error when adding and removing nodes from hypergraph #42

@GitKalo

Description

@GitKalo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions