Issue with adding edges and verts to a graph

User 912 | 3/12/2015, 7:21:56 PM


I've been experiencing a very strange issue. Basically, I am trying to parse graph data from a text file and create many graphs, which will be saved for later use.

I am creating a list of objects Vertex and a list of objects Edge and then adding them to an already initialized graph. However, for testing reasons I have added print statements right after the graph is supposedly populated and while both lists are populated, the graph remains empty.

Here's a snippet of the code:

<pre class="CodeBlock"><code>line = f.readline() while(line != ""): info = line.split()

	if(info[0] == 't'):
		if(len(vertices) > 0):
			print 'Processed', graphname, '...'
			print 'v:', vertices
			print 'e:', edges
			print 'g:', g</code></pre>

The print statements return results such as: for vertices -> [V(0, {'elem': 0}), V(1, {'elem': 0}), V(2, {'elem': 0}),...] for edges -> [E(0 -> 1, {}), E(0 -> 2, {}), E(0 -> 19, {}),...] but for the graph -> SGraph({'numedges': 0, 'numvertices': 0})

I was wondering if there's something I might be doing wrong that I am missing. When I try to populate a graph with Vertex and Edge lists straight from the Python console - there aren't problems. I just can't find a reason why this won't work.



User 18 | 3/13/2015, 4:08:11 AM

@vyara, SGraphs (as well as SArrays) are immutable. So when you add edges or vertices to the graph, a new graph is (lazily) created. In order to retain the graph, you have to assign the output back to g.

<pre class="CodeBlock"><code>g = g.addvertices(vertices) g = g.addedges(edges) </code></pre>

Then it should work.

User 912 | 3/13/2015, 9:41:08 AM

Oh, yes, that actually makes sense. Thank you very much!

User 1768 | 6/10/2015, 1:11:24 PM

Hi, I have the another problem that i think it is related to your discussion. I tried to add some edges to the current graph with the current vertices.

sf= graphlab.SFrame.readcsv('target.csv') sa=sf[‘__id’] for i in sa: da= SArray(data=[6,7,8,9,10], dtype=int) for j in da: g = g.addedges(Edge(i, j))

Although the number of vertices in 'sa' is 50. and for each vertices in 'sa' I am adding around 200 edges in stead of this small array. After adding them when I want o work on this graph by call it , if I try in my macbook, it gives me "RuntimeError: Communication Failure: 65. " and I try to add in Amazon AWS ubuntu, It gives me "disk is full". What is the most efficient way to add edges? (sorry I can not select code, for my code, the look of j is inside the look for i)

User 19 | 6/10/2015, 5:47:35 PM

Hi Naoomi,

A few things:

  • Rather than construct each Edge individually, I'd recommend creating an SFrame of edges for each i. For example, edges_i = gl.SFrame({'j': da}); edges_i['i'] = i. Then you can add these in bulk via g.add_edges(edges_i).
  • When using EC2 instances, make sure you have configured your volumes correctly (see for instance), and that your /tmp directory has plenty of space.

Hope that helps! Chris

User 1768 | 6/11/2015, 10:14:16 AM

Thanks a lot @ChrisDuBois for your solution. I will try it.