-
Notifications
You must be signed in to change notification settings - Fork 32
Description
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.