Tiago, I’m sorry that you feel that my code to use the graph_union with intersection, following which to remove parallel edges, then call Graph.copy_property on the union graph, did not follow your instructions which, as far as I can read, specifically asked I use all of those and in that order.
# To take the union of all edges between two graphs, you can use the graph_union(g1, g2) function, while passing the 'intersection’ parameter with the Graph.vertex_index property map of g2 (to avoid the nodes being duplicated). This will create parallel edges for those that appear in both graphs, which you can remove with remove_parallel_edges(). You can then copy any edge property map from either g1 or g2 by calling Graph.copy_property() on the union graph.
A complete and minimal example with just vertex labels is the following: from graph_tool.all import *; import graph_tool.all as gt; import matplotlib; import math; import numpy as np; import seaborn as sns g = gt.collection.data["lesmis"].copy() state = gt.MixedMeasuredBlockState(g, n=n, n_default=1, x=x, x_default=0) gt.mcmc_equilibrate(state, wait=1000, mcmc_args=dict(niter=10) u = None; bs = []; cs = [] def collect_marginals(s): global u, bs, cs u = s.collect_marginal(u) bstate = s.get_block_state() bs.append(bstate.levels[0].b.a.copy()) cs.append(gt.local_clustering(s.get_graph()).fa.mean()) gt.mcmc_equilibrate(state, force_niter=5, mcmc_args=dict(niter=10), callback=collect_marginals) #take the graph union with intersection ug = gt.graph_union(g,u,intersection=u.vertex_index,internal_props=True) #remove the parallel edges gt.remove_parallel_edges(ug) #this process will erase the labels property in the union graph object, proved here for vertex 0. print(ug.vp.label[0]) #' ' #run copy property on the union graph, where src is the source property, namely the original label file ug.copy_property(src=g.vp.label) ####This is the error I want to fix in this example, and transfer the label property from the original lesmis graph object to the union graph Please do let me know if this example is not clear enough. James
On 15 Jun 2020, at 15:17, Tiago de Paula Peixoto <tiago@skewed.de> wrote:
Am 15.06.20 um 15:52 schrieb James Ruffle:
Thanks for the suggestion Tiago. Unfortunately, it is resulting in the same issue for me.
In extension to the previous example: ug = gt.graph_union(g,u,intersection=u.vertex_index,internal_props=True) gt.remove_parallel_edges(ug) print(ug)
print(g.vp.label[0]) #Myriel
print(ug.vp.label[0]) #’ ‘ #Presumably graph_union wipes the original properties to blank?
#reclaim the lost labels... label=g.copy_property(src=g.vp.label) label[0] #’Myriel’
ug.vp["copied_label"]=label #or similarly, ug.copy_property(src=g.vp.label,tgt=ug.vp.label) #ValueError: Received property map for graph <Graph object, undirected, with 77 vertices and 255 edges, 2 internal vertex properties, 1 internal edge property, 2 internal graph properties, at 0x152bc7410> (base: <Graph object, undirected, with 77 vertices and 255 edges, 2 internal vertex properties, 1 internal edge property, 2 internal graph properties, at 0x152bc7410>), expected: <Graph object, undirected, with 77 vertices and 447 edges, 2 internal vertex properties, 3 internal edge properties, 3 internal graph properties, at 0x153ebb890> (base: <Graph object, undirected, with 77 vertices and 447 edges, 2 internal vertex properties, 3 internal edge properties, 3 internal graph properties, at 0x153ebb890>)
#naturally, collecting the eprob will cause the same error: ug.copy_property(src=u.ep.eprob,tgt=ug.ep.eprob) #ValueError: ….
Could you kindly provide a working example to the advised solution?
Why won't you even attempt to do what I described?
You keep insisting on passing properties belonging to other graphs as internal properties, despite the explicit error messages that tell you that you cannot do that. You need to use `Graph.copy_property()`.
Please show me an example of where you do something that is _supposed_ to work, so I can say what the problem is.
Please send complete and minimal examples.
Best, Tiago
-- Tiago de Paula Peixoto <tiago@skewed.de>
<signature.asc>_______________________________________________ graph-tool mailing list graph-tool@skewed.de https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.skewed.de%2Fmailman%2Flistinfo%2Fgraph-tool&data=02%7C01%7C%7C51b75ba1b3874e23669508d81136e5a9%7C569df091b01340e386eebd9cb9e25814%7C0%7C0%7C637278274768577824&sdata=OMEuKsXpAVVxDcIVWzyimUqS0yajXsIRonRZcRWNLvE%3D&reserved=0