[graph-tool] running minimize_blockmodel_dl() in parallel
hi, here is a simple example where i run minimize_blockmodel_dl() 10 times in parallel using multiprocessing and collect the entropy. when i run this, i get the same value of entropy every single time. ``` import multiprocessing as mp import numpy as np import time import graph_tool.all as gt # load graph g = gt.collection.data["celegansneural"] N_iter = 10 def get_sbm_entropy(): np.random.seed() state = gt.minimize_blockmodel_dl(g) return state.entropy() def _parallel_mc(iter=N_iter): pool = mp.Pool(10) future_res = [pool.apply_async(get_sbm_entropy) for _ in range(iter)] res = [f.get() for f in future_res] return res def parallel_monte_carlo(iter=N_iter): entropies = _parallel_mc(iter) return entropies parallel_monte_carlo() ``` result: [8331.810102822546, 8331.810102822546, 8331.810102822546, 8331.810102822546, 8331.810102822546, 8331.810102822546, 8331.810102822546, 8331.810102822546, 8331.810102822546, 8331.810102822546] ultimately i would like to use this to keep entropy as well as the block membership vector for each iteration any ideas? cheers, -sam ___ graph-tool mailing list -- graph-tool@skewed.de To unsubscribe send an email to graph-tool-le...@skewed.de
[graph-tool] Re: error: Received Orphaned Property Map
here is a working example ``` import graph_tool.all as gt import multiprocessing as mp g = gt.collection.data["celegansneural"] pool = mp.Pool(5) def fit_sbm(i): state = gt.minimize_blockmodel_dl(g) b = state.get_blocks() print(i) return(b) blocks = pool.map(fit_sbm, range(5)) pool.close #print(blocks) #b0 = blocks[0] #print(b0) b0 = blocks[0] g.vertex_properties["membership"] = b0 ``` i wasn't aware of the own_property() function and can't find it in the graph-tool documentation (other than seeing it being used in examples involving visualization). whatever it does, it seems to work, and the modified code below seems to work ``` import graph_tool.all as gt import multiprocessing as mp g = gt.collection.data["celegansneural"] pool = mp.Pool(5) def fit_sbm(i): state = gt.minimize_blockmodel_dl(g) b = state.get_blocks() print(i) return(b) blocks = pool.map(fit_sbm, range(5)) pool.close #print(blocks) #b0 = blocks[0] #print(b0) b0 = blocks[0] g.vertex_properties["membership"] = g.own_property(b0) ``` ___ graph-tool mailing list -- graph-tool@skewed.de To unsubscribe send an email to graph-tool-le...@skewed.de
[graph-tool] Re: error: Received Orphaned Property Map
Am 04.10.21 um 10:29 schrieb sam.gyet...@gmail.com: hi, i received this error while trying to assign a vertex property map to a graph, and i'm not sure how to get around it. context: i am running minimize_blockmodel_dl() many times in parallel using microprocessing. because my graph is large, i don't want it to save multiple copies of the graph. so i am trying to only keep the block id each time. however, when i try to do this, i get the above error here's a somewhat simplified example: ``` import graph_tool.all as gt import multiprocessing as mp pool = mp.Pool(5) def fit_sbm(): state = gt.minimize_blockmodel_dl(g) b = state.get_blocks() return b blocks = pool.map(fit_sbm, range(5)) pool.close b0 = blocks[0] membership = g.new_vertex_property("int") membership = b0 g.vertex_properties["membership"] = b0 ``` could you explain why this error comes up, and also if possible suggest an alternative way to proceed? The code you provided does not run. Could you please provide a minimal _working_ example that shows the problem? Additionally, you seem confused about how variable assignment works in Python, since the first line does nothing in: membership = g.new_vertex_property("int") membership = b0 And these two lines are also irrelevant to what follows, since you never use the variable "membership" again. Presumably, you wanted to do something like: g.vp["membership"] = g.own_property(blocks[0]) But I can only guess. Best, Tiago -- Tiago de Paula Peixoto ___ graph-tool mailing list -- graph-tool@skewed.de To unsubscribe send an email to graph-tool-le...@skewed.de
[graph-tool] error: Received Orphaned Property Map
hi, i received this error while trying to assign a vertex property map to a graph, and i'm not sure how to get around it. context: i am running minimize_blockmodel_dl() many times in parallel using microprocessing. because my graph is large, i don't want it to save multiple copies of the graph. so i am trying to only keep the block id each time. however, when i try to do this, i get the above error here's a somewhat simplified example: ``` import graph_tool.all as gt import multiprocessing as mp pool = mp.Pool(5) def fit_sbm(): state = gt.minimize_blockmodel_dl(g) b = state.get_blocks() return b blocks = pool.map(fit_sbm, range(5)) pool.close b0 = blocks[0] membership = g.new_vertex_property("int") membership = b0 g.vertex_properties["membership"] = b0 ``` could you explain why this error comes up, and also if possible suggest an alternative way to proceed? thanks, -sam ___ graph-tool mailing list -- graph-tool@skewed.de To unsubscribe send an email to graph-tool-le...@skewed.de