Modifying a graph's edges changes the entropy differently from a copy

Hey! I’m trying to record the community assignments of a changing graph using PPBlockState. I add and remove edges, and every 1,000 adds/removes I use multilevel_mcmc_sweep to update the block assignments.

At the moment, I find that the entropy values will be wrong after changing the graph, and sweeps usually produce -inf or nan results.
If I copy the PPBlockState object before sweeping it will be fine. However, this takes a lot of time I’d like to avoid.

If there’s another way to update a graph other than add_edge and remove_edge that would bypass this, I’m open to that too.

graph-tool version 2.88
WSL 2.0

minimal working example

# Create simple graph
g = gt.Graph(directed=False)
g.add_edge_list([(0, 1), (1, 2)])

# Create state
state = gt.PPBlockState(g)
print('Entropy Before Removal:', state.entropy())

# Modify graph
g.remove_edge(g.edge(1, 2))
# g.add_edge(1, 2)

# Measure entropy
print('Entropy After Removal:', state.entropy())
print('Entropy of Copy:', state.copy().entropy())

Entropy Before Removal: 3.9889840465642745
Entropy After Removal: 4.68213122712422
Entropy of Copy: 2.8903717578961645

Note that, if I immediately add back the same edge I had removed, the values seem correct.

You’re not allowed to modify the graph, since this invalidates the internal state.

Is there a faster way to accomplish what I’m doing, or is .copy() pretty much it?

There’s currently no other option.

Alright, thank you kindly for the quick answer and the awesome tool!