Looking back at this I'm not totally sure what I was thinking... I think I saw the tiny filesize of the pickled State and assumed it was missing a reference to the graph. Anyway, I got it now. Apologies for the utter puzzlement.
Thanks as always On Mon, Mar 23, 2020 at 10:18 AM Tiago de Paula Peixoto <[email protected]> wrote: > Am 19.03.20 um 18:38 schrieb Deklan Webster: > > I'm saving NestedState with pickle and then loading it later to use > > get_edges_prob. > > > > nested_state = pickle.load( > > > open(f"output/graphtool_output/pickle/{name}_nested_blockstate.p", > > "rb")) > > > > I realized that NestedState needs a reference to the underlying graph > > for get_edges_prob to work. So, I try this. > > > > G = gt.load_graph(f'output/graphtool_output/{name}.graphml') > > nested_state.g = G > > I'm utterly puzzled by what you are trying to do. > > First, unpickling should just work, there is no need for you to "fix" it. > > Second, you should never ever try to modify an object like this, in > graph-tool and otherwise, just by randomly changing an internal > variable. In languages such as C++ this kind of meddling can be > forbidden, but in Python is unfortunatelly always allowed. If you > replace the graph inside a NestedBlockState, the object becomes > inconsistent and corrupted. There is no need ever to try to do this, and > it will never work. > > > Now, get_edges_prob is working if I use the base level of the state, > > like so: > > > > def collect_edge_probs(s): > > s = s.levels[0] > > for i, non_edge in enumerate(non_edges): > > p = s.get_edges_prob([non_edge], [], > > entropy_args=dict(partition_dl=False)) > > non_edges_probs[i].append(p) > > > > If I remove this " s = s.levels[0]" I'm getting an error about "invalid > > edge descriptor". Is there some other reference I need to recover for > > this to work correctly? > > See above. In order for this to "work correctly" it must never be > attempted to begin with. > > Best, > Tiago > > -- > Tiago de Paula Peixoto <[email protected]> > > _______________________________________________ > graph-tool mailing list > [email protected] > https://lists.skewed.de/mailman/listinfo/graph-tool >
_______________________________________________ graph-tool mailing list [email protected] https://lists.skewed.de/mailman/listinfo/graph-tool
